UNPKG

2.01 kBJavaScriptView Raw
1const Generator = require('yeoman-generator')
2const yosay = require('yosay')
3const _ = require('lodash')
4
5module.exports = class extends Generator {
6 constructor (args, opts) {
7 super(args, opts)
8 }
9
10 initializing () {
11 this.log(yosay('Iniciando generator'))
12 }
13
14 prompting () {
15 return this.prompt([{
16 type: 'input',
17 name: 'name',
18 message : 'Nome do projeto (kebab-case):',
19 default: _.kebabCase(this.appname)
20 }]).then(answers => {
21 if (answers.name != "") {
22 this.appname = answers.name
23
24 this.config.set({
25 name: answers.name,
26 modules: ['Login', 'Dashboard']
27 })
28
29 this.config.save()
30 }
31 })
32 }
33
34 writing() {
35 this.fs.copy(
36 this.templatePath('app/**!(node_modules)/*!(package.json)'),
37 this.destinationPath(), { globOptions: { dot: true } }
38 )
39
40 this.fs.copy(
41 this.templatePath('app/src/**/*'),
42 this.destinationPath('src')
43 )
44
45 this.fs.copy(
46 this.templatePath('app/static/**/*'),
47 this.destinationPath('static')
48 )
49
50 this.fs.copy(
51 this.templatePath('app/test/**/*'),
52 this.destinationPath('test')
53 )
54
55 this.fs.copyTpl(
56 this.templatePath('_package.json'),
57 this.destinationPath('package.json'),
58 { name: _.kebabCase(this.appname) }
59 )
60
61 this.fs.copyTpl(
62 this.templatePath('_gitlab-ci.yml'),
63 this.destinationPath('.gitlab-ci.yml'),
64 { name: _.kebabCase(this.appname) }
65 )
66
67 this.fs.copyTpl(
68 this.templatePath('_gitignore'),
69 this.destinationPath('.gitignore')
70 )
71
72 const dotfiles = [
73 '.babelrc',
74 '.editorconfig',
75 '.eslintignore',
76 '.eslintrc.js',
77 '.postcssrc.js',
78 'index.html',
79 'README.md'
80 ]
81
82 dotfiles.map(file => {
83 this.fs.copy(
84 this.templatePath(`app/${file}`),
85 this.destinationPath(`./${file}`)
86 )
87 })
88 }
89
90 install() {
91 this.installDependencies({bower: false, npm: false, yarn: true})
92 }
93}