Skip to content

Commit b410872

Browse files
author
Denis Bardadym
committed
Add open option to cli and make CLI use strict mode
1 parent e1b03a0 commit b410872

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

bin/cli.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { promises as fs } from "fs";
44
import path from "path";
55

6+
import opn from "open";
67
import yargs from "yargs";
78
import { hideBin } from "yargs/helpers";
89

@@ -34,6 +35,12 @@ const argv = yargs(hideBin(process.argv))
3435
type: "boolean",
3536
default: false,
3637
})
38+
.option("open", {
39+
describe: "Open generated tempate in default user agent",
40+
type: "boolean",
41+
default: false,
42+
})
43+
.strict()
3744
.help()
3845
.parseSync();
3946

@@ -44,9 +51,10 @@ interface CliArgs {
4451
title: string;
4552
template: TemplateType;
4653
sourcemap: boolean;
54+
open: boolean;
4755
}
4856

49-
const runForPluginJson = async ({ title, template, filename }: CliArgs, files: string[]) => {
57+
const runForPluginJson = async ({ title, template, filename, open }: CliArgs, files: string[]) => {
5058
if (files.length === 0) {
5159
throw new Error("Empty file list");
5260
}
@@ -57,7 +65,7 @@ const runForPluginJson = async ({ title, template, filename }: CliArgs, files: s
5765
const data = JSON.parse(textContent) as VisualizerData;
5866

5967
return { file, data };
60-
})
68+
}),
6169
);
6270

6371
const tree: ModuleTree = {
@@ -70,7 +78,7 @@ const runForPluginJson = async ({ title, template, filename }: CliArgs, files: s
7078
for (const { file, data } of fileContents) {
7179
if (data.version !== version) {
7280
warn(
73-
`Version in ${file} is not supported (${data.version}). Current version ${version}. Skipping...`
81+
`Version in ${file} is not supported (${data.version}). Current version ${version}. Skipping...`,
7482
);
7583
continue;
7684
}
@@ -106,6 +114,10 @@ const runForPluginJson = async ({ title, template, filename }: CliArgs, files: s
106114
// ignore
107115
}
108116
await fs.writeFile(filename, fileContent);
117+
118+
if (open) {
119+
await opn(filename);
120+
}
109121
};
110122

111123
runForPluginJson(argv, listOfFiles as string[]).catch((err: Error) => {

0 commit comments

Comments
 (0)