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