import * as _ from "lodash"; import * as fs from "fs-extra"; import { generateAttributes } from "../classBlocks"; export const generateComponentStoriesTsx = (data: any) => { const { filteredComponents, componentFolder, templateFolder, name, type, } = data; const featureName = name; const featureType = type; // component | module fs.readFile( `${templateFolder}/components/component.template/Component.stories.tsx.template`, "utf8", (err, data) => { if (err) return console.log(err); // loop over array of components _.forEach(filteredComponents, (component) => { // grab [name] from the item in the loop // grab [description] from the item in the loop const { name, description, type } = component; // pass in [name], [description] to component.template/Component.stories.tsx.template const componentStoriesTsx = _.template(data)({ name, description, featureName, featureType, type, attributesBlock: generateAttributes(component["schema"]), }); // save result to {outFolder}/components/[Name]/[Name].tsx fs.outputFile( `${componentFolder}/${name}/${name}.stories.tsx`, componentStoriesTsx ); }); } ); };