Guest User

Untitled

a guest
Jan 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. async function generateComponent({ name, path, templates }) {
  2. try {
  3. const files = glob.sync('**/*', { cwd: templates, nodir: true })
  4. const config = getConfig(null, templates, templates)
  5. const output = config.noMkdir ? `${path}` : `${path}/${name}`
  6. files.map(async (name) => {
  7. // Get the template content
  8. const content = await readFile(templates, name)
  9. const replacement = content.replace(/COMPONENT_NAME/g, name)
  10.  
  11. const newFileName = generateFileName(name, name)
  12.  
  13. fs.outputFile(`${output}/${newFileName}`, replacement)
  14. })
  15. } catch (e) {
  16. Logger.error(e.message)
  17. }
  18. }
  19.  
  20. async function startComponentGenerator(templates) {
  21. try {
  22. const { path } = config
  23. const componentConfig = await inquirer.prompt(
  24. [questions.name, path ? undefined : questions.path].filter(
  25. question => question
  26. )
  27. )
  28.  
  29. const results = {
  30. ...config,
  31. ...componentConfig,
  32. templates,
  33. }
  34.  
  35. generateComponent(results)
  36. } catch (error) {
  37. Logger.error(error.message)
  38. }
  39. }
Add Comment
Please, Sign In to add comment