Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | var generators = require('yeoman-generator'); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 4 | var user = require('../node_modules/yeoman-generator/lib/actions/user'); |
| 5 | |
| 6 | var config = {}; |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 7 | |
| 8 | module.exports = generators.Base.extend({ |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 9 | _fistCharToUpper: function(string){ |
| 10 | return string.replace(/^./, string[0].toUpperCase()); |
| 11 | }, |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 12 | prompting: function(){ |
| 13 | var done = this.async(); |
| 14 | this.prompt({ |
| 15 | type : 'input', |
| 16 | name : 'name', |
| 17 | message : 'Your project name', |
| 18 | default : this.config.get('name') // value set in .yo-rc.json |
| 19 | }, function (answers) { |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 20 | // TODO check if this view already exist |
| 21 | config.name = answers.name; |
| 22 | done(); |
| 23 | }.bind(this)); |
| 24 | }, |
| 25 | writing: { |
| 26 | rcFiles: function(){ |
| 27 | this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`)); |
| 28 | this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`)); |
| 29 | }, |
| 30 | packageJson: function(){ |
| 31 | this.fs.copyTpl( |
| 32 | this.templatePath('package.json'), |
| 33 | this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`), |
| 34 | { name: config.name, author: {name:user.git.name()} } |
| 35 | ); |
| 36 | }, |
| 37 | bowerJson: function(){ |
| 38 | this.fs.copyTpl( |
| 39 | this.templatePath('bower.json'), |
| 40 | this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`), |
| 41 | { name: config.name, author: {name:user.git.name(), email: user.git.email()} } |
| 42 | ); |
| 43 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame^] | 44 | index: function(){ |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 45 | this.fs.copyTpl( |
| 46 | this.templatePath('src/index.html'), |
| 47 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`), |
| 48 | { name: config.name } |
| 49 | ); |
| 50 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame^] | 51 | css: function(){ |
| 52 | this.fs.copy( |
| 53 | this.templatePath('src/css/dev.css'), |
| 54 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`) |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 55 | ); |
| 56 | }, |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 57 | mainJs: function(){ |
| 58 | this.fs.copyTpl( |
| 59 | this.templatePath('src/js/main.js'), |
| 60 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`), |
| 61 | { name: config.name } |
| 62 | ); |
| 63 | }, |
| 64 | template: function(){ |
| 65 | this.fs.copy(this.templatePath('src/templates/users-list.tpl.html'), this.destinationPath(`${this.config.get('folder')}/${config.name}/src/templates/users-list.tpl.html`)); |
| 66 | }, |
| 67 | gulp: function(){ |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 68 | this.fs.copyTpl( |
| 69 | this.templatePath('gulp/*.js'), |
| 70 | this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`), |
| 71 | {name:config.name, fileName: this._fistCharToUpper(config.name)} |
| 72 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 73 | this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`)); |
Matteo Scandolo | b165a3f | 2015-11-04 17:28:38 +0100 | [diff] [blame] | 74 | }, |
| 75 | karma: function(){ |
| 76 | this.fs.copy( |
| 77 | this.templatePath('karma.conf.js'), |
| 78 | this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`) |
| 79 | ); |
| 80 | }, |
| 81 | spec: function(){ |
| 82 | const userName = user.git.name().split(' '); |
| 83 | this.fs.copyTpl( |
| 84 | this.templatePath('spec/sample.test.js'), |
| 85 | this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`), |
| 86 | { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } } |
| 87 | ); |
Matteo Scandolo | e3bc18d | 2015-11-05 18:36:10 +0100 | [diff] [blame] | 88 | }, |
| 89 | lint: function(){ |
| 90 | this.fs.copy( |
| 91 | this.templatePath('.eslintrc'), |
| 92 | this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`) |
| 93 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 94 | } |
| 95 | }, |
| 96 | install: function(){ |
| 97 | var done = this.async(); |
| 98 | this.prompt({ |
| 99 | type : 'confirm', |
| 100 | name : 'deps', |
| 101 | message : 'Install dependecies?', |
| 102 | default : false // value set in .yo-rc.json |
| 103 | }, function (answers) { |
| 104 | if(answers.deps){ |
| 105 | process.chdir(`${this.config.get('folder')}/${config.name}`); |
| 106 | this.installDependencies(); |
| 107 | } |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 108 | done(); |
| 109 | }.bind(this)); |
| 110 | } |
| 111 | }); |