Matteo Scandolo | 46485ac | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | var generators = require('yeoman-generator'); |
Matteo Scandolo | f813b6a | 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 | ecc988d | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 7 | var userName; |
Matteo Scandolo | 46485ac | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 8 | |
| 9 | module.exports = generators.Base.extend({ |
Matteo Scandolo | dc88bf1 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 10 | _fistCharToUpper: function(string){ |
| 11 | return string.replace(/^./, string[0].toUpperCase()); |
| 12 | }, |
Matteo Scandolo | bbfc062 | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 13 | prompting: { |
| 14 | name:function(){ |
| 15 | var done = this.async(); |
| 16 | this.prompt({ |
| 17 | type : 'input', |
| 18 | name : 'name', |
| 19 | message : 'Your project name', |
| 20 | default : this.config.get('name') // value set in .yo-rc.json |
| 21 | }, function (answers) { |
Matteo Scandolo | bbfc062 | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 22 | // TODO check if this view already exist |
| 23 | config.name = answers.name; |
| 24 | done(); |
| 25 | }.bind(this)); |
| 26 | }, |
| 27 | host:function(){ |
| 28 | var done = this.async(); |
| 29 | this.prompt({ |
| 30 | type : 'input', |
| 31 | name : 'host', |
| 32 | message : 'Your project remote host (with port)' |
| 33 | }, function (answers) { |
| 34 | config.host = answers.host; |
| 35 | done(); |
| 36 | }.bind(this)); |
| 37 | }, |
| 38 | token:function(){ |
| 39 | var done = this.async(); |
| 40 | this.prompt({ |
| 41 | type : 'input', |
| 42 | name : 'token', |
| 43 | message : 'Insert your active session token' |
| 44 | }, function (answers) { |
| 45 | config.token = answers.token; |
| 46 | done(); |
| 47 | }.bind(this)); |
| 48 | }, |
| 49 | session:function(){ |
| 50 | var done = this.async(); |
| 51 | this.prompt({ |
| 52 | type : 'input', |
| 53 | name : 'session', |
| 54 | message : 'Insert your active session id' |
| 55 | }, function (answers) { |
| 56 | config.session = answers.session; |
| 57 | done(); |
| 58 | }.bind(this)); |
| 59 | } |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 60 | }, |
| 61 | writing: { |
| 62 | rcFiles: function(){ |
arpiagariu | c959e4f | 2016-05-17 15:37:38 -0700 | [diff] [blame] | 63 | if (!user.git.name()){ |
| 64 | userName = ['',''] |
| 65 | } |
| 66 | else { |
| 67 | userName = user.git.name().split(' '); |
| 68 | } |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 69 | this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`)); |
| 70 | this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`)); |
| 71 | }, |
| 72 | packageJson: function(){ |
| 73 | this.fs.copyTpl( |
| 74 | this.templatePath('package.json'), |
| 75 | this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`), |
| 76 | { name: config.name, author: {name:user.git.name()} } |
| 77 | ); |
| 78 | }, |
Matteo Scandolo | bbfc062 | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 79 | envConfig: function(){ |
| 80 | this.fs.copyTpl( |
| 81 | this.templatePath('env/default.js'), |
| 82 | this.destinationPath(`${this.config.get('folder')}/${config.name}/env/default.js`), |
| 83 | { host: config.host, token: config.token, session: config.session } |
| 84 | ); |
| 85 | }, |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 86 | bowerJson: function(){ |
| 87 | this.fs.copyTpl( |
| 88 | this.templatePath('bower.json'), |
| 89 | this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`), |
| 90 | { name: config.name, author: {name:user.git.name(), email: user.git.email()} } |
| 91 | ); |
| 92 | }, |
Matteo Scandolo | c779496 | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 93 | index: function(){ |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 94 | this.fs.copyTpl( |
| 95 | this.templatePath('src/index.html'), |
| 96 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`), |
Matteo Scandolo | ecc988d | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 97 | { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}} |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 98 | ); |
| 99 | }, |
Matteo Scandolo | c779496 | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 100 | css: function(){ |
Matteo Scandolo | ab91f43 | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 101 | this.fs.copyTpl( |
Matteo Scandolo | c779496 | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 102 | this.templatePath('src/css/dev.css'), |
Matteo Scandolo | ab91f43 | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 103 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`), |
| 104 | {fileName: this._fistCharToUpper(config.name)} |
Matteo Scandolo | dc88bf1 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 105 | ); |
| 106 | }, |
Matteo Scandolo | ba1ed91 | 2016-03-29 14:23:20 -0700 | [diff] [blame] | 107 | css: function(){ |
| 108 | this.fs.copyTpl( |
| 109 | this.templatePath('src/sass/main.scss'), |
| 110 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`), |
| 111 | {fileName: this._fistCharToUpper(config.name)} |
| 112 | ); |
| 113 | }, |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 114 | mainJs: function(){ |
| 115 | this.fs.copyTpl( |
| 116 | this.templatePath('src/js/main.js'), |
| 117 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`), |
Matteo Scandolo | ab91f43 | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 118 | { name: config.name, fileName: this._fistCharToUpper(config.name) } |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 119 | ); |
| 120 | }, |
| 121 | template: function(){ |
| 122 | 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`)); |
| 123 | }, |
| 124 | gulp: function(){ |
Matteo Scandolo | dc88bf1 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 125 | this.fs.copyTpl( |
| 126 | this.templatePath('gulp/*.js'), |
| 127 | this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`), |
| 128 | {name:config.name, fileName: this._fistCharToUpper(config.name)} |
| 129 | ); |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 130 | this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`)); |
Matteo Scandolo | 78a9433 | 2015-11-04 17:28:38 +0100 | [diff] [blame] | 131 | }, |
| 132 | karma: function(){ |
| 133 | this.fs.copy( |
| 134 | this.templatePath('karma.conf.js'), |
| 135 | this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`) |
| 136 | ); |
| 137 | }, |
| 138 | spec: function(){ |
Matteo Scandolo | 78a9433 | 2015-11-04 17:28:38 +0100 | [diff] [blame] | 139 | this.fs.copyTpl( |
| 140 | this.templatePath('spec/sample.test.js'), |
| 141 | this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`), |
| 142 | { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } } |
| 143 | ); |
Matteo Scandolo | 7cf73ad | 2015-11-05 18:36:10 +0100 | [diff] [blame] | 144 | }, |
| 145 | lint: function(){ |
| 146 | this.fs.copy( |
| 147 | this.templatePath('.eslintrc'), |
| 148 | this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`) |
| 149 | ); |
Matteo Scandolo | f813b6a | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 150 | } |
| 151 | }, |
| 152 | install: function(){ |
| 153 | var done = this.async(); |
| 154 | this.prompt({ |
| 155 | type : 'confirm', |
| 156 | name : 'deps', |
| 157 | message : 'Install dependecies?', |
| 158 | default : false // value set in .yo-rc.json |
| 159 | }, function (answers) { |
| 160 | if(answers.deps){ |
| 161 | process.chdir(`${this.config.get('folder')}/${config.name}`); |
| 162 | this.installDependencies(); |
| 163 | } |
Matteo Scandolo | 46485ac | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 164 | done(); |
| 165 | }.bind(this)); |
| 166 | } |
| 167 | }); |