Skip to content

Commit

Permalink
Add printing to stdout
Browse files Browse the repository at this point in the history
Add printing to stdout using -s or --stdout flag.
  • Loading branch information
EivindSul committed Aug 22, 2024
1 parent 8f1fe4c commit feb2f90
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions bin/ical2json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ program
.version(pkg.version)
.option('-r, --revert', 'Revert JSON to ical')
.option('-o, --output-dir <path>', 'Output directory')
.option('-s, --stdout', 'Output to stdout')
.usage('[options] [FILES...]')
.parse(process.argv);

Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"prettier": "^3.3.2",
"tempy": "^3.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
"typescript": "^5.5.4"
},
"dependencies": {
"commander": "^12.1.0"
Expand Down
8 changes: 7 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const cwd = process.cwd();
interface Ical2JsonOptions {
revert?: boolean;
outputDir?: string;
stdout?: boolean;
}

export default function (
Expand Down Expand Up @@ -62,7 +63,12 @@ export default function (
const compiledExt = isConvert ? '.json' : '.ics';
const writePath = path.join(dirname, basename) + compiledExt;

fs.writeFileSync(writePath, output);
if (options.stdout) {
console.log(output)

Check failure on line 67 in src/cli.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `;`

Check failure on line 67 in src/cli.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Insert `;`
}

Check failure on line 68 in src/cli.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `⏎···`

Check failure on line 68 in src/cli.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Delete `⏎···`
else {
fs.writeFileSync(writePath, output);
}
}

return true;
Expand Down

0 comments on commit feb2f90

Please sign in to comment.