]>
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
) {
7 return function promise_wrap() {
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
];
36 appWriter
: (base_out_path
, script_base_path
, out_path
) => {
37 const browserify
= require('browserify');
38 const b
= browserify(path
.join(script_base_path
, 'app/ui.js'), {});
39 return promisify(b
.bundle
).call(b
)
40 .then(buf
=> writeFile(out_path
, buf
))
46 appWriter
: (base_out_path
, script_base_path
, out_path
) => {
47 const ui_path
= path
.relative(base_out_path
,
48 path
.join(script_base_path
, 'app', 'ui.js'));
49 return writeFile(out_path
, `SystemJS.import("${ui_path}");`)
51 console
.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
52 const systemjs_path
= path
.relative(base_out_path
,
53 path
.join(script_base_path
, 'system-production.js'));
54 return [ systemjs_path
];