-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathyalc.ts
227 lines (220 loc) · 5.51 KB
/
yalc.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env node
import * as yargs from 'yargs'
import { join } from 'path'
import {
values,
publishPackage,
addPackages,
updatePackages,
removePackages,
getStoreMainDir
} from '.'
import { showInstallations, cleanInstallations } from './installations'
import { checkManifest } from './check'
const publishFlags = ['knit', 'force', 'sig', 'changed', 'yarn', 'files']
const cliCommand = values.myNameIs
const getVersionMessage = () => {
const pkg = require(__dirname + '/../package.json')
return pkg.version
}
const showVersion = () => {
console.log(getVersionMessage())
}
/* tslint:disable-next-line */
yargs
.usage(cliCommand + ' [command] [options] [package1 [package2...]]')
.command({
command: '*',
builder: () => {
return yargs.boolean(['version'])
},
handler: argv => {
let msg = 'Use `yalc help` to see available commands.'
if (argv._[0]) {
msg = 'Unknown command `' + argv._[0] + '`. ' + msg
} else {
if (argv.version) {
msg = getVersionMessage()
}
}
console.log(msg)
}
})
.command({
command: 'publish',
describe: 'Publish package in yalc local repo',
builder: () => {
return yargs
.default('sig', true)
.boolean(['push', 'push-safe'].concat(publishFlags))
},
handler: argv => {
const folder = argv._[1]
return publishPackage({
workingDir: join(process.cwd(), folder || ''),
push: argv.push,
pushSafe: argv.pushSafe,
force: argv.force,
knit: argv.knit,
signature: argv.sig,
yarn: argv.yarn,
changed: argv.changed,
files: argv.files,
private: argv.private
})
}
})
.command({
command: 'installations',
describe: 'Work with installations file: show/clean',
builder: () => {
return yargs.boolean(['dry'])
},
handler: async argv => {
const action = argv._[1]
const packages = argv._.slice(2)
switch (action) {
case 'show':
showInstallations({ packages })
break
case 'clean':
await cleanInstallations({ packages, dry: argv.dry })
break
default:
console.log('Need installation action: show | clean')
}
}
})
.command({
command: 'push',
describe:
'Publish package in yalc local repo and push to all installations',
builder: () => {
return yargs
.default('force', undefined)
.default('sig', true)
.boolean(['safe'].concat(publishFlags))
},
handler: argv => {
return publishPackage({
workingDir: join(process.cwd(), argv._[1] || ''),
force: argv.force !== undefined ? argv.force : true,
knit: argv.knit,
push: true,
pushSafe: argv.safe,
signature: argv.sig,
yarn: argv.yarn,
changed: argv.changed,
files: argv.files,
private: argv.private
})
}
})
.command({
command: 'add',
describe: 'Add package from yalc repo to the project',
builder: () => {
return yargs
.boolean(['link', 'dev', 'save', 'yarn', 'pure'])
.default('link', true)
.default('save', true)
.help(true)
},
handler: argv => {
const hasPureArg = process.argv.reduce(
(res, arg) => res || /-pure/.test(arg),
false
)
return addPackages(argv._.slice(1), {
dev: argv.dev,
link: argv.link,
pure: hasPureArg ? argv.pure : undefined,
noSave: !argv.save,
workingDir: process.cwd()
})
}
})
.command({
command: 'link',
describe: 'Link package from yalc repo to the project',
builder: () => {
return yargs.default('yarn', true).help(true)
},
handler: argv => {
return addPackages(argv._.slice(1), {
link: true,
noSave: true,
workingDir: process.cwd()
})
}
})
.command({
command: 'update',
describe: 'Update packages from yalc repo',
builder: () => {
return yargs.help(true)
},
handler: argv => {
return updatePackages(argv._.slice(1), {
workingDir: process.cwd()
})
}
})
.command({
command: 'remove',
describe: 'Remove packages from the project',
builder: () => {
return yargs.boolean(['retreat', 'all']).help(true)
},
handler: argv => {
return removePackages(argv._.slice(1), {
retreat: argv.retreat,
workingDir: process.cwd(),
all: argv.all
})
}
})
.command({
command: 'retreat',
describe:
'Remove packages from project, but leave in lock file (to be restored later)',
builder: () => {
return yargs.boolean(['all']).help(true)
},
handler: argv => {
return removePackages(argv._.slice(1), {
all: argv.all,
retreat: true,
workingDir: process.cwd()
})
}
})
.command({
command: 'check',
describe: 'Check package.json for yalc packages',
builder: () => {
return yargs
.boolean(['commit'])
.usage('check usage here')
.help(true)
},
handler: argv => {
const gitParams = process.env.GIT_PARAMS
if (argv.commit) {
console.log('gitParams', gitParams)
}
checkManifest({
commit: argv.commit,
all: argv.all,
workingDir: process.cwd()
})
}
})
.command({
command: 'dir',
describe: 'Show yalc system directory',
handler: () => {
console.log(getStoreMainDir())
}
})
.help('help').argv