]>
Commit | Line | Data |
---|---|---|
6cae7b58 | 1 | // writes helpers require for vnc.html (they should output app.js) |
2b5f94fa JD |
2 | const fs = require('fs'); |
3 | const path = require('path'); | |
6cae7b58 | 4 | |
21633268 PO |
5 | // util.promisify requires Node.js 8.x, so we have our own |
6 | function promisify(original) { | |
8b0034ee | 7 | return function promiseWrap() { |
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 | ||
18 | const writeFile = promisify(fs.writeFile); | |
19 | ||
6cae7b58 SR |
20 | module.exports = { |
21 | 'amd': { | |
8b0034ee | 22 | appWriter: (baseOutPath, scriptBasePath, outPath) => { |
6cae7b58 | 23 | // setup for requirejs |
8b0034ee SM |
24 | const uiPath = path.relative(baseOutPath, |
25 | path.join(scriptBasePath, 'app', 'ui')); | |
26 | return writeFile(outPath, `requirejs(["${uiPath}"], function (ui) {});`) | |
7b536961 | 27 | .then(() => { |
8b0034ee SM |
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 ]; | |
7b536961 | 32 | }); |
6cae7b58 SR |
33 | }, |
34 | }, | |
35 | 'commonjs': { | |
8b0034ee | 36 | appWriter: (baseOutPath, scriptBasePath, outPath) => { |
2b5f94fa | 37 | const browserify = require('browserify'); |
8b0034ee | 38 | const b = browserify(path.join(scriptBasePath, 'app/ui.js'), {}); |
21633268 | 39 | return promisify(b.bundle).call(b) |
8b0034ee | 40 | .then(buf => writeFile(outPath, buf)) |
7b536961 | 41 | .then(() => []); |
6cae7b58 | 42 | }, |
be7b4e88 | 43 | removeModules: true, |
6cae7b58 SR |
44 | }, |
45 | 'systemjs': { | |
8b0034ee SM |
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}");`) | |
7b536961 | 50 | .then(() => { |
8b0034ee SM |
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 ]; | |
7b536961 | 55 | }); |
152c3995 | 56 | }, |
6cae7b58 SR |
57 | }, |
58 | 'umd': { | |
6cae7b58 | 59 | }, |
0ae5c54a | 60 | }; |