@xylabs/ts-scripts-yarn3 2.7.0-rc.25 → 2.7.0-rc.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/bin/xy.ts CHANGED
@@ -1,318 +1,5 @@
1
- import yargs from 'yargs'
2
- // eslint-disable-next-line import/no-internal-modules
3
- import { hideBin } from 'yargs/helpers'
1
+ #!/usr/bin/env node
4
2
 
5
- import { build, compile, clean, copyAssets, cycle, dead, lint, deps, fix, genDocs, gitlint, gitlintFix, lintFast, lintProfile, rebuild, relint, reinstall, sonar, test, tsconfigGen, tsconfigGenClean, up, updo, yarn3Only, license } from '../actions'
3
+ import { xy } from '../lib'
6
4
 
7
- const parseOptions = async (y: typeof yargs) => {
8
- return await y.option('verbose', {
9
- default: false,
10
- alias: 'v',
11
- description: 'Run with verbose logging',
12
- type: 'boolean',
13
- })
14
- .option('target', {
15
- alias: 't',
16
- description: 'Limit output to specific target',
17
- type: 'string',
18
- choices: ['esm', 'cjs']
19
- })
20
- .option('fix', {
21
- default: false,
22
- alias: 'f',
23
- description: 'Try to fix errors',
24
- type: 'boolean'
25
- })
26
- .option('cache', {
27
- default: false,
28
- alias: 'c',
29
- description: 'Use caching for performance',
30
- type: 'boolean'
31
- })
32
- .option('profile', {
33
- default: false,
34
- alias: 'p',
35
- description: 'Profile action',
36
- type: 'boolean'
37
- })
38
- .parse()
39
- }
40
-
41
- const run = async () => {
42
- const y = yargs(hideBin(process.argv))
43
- const options = await parseOptions(y)
44
-
45
- y.command(
46
- 'build [package]',
47
- 'Build - Compile & Lint',
48
- (yargs) => {
49
- return yargs.positional('package', {
50
- describe: 'Specific package to build'
51
- })
52
- },
53
- (argv) => {
54
- if (options.verbose) console.info(`Building: ${(argv.package ?? 'all')}`)
55
- process.exitCode = build({target: options.target as ('esm' | 'cjs')})
56
- },
57
- )
58
- .command(
59
- 'compile [package]',
60
- 'Compile with Typescript & Copy Images',
61
- (yargs) => {
62
- return yargs.positional('package', {
63
- describe: 'Specific package to compile'
64
- })
65
- },
66
- async (argv) => {
67
- if (options.verbose) console.info(`Compiling: ${(argv.package ?? 'all')}`)
68
- process.exitCode = await compile({target: options.target as ('esm' | 'cjs')})
69
- },
70
- )
71
- .command(
72
- 'clean [package]',
73
- 'Clean - Remove intermediate files',
74
- (yargs) => {
75
- return yargs.positional('package', {
76
- describe: 'Specific package to clean'
77
- })
78
- },
79
- (argv) => {
80
- if (options.verbose) console.info(`Cleaning: ${(argv.package ?? 'all')}`)
81
- process.exitCode = clean()
82
- },
83
- )
84
- .command(
85
- 'license [package]',
86
- 'License - Check licenses of dependencies',
87
- (yargs) => {
88
- return yargs.positional('package', {
89
- describe: 'Specific package to check'
90
- })
91
- },
92
- (argv) => {
93
- if (options.verbose) console.info(`License: ${(argv.package ?? 'all')}`)
94
- process.exitCode = license()
95
- },
96
- )
97
- .command(
98
- 'copy-assets [package]',
99
- 'Copy Assets - Copy the assets from src to dist',
100
- (yargs) => {
101
- return yargs.positional('package', {
102
- describe: 'Specific package to copy assets'
103
- })
104
- },
105
- (argv) => {
106
- if (options.verbose) console.info(`Copying Assets: ${(argv.package ?? 'all')}`)
107
- process.exitCode = copyAssets({target: options.target as ('esm' | 'cjs')})
108
- },
109
- )
110
- .command(
111
- 'cycle [package]',
112
- 'Cycle - Check for dependency cycles',
113
- (yargs) => {
114
- return yargs.positional('package', {
115
- describe: 'Specific package to check'
116
- })
117
- },
118
- () => {
119
- if (options.verbose) console.info(`Cycle`)
120
- process.exitCode = cycle()
121
- },
122
- )
123
- .command(
124
- 'dead [package]',
125
- 'Dead - Check for dead code',
126
- (yargs) => {
127
- return yargs.positional('package', {
128
- describe: 'Specific package to check'
129
- })
130
- },
131
- () => {
132
- if (options.verbose) console.info(`Dead`)
133
- process.exitCode = dead()
134
- },
135
- )
136
- .command(
137
- 'lint [package]',
138
- 'Lint - Run Eslint',
139
- (yargs) => {
140
- return yargs.positional('package', {
141
- describe: 'Specific package to check'
142
- })
143
- },
144
- () => {
145
- if (options.verbose) console.info(`Lint`)
146
- process.exitCode = options.fix ? fix() : options.profile ? lintProfile() : options.cache ? lintFast() : lint()
147
- },
148
- )
149
- .command(
150
- 'fix [package]',
151
- 'Fix - Run Eslint w/fix',
152
- (yargs) => {
153
- return yargs.positional('package', {
154
- describe: 'Specific package to check'
155
- })
156
- },
157
- () => {
158
- if (options.verbose) console.info(`Fix`)
159
- process.exitCode = fix()
160
- },
161
- )
162
- .command(
163
- 'deps [package]',
164
- 'Deps - Check for unused or missing dependencies',
165
- (yargs) => {
166
- return yargs.positional('package', {
167
- describe: 'Specific package to check'
168
- })
169
- },
170
- () => {
171
- if (options.verbose) console.info(`Deps`)
172
- process.exitCode = deps()
173
- },
174
- )
175
- .command(
176
- 'gen-docs [package]',
177
- 'GenDocs - Generate TypeDocs',
178
- (yargs) => {
179
- return yargs.positional('package', {
180
- describe: 'Specific package to generate docs for'
181
- })
182
- },
183
- () => {
184
- if (options.verbose) console.info(`Deps`)
185
- process.exitCode = genDocs()
186
- },
187
- )
188
- .command(
189
- 'gitlint [package]',
190
- 'Gitlint - Lint your git config',
191
- (yargs) => {
192
- return yargs
193
- },
194
- () => {
195
- if (options.verbose) console.info(`Gitlint`)
196
- process.exitCode = options.fix ? gitlintFix() : gitlint()
197
- },
198
- )
199
- .command(
200
- 'rebuild [package]',
201
- 'Rebuild - Clean, Compile & Lint',
202
- (yargs) => {
203
- return yargs.positional('package', {
204
- describe: 'Specific package to rebuild'
205
- })
206
- },
207
- () => {
208
- if (options.verbose) console.info(`Rebuilding: ${(options.package ?? 'all')}`)
209
- process.exitCode = rebuild({target: options.target as ('esm' | 'cjs')})
210
- },
211
- )
212
- .command(
213
- 'relint [package]',
214
- 'Relint - Clean & Lint',
215
- (yargs) => {
216
- return yargs.positional('package', {
217
- describe: 'Specific package to relint'
218
- })
219
- },
220
- () => {
221
- if (options.verbose) console.info(`Relinting`)
222
- process.exitCode = relint()
223
- },
224
- )
225
- .command(
226
- 'reinstall',
227
- 'Reinstall - Clean & Install',
228
- (yargs) => {
229
- return yargs
230
- },
231
- () => {
232
- if (options.verbose) console.info(`Reinstalling`)
233
- process.exitCode = reinstall()
234
- },
235
- )
236
- .command(
237
- 'sonar',
238
- 'Sonar - Run Sonar Check',
239
- (yargs) => {
240
- return yargs
241
- },
242
- () => {
243
- if (options.verbose) console.info(`Sonar Check`)
244
- process.exitCode = sonar()
245
- },
246
- )
247
- .command(
248
- 'test',
249
- 'Test - Run Jest Tests',
250
- (yargs) => {
251
- return yargs
252
- },
253
- () => {
254
- if (options.verbose) console.info(`Testing`)
255
- process.exitCode = test()
256
- },
257
- )
258
- .command(
259
- 'tsconfig-gen [package]',
260
- 'Tsconfig Gen - Generate tsconfog.json file for building',
261
- (yargs) => {
262
- return yargs.positional('package', {
263
- describe: 'Specific package for generation'
264
- })
265
- },
266
- () => {
267
- if (options.verbose) console.info(`TsconfigGen: ${(options.package ?? 'all')}`)
268
- process.exitCode = tsconfigGen({target: options.target as ('esm' | 'cjs')})
269
- },
270
- )
271
- .command(
272
- 'tsconfig-clean',
273
- 'Tsconfig Clean - Remove generated tsconfig.json files',
274
- (yargs) => {
275
- return yargs
276
- },
277
- () => {
278
- if (options.verbose) console.info(`Tsconfig Clean`)
279
- process.exitCode = tsconfigGenClean()
280
- },
281
- )
282
- .command(
283
- 'up',
284
- 'Up - Update dependencies',
285
- (yargs) => {
286
- return yargs
287
- },
288
- () => {
289
- if (options.verbose) console.info(`Up`)
290
- process.exitCode = up()
291
- },
292
- )
293
- .command(
294
- 'updo',
295
- 'Updo - Update dependencies [Interactive]',
296
- (yargs) => {
297
- return yargs
298
- },
299
- () => {
300
- if (options.verbose) console.info(`Updo`)
301
- process.exitCode = updo()
302
- },
303
- )
304
- .command(
305
- 'yarn3only',
306
- 'Yarn3Only - Check if using Yarn v3',
307
- (yargs) => {
308
- return yargs
309
- },
310
- () => {
311
- if (options.verbose) console.info(`Yarn 3 Check`)
312
- process.exitCode = yarn3Only()
313
- },
314
- )
315
- .parse()
316
- }
317
-
318
- run()
5
+ xy()
package/src/lib/index.ts CHANGED
@@ -6,5 +6,6 @@ export * from './runXy'
6
6
  export * from './safeExit'
