]>
git.proxmox.com Git - mirror_novnc.git/blob - utils/use_require_helpers.js
1 // writes helpers require for vnc.html (they should output app.js)
2 const fs
= require('fs');
3 const path
= require('path');
5 // util.promisify requires Node.js 8.x, so we have our own
6 function promisify(original
) {
8 const args
= Array
.prototype.slice
.call(arguments
);
9 return new Promise((resolve
, reject
) => {
10 original
.apply(this, args
.concat((err
, value
) => {
11 if (err
) return reject(err
);
18 const writeFile
= promisify(fs
.writeFile
);
22 appWriter
: (base_out_path
, script_base_path
, out_path
) => {
23 // setup for requirejs
24 const ui_path
= path
.relative(base_out_path
,
25 path
.join(script_base_path
, 'app', 'ui'));
26 return writeFile(out_path
, `requirejs(["${ui_path}"], (ui) => {});`)
28 console
.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
29 const require_path
= path
.relative(base_out_path
,
30 path
.join(script_base_path
, 'require.js'))
31 return [ require_path
];
34 noCopyOverride
: () => {},
37 optionsOverride
: (opts
) => {
38 // CommonJS supports properly shifting the default export to work as normal
39 opts
.plugins
.unshift("add-module-exports");
41 appWriter
: (base_out_path
, script_base_path
, out_path
) => {
42 const browserify
= require('browserify');
43 const b
= browserify(path
.join(script_base_path
, 'app/ui.js'), {});
44 return promisify(b
.bundle
).call(b
)
45 .then(buf
=> writeFile(out_path
, buf
))
48 noCopyOverride
: () => {},
52 appWriter
: (base_out_path
, script_base_path
, out_path
) => {
53 const ui_path
= path
.relative(base_out_path
,
54 path
.join(script_base_path
, 'app', 'ui.js'));
55 return writeFile(out_path
, `SystemJS.import("${ui_path}");`)
57 console
.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
58 // FIXME: Should probably be in the legacy directory
59 const promise_path
= path
.relative(base_out_path
,
60 path
.join(base_out_path
, 'vendor', 'promise.js'))
61 const systemjs_path
= path
.relative(base_out_path
,
62 path
.join(script_base_path
, 'system-production.js'))
63 return [ promise_path
, systemjs_path
];
66 noCopyOverride
: (paths
, no_copy_files
) => {
67 no_copy_files
.delete(path
.join(paths
.vendor
, 'promise.js'));
71 optionsOverride
: (opts
) => {
72 // umd supports properly shifting the default export to work as normal
73 opts
.plugins
.unshift("add-module-exports");