Last active
November 12, 2017 04:36
-
-
Save pawelgalazka/883d165b744c1c0f053c75290a52f88f to your computer and use it in GitHub Desktop.
code scaffolding - medium article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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