|
1 | 1 | #!/usr/bin/env node
|
2 |
| -import path from 'path'; |
3 |
| - |
4 |
| -import execa from 'execa'; |
5 | 2 | import globby from 'globby';
|
6 | 3 | import inquirer from 'inquirer';
|
7 |
| -import isGitClean from 'is-git-clean'; |
8 | 4 | import meow from 'meow';
|
9 | 5 | import updateNotifier from 'update-notifier';
|
10 | 6 |
|
11 |
| -function checkGitStatus(force) { |
12 |
| - let clean = false; |
13 |
| - let errorMessage = 'Unable to determine if git directory is clean'; |
14 |
| - try { |
15 |
| - clean = isGitClean.sync(process.cwd()); |
16 |
| - errorMessage = 'Git directory is not clean'; |
17 |
| - } catch (err) { |
18 |
| - if (err && err.stderr && err.stderr.indexOf('Not a git repository') >= 0) { |
19 |
| - clean = true; |
20 |
| - } |
21 |
| - } |
22 |
| - |
23 |
| - const ENSURE_BACKUP_MESSAGE = 'Ensure you have a backup of your tests or commit the latest changes before continuing.'; |
24 |
| - |
25 |
| - if (!clean) { |
26 |
| - if (force) { |
27 |
| - console.log(`WARNING: ${errorMessage}. Forcibly continuing.`, ENSURE_BACKUP_MESSAGE); |
28 |
| - } else { |
29 |
| - console.log( |
30 |
| - `ERROR: ${errorMessage}. Refusing to continue.`, |
31 |
| - ENSURE_BACKUP_MESSAGE, |
32 |
| - 'You may use the --force flag to override this safety check.' |
33 |
| - ); |
34 |
| - process.exit(1); |
35 |
| - } |
36 |
| - } |
37 |
| -} |
38 |
| - |
39 |
| -function executeTransformation(files, flags, transformer) { |
40 |
| - const transformerPath = path.join(__dirname, 'transformers', `${transformer}.js`); |
41 |
| - |
42 |
| - const args = ['-t', transformerPath].concat(files); |
43 |
| - if (flags.dry) { |
44 |
| - args.push('--dry'); |
45 |
| - } |
46 |
| - if (['babel', 'babylon', 'flow'].indexOf(flags.parser) >= 0) { |
47 |
| - args.push('--parser', flags.parser); |
48 |
| - } |
49 |
| - |
50 |
| - console.log(`Executing command: jscodeshift ${args.join(' ')}`); |
51 |
| - |
52 |
| - const result = execa.sync(require.resolve('.bin/jscodeshift'), args, { |
53 |
| - stdio: 'inherit', |
54 |
| - stripEof: false, |
55 |
| - }); |
56 |
| - |
57 |
| - if (result.error) { |
58 |
| - throw result.error; |
59 |
| - } |
60 |
| -} |
61 |
| - |
62 |
| -function executeTransformations(files, flags, transformers) { |
63 |
| - transformers.forEach(t => { |
64 |
| - executeTransformation(files, flags, t); |
65 |
| - }); |
66 |
| -} |
| 7 | +import checkGitStatus from './git-status'; |
| 8 | +import { executeTransformations } from './transformers'; |
67 | 9 |
|
68 | 10 | const cli = meow(
|
69 | 11 | {
|
@@ -150,8 +92,6 @@ if (cli.input.length) {
|
150 | 92 | }
|
151 | 93 |
|
152 | 94 | const transformers = transformer === 'all' ? ['tape', 'ava'] : [transformer];
|
153 |
| - transformers.forEach(t => { |
154 |
| - executeTransformation(filesExpanded, cli.flags, t); |
155 |
| - }); |
| 95 | + executeTransformations(filesExpanded, cli.flags, transformers); |
156 | 96 | });
|
157 | 97 | }
|
0 commit comments