]>
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 var fs
= require('fs');
3 var fse
= require('fs-extra');
4 var path
= require('path');
6 // util.promisify requires Node.js 8.x, so we have our own
7 function promisify(original
) {
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
);
20 const writeFile
= promisify(fs
.writeFile
);
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) {});`)
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
];
36 noCopyOverride
: () => {},
39 optionsOverride
: (opts
) => {
40 // CommonJS supports properly shifting the default export to work as normal
41 opts
.plugins
.unshift("add-module-exports");
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
))
50 noCopyOverride
: () => {},
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}");`)
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
];
68 noCopyOverride
: (paths
, no_copy_files
) => {
69 no_copy_files
.delete(path
.join(paths
.vendor
, 'promise.js'));
73 optionsOverride
: (opts
) => {
74 // umd supports properly shifting the default export to work as normal
75 opts
.plugins
.unshift("add-module-exports");