Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. var fileGen = function(componentName) {
  2. // Each createFile instance should run only after the previous one has completed.
  3. createFile('view.php', componentName)
  4. createFile('style.styl', componentName)
  5. createFile('script.js', componentName)
  6. createFile('style.print.styl', componentName)
  7. // finishUp should only run when all createFile instances have completed.
  8. finishUp()
  9. }
  10.  
  11. var createFile = function (fileName, componentName, doc) {
  12. // Tell the user what is happening
  13. console.log(chalk.blue('nCreating', fileName, '...'))
  14. // Bring in the view.php scaffold file
  15. var scaffold = './scaffold/' + fileName
  16. fs.readFile(scaffold, 'utf8', function (err, data) {
  17. if (err) return console.log(chalk.red(err))
  18. var result = data.replace(/%cname%/g, componentName)
  19. if (doc) {
  20. var d = new Date()
  21. result = result.replace(/%cfname%/g, doc.componentName)
  22. result = result.replace(/%cdesc%/g, doc.componentDesc)
  23. result = result.replace(/%cauthor%/g, doc.userName)
  24. result = result.replace(/%cagithub%/g, doc.userGithub)
  25. result = result.replace(/%creationdate%/g, d.getDate() + '/' + d.getMonth() + '/' + d.getFullYear())
  26. }
  27.  
  28. fs.writeFile('./src/components/' + componentName + '/' + fileName, result, function (err) {
  29. if (err) return console.log(chalk.red(err))
  30. console.log(chalk.green(fileName, 'created!'))
  31. })
  32. })
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement