]> git.proxmox.com Git - mirror_novnc.git/blob - utils/use_require_helpers.js
Standardize on camelCase in utils
[mirror_novnc.git] / 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');
4
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);
12 resolve(value);
13 }));
14 });
15 };
16 }
17
18 const writeFile = promisify(fs.writeFile);
19
20 module.exports = {
21 'amd': {
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) {});`)
27 .then(() => {
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 ];
32 });
33 },
34 },
35 'commonjs': {
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))
41 .then(() => []);
42 },
43 removeModules: true,
44 },
45 'systemjs': {
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}");`)
50 .then(() => {
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 ];
55 });
56 },
57 },
58 'umd': {
59 },
60 };