|
5 | 5 | */
|
6 | 6 | "use strict"
|
7 | 7 |
|
8 |
| -//------------------------------------------------------------------------------ |
9 |
| -// Helpers |
10 |
| -//------------------------------------------------------------------------------ |
11 |
| - |
12 |
| -/** |
13 |
| - * Define the function for main process. |
14 |
| - * |
15 |
| - * @param {string} name - A program name. |
16 |
| - * @returns {function} The function for main process. |
17 |
| - */ |
18 |
| -function defineMain(name) { |
19 |
| - /** |
20 |
| - * The main process of `npm-run-all` command. |
21 |
| - * |
22 |
| - * @param {string[]} args - Arguments to parse. |
23 |
| - * @param {stream.Writable} stdout - A writable stream to print logs. |
24 |
| - * @param {stream.Writable} stderr - A writable stream to print errors. |
25 |
| - * @returns {Promise} A promise which comes to be fulfilled when all |
26 |
| - * npm-scripts are completed. |
27 |
| - * @private |
28 |
| - */ |
29 |
| - return function main(args, stdout = null, stderr = null) { |
30 |
| - switch (args[0]) { |
31 |
| - case undefined: |
32 |
| - case "-h": |
33 |
| - case "--help": |
34 |
| - return require(`../${name}/help`)(stdout) |
35 |
| - |
36 |
| - case "-v": |
37 |
| - case "--version": |
38 |
| - return require("./version")(stdout) |
39 |
| - |
40 |
| - default: |
41 |
| - return require(`../${name}/main`)(args, stdout, stderr) |
42 |
| - } |
43 |
| - } |
44 |
| -} |
45 |
| - |
46 | 8 | //------------------------------------------------------------------------------
|
47 | 9 | // Public Interface
|
48 | 10 | //------------------------------------------------------------------------------
|
49 |
| - |
50 |
| -module.exports = function bootstrap(entryModule, name) { |
51 |
| - const main = entryModule.exports = defineMain(name) |
52 |
| - |
53 |
| - /* eslint-disable no-console, no-process-exit */ |
54 |
| - /* istanbul ignore if */ |
55 |
| - if (require.main === entryModule) { |
56 |
| - const argv = process.argv.slice(2) |
57 |
| - |
58 |
| - // Execute. |
59 |
| - const promise = main(argv, process.stdout, process.stderr) |
60 |
| - |
61 |
| - // Error Handling. |
62 |
| - promise.then( |
63 |
| - () => { |
64 |
| - // I'm not sure why, but maybe the process never exits |
65 |
| - // on Git Bash (MINGW64) |
66 |
| - process.exit(0) |
67 |
| - }, |
68 |
| - () => { |
69 |
| - process.exit(1) |
70 |
| - } |
71 |
| - ) |
| 11 | +/*eslint-disable no-console, no-process-exit */ |
| 12 | + |
| 13 | +module.exports = function bootstrap(name) { |
| 14 | + const argv = process.argv.slice(2) |
| 15 | + |
| 16 | + switch (argv[0]) { |
| 17 | + case undefined: |
| 18 | + case "-h": |
| 19 | + case "--help": |
| 20 | + return require(`../${name}/help`)(process.stdout) |
| 21 | + |
| 22 | + case "-v": |
| 23 | + case "--version": |
| 24 | + return require("./version")(process.stdout) |
| 25 | + |
| 26 | + default: |
| 27 | + return require(`../${name}/main`)( |
| 28 | + argv, |
| 29 | + process.stdout, |
| 30 | + process.stderr |
| 31 | + ).then( |
| 32 | + () => { |
| 33 | + // I'm not sure why, but maybe the process never exits |
| 34 | + // on Git Bash (MINGW64) |
| 35 | + process.exit(0) |
| 36 | + }, |
| 37 | + () => { |
| 38 | + process.exit(1) |
| 39 | + } |
| 40 | + ) |
72 | 41 | }
|
73 | 42 | }
|
74 | 43 |
|
| 44 | +/*eslint-enable */ |
0 commit comments