Skip to content

Commit

Permalink
Merge pull request #48 from Ubugeeei/39-tweak-cli-options
Browse files Browse the repository at this point in the history
tweak: #39 🔧 if cjs option is true, ts option is ignored
  • Loading branch information
ubugeeei authored Oct 17, 2023
2 parents 1307b5c + a16a603 commit 7846360
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"datagen": "node ../../packages/cli/bin/bin.js datagen",
"datagen:ts": "pnpm run datagen -d=dataset -o=out/data.ts",
"datagen:js": "pnpm run datagen -d=dataset -o=out/data.js --ts=false",
"datagen:cjs": "pnpm run datagen -d=dataset -o=out/data.cjs --ts=false --cjs",
"datagen:cjs": "pnpm run datagen -d=dataset -o=out/data.cjs --cjs",
"datagen:named": "pnpm run datagen -d=dataset -o=out/named.ts --n=MY_TEGAKI_DATA"
},
"author": "Ubugeeei <ubuge1122@gmail.com>",
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/cmd/datagen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export const datagen = defineCommand({
default: "TEGAKI_DATA_SET",
},
ts: {
description: "use typescript",
description: "use typescript. if cjs option is true, this option is ignored",
type: "boolean",
default: true,
},
cjs: {
description: "use commonjs. if ts option is true, this option is ignored",
description: "use commonjs.",
type: "boolean",
default: false,
},
Expand All @@ -59,10 +59,11 @@ export const datagen = defineCommand({

type CodegenOptions = { ts: boolean; cjs: boolean; exportName: string };
const codegen = (parsed: TegakiStroke[], { ts, cjs, exportName }: CodegenOptions): string => {
const asTs = ts && !cjs;
const code = `/// This file is generated by tegaki-cli. Do not edit this file directly
${ts ? 'import type { TegakiStroke } from "@tegaki/shared";' : ""}
${asTs ? 'import type { TegakiStroke } from "@tegaki/shared";' : ""}
${cjs ? `module.exports.${exportName}` : `export const ${exportName}`}${
ts ? ": Array<TegakiStroke>" : ""
asTs ? ": Array<TegakiStroke>" : ""
} = ${JSON.stringify(parsed)};
`;
return code;
Expand Down

0 comments on commit 7846360

Please sign in to comment.