Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.

Commit b32c812

Browse files
committed
Add --keep-*-files options for easier debugging
1 parent 97eec18 commit b32c812

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/cli.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ program
2222
.option('--trailing-comma <none|es5|all>', 'Print trailing commas wherever possible when multi-line.', 'none')
2323
.option('--use-tabs', 'Indent with tabs instead of spaces.', false)
2424
.option('--ignore-prettier-errors', 'Ignore (but warn about) errors in Prettier', false)
25+
.option('--keep-original-files', 'Keep original files', false)
26+
.option('--keep-temporary-files', 'Keep temporary files', false)
2527
.usage('[options] <filename or glob>')
2628
.command('* <glob>')
2729
.action(globPattern => {
@@ -52,12 +54,18 @@ program
5254
fs.copyFileSync(filePath, temporaryPath);
5355
const result = run(temporaryPath, prettierOptions, compilationOptions);
5456
fs.writeFileSync(newPath, result);
55-
fs.unlinkSync(filePath);
56-
fs.unlinkSync(temporaryPath);
57+
if (!program.keepOriginalFiles) {
58+
fs.unlinkSync(filePath);
59+
}
5760
} catch (error) {
5861
console.warn(`Failed to convert ${file}`);
5962
console.warn(error);
6063
}
64+
if (!program.keepTemporaryFiles) {
65+
if (fs.existsSync(temporaryPath)) {
66+
fs.unlinkSync(temporaryPath);
67+
}
68+
}
6169
}
6270
});
6371

0 commit comments

Comments
 (0)