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