Files
noVNC/utils/use_require_helpers.js
T

77 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-02-04 17:12:00 -05:00
// writes helpers require for vnc.html (they should output app.js)
2018-05-24 00:27:09 +03:00
const fs = require('fs');
const path = require('path');
2017-02-04 17:12:00 -05:00
2017-12-09 13:46:21 +01:00
// util.promisify requires Node.js 8.x, so we have our own
function promisify(original) {
2018-09-06 16:53:40 +02:00
return function promise_wrap() {
2018-05-24 00:27:09 +03:00
const args = Array.prototype.slice.call(arguments);
2017-12-09 13:46:21 +01:00
return new Promise((resolve, reject) => {
original.apply(this, args.concat((err, value) => {
2017-12-09 13:46:21 +01:00
if (err) return reject(err);
resolve(value);
}));
});
2018-09-06 17:25:02 +02:00
};
2017-12-09 13:46:21 +01:00
}
const writeFile = promisify(fs.writeFile);
2017-02-04 17:12:00 -05:00
module.exports = {
'amd': {
appWriter: (base_out_path, script_base_path, out_path) => {
2017-02-04 17:12:00 -05:00
// setup for requirejs
2018-05-24 00:27:09 +03:00
const ui_path = path.relative(base_out_path,
2018-09-06 16:17:43 +02:00
path.join(script_base_path, 'app', 'ui'));
return writeFile(out_path, `requirejs(["${ui_path}"], (ui) => {});`)
2018-09-06 16:17:43 +02:00
.then(() => {
console.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
const require_path = path.relative(base_out_path,
2018-09-06 17:25:02 +02:00
path.join(script_base_path, 'require.js'));
2018-09-06 16:17:43 +02:00
return [ require_path ];
});
2017-02-04 17:12:00 -05:00
},
2017-03-01 11:17:44 -05:00
noCopyOverride: () => {},
2017-02-04 17:12:00 -05:00
},
'commonjs': {
2018-09-06 17:12:45 +02:00
optionsOverride: (opts) => {
2017-02-04 17:12:00 -05:00
// CommonJS supports properly shifting the default export to work as normal
opts.plugins.unshift("add-module-exports");
},
appWriter: (base_out_path, script_base_path, out_path) => {
2018-05-24 00:27:09 +03:00
const browserify = require('browserify');
const b = browserify(path.join(script_base_path, 'app/ui.js'), {});
2017-12-09 13:46:21 +01:00
return promisify(b.bundle).call(b)
2018-09-06 16:17:43 +02:00
.then(buf => writeFile(out_path, buf))
.then(() => []);
2017-02-04 17:12:00 -05:00
},
2017-03-01 11:17:44 -05:00
noCopyOverride: () => {},
2017-12-09 14:14:04 +01:00
removeModules: true,
2017-02-04 17:12:00 -05:00
},
'systemjs': {
appWriter: (base_out_path, script_base_path, out_path) => {
2018-05-24 00:27:09 +03:00
const ui_path = path.relative(base_out_path,
2018-09-06 16:17:43 +02:00
path.join(script_base_path, 'app', 'ui.js'));
return writeFile(out_path, `SystemJS.import("${ui_path}");`)
2018-09-06 16:17:43 +02:00
.then(() => {
console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
// FIXME: Should probably be in the legacy directory
2018-09-06 16:17:43 +02:00
const promise_path = path.relative(base_out_path,
2018-09-06 17:25:02 +02:00
path.join(base_out_path, 'vendor', 'promise.js'));
2018-09-06 16:17:43 +02:00
const systemjs_path = path.relative(base_out_path,
2018-09-06 17:25:02 +02:00
path.join(script_base_path, 'system-production.js'));
2018-09-06 16:17:43 +02:00
return [ promise_path, systemjs_path ];
});
2017-03-01 11:17:44 -05:00
},
noCopyOverride: (paths, no_copy_files) => {
no_copy_files.delete(path.join(paths.vendor, 'promise.js'));
2017-02-04 17:12:00 -05:00
},
},
'umd': {
2018-09-06 17:12:45 +02:00
optionsOverride: (opts) => {
2017-02-04 17:12:00 -05:00
// umd supports properly shifting the default export to work as normal
opts.plugins.unshift("add-module-exports");
},
},
2018-09-06 17:25:02 +02:00
};