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 | a3839e3 | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 7 | var userName; |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 8 | |
| 9 | module.exports = generators.Base.extend({ |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 10 | _fistCharToUpper: function(string){ |
| 11 | return string.replace(/^./, string[0].toUpperCase()); |
| 12 | }, |
Matteo Scandolo | d05ac6c | 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 | d05ac6c | 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 | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 60 | }, |
| 61 | writing: { |
| 62 | rcFiles: function(){ |
arpiagariu | 4bb9e5b | 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 | e53ee05 | 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 | d05ac6c | 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 | e53ee05 | 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 | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 93 | index: function(){ |
Matteo Scandolo | e53ee05 | 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 | a3839e3 | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 97 | { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}} |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 98 | ); |
| 99 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 100 | css: function(){ |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 101 | this.fs.copyTpl( |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 102 | this.templatePath('src/css/dev.css'), |
Matteo Scandolo | ba5e19d | 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 | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 105 | ); |
| 106 | }, |
Matteo Scandolo | b7c91cf | 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 | e53ee05 | 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 | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 118 | { name: config.name, fileName: this._fistCharToUpper(config.name) } |
Matteo Scandolo | e53ee05 | 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 | 6be0cd2 | 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 | e53ee05 | 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 | b165a3f | 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 | b165a3f | 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 | e3bc18d | 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 | e53ee05 | 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 | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 164 | done(); |
| 165 | }.bind(this)); |
| 166 | } |
| 167 | }); |