]>
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
) {
9 const 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
);
19 const writeFile
= promisify(fs
.writeFile
);
23 appWriter
: (base_out_path
, script_base_path
, out_path
) => {
24 // setup for requirejs
25 const 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) {});`)
29 console
.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
30 const require_path
= path
.relative(base_out_path
,
31 path
.join(script_base_path
, 'require.js'))
32 return [ require_path
];
35 noCopyOverride
: () => {},
38 optionsOverride
: (opts
) => {
39 // CommonJS supports properly shifting the default export to work as normal
40 opts
.plugins
.unshift("add-module-exports");
42 appWriter
: (base_out_path
, script_base_path
, out_path
) => {
43 const browserify
= require('browserify');
44 const b
= browserify(path
.join(script_base_path
, 'app/ui.js'), {});
45 return promisify(b
.bundle
).call(b
)
46 .then((buf
) => writeFile(out_path
, buf
))
49 noCopyOverride
: () => {},
53 appWriter
: (base_out_path
, script_base_path
, out_path
) => {
54 const 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}");`)
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 const promise_path
= path
.relative(base_out_path
,
61 path
.join(base_out_path
, 'vendor', 'promise.js'))
62 const systemjs_path
= path
.relative(base_out_path
,
63 path
.join(script_base_path
, 'system-production.js'))
64 return [ promise_path
, systemjs_path
];
67 noCopyOverride
: (paths
, no_copy_files
) => {
68 no_copy_files
.delete(path
.join(paths
.vendor
, 'promise.js'));
72 optionsOverride
: (opts
) => {
73 // umd supports properly shifting the default export to work as normal
74 opts
.plugins
.unshift("add-module-exports");