]>
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) { | |
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 | }); | |
15 | } | |
16 | } | |
17 | ||
18 | const writeFile = promisify(fs.writeFile); | |
19 | ||
6cae7b58 SR |
20 | module.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')); |
651c23ec | 26 | return writeFile(out_path, `requirejs(["${ui_path}"], (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, | |
30 | path.join(script_base_path, 'require.js')) | |
31 | return [ require_path ]; | |
32 | }); | |
6cae7b58 | 33 | }, |
152c3995 | 34 | noCopyOverride: () => {}, |
6cae7b58 SR |
35 | }, |
36 | 'commonjs': { | |
4a16dc51 | 37 | optionsOverride: (opts) => { |
6cae7b58 SR |
38 | // CommonJS supports properly shifting the default export to work as normal |
39 | opts.plugins.unshift("add-module-exports"); | |
40 | }, | |
4a65d50d | 41 | appWriter: (base_out_path, script_base_path, out_path) => { |
2b5f94fa JD |
42 | const browserify = require('browserify'); |
43 | const b = browserify(path.join(script_base_path, 'app/ui.js'), {}); | |
21633268 | 44 | return promisify(b.bundle).call(b) |
7b536961 PO |
45 | .then(buf => writeFile(out_path, buf)) |
46 | .then(() => []); | |
6cae7b58 | 47 | }, |
152c3995 | 48 | noCopyOverride: () => {}, |
be7b4e88 | 49 | removeModules: true, |
6cae7b58 SR |
50 | }, |
51 | 'systemjs': { | |
4a65d50d | 52 | appWriter: (base_out_path, script_base_path, out_path) => { |
2b5f94fa | 53 | const ui_path = path.relative(base_out_path, |
7b536961 | 54 | path.join(script_base_path, 'app', 'ui.js')); |
4a65d50d | 55 | return writeFile(out_path, `SystemJS.import("${ui_path}");`) |
7b536961 PO |
56 | .then(() => { |
57 | console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`); | |
4a65d50d | 58 | // FIXME: Should probably be in the legacy directory |
7b536961 PO |
59 | const promise_path = path.relative(base_out_path, |
60 | path.join(base_out_path, 'vendor', 'promise.js')) | |
61 | const systemjs_path = path.relative(base_out_path, | |
62 | path.join(script_base_path, 'system-production.js')) | |
63 | return [ promise_path, systemjs_path ]; | |
64 | }); | |
152c3995 SR |
65 | }, |
66 | noCopyOverride: (paths, no_copy_files) => { | |
67 | no_copy_files.delete(path.join(paths.vendor, 'promise.js')); | |
6cae7b58 SR |
68 | }, |
69 | }, | |
70 | 'umd': { | |
4a16dc51 | 71 | optionsOverride: (opts) => { |
6cae7b58 SR |
72 | // umd supports properly shifting the default export to work as normal |
73 | opts.plugins.unshift("add-module-exports"); | |
74 | }, | |
75 | }, | |
76 | } |