]> git.proxmox.com Git - mirror_novnc.git/blob - utils/use_require_helpers.js
Merge branch 'userequire' of https://github.com/CendioOssman/noVNC
[mirror_novnc.git] / utils / use_require_helpers.js
1 // writes helpers require for vnc.html (they should output app.js)
2 var fs = require('fs');
3 var fse = require('fs-extra');
4 var path = require('path');
5
6 // util.promisify requires Node.js 8.x, so we have our own
7 function promisify(original) {
8 return function () {
9 let obj = this;
10 let args = Array.prototype.slice.call(arguments);
11 return new Promise((resolve, reject) => {
12 original.apply(obj, args.concat((err, value) => {
13 if (err) return reject(err);
14 resolve(value);
15 }));
16 });
17 }
18 }
19
20 const writeFile = promisify(fs.writeFile);
21
22 module.exports = {
23 'amd': {
24 appWriter: (base_out_path, script_base_path, out_path) => {
25 // setup for requirejs
26 let ui_path = path.relative(base_out_path,
27 path.join(script_base_path, 'app', 'ui'));
28 return writeFile(out_path, `requirejs(["${ui_path}"], function (ui) {});`)
29 .then(() => {
30 console.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
31 let require_path = path.relative(base_out_path,
32 path.join(script_base_path, 'require.js'))
33 return [ require_path ];
34 });
35 },
36 noCopyOverride: () => {},
37 },
38 'commonjs': {
39 optionsOverride: (opts) => {
40 // CommonJS supports properly shifting the default export to work as normal
41 opts.plugins.unshift("add-module-exports");
42 },
43 appWriter: (base_out_path, script_base_path, out_path) => {
44 var browserify = require('browserify');
45 var b = browserify(path.join(script_base_path, 'app/ui.js'), {});
46 return promisify(b.bundle).call(b)
47 .then((buf) => writeFile(out_path, buf))
48 .then(() => []);
49 },
50 noCopyOverride: () => {},
51 removeModules: true,
52 },
53 'systemjs': {
54 appWriter: (base_out_path, script_base_path, out_path) => {
55 let ui_path = path.relative(base_out_path,
56 path.join(script_base_path, 'app', 'ui.js'));
57 return writeFile(out_path, `SystemJS.import("${ui_path}");`)
58 .then(() => {
59 console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
60 // FIXME: Should probably be in the legacy directory
61 let promise_path = path.relative(base_out_path,
62 path.join(base_out_path, 'vendor', 'promise.js'))
63 let systemjs_path = path.relative(base_out_path,
64 path.join(script_base_path, 'system-production.js'))
65 return [ promise_path, systemjs_path ];
66 });
67 },
68 noCopyOverride: (paths, no_copy_files) => {
69 no_copy_files.delete(path.join(paths.vendor, 'promise.js'));
70 },
71 },
72 'umd': {
73 optionsOverride: (opts) => {
74 // umd supports properly shifting the default export to work as normal
75 opts.plugins.unshift("add-module-exports");
76 },
77 },
78 }