import type { Tree } from '@nrwl/devkit'; import { generateFiles, joinPathFragments } from '@nrwl/devkit'; import { getComponentProps } from '../utils/storybook'; import { getKnobDefaultValue } from './lib/get-knob-default-value'; import type { ComponentStoryGeneratorOptions } from './schema'; export function componentStoryGenerator( tree: Tree, options: ComponentStoryGeneratorOptions ): void { const { componentFileName, componentName, componentPath, projectPath, } = options; const templatesDir = joinPathFragments(__dirname, 'files'); const destinationDir = joinPathFragments(projectPath, componentPath); const storyFile = joinPathFragments( destinationDir, `${componentFileName}.stories.ts` ); if (tree.exists(storyFile)) { return; } const props = getComponentProps( tree, joinPathFragments(destinationDir, `${componentFileName}.ts`), getKnobDefaultValue ); generateFiles(tree, templatesDir, destinationDir, { componentFileName: componentFileName, componentName: componentName, props, tmpl: '', }); } export default componentStoryGenerator;