src/files.js
function generateFiles(params) {
  const {
    type,
    name,
    fileNames,
    path,
    indexFile,
    cssExtension,
    componentMethods,
    jsExtension,
    connected,
    includeStories,
    includeTests,
  } = params
  const destination = `${path}/${name}`

  const { testFileName, componentFileName, styleFileName } = getFileNames(fileNames, name)

  if (indexFile || connected) {
    fs.outputFile(`${destination}/index.js`, generateIndexFile(componentFileName, connected))
  }

  if (includeStories) {
    fs.outputFile(`${destination}/${name}.stories.${jsExtension}`, generateStorybookTemplate(name))
  }

  if (includeTests) {
    fs.outputFile(`${destination}/${testFileName}.${jsExtension}`, generateTestTemplate(name))
  }

  // Create js file
  fs.outputFile(
    `${destination}/${componentFileName}.${jsExtension}`,
    generateComponentTemplate(type, componentFileName, {
      cssExtension,
      componentMethods,
      styleFileName,
    })
  )

  // Create css file
  if (cssExtension) {
    fs.outputFile(
      `${destination}/${styleFileName}.${cssExtension}`,
      generateStyleFile(styleFileName)
    )
  }
}
function generateFiles(params) {
  const {
    type,
    name,
    fileNames,
    path,
    indexFile,
    cssExtension,
    componentMethods,
    jsExtension,
    connected,
    includeStories,
    includeTests,
  } = params
  const destination = `${path}/${name}`

  const { testFileName, componentFileName, styleFileName } = getFileNames(fileNames, name)

  if (indexFile || connected) {
    fs.outputFile(`${destination}/index.js`, generateIndexFile(componentFileName, connected))
  }

  if (includeStories) {
    fs.outputFile(`${destination}/${name}.stories.${jsExtension}`, generateStorybookTemplate(name))
  }

  if (includeTests) {
    fs.outputFile(`${destination}/${testFileName}.${jsExtension}`, generateTestTemplate(name))
  }

  // Create js file
  fs.outputFile(
    `${destination}/${componentFileName}.${jsExtension}`,
    generateComponentTemplate(type, componentFileName, {
      cssExtension,
      componentMethods,
      styleFileName,
    })
  )

  // Create css file
  if (cssExtension) {
    fs.outputFile(
      `${destination}/${styleFileName}.${cssExtension}`,
      generateStyleFile(styleFileName)
    )
  }
}
function generateFiles ( params ) { const { type , name , fileNames , path , indexFile , cssExtension , componentMethods , jsExtension , connected , includeStories , includeTests , } = params const destination = ` ${ path } ${ name } ` const { testFileName , componentFileName , styleFileName } = getFileNames ( fileNames , name ) if ( indexFile || connected ) { fs . outputFile ( ` ${ destination } ` , generateIndexFile ( componentFileName , connected ) ) } if ( includeStories ) { fs . outputFile ( ` ${ destination } ${ name } ${ jsExtension } ` , generateStorybookTemplate ( name ) ) } if ( includeTests ) { fs . outputFile ( ` ${ destination } ${ testFileName } ${ jsExtension } ` , generateTestTemplate ( name ) ) } // Create js file fs . outputFile ( ` ${ destination } ${ componentFileName } ${ jsExtension } ` , generateComponentTemplate ( type , componentFileName , { cssExtension , componentMethods , styleFileName , } ) ) // Create css file if ( cssExtension ) { fs . outputFile ( ` ${ destination } ${ styleFileName } ${ cssExtension } ` , generateStyleFile ( styleFileName ) ) } }
Generate component files

@param {object} params object with:
@param {string} type: the type of component template
@param {object} fileNames: object that contains the filenames to replace
@param {string} name: the name of the component used to create folder and file
@param {string} path: where the component folder is created
@param {string} cssExtension: the extension of the css file
@param {string} jsExtension: the extension of the component file
@param {array} componentMethods: Array of strings of methods to include in a class component
@param {boolean} indexFile: include or not an index file
@param {boolean} connected: include or not the connect function of redux
@param {boolean} includeStories: include or not the storybook file
@param {boolean} includeTests: include or not the test file
Generate component files