]> git.proxmox.com Git - mirror_novnc.git/blame - utils/use_require_helpers.js
Hide clipboard side bar button when view only mode
[mirror_novnc.git] / utils / use_require_helpers.js
CommitLineData
6cae7b58 1// writes helpers require for vnc.html (they should output app.js)
2b5f94fa
JD
2const fs = require('fs');
3const path = require('path');
6cae7b58 4
21633268
PO
5// util.promisify requires Node.js 8.x, so we have our own
6function promisify(original) {
e7777653 7 return function promise_wrap() {
2b5f94fa 8 const args = Array.prototype.slice.call(arguments);
21633268 9 return new Promise((resolve, reject) => {
651c23ec 10 original.apply(this, args.concat((err, value) => {
21633268
PO
11 if (err) return reject(err);
12 resolve(value);
13 }));
14 });
0ae5c54a 15 };
21633268
PO
16}
17
18const writeFile = promisify(fs.writeFile);
19
6cae7b58
SR
20module.exports = {
21 'amd': {
4a65d50d 22 appWriter: (base_out_path, script_base_path, out_path) => {
6cae7b58 23 // setup for requirejs
2b5f94fa 24 const ui_path = path.relative(base_out_path,
7b536961 25 path.join(script_base_path, 'app', 'ui'));
d01ecc18 26 return writeFile(out_path, `requirejs(["${ui_path}"], function (ui) {});`)
7b536961
PO
27 .then(() => {
28 console.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
29 const require_path = path.relative(base_out_path,
0ae5c54a 30 path.join(script_base_path, 'require.js'));
7b536961
PO
31 return [ require_path ];
32 });
6cae7b58
SR
33 },
34 },
35 'commonjs': {
4a65d50d 36 appWriter: (base_out_path, script_base_path, out_path) => {
2b5f94fa
JD
37 const browserify = require('browserify');
38 const b = browserify(path.join(script_base_path, 'app/ui.js'), {});
21633268 39 return promisify(b.bundle).call(b)
7b536961
PO
40 .then(buf => writeFile(out_path, buf))
41 .then(() => []);
6cae7b58 42 },
be7b4e88 43 removeModules: true,
6cae7b58
SR
44 },
45 'systemjs': {
4a65d50d 46 appWriter: (base_out_path, script_base_path, out_path) => {
2b5f94fa 47 const ui_path = path.relative(base_out_path,
7b536961 48 path.join(script_base_path, 'app', 'ui.js'));
4a65d50d 49 return writeFile(out_path, `SystemJS.import("${ui_path}");`)
7b536961
PO
50 .then(() => {
51 console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
7b536961 52 const systemjs_path = path.relative(base_out_path,
0ae5c54a 53 path.join(script_base_path, 'system-production.js'));
b88a92af 54 return [ systemjs_path ];
7b536961 55 });
152c3995 56 },
6cae7b58
SR
57 },
58 'umd': {
6cae7b58 59 },
0ae5c54a 60};