-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
utils.ts
91 lines (83 loc) · 1.91 KB
/
utils.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
import * as yargsParser from 'yargs-parser';
import * as yargs from 'yargs';
/**
* These options are only for getting an array with properties of AffectedOptions.
*
* @remark They are not defaults or useful for anything else
*/
const dummyOptions: NxArgs = {
target: '',
configuration: '',
runner: '',
parallel: false,
maxParallel: 0,
'max-parallel': 0,
untracked: false,
uncommitted: false,
all: false,
base: 'base',
head: 'head',
exclude: ['exclude'],
files: [''],
onlyFailed: false,
'only-failed': false,
verbose: false,
help: false,
version: false,
quiet: false,
plain: false,
withDeps: false,
'with-deps': false,
projects: [],
select: '',
_: []
} as any;
const nxSpecific = Object.keys(dummyOptions);
export interface NxArgs {
target?: string;
configuration?: string;
runner?: string;
parallel?: boolean;
maxParallel?: number;
'max-parallel'?: number;
untracked?: boolean;
uncommitted?: boolean;
all?: boolean;
base?: string;
head?: string;
exclude?: string[];
files?: string[];
onlyFailed?: boolean;
'only-failed'?: boolean;
verbose?: boolean;
help?: boolean;
version?: boolean;
quiet?: boolean;
plain?: boolean;
withDeps?: boolean;
'with-deps'?: boolean;
projects?: string[];
select?: string;
_: string[];
}
const ignoreArgs = ['$0', '_'];
export function splitArgsIntoNxArgsAndOverrides(
args: yargs.Arguments
): { nxArgs: NxArgs; overrides: yargs.Arguments } {
const nxArgs: any = {};
const overrides = yargsParser(args._);
delete overrides._;
Object.entries(args).forEach(([key, value]) => {
if (nxSpecific.includes(key as any)) {
nxArgs[key] = value;
} else if (!ignoreArgs.includes(key)) {
overrides[key] = value;
}
});
if (!nxArgs.projects) {
nxArgs.projects = [];
} else {
nxArgs.projects = args.projects.split(',').map((p: string) => p.trim());
}
return { nxArgs, overrides };
}