Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
feat: add dry and print options to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
KnisterPeter committed May 31, 2017
1 parent 3900bda commit a1babe5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { applyTransforms } from './transform';
import * as types from './types';

async function main(cli: meow.Result): Promise<void> {
if (cli.flags.h) {
cli.showHelp(0);
return;
}
const transformPaths = [].concat(
cli.flags['t'] || [],
cli.flags['transform'] || []
Expand All @@ -15,9 +19,13 @@ async function main(cli: meow.Result): Promise<void> {
paths.forEach(async path => {
const source = (await fs.readFile(path)).toString();
const result = applyTransforms(path, source, transforms);
if (result !== source) {
if (result !== source && !cli.flags.d && !cli.flags.dry) {
await fs.writeFile(path, result);
}
if (cli.flags.print || cli.flags.p) {
console.log(`Output for ${path}`);
console.log(result);
}
});
}

Expand All @@ -28,6 +36,8 @@ const cli = meow(`
Options:
-t FILE, --transform FILE Path to the transform file. Can be either a local path or url [./transform.js]
-d, --dry Dry run (no changes are made to files)
-p, --print Print output, useful for development
`);

main(cli)
Expand Down

0 comments on commit a1babe5

Please sign in to comment.