diff --git a/utils/gen-component-script.ts b/utils/gen-component-script.ts index 3396f728..b357bb75 100644 --- a/utils/gen-component-script.ts +++ b/utils/gen-component-script.ts @@ -1,7 +1,11 @@ import fs from "fs"; import path from "path"; +import { promisify } from "util"; + import { component, story, test, barrel, type } from "./gen-component-template"; +const writeFile = promisify(fs.writeFile); + // Grab component name from terminal argument const [name] = process.argv.slice(2); if (!name) { @@ -30,41 +34,19 @@ if (fs.existsSync(dir)) { // Create the folder fs.mkdirSync(dir); -const writeFileErrorHandler = (err: Error | null) => { - if (err) { - throw err; - } -}; - // Create the component file - my-component.tsx -fs.writeFile( - `${dir}/${kebabCasedName}.tsx`, - component(name), - writeFileErrorHandler, -); +writeFile(`${dir}/${kebabCasedName}.tsx`, component(name)); // Create the type file - types.ts -fs.writeFile(`${dir}/types.ts`, type(name), writeFileErrorHandler); +writeFile(`${dir}/types.ts`, type(name)); // Create the test file - my-component.test.tsx -fs.writeFile( - `${dir}/${kebabCasedName}.test.tsx`, - test(name), - writeFileErrorHandler, -); +writeFile(`${dir}/${kebabCasedName}.test.tsx`, test(name)); // Create the Storybook file - my-component.stories.tsx -fs.writeFile( - `${dir}/${kebabCasedName}.stories.tsx`, - story(name), - writeFileErrorHandler, -); +writeFile(`${dir}/${kebabCasedName}.stories.tsx`, story(name)); // Create the barrel file - index.ts -fs.writeFile( - `${dir}/index.ts`, - barrel(name, kebabCasedName), - writeFileErrorHandler, -); +writeFile(`${dir}/index.ts`, barrel(name, kebabCasedName)); console.log(`The ${name} component has been created successfully! 🎉`);