Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function generateComponent({ name, path, templates }) {
- try {
- const files = glob.sync('**/*', { cwd: templates, nodir: true })
- const config = getConfig(null, templates, templates)
- const output = config.noMkdir ? `${path}` : `${path}/${name}`
- files.map(async (name) => {
- // Get the template content
- const content = await readFile(templates, name)
- const replacement = content.replace(/COMPONENT_NAME/g, name)
- const newFileName = generateFileName(name, name)
- fs.outputFile(`${output}/${newFileName}`, replacement)
- })
- } catch (e) {
- Logger.error(e.message)
- }
- }
- async function startComponentGenerator(templates) {
- try {
- const { path } = config
- const componentConfig = await inquirer.prompt(
- [questions.name, path ? undefined : questions.path].filter(
- question => question
- )
- )
- const results = {
- ...config,
- ...componentConfig,
- templates,
- }
- generateComponent(results)
- } catch (error) {
- Logger.error(error.message)
- }
- }
Add Comment
Please, Sign In to add comment