Skip to content

Instantly share code, notes, and snippets.

@pawelgalazka
Last active November 12, 2017 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawelgalazka/883d165b744c1c0f053c75290a52f88f to your computer and use it in GitHub Desktop.
Save pawelgalazka/883d165b744c1c0f053c75290a52f88f to your computer and use it in GitHub Desktop.
code scaffolding - medium article
const fs = require('fs')
const path = require('path')
const dedent = require('dedent')
const { run } = require('runjs')
function createComponent(filePath) {
const dirName = path.basename(filePath)
const componentName = dirName.toUpperCase()
const content = dedent`
import React from 'react'
const ${componentName} = ({}) => {
return (
<div>
</div>
)
}
export default ${componentName}
`
run(`mkdir ${filePath}`)
console.log(`Creating file ${filePath}/index.js`)
fs.writeFileSync(`${filePath}/index.js`, content)
console.log('Done!')
}
module.exports = {
createComponent
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment