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(){ |
Matteo Scandolo | a3839e3 | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 63 | userName = user.git.name().split(' '); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 64 | this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`)); |
| 65 | this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`)); |
| 66 | }, |
| 67 | packageJson: function(){ |
| 68 | this.fs.copyTpl( |
| 69 | this.templatePath('package.json'), |
| 70 | this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`), |
| 71 | { name: config.name, author: {name:user.git.name()} } |
| 72 | ); |
| 73 | }, |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 74 | envConfig: function(){ |
| 75 | this.fs.copyTpl( |
| 76 | this.templatePath('env/default.js'), |
| 77 | this.destinationPath(`${this.config.get('folder')}/${config.name}/env/default.js`), |
| 78 | { host: config.host, token: config.token, session: config.session } |
| 79 | ); |
| 80 | }, |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 81 | bowerJson: function(){ |
| 82 | this.fs.copyTpl( |
| 83 | this.templatePath('bower.json'), |
| 84 | this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`), |
| 85 | { name: config.name, author: {name:user.git.name(), email: user.git.email()} } |
| 86 | ); |
| 87 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 88 | index: function(){ |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 89 | this.fs.copyTpl( |
| 90 | this.templatePath('src/index.html'), |
| 91 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`), |
Matteo Scandolo | a3839e3 | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 92 | { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}} |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 93 | ); |
| 94 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 95 | css: function(){ |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 96 | this.fs.copyTpl( |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 97 | this.templatePath('src/css/dev.css'), |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 98 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`), |
| 99 | {fileName: this._fistCharToUpper(config.name)} |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 100 | ); |
| 101 | }, |
Matteo Scandolo | b7c91cf | 2016-03-29 14:23:20 -0700 | [diff] [blame] | 102 | css: function(){ |
| 103 | this.fs.copyTpl( |
| 104 | this.templatePath('src/sass/main.scss'), |
| 105 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`), |
| 106 | {fileName: this._fistCharToUpper(config.name)} |
| 107 | ); |
| 108 | }, |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 109 | mainJs: function(){ |
| 110 | this.fs.copyTpl( |
| 111 | this.templatePath('src/js/main.js'), |
| 112 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`), |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 113 | { name: config.name, fileName: this._fistCharToUpper(config.name) } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 114 | ); |
| 115 | }, |
| 116 | template: function(){ |
| 117 | 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`)); |
| 118 | }, |
| 119 | gulp: function(){ |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 120 | this.fs.copyTpl( |
| 121 | this.templatePath('gulp/*.js'), |
| 122 | this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`), |
| 123 | {name:config.name, fileName: this._fistCharToUpper(config.name)} |
| 124 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 125 | 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] | 126 | }, |
| 127 | karma: function(){ |
| 128 | this.fs.copy( |
| 129 | this.templatePath('karma.conf.js'), |
| 130 | this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`) |
| 131 | ); |
| 132 | }, |
| 133 | spec: function(){ |
Matteo Scandolo | b165a3f | 2015-11-04 17:28:38 +0100 | [diff] [blame] | 134 | this.fs.copyTpl( |
| 135 | this.templatePath('spec/sample.test.js'), |
| 136 | this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`), |
| 137 | { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } } |
| 138 | ); |
Matteo Scandolo | e3bc18d | 2015-11-05 18:36:10 +0100 | [diff] [blame] | 139 | }, |
| 140 | lint: function(){ |
| 141 | this.fs.copy( |
| 142 | this.templatePath('.eslintrc'), |
| 143 | this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`) |
| 144 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 145 | } |
| 146 | }, |
| 147 | install: function(){ |
| 148 | var done = this.async(); |
| 149 | this.prompt({ |
| 150 | type : 'confirm', |
| 151 | name : 'deps', |
| 152 | message : 'Install dependecies?', |
| 153 | default : false // value set in .yo-rc.json |
| 154 | }, function (answers) { |
| 155 | if(answers.deps){ |
| 156 | process.chdir(`${this.config.get('folder')}/${config.name}`); |
| 157 | this.installDependencies(); |
| 158 | } |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 159 | done(); |
| 160 | }.bind(this)); |
| 161 | } |
| 162 | }); |