From 78d3a5312d2f790ee3ad8477798320dd1d817db8 Mon Sep 17 00:00:00 2001 From: takuma-ru Date: Wed, 3 Apr 2024 16:41:54 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Integrate=20genStoryFile?= =?UTF-8?q?=20and=20runGenStoryFile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .scripts/release.cjs | 10 +- packages/auto-story-generator/.release-it.cjs | 18 - packages/auto-story-generator/package.json | 11 +- .../src/constants/error.ts | 2 +- .../src/core/genStoryFile.ts | 462 ++++++++++++------ .../src/core/runGenStoryFile.ts | 138 ------ packages/auto-story-generator/src/index.ts | 6 +- .../src/presets/lit/genLitStoryFile.ts | 9 +- .../src/presets/react/genReactStoryFile.ts | 9 +- .../src/types/{error.ts => ErrorType.ts} | 0 .../src/types/GenStoryFileType.ts | 8 +- 11 files changed, 335 insertions(+), 338 deletions(-) delete mode 100644 packages/auto-story-generator/.release-it.cjs delete mode 100644 packages/auto-story-generator/src/core/runGenStoryFile.ts rename packages/auto-story-generator/src/types/{error.ts => ErrorType.ts} (100%) diff --git a/.scripts/release.cjs b/.scripts/release.cjs index 3f8bc5d..fc762c6 100644 --- a/.scripts/release.cjs +++ b/.scripts/release.cjs @@ -13,6 +13,11 @@ const packageJsonPath = path.join( ); try { + // Create a new branch and push it to origin + const branchName = `release/${new Date().toISOString().replace(/[-:.]/g, "")}`; + execSync(`git checkout -b ${branchName}`); + execSync(`git push --set-upstream origin ${branchName}`); + // Read the package.json file const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); @@ -48,11 +53,6 @@ try { // Write the updated package.json back to file fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); - // Create a new branch and push it to origin - const branchName = `release/${new Date().toISOString().replace(/[-:.]/g, "")}`; - execSync(`git checkout -b ${branchName}`); - execSync(`git push --set-upstream origin ${branchName}`); - // Build the package execSync("pnpm asg build", { stdio: "inherit" }); diff --git a/packages/auto-story-generator/.release-it.cjs b/packages/auto-story-generator/.release-it.cjs deleted file mode 100644 index ae1b575..0000000 --- a/packages/auto-story-generator/.release-it.cjs +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - npm: { - publish: true, - }, - /* github: { - release: true, - }, */ - git: { - tag: false, - requireCleanWorkingDir: false, - commitMessage: - ":bookmark: release @takuma-ru/auto-story-generator@${version}", - }, - /* hooks: { - "after:git:release": "git pull origin ${version}", - }, */ - plugins: {}, -}; diff --git a/packages/auto-story-generator/package.json b/packages/auto-story-generator/package.json index 119f8e8..0a6d0ac 100644 --- a/packages/auto-story-generator/package.json +++ b/packages/auto-story-generator/package.json @@ -30,14 +30,7 @@ "lint:fix": "eslint --ext .ts,.js . --fix", "lint:type-check": "tsc --noEmit", "format": "prettier --write .", - "format:check": "prettier --check .", - "publish:major": "pnpm build && pnpm dlx release-it major --ci -VV", - "publish:minor": "pnpm build && pnpm dlx release-it minor --ci -VV", - "publish:patch": "pnpm build && pnpm dlx release-it patch --ci -VV", - "publish:major-beta": "pnpm build && pnpm dlx release-it major --preRelease=beta --ci -VV", - "publish:minor-beta": "pnpm build && pnpm dlx release-it minor --preRelease=beta --ci -VV", - "publish:patch-beta": "pnpm build && pnpm dlx release-it patch --preRelease=beta --ci -VV", - "publish:prerelease": "pnpm build && pnpm dlx release-it --preRelease --ci -VV" + "format:check": "prettier --check ." }, "keywords": [ "storybook", @@ -82,4 +75,4 @@ "tsup": "^8.0.1", "typescript": "^5.3.3" } -} \ No newline at end of file +} diff --git a/packages/auto-story-generator/src/constants/error.ts b/packages/auto-story-generator/src/constants/error.ts index 4487dcd..9136d57 100644 --- a/packages/auto-story-generator/src/constants/error.ts +++ b/packages/auto-story-generator/src/constants/error.ts @@ -1,4 +1,4 @@ -import { ErrorType } from "~/src/types/error"; +import { ErrorType } from "~/src/types/ErrorType"; export const errorDefinition = { // Common diff --git a/packages/auto-story-generator/src/core/genStoryFile.ts b/packages/auto-story-generator/src/core/genStoryFile.ts index 8defbc1..ccbb0d7 100644 --- a/packages/auto-story-generator/src/core/genStoryFile.ts +++ b/packages/auto-story-generator/src/core/genStoryFile.ts @@ -1,217 +1,381 @@ import fs from "fs"; -import { consola } from "consola"; +import consola from "consola"; +import { loadFile } from "magicast"; +import { minimatch } from "minimatch"; import * as prettier from "prettier"; import { Project, SyntaxKind } from "ts-morph"; +import { UnpluginOptions } from "unplugin"; +import { getComponentInfo } from "~/src/core/getComponentInfo"; +import { genLitStoryFile } from "~/src/presets/lit/genLitStoryFile"; +import { genReactStoryFile } from "~/src/presets/react/genReactStoryFile"; import { GenStoryFileOptions } from "~/src/types/GenStoryFileType"; +import { Options } from "~/src/types/Options"; import { throwErr } from "~/src/utils/throwError"; export const genStoryFile = async ({ - fileOptions, - generateOptions, -}: GenStoryFileOptions) => { - const storiesFilePath = fileOptions.path.replace( - fileOptions.filePrefixExt - ? fileOptions.filePrefixExt - : "" + fileOptions.fileExt, - generateOptions.fileExt, - ); - - fs.open(storiesFilePath, "r", async (err) => { - // ファイルを開けなかったらファイルを作成する - if (err) { - // 同期処理でファイルを作成する - fs.writeFileSync(storiesFilePath, generateOptions.initialCode); - } - - const storiesProject = new Project(); - - // ファイルを読み込む - const storiesSourceFile = - storiesProject.addSourceFileAtPath(storiesFilePath); - - // stories.ts内のmetaを取得する - const meta = storiesSourceFile.getVariableDeclaration("meta"); + options, + id, + projectRootDir, +}: { + options: Options; + id: Parameters>[0]; + projectRootDir: ReturnType; +}) => { + if (id.includes(".stories")) return; + + const hasGenFile = () => { + let relativeSourceFilePath = id.replace(projectRootDir, ""); if ( - !meta || - !meta.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression) + relativeSourceFilePath.startsWith("/") || + relativeSourceFilePath.startsWith("\\") ) { - throwErr({ - errorCode: "EC05", - detail: `Could not find meta in file ${storiesSourceFile.getFilePath()}`, - }); - - return; + relativeSourceFilePath = id.replace(projectRootDir, "").slice(1); } - const initializer = meta.getInitializerIfKindOrThrow( - SyntaxKind.ObjectLiteralExpression, - ); + const isMatchImports = options.imports + ? options.imports.some((importDir) => + minimatch(relativeSourceFilePath, importDir), + ) + : true; + + const isMatchIgnores = options.ignores + ? options.ignores.some((ignorePath) => + minimatch(relativeSourceFilePath, ignorePath), + ) + : false; + + return isMatchImports && !isMatchIgnores; + }; + const isGenFile = hasGenFile(); + + if (!isGenFile) return; + + const { + fileBase, + fileName, + fileExt, + filePrefixExt, + componentName, + relativeSourceFilePath, + } = getComponentInfo(id); + + try { + const mod = await loadFile(id); + const project = new Project(); + const sourceFile = project.createSourceFile(fileBase || "", mod.$code); + + consola.start(`${componentName} Story file is being generated ....`); + + let genStoryFileOptions: GenStoryFileOptions | undefined = undefined; + + switch (options.preset) { + case "lit": { + genStoryFileOptions = await genLitStoryFile({ + componentName: componentName, + fileBase: fileBase, + fileName: fileName, + path: id, + fileExt: fileExt, + filePrefixExt: filePrefixExt, + relativeSourceFilePath: relativeSourceFilePath, + sourceFile: sourceFile, + prettierConfigPath: options.prettierConfigPath, + }); - if (!initializer) { - throwErr({ - errorCode: "EC06", - }); + break; + } - return; - } + case "react": { + genStoryFileOptions = await genReactStoryFile({ + componentName: componentName, + fileBase: fileBase, + fileName: fileName, + path: id, + fileExt: fileExt, + filePrefixExt: filePrefixExt, + relativeSourceFilePath: relativeSourceFilePath, + sourceFile: sourceFile, + prettierConfigPath: options.prettierConfigPath, + }); - if (generateOptions.meta.render) { - // metaのrenderオブジェクトを取得する - let renderProperty = initializer.getProperty("render"); + break; + } - while (!renderProperty) { - initializer.addPropertyAssignment({ - name: "render", - initializer: "() => {}", + case "vue": { + throwErr({ + errorCode: "EC01", }); - renderProperty = initializer.getProperty("render"); + break; } - if (!renderProperty) { + case "angular": { throwErr({ - errorCode: "EC10", - detail: `Could not find render in file ${storiesSourceFile.getFilePath()}`, + errorCode: "EC01", }); - return; + break; } - // renderオブジェクトの値を書き換える - renderProperty.set({ - initializer: generateOptions.meta.render, - }); - } + case "custom": { + throwErr({ + errorCode: "EC01", + }); - if (generateOptions.meta.component) { - // metaのcomponentオブジェクトを取得する - let componentProperty = initializer.getProperty("component"); + break; + } - while (!componentProperty) { - initializer.addPropertyAssignment({ - name: "component", - initializer: "null", + default: { + throwErr({ + errorCode: "EC02", + detail: `Preset ${options.preset} is not supported. Please use one of the following: lit, react, vue, angular, custom`, }); - - componentProperty = initializer.getProperty("component"); } + } + + if (!genStoryFileOptions) { + throwErr({ + errorCode: "EC03", + }); + + return; + } - if (!componentProperty) { + const storiesFilePath = genStoryFileOptions.fileOptions.path.replace( + genStoryFileOptions.fileOptions.filePrefixExt + ? genStoryFileOptions.fileOptions.filePrefixExt + : "" + genStoryFileOptions.fileOptions.fileExt, + genStoryFileOptions.generateOptions.fileExt, + ); + + fs.open(storiesFilePath, "r", async (err) => { + if (!genStoryFileOptions) { throwErr({ - errorCode: "EC10", - detail: `Could not find component in file ${storiesSourceFile.getFilePath()}`, + errorCode: "EC03", }); return; } - // componentオブジェクトの値を書き換える - componentProperty.set({ - initializer: generateOptions.meta.component, - }); - } + // ファイルを開けなかったらファイルを作成する + if (err) { + // 同期処理でファイルを作成する + fs.writeFileSync( + storiesFilePath, + genStoryFileOptions.generateOptions.initialCode, + ); + } + + const storiesProject = new Project(); - if (generateOptions.meta.args) { - // metaのargsオブジェクトを取得する - let argsProperty = initializer.getProperty("args"); + // ファイルを読み込む + const storiesSourceFile = + storiesProject.addSourceFileAtPath(storiesFilePath); - while (!argsProperty) { - initializer.addPropertyAssignment({ - name: "args", - initializer: "{}", + // stories.ts内のmetaを取得する + const meta = storiesSourceFile.getVariableDeclaration("meta"); + + if ( + !meta || + !meta.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression) + ) { + throwErr({ + errorCode: "EC05", + detail: `Could not find meta in file ${storiesSourceFile.getFilePath()}`, }); - argsProperty = initializer.getProperty("args"); + return; } - if (!argsProperty) { + const initializer = meta.getInitializerIfKindOrThrow( + SyntaxKind.ObjectLiteralExpression, + ); + + if (!initializer) { throwErr({ - errorCode: "EC10", - detail: `Could not find args in file ${storiesSourceFile.getFilePath()}`, + errorCode: "EC06", }); return; } - const argText = Object.entries(generateOptions.meta.args) - .map((x) => x.join(":")) - .join(", "); + if (genStoryFileOptions.generateOptions.meta.render) { + // metaのrenderオブジェクトを取得する + let renderProperty = initializer.getProperty("render"); - argsProperty.set({ - initializer: `{ ${argText} }`, - }); - } + while (!renderProperty) { + initializer.addPropertyAssignment({ + name: "render", + initializer: "() => {}", + }); - if (generateOptions.meta.argTypes) { - let argTypesProperty = initializer.getProperty("argTypes"); + renderProperty = initializer.getProperty("render"); + } - while (!argTypesProperty) { - initializer.addPropertyAssignment({ - name: "argTypes", - initializer: "{}", - }); + if (!renderProperty) { + throwErr({ + errorCode: "EC10", + detail: `Could not find render in file ${storiesSourceFile.getFilePath()}`, + }); + + return; + } - argTypesProperty = initializer.getProperty("argTypes"); + // renderオブジェクトの値を書き換える + renderProperty.set({ + initializer: genStoryFileOptions.generateOptions.meta.render, + }); } - if (!argTypesProperty) { - throwErr({ - errorCode: "EC10", - detail: `Could not find argTypes in file ${storiesSourceFile.getFilePath()}`, + if (genStoryFileOptions.generateOptions.meta.component) { + // metaのcomponentオブジェクトを取得する + let componentProperty = initializer.getProperty("component"); + + while (!componentProperty) { + initializer.addPropertyAssignment({ + name: "component", + initializer: "null", + }); + + componentProperty = initializer.getProperty("component"); + } + + if (!componentProperty) { + throwErr({ + errorCode: "EC10", + detail: `Could not find component in file ${storiesSourceFile.getFilePath()}`, + }); + + return; + } + + // componentオブジェクトの値を書き換える + componentProperty.set({ + initializer: genStoryFileOptions.generateOptions.meta.component, }); + } - return; + if (genStoryFileOptions.generateOptions.meta.args) { + // metaのargsオブジェクトを取得する + let argsProperty = initializer.getProperty("args"); + + while (!argsProperty) { + initializer.addPropertyAssignment({ + name: "args", + initializer: "{}", + }); + + argsProperty = initializer.getProperty("args"); + } + + if (!argsProperty) { + throwErr({ + errorCode: "EC10", + detail: `Could not find args in file ${storiesSourceFile.getFilePath()}`, + }); + + return; + } + + const argText = Object.entries( + genStoryFileOptions.generateOptions.meta.args, + ) + .map((x) => x.join(":")) + .join(", "); + + argsProperty.set({ + initializer: `{ ${argText} }`, + }); } - const argTypesText = JSON.stringify( - generateOptions.meta.argTypes, - null, - "", - ); + if (genStoryFileOptions.generateOptions.meta.argTypes) { + let argTypesProperty = initializer.getProperty("argTypes"); - argTypesProperty.set({ - initializer: `${argTypesText}`, - }); - } + while (!argTypesProperty) { + initializer.addPropertyAssignment({ + name: "argTypes", + initializer: "{}", + }); + + argTypesProperty = initializer.getProperty("argTypes"); + } + + if (!argTypesProperty) { + throwErr({ + errorCode: "EC10", + detail: `Could not find argTypes in file ${storiesSourceFile.getFilePath()}`, + }); - // ファイルを保存する - await storiesProject - .save() - .then(async () => { - consola.success( - `Successfully updated args in ${storiesSourceFile.getFilePath()}`, + return; + } + + const argTypesText = JSON.stringify( + genStoryFileOptions.generateOptions.meta.argTypes, + null, + "", ); - const fileContent = fs.readFileSync(storiesFilePath, "utf-8"); - - const config: prettier.Options | null = fileOptions.prettierConfigPath - ? await prettier.resolveConfig(fileOptions.prettierConfigPath) - : { - semi: true, - trailingComma: "all", - singleQuote: false, - printWidth: 80, - tabWidth: 2, - endOfLine: "lf", - }; - - // Format the content using Prettier - const formattedContent = await prettier.format(fileContent, { - ...config, - parser: "typescript", + argTypesProperty.set({ + initializer: `${argTypesText}`, }); + } - // Write the formatted content back to the file - fs.writeFileSync(storiesFilePath, formattedContent); - }) - .catch((err) => { - throwErr({ - errorCode: "EC07", - detail: err, + // ファイルを保存する + await storiesProject + .save() + .then(async () => { + consola.success( + `Successfully updated args in ${storiesSourceFile.getFilePath()}`, + ); + + const fileContent = fs.readFileSync(storiesFilePath, "utf-8"); + + if (!genStoryFileOptions) { + throwErr({ + errorCode: "EC03", + }); + + return; + } + + const config: prettier.Options | null = genStoryFileOptions + .fileOptions.prettierConfigPath + ? await prettier.resolveConfig( + genStoryFileOptions.fileOptions.prettierConfigPath, + ) + : { + semi: true, + trailingComma: "all", + singleQuote: false, + printWidth: 80, + tabWidth: 2, + endOfLine: "lf", + }; + + // Format the content using Prettier + const formattedContent = await prettier.format(fileContent, { + ...config, + parser: "typescript", + }); + + // Write the formatted content back to the file + fs.writeFileSync(storiesFilePath, formattedContent); + }) + .catch((err) => { + throwErr({ + errorCode: "EC07", + detail: err, + }); }); - }); - }); + }); + } catch (err) { + throwErr({ + errorCode: "EC11", + }); + + return; + } }; diff --git a/packages/auto-story-generator/src/core/runGenStoryFile.ts b/packages/auto-story-generator/src/core/runGenStoryFile.ts deleted file mode 100644 index aa33e5c..0000000 --- a/packages/auto-story-generator/src/core/runGenStoryFile.ts +++ /dev/null @@ -1,138 +0,0 @@ -import consola from "consola"; -import { loadFile } from "magicast"; -import { minimatch } from "minimatch"; -import { Project } from "ts-morph"; -import { UnpluginOptions } from "unplugin"; - -import { getComponentInfo } from "~/src/core/getComponentInfo"; -import { genLitStoryFile } from "~/src/presets/lit/genLitStoryFile"; -import { genReactStoryFile } from "~/src/presets/react/genReactStoryFile"; -import { Options } from "~/src/types/Options"; -import { throwErr } from "~/src/utils/throwError"; - -export const runGenStoryFile = async ({ - options, - id, - projectRootDir, -}: { - options: Options; - id: Parameters>[0]; - projectRootDir: ReturnType; -}) => { - if (id.includes(".stories")) return; - - const isGenFile = () => { - let relativeSourceFilePath = id.replace(projectRootDir, ""); - - if ( - relativeSourceFilePath.startsWith("/") || - relativeSourceFilePath.startsWith("\\") - ) { - relativeSourceFilePath = id.replace(projectRootDir, "").slice(1); - } - - const isMatchImports = options.imports - ? options.imports.some((importDir) => - minimatch(relativeSourceFilePath, importDir), - ) - : true; - - const isMatchIgnores = options.ignores - ? options.ignores.some((ignorePath) => - minimatch(relativeSourceFilePath, ignorePath), - ) - : false; - - return isMatchImports && !isMatchIgnores; - }; - - if (!isGenFile()) return; - - const { - fileBase, - fileName, - fileExt, - filePrefixExt, - componentName, - relativeSourceFilePath, - } = getComponentInfo(id); - - try { - const mod = await loadFile(id); - const project = new Project(); - const sourceFile = project.createSourceFile(fileBase || "", mod.$code); - - consola.start(`${componentName} Story file is being generated ....`); - - switch (options.preset) { - case "lit": { - await genLitStoryFile({ - componentName: componentName, - fileBase: fileBase, - fileName: fileName, - path: id, - fileExt: fileExt, - filePrefixExt: filePrefixExt, - relativeSourceFilePath: relativeSourceFilePath, - sourceFile: sourceFile, - prettierConfigPath: options.prettierConfigPath, - }); - - break; - } - - case "react": { - await genReactStoryFile({ - componentName: componentName, - fileBase: fileBase, - fileName: fileName, - path: id, - fileExt: fileExt, - filePrefixExt: filePrefixExt, - relativeSourceFilePath: relativeSourceFilePath, - sourceFile: sourceFile, - prettierConfigPath: options.prettierConfigPath, - }); - - break; - } - - case "vue": { - throwErr({ - errorCode: "EC01", - }); - - break; - } - - case "angular": { - throwErr({ - errorCode: "EC01", - }); - - break; - } - - case "custom": { - throwErr({ - errorCode: "EC01", - }); - - break; - } - - default: { - throwErr({ - errorCode: "EC02", - detail: `Preset ${options.preset} is not supported. Please use one of the following: lit, react, vue, angular, custom`, - }); - } - } - } catch (err) { - throwErr({ - errorCode: "EC11", - }); - - return; - } -}; diff --git a/packages/auto-story-generator/src/index.ts b/packages/auto-story-generator/src/index.ts index 6f575d7..6937d3a 100644 --- a/packages/auto-story-generator/src/index.ts +++ b/packages/auto-story-generator/src/index.ts @@ -5,7 +5,7 @@ import { sync } from "glob"; import { from, mergeMap } from "rxjs"; import { createUnplugin } from "unplugin"; -import { runGenStoryFile } from "~/src/core/runGenStoryFile"; +import { genStoryFile } from "~/src/core/genStoryFile"; import { Options } from "~/src/types/Options"; import { getAllFilePaths } from "~/src/utils/getAllFilePaths"; @@ -34,7 +34,7 @@ const unplugin = createUnplugin((options: Options, meta) => { from(allFiles) .pipe( mergeMap(async (filePath) => { - await runGenStoryFile({ + await genStoryFile({ options, id: filePath, projectRootDir, @@ -50,7 +50,7 @@ const unplugin = createUnplugin((options: Options, meta) => { async watchChange(this, id, change) { if (change.event === "delete") return; - await runGenStoryFile({ options, id, projectRootDir }); + await genStoryFile({ options, id, projectRootDir }); }, webpack: (compiler) => { diff --git a/packages/auto-story-generator/src/presets/lit/genLitStoryFile.ts b/packages/auto-story-generator/src/presets/lit/genLitStoryFile.ts index 916cde2..8461651 100644 --- a/packages/auto-story-generator/src/presets/lit/genLitStoryFile.ts +++ b/packages/auto-story-generator/src/presets/lit/genLitStoryFile.ts @@ -1,6 +1,5 @@ import { kebabCase, pascalCase } from "scule"; -import { genStoryFile } from "~/src/core/genStoryFile"; import { getLitPropTypes } from "~/src/presets/lit/getLitPropTypes"; import { GenStoryFileOptions } from "~/src/types/GenStoryFileType"; import { throwErr } from "~/src/utils/throwError"; @@ -15,7 +14,9 @@ export const genLitStoryFile = async ({ relativeSourceFilePath, sourceFile, prettierConfigPath, -}: GenStoryFileOptions["fileOptions"]) => { +}: GenStoryFileOptions["fileOptions"]): Promise< + GenStoryFileOptions | undefined +> => { if (!componentName || !fileBase) { throwErr({ errorCode: "EC03", @@ -141,7 +142,7 @@ export const Primary: ${pascalComponentName}Story = {}; } }); - genStoryFile({ + return { fileOptions: { componentName, fileBase, @@ -162,5 +163,5 @@ export const Primary: ${pascalComponentName}Story = {}; argTypes, }, }, - }); + }; }; diff --git a/packages/auto-story-generator/src/presets/react/genReactStoryFile.ts b/packages/auto-story-generator/src/presets/react/genReactStoryFile.ts index 137eab1..c2b7adb 100644 --- a/packages/auto-story-generator/src/presets/react/genReactStoryFile.ts +++ b/packages/auto-story-generator/src/presets/react/genReactStoryFile.ts @@ -1,6 +1,5 @@ import { pascalCase } from "scule"; -import { genStoryFile } from "~/src/core/genStoryFile"; import { getReactPropTypes } from "~/src/presets/react/getReactPropTypes"; import { GenStoryFileOptions } from "~/src/types/GenStoryFileType"; import { throwErr } from "~/src/utils/throwError"; @@ -15,7 +14,9 @@ export const genReactStoryFile = async ({ relativeSourceFilePath, sourceFile, prettierConfigPath, -}: GenStoryFileOptions["fileOptions"]) => { +}: GenStoryFileOptions["fileOptions"]): Promise< + GenStoryFileOptions | undefined +> => { if (!componentName || !fileBase) { throwErr({ errorCode: "EC03", @@ -123,7 +124,7 @@ export const Primary: Story = {}; } }); - genStoryFile({ + return { fileOptions: { componentName, fileBase, @@ -144,5 +145,5 @@ export const Primary: Story = {}; argTypes, }, }, - }); + }; }; diff --git a/packages/auto-story-generator/src/types/error.ts b/packages/auto-story-generator/src/types/ErrorType.ts similarity index 100% rename from packages/auto-story-generator/src/types/error.ts rename to packages/auto-story-generator/src/types/ErrorType.ts diff --git a/packages/auto-story-generator/src/types/GenStoryFileType.ts b/packages/auto-story-generator/src/types/GenStoryFileType.ts index bc4170b..34d788c 100644 --- a/packages/auto-story-generator/src/types/GenStoryFileType.ts +++ b/packages/auto-story-generator/src/types/GenStoryFileType.ts @@ -5,16 +5,10 @@ import { Options } from "~/src/types/Options"; export type GenStoryFileOptions = { fileOptions: { - componentName: GetComponentInfoReturnType["componentName"]; - fileBase: GetComponentInfoReturnType["fileBase"]; - fileName: GetComponentInfoReturnType["fileName"]; - fileExt: GetComponentInfoReturnType["fileExt"]; - filePrefixExt: GetComponentInfoReturnType["filePrefixExt"]; - relativeSourceFilePath: GetComponentInfoReturnType["relativeSourceFilePath"]; path: string; sourceFile: SourceFile; prettierConfigPath?: Options["prettierConfigPath"]; - }; + } & GetComponentInfoReturnType; generateOptions: { fileExt: `.stories.${string}`; initialCode: string;