-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
cli-run-commands.ts
134 lines (128 loc) · 4.27 KB
/
cli-run-commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import log from 'npmlog';
import { RunCommandOption } from '@lerna-lite/core';
import { filterOptions } from '../filter-options';
/**
* @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module
*/
export default {
command: 'run <script>',
describe: 'Run an npm script in each package that contains that script',
builder: (yargs: any) => {
yargs
.example('$0 run build -- --silent', '# `npm run build --silent` in all packages with a build script')
.parserConfiguration({
'populate--': true,
})
.positional('script', {
describe: 'The npm script to run. Pass flags to send to the npm client after --',
type: 'string',
})
.options({
'dry-run': {
group: 'Command Options:',
describe: 'Displays the process command that would be performed without executing it.',
type: 'boolean',
},
'npm-client': {
group: 'Command Options:',
describe: 'Executable used to run scripts (npm, yarn, pnpm, ...).',
defaultDescription: 'npm',
type: 'string',
requiresArg: true,
},
stream: {
group: 'Command Options:',
describe: 'Stream output with lines prefixed by package.',
type: 'boolean',
},
parallel: {
group: 'Command Options:',
describe: 'Run script with unlimited concurrency, streaming prefixed output.',
type: 'boolean',
},
'no-bail': {
group: 'Command Options:',
describe: 'Continue running script despite non-zero exit in a given package.',
type: 'boolean',
},
bail: {
// proxy for --no-bail
hidden: true,
type: 'boolean',
},
// This option controls prefix for stream output so that it can be disabled to be friendly
// to tools like Visual Studio Code to highlight the raw results
'no-prefix': {
group: 'Command Options:',
describe: 'Do not prefix streaming output.',
type: 'boolean',
},
prefix: {
// proxy for --no-prefix
hidden: true,
type: 'boolean',
},
profile: {
group: 'Command Options:',
describe: 'Profile script executions and output performance profile to default location.',
type: 'boolean',
},
'profile-location': {
group: 'Command Options:',
describe: 'Output performance profile to custom location instead of default project root.',
type: 'string',
},
'skip-nx-cache': {
hidden: true,
type: 'boolean',
},
'load-env-files': {
group: 'Command Options:',
describe: 'When useNx is enabled, do we want to automatically load .env files',
type: 'boolean',
},
'use-nx': {
group: 'Command Options:',
describe:
'enables integration with Nx instead of the default Lerna task runner (which uses `p-map` and `p-queue`).',
type: 'boolean',
},
verbose: {
group: 'Command Options:',
describe: 'When "useNx" is true, show verbose output from dependent tasks.',
type: 'boolean',
},
})
.option('cmd-dry-run', {
// TODO: remove in next major release
hidden: true,
conflicts: 'dry-run',
type: 'boolean',
})
.check((argv) => {
// override deprecated options
/* eslint-disable no-param-reassign */
if (argv.cmdDryRun) {
argv.dryRun = argv.cmdDryRun;
delete argv.cmdDryRun;
log.warn('deprecated', '--cmd-dry-run has been renamed --dry-run');
}
/* eslint-enable no-param-reassign */
return argv;
});
return filterOptions(yargs);
},
handler: async (argv: RunCommandOption) => {
try {
// @ts-ignore
// eslint-disable-next-line import/no-unresolved
const { RunCommand } = await import('@lerna-lite/run');
new RunCommand(argv);
} catch (err: unknown) {
console.error(
`"@lerna-lite/run" is optional and was not found. Please install it with "npm install @lerna-lite/run -D -W".`,
err
);
}
},
};