7
7
  export * from './withErrnoException'
8
8
  export * from './withError'
9
+ export * from './xy'
9
10
  export * from './yarnInitCwd'
10
11
  export * from './yarnWorkspaces'
package/src/lib/xy.ts ADDED
@@ -0,0 +1,344 @@
1
+ import yargs from 'yargs'
2
+ // eslint-disable-next-line import/no-internal-modules
3
+ import { hideBin } from 'yargs/helpers'
4
+
5
+ import {
6
+ build,
7
+ clean,
8
+ compile,
9
+ copyAssets,
10
+ cycle,
11
+ dead,
12
+ deps,
13
+ fix,
14
+ genDocs,
15
+ gitlint,
16
+ gitlintFix,
17
+ license,
18
+ lint,
19
+ lintFast,
20
+ lintProfile,
21
+ rebuild,
22
+ reinstall,
23
+ relint,
24
+ sonar,
25
+ test,
26
+ tsconfigGen,
27
+ tsconfigGenClean,
28
+ up,
29
+ updo,
30
+ yarn3Only,
31
+ } from '../actions'
32
+
33
+ const parseOptions = async (yargsInstance: typeof yargs) => {
34
+ return await yargsInstance
35
+ .option('verbose', {
36
+ alias: 'v',
37
+ default: false,
38
+ description: 'Run with verbose logging',
39
+ type: 'boolean',
40
+ })
41
+ .option('target', {
42
+ alias: 't',
43
+ choices: ['esm', 'cjs'],
44
+ description: 'Limit output to specific target',
45
+ type: 'string',
46
+ })
47
+ .option('fix', {
48
+ alias: 'f',
49
+ default: false,
50
+ description: 'Try to fix errors',
51
+ type: 'boolean',
52
+ })
53
+ .option('cache', {
54
+ alias: 'c',
55
+ default: false,
56
+ description: 'Use caching for performance',
57
+ type: 'boolean',
58
+ })
59
+ .option('profile', {
60
+ alias: 'p',
61
+ default: false,
62
+ description: 'Profile action',
63
+ type: 'boolean',
64
+ })
65
+ .parse()
66
+ }
67
+
68
+ export const xy = async () => {
69
+ const yargsInstance = yargs(hideBin(process.argv))
70
+ const options = await parseOptions(yargsInstance)
71
+
72
+ await yargsInstance
73
+ .command(
74
+ 'build [package]',
75
+ 'Build - Compile & Lint',
76
+ (yargs) => {
77
+ return yargs.positional('package', {
78
+ describe: 'Specific package to build',
79
+ })
80
+ },
81
+ (argv) => {
82
+ if (options.verbose) console.info(`Building: ${argv.package ?? 'all'}`)
83
+ process.exitCode = build({ target: options.target as 'esm' | 'cjs' })
84
+ },
85
+ )
86
+ .command(
87
+ 'compile [package]',
88
+ 'Compile with Typescript & Copy Images',
89
+ (yargs) => {
90
+ return yargs.positional('package', {
91
+ describe: 'Specific package to compile',
92
+ })
93
+ },
94
+ async (argv) => {
95
+ if (options.verbose) console.info(`Compiling: ${argv.package ?? 'all'}`)
96
+ process.exitCode = await compile({ target: options.target as 'esm' | 'cjs' })
97
+ },
98
+ )
99
+ .command(
100
+ 'clean [package]',
101
+ 'Clean - Remove intermediate files',
102
+ (yargs) => {
103
+ return yargs.positional('package', {
104
+ describe: 'Specific package to clean',
105
+ })
106
+ },
107
+ (argv) => {
108
+ if (options.verbose) console.info(`Cleaning: ${argv.package ?? 'all'}`)
109
+ process.exitCode = clean()
110
+ },
111
+ )
112
+ .command(
113
+ 'license [package]',
114
+ 'License - Check licenses of dependencies',
115
+ (yargs) => {
116
+ return yargs.positional('package', {
117
+ describe: 'Specific package to check',
118
+ })
119
+ },
120
+ (argv) => {
121
+ if (options.verbose) console.info(`License: ${argv.package ?? 'all'}`)
122
+ process.exitCode = license()
123
+ },
124
+ )
125
+ .command(
126
+ 'copy-assets [package]',
127
+ 'Copy Assets - Copy the assets from src to dist',
128
+ (yargs) => {
129
+ return yargs.positional('package', {
130
+ describe: 'Specific package to copy assets',
131
+ })
132
+ },
133
+ (argv) => {
134
+ if (options.verbose) console.info(`Copying Assets: ${argv.package ?? 'all'}`)
135
+ process.exitCode = copyAssets({ target: options.target as 'esm' | 'cjs' })
136
+ },
137
+ )
138
+ .command(
139
+ 'cycle [package]',
140
+ 'Cycle - Check for dependency cycles',
141
+ (yargs) => {
142
+ return yargs.positional('package', {
143
+ describe: 'Specific package to check',
144
+ })
145
+ },
146
+ () => {
147
+ if (options.verbose) console.info('Cycle')
148
+ process.exitCode = cycle()
149
+ },
150
+ )
151
+ .command(
152
+ 'dead [package]',
153
+ 'Dead - Check for dead code',
154
+ (yargs) => {
155
+ return yargs.positional('package', {
156
+ describe: 'Specific package to check',
157
+ })
158
+ },
159
+ () => {
160
+ if (options.verbose) console.info('Dead')
161
+ process.exitCode = dead()
162
+ },
163
+ )
164
+ .command(
165
+ 'lint [package]',
166
+ 'Lint - Run Eslint',
167
+ (yargs) => {
168
+ return yargs.positional('package', {
169
+ describe: 'Specific package to check',
170
+ })
171
+ },
172
+ () => {
173
+ if (options.verbose) console.info('Lint')
174
+ process.exitCode = options.fix ? fix() : options.profile ? lintProfile() : options.cache ? lintFast() : lint()
175
+ },
176
+ )
177
+ .command(
178
+ 'fix [package]',
179
+ 'Fix - Run Eslint w/fix',
180
+ (yargs) => {
181
+ return yargs.positional('package', {
182
+ describe: 'Specific package to check',
183
+ })
184
+ },
185
+ () => {
186
+ if (options.verbose) console.info('Fix')
187
+ process.exitCode = fix()
188
+ },
189
+ )
190
+ .command(
191
+ 'deps [package]',
192
+ 'Deps - Check for unused or missing dependencies',
193
+ (yargs) => {
194
+ return yargs.positional('package', {
195
+ describe: 'Specific package to check',
196
+ })
197
+ },
198
+ () => {
199
+ if (options.verbose) console.info('Deps')
200
+ process.exitCode = deps()
201
+ },
202
+ )
203
+ .command(
204
+ 'gen-docs [package]',
205
+ 'GenDocs - Generate TypeDocs',
206
+ (yargs) => {
207
+ return yargs.positional('package', {
208
+ describe: 'Specific package to generate docs for',
209
+ })
210
+ },
211
+ () => {
212
+ if (options.verbose) console.info('Deps')
213
+ process.exitCode = genDocs()
214
+ },
215
+ )
216
+ .command(
217
+ 'gitlint [package]',
218
+ 'Gitlint - Lint your git config',
219
+ (yargs) => {
220
+ return yargs
221
+ },
222
+ () => {
223
+ if (options.verbose) console.info('Gitlint')
224
+ process.exitCode = options.fix ? gitlintFix() : gitlint()
225
+ },
226
+ )
227
+ .command(
228
+ 'rebuild [package]',
229
+ 'Rebuild - Clean, Compile & Lint',
230
+ (yargs) => {
231
+ return yargs.positional('package', {
232
+ describe: 'Specific package to rebuild',
233
+ })
234
+ },
235
+ () => {
236
+ if (options.verbose) console.info(`Rebuilding: ${options.package ?? 'all'}`)
237
+ process.exitCode = rebuild({ target: options.target as 'esm' | 'cjs' })
238
+ },
239
+ )
240
+ .command(
241
+ 'relint [package]',
242
+ 'Relint - Clean & Lint',
243
+ (yargs) => {
244
+ return yargs.positional('package', {
245
+ describe: 'Specific package to relint',
246
+ })
247
+ },
248
+ () => {
249
+ if (options.verbose) console.info('Relinting')
250
+ process.exitCode = relint()
251
+ },
252
+ )
253
+ .command(
254
+ 'reinstall',
255
+ 'Reinstall - Clean & Install',
256
+ (yargs) => {
257
+ return yargs
258
+ },
259
+ () => {
260
+ if (options.verbose) console.info('Reinstalling')
261
+ process.exitCode = reinstall()
262
+ },
263
+ )
264
+ .command(
265
+ 'sonar',
266
+ 'Sonar - Run Sonar Check',
267
+ (yargs) => {
268
+ return yargs
269
+ },
270
+ () => {
271
+ if (options.verbose) console.info('Sonar Check')
272
+ process.exitCode = sonar()
273
+ },
274
+ )
275
+ .command(
276
+ 'test',
277
+ 'Test - Run Jest Tests',
278
+ (yargs) => {
279
+ return yargs
280
+ },
281
+ () => {
282
+ if (options.verbose) console.info('Testing')
283
+ process.exitCode = test()
284
+ },
285
+ )
286
+ .command(
287
+ 'tsconfig-gen [package]',
288
+ 'Tsconfig Gen - Generate tsconfog.json file for building',
289
+ (yargs) => {
290
+ return yargs.positional('package', {
291
+ describe: 'Specific package for generation',
292
+ })
293
+ },
294
+ () => {
295
+ if (options.verbose) console.info(`TsconfigGen: ${options.package ?? 'all'}`)
296
+ process.exitCode = tsconfigGen({ target: options.target as 'esm' | 'cjs' })
297
+ },
298
+ )
299
+ .command(
300
+ 'tsconfig-clean',
301
+ 'Tsconfig Clean - Remove generated tsconfig.json files',
302
+ (yargs) => {
303
+ return yargs
304
+ },
305
+ () => {
306
+ if (options.verbose) console.info('Tsconfig Clean')
307
+ process.exitCode = tsconfigGenClean()
308
+ },
309
+ )
310
+ .command(
311
+ 'up',
312
+ 'Up - Update dependencies',
313
+ (yargs) => {
314
+ return yargs
315
+ },
316
+ () => {
317
+ if (options.verbose) console.info('Up')
318
+ process.exitCode = up()
319
+ },
320
+ )
321
+ .command(
322
+ 'updo',
323
+ 'Updo - Update dependencies [Interactive]',
324
+ (yargs) => {
325
+ return yargs
326
+ },
327
+ () => {
328
+ if (options.verbose) console.info('Updo')
329
+ process.exitCode = updo()
330
+ },
331
+ )
332
+ .command(
333
+ 'yarn3only',
334
+ 'Yarn3Only - Check if using Yarn v3',
335
+ (yargs) => {
336
+ return yargs
337
+ },
338
+ () => {
339
+ if (options.verbose) console.info('Yarn 3 Check')
340
+ process.exitCode = yarn3Only()
341
+ },
342
+ )
343
+ .parse()
344
+ }