Skip to content

Commit 95e6231

Browse files
committed
feat: add new clean command
1 parent 5824b78 commit 95e6231

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Commands:
2222
e2cct update Update e2cct to the latest version
2323
e2cct reset Caution: Reverts unstaged changes and
2424
decaffeinate commits.
25+
e2cct clean Remove the .original.coffee artifact
26+
files
2527
2628
Options:
2729
--help Show help [boolean]
@@ -45,7 +47,7 @@ Linting can be done as part of the conversion process if passing in the optional
4547
Alternatively is done separately as final step.
4648
Rules are inherited from the project.
4749

48-
NOTE: With bigger files you might have to run the linting more than once, we automatically do 3 passes for convenience. In case you still see the message indicating potentially fixable issues with the '--fix' option after the conversion, you can manually run linting again using `e2cct lint`
50+
NOTE: With bigger files you might have to run the linting more than once, we automatically do 2 passes for convenience. In case you still see the message indicating potentially fixable issues with the '--fix' option after the conversion, you can manually run linting again using `e2cct lint`
4951

5052
#### Eslint and Prettier rules
5153
This toolkit makes the assumption that your project already aligns the prettier and eslint rules. If not, the automated fixing might result in a half-baked solution which potentially does not match your existing linting checks.

commands/clean.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { spawnSync } = require('child_process');
2+
const { getBinaryFromBin } = require('../shared/utils')
3+
4+
exports.command = 'clean'
5+
exports.describe = 'Remove the .original.coffee artifact files'
6+
exports.builder = {}
7+
8+
exports.handler = function (/* argv */) {
9+
console.info(
10+
`\x1b[94me2cct: Removing .original.coffee files... \x1b[0m`
11+
);
12+
13+
const result = spawnSync(getBinaryFromBin("bulk-decaffeinate"), ['clean'], { stdio: ["inherit", "inherit", "pipe"] });
14+
15+
if (result.status !== 0) {
16+
console.error(`e2cct: Clean failed with code ${result.status}: ${result.stderr}`);
17+
} else {
18+
console.info(
19+
`\x1b[94me2cct: Clean done \x1b[0m`
20+
);
21+
}
22+
}

commands/convert.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11

22
const { spawnSync } = require('child_process');
3-
const path = require("path");
43
const root = `${__dirname}/..`
5-
const { getFilePaths } = require('../shared/utils')
6-
7-
function getBinaryFromBin(name) {
8-
return path.join(root, "/node_modules", ".bin", name);
9-
}
4+
const { getFilePaths, getBinaryFromBin } = require('../shared/utils')
105

116
module.exports = function(args) {
127
const { absCsPath, absJsPath } = getFilePaths(args)

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const argv = yargs(hideBin(process.argv))
1313
}).option('lint', {
1414
alias: 'l',
1515
describe: 'Lint file post convert'
16+
}).option('clean', {
17+
alias: 'c',
18+
describe: 'Remove .original.coffee files post convert'
1619
})
1720
return yargs
1821
}, (argv) => {
@@ -41,5 +44,6 @@ const argv = yargs(hideBin(process.argv))
4144
})
4245
.command(require('./commands/update.js'))
4346
.command(require('./commands/reset.js'))
47+
.command(require('./commands/clean.js'))
4448
.help()
4549
.parse()

shared/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require("path");
2+
const root = `${__dirname}/..`
23

34
module.exports.getFilePaths = function(args) {
45
const filePath = args.file
@@ -14,3 +15,7 @@ module.exports.getFilePaths = function(args) {
1415
absJsPath: absoluteJsFilePath
1516
}
1617
}
18+
19+
module.exports.getBinaryFromBin = function(name) {
20+
return path.join(root, "/node_modules", ".bin", name);
21+
}

0 commit comments

Comments
 (0)