|
1 | 1 | const { spawnSync } = require('child_process');
|
2 | 2 | const lernaBin = require.resolve('lerna/cli.js');
|
3 |
| -const getAllPackageInfo = require('./getAllPackageInfo'); |
4 | 3 | const os = require('os');
|
5 | 4 |
|
6 |
| -const argv = process.argv.slice(2); |
| 5 | +const { getAllPackageInfo } = require('@fluentui/scripts-monorepo'); |
7 | 6 |
|
8 |
| -if (require.main === module) { |
9 |
| - // Display a usage message when there are no projects specified |
10 |
| - if (argv.length < 2) { |
11 |
| - console.log(`Usage: |
12 |
| -
|
13 |
| - yarn runto <script> <packagename1> [<packagename2> ...] [<args>] |
14 |
| -
|
15 |
| -This command runs <script> for all packages up to and including "packagename1" (and "packagename2" etc). |
16 |
| -The package name can be a substring. |
17 |
| -If multiple packages match a pattern, they will all be built (along with their dependencies). |
18 |
| -`); |
19 |
| - |
20 |
| - process.exit(0); |
21 |
| - } |
22 |
| - |
23 |
| - const restIndex = argv.findIndex(arg => arg.startsWith('--')); |
24 |
| - const script = argv[0]; |
25 |
| - const projects = restIndex === -1 ? argv.slice(1) : argv.slice(1, restIndex); |
26 |
| - const rest = restIndex === -1 ? [] : argv.slice(argv[restIndex] === '--' ? restIndex + 1 : restIndex); |
27 |
| - |
28 |
| - runTo(script, projects, rest); |
29 |
| -} |
| 7 | +const isExecutedFromCli = require.main === module; |
30 | 8 |
|
31 | 9 | /**
|
32 | 10 | * @param {string} script - Script to run
|
33 | 11 | * @param {string[]} projects - Projects to run in
|
34 | 12 | * @param {string[]} rest - Args to pass on
|
| 13 | + * @returns {void} |
35 | 14 | */
|
36 | 15 | function runTo(script, projects, rest) {
|
37 | 16 | // This script matches substrings of the input for one more many projects
|
@@ -91,4 +70,32 @@ function runTo(script, projects, rest) {
|
91 | 70 | }
|
92 | 71 | }
|
93 | 72 |
|
94 |
| -module.exports = runTo; |
| 73 | +function main() { |
| 74 | + const argv = process.argv.slice(2); |
| 75 | + // Display a usage message when there are no projects specified |
| 76 | + if (argv.length < 2) { |
| 77 | + console.log(`Usage: |
| 78 | +
|
| 79 | + yarn runto <script> <packagename1> [<packagename2> ...] [<args>] |
| 80 | +
|
| 81 | +This command runs <script> for all packages up to and including "packagename1" (and "packagename2" etc). |
| 82 | +The package name can be a substring. |
| 83 | +If multiple packages match a pattern, they will all be built (along with their dependencies). |
| 84 | +`); |
| 85 | + |
| 86 | + process.exit(0); |
| 87 | + } |
| 88 | + |
| 89 | + const restIndex = argv.findIndex(arg => arg.startsWith('--')); |
| 90 | + const script = argv[0]; |
| 91 | + const projects = restIndex === -1 ? argv.slice(1) : argv.slice(1, restIndex); |
| 92 | + const rest = restIndex === -1 ? [] : argv.slice(argv[restIndex] === '--' ? restIndex + 1 : restIndex); |
| 93 | + |
| 94 | + runTo(script, projects, rest); |
| 95 | +} |
| 96 | + |
| 97 | +if (isExecutedFromCli) { |
| 98 | + main(); |
| 99 | +} |
| 100 | + |
| 101 | +exports.runTo = runTo; |
0 commit comments