]>
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 promiseWrap() {
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
: (baseOutPath
, scriptBasePath
, outPath
) => {
23 // setup for requirejs
24 const uiPath
= path
.relative(baseOutPath
,
25 path
.join(scriptBasePath
, 'app', 'ui'));
26 return writeFile(outPath
, `requirejs(["${uiPath}"], function (ui) {});`)
28 console
.log(`Please place RequireJS in ${path.join(scriptBasePath, 'require.js')}`);
29 const requirePath
= path
.relative(baseOutPath
,
30 path
.join(scriptBasePath
, 'require.js'));
31 return [ requirePath
];
36 appWriter
: (baseOutPath
, scriptBasePath
, outPath
) => {
37 const browserify
= require('browserify');
38 const b
= browserify(path
.join(scriptBasePath
, 'app/ui.js'), {});
39 return promisify(b
.bundle
).call(b
)
40 .then(buf
=> writeFile(outPath
, buf
))
46 appWriter
: (baseOutPath
, scriptBasePath
, outPath
) => {
47 const uiPath
= path
.relative(baseOutPath
,
48 path
.join(scriptBasePath
, 'app', 'ui.js'));
49 return writeFile(outPath
, `SystemJS.import("${uiPath}");`)
51 console
.log(`Please place SystemJS in ${path.join(scriptBasePath, 'system-production.js')}`);
52 const systemjsPath
= path
.relative(baseOutPath
,
53 path
.join(scriptBasePath
, 'system-production.js'));
54 return [ systemjsPath
];