Skip to content

Commit

Permalink
refactor(generate): add fileName and ext for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuayoes committed Nov 19, 2022
1 parent d9b102b commit df119b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions boilerplate/bin/generate/component.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { dir } from "../tools/path.mjs"
import { update } from "../tools/patch.mjs"

const name = await question("Component name? ")
const fileName = name;
const ext = "tsx"

const file = prettier(
/*ts*/ `
Expand Down Expand Up @@ -48,6 +50,6 @@ const $text: TextStyle = {
{ Name: name },
)

await fs.writeFile(dir.components(`${name}.tsx`), file)
await fs.writeFile(dir.components(`${fileName}.${ext}`), file)

await update(dir.components("index.ts"), (file) => file + `export * from "./${name}"` + "\n")
await update(dir.components("index.ts"), (file) => file + `export * from "./${fileName}"` + "\n")
8 changes: 5 additions & 3 deletions boilerplate/bin/generate/model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { camelCase, prettier } from "../tools/string.mjs"
import { dir } from "../tools/path.mjs"

const name = await question("Model name? ")
const fileName = name;
const ext = "ts";

const file = prettier(
/*ts*/ `
Expand All @@ -28,9 +30,9 @@ export const createNameDefaultModel = () => types.optional(NameModel, {})
`,
{ Name: name },
)
await fs.writeFile(dir.models(`${name}.ts`), file)
await fs.writeFile(dir.models(`${fileName}.${ext}`), file)

await update(dir.models("index.ts"), (file) => file + `export * from "./${name}"` + "\n")
await update(dir.models("index.ts"), (file) => file + `export * from "./${fileName}"` + "\n")

if (!name.endsWith("Store")) {
process.exit(0)
Expand All @@ -39,7 +41,7 @@ if (!name.endsWith("Store")) {
await update(
dir.models("RootStore.ts"),
(file) =>
insert(file, `"mobx-state-tree"`, (s) => s + `\n` + `import { ${name}Model } from "./${name}"`),
insert(file, `"mobx-state-tree"`, (s) => s + `\n` + `import { ${name}Model } from "./${fileName}"`),
(file) =>
insert(
file,
Expand Down

0 comments on commit df119b6

Please sign in to comment.