-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathyall.ts
145 lines (129 loc) · 2.97 KB
/
yall.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
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env node
import * as yargs from 'yargs'
import { runAll, watchAll, YallOptions } from '.'
const yallFlags = [
'debug',
'concurrency',
'con',
'clean-up',
'fail-fast',
'cmd',
'npm',
'in',
'folders',
'exclude-folders',
'include-folders',
'here',
'link-file',
'link-files',
'watch',
'watch-content',
'force',
'force-local',
'force-remote',
'cwd',
'dot-folders',
'lock',
'lock-each',
'cache-folder',
'only-workspaces',
'separate-cache-folders',
'skip-first-run',
'sep-cache',
'exec-after'
]
const cliCommand = 'yall'
interface Args extends YallOptions {
watch?: string[]
watchContent?: string[]
_: string[]
}
const removeDoubleHypenFromArgv = () => {
const rev = process.argv.concat([]).reverse()
rev.forEach(
(arg, i) => arg === '--' && process.argv.splice(rev.length - i - 1, 1)
)
return process.argv.slice(2)
}
yargs
.usage(cliCommand + '[yarn|npm command] [yarn|npm flags] [yall flags]')
.string(['cache-folder', 'modules-folder'])
.option('concurrency', {
alias: 'con',
type: 'number',
describe: 'Number of concurrenlty running commands',
default: 10,
})
.option('cmd', {
type: 'string',
describe: 'custom cmd to run instead of yarn/npm',
})
.option('interval', {
type: 'number',
describe: 'Watch pooling interval, in ms',
default: 1000,
})
.options('link-file', {
alias: 'link-files',
describe: 'Create symlinks for `file:` dependencies',
type: 'boolean',
})
.options('separate-cache-folders', {
alias: 'sep-cache',
describe: 'Seed to make a separate cache folder for each installation.',
type: 'string',
})
.string(['lock', 'lock-each', 'exec-after'])
.array([
'folders',
'exclude-folders',
'include-folders',
'in',
'watch',
'watch-content',
])
.boolean([
'force',
'debug',
'here',
'fail-fast',
'npm',
'dot-folders',
'only-workspaces',
])
.help(true).argv as Args
const argv = yargs.parse(removeDoubleHypenFromArgv()) as Args
process.stdin.setMaxListeners(0)
process.stdout.setMaxListeners(0)
process.setMaxListeners(0)
const isFlag = (arg: string) => arg.match(/^--?\w/)
const isYallFlag = (arg: string) =>
yallFlags.indexOf(arg.replace(/^--?/, '')) >= 0
const parseRunArguments = () => {
const runArgs: string[] = []
let takeArg = false
process.argv.forEach((arg, i) => {
if (isFlag(arg)) {
takeArg = !isYallFlag(arg)
}
takeArg && runArgs.push(arg)
})
return runArgs
}
const command = argv._.concat(parseRunArguments()).join(' ')
const options = argv
if (options.in) {
options.folders = options.in
options.here = true
}
options.cwd = options.cwd || process.cwd()
const version = require('./package.json').version
console.log(`yall v${version}`)
if (argv.onlyWorkspaces) {
console.log('Running only for Yarn workspaces.')
}
if (argv.watch || argv.watchContent) {
watchAll(command, argv, argv.watch, argv.watchContent)
} else {
runAll(command, argv)
}