-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator2async.js
57 lines (50 loc) · 1.47 KB
/
generator2async.js
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
#!/usr/bin/env node
'use strict'
const path = require('path')
const execa = require('execa')
const meow = require('meow')
const transformers = ['generator2async.js']
function executeTransformation (transformer, files, flags) {
const spawnOptions = {
stdio: 'inherit',
stripEof: false
}
const args = ['-t', path.join(__dirname, 'lib', transformer)].concat(files)
if (flags.dry) {
args.push('--dry')
}
if (['babel', 'babylon', 'flow'].indexOf(flags.parser) >= 0) {
args.push('--parser', flags.parser)
}
console.log(`Executing command: jscodeshift ${args.join(' ')}`)
const result = execa.sync(require.resolve('.bin/jscodeshift'), args, spawnOptions)
if (result.error) {
throw result.error
}
}
const cli = meow({
description: 'Codemod to change test runner from generator function to async function',
help: `
Usage
$ generator2async <path> [options]
path Files or directory to transform. Can be a glob like src/**.test.js
Options
--force, -f Bypass Git safety checks and forcibly run codemods
--dry, -d Dry run (no changes are made to files)
--parser Parser to use for parsing your source files (babel | babylon | flow) [babel]
`}, {
boolean: ['force', 'dry'],
string: ['_'],
alias: {
f: 'force',
h: 'help',
d: 'dry'
}
}
)
const files = cli.input
if (files.length === 0) {
cli.showHelp()
} else {
transformers.forEach(t => executeTransformation(t, files, cli.flags))
}