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 | d05ac6c | 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 | d05ac6c | 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 | e53ee05 | 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 | d05ac6c | 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 | e53ee05 | 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 | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 86 | index: function(){ |
Matteo Scandolo | e53ee05 | 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 | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 90 | { name: config.name, fileName: this._fistCharToUpper(config.name) } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 91 | ); |
| 92 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 93 | css: function(){ |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 94 | this.fs.copyTpl( |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 95 | this.templatePath('src/css/dev.css'), |
Matteo Scandolo | ba5e19d | 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 | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 98 | ); |
| 99 | }, |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 100 | mainJs: function(){ |
| 101 | this.fs.copyTpl( |
| 102 | this.templatePath('src/js/main.js'), |
| 103 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`), |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 104 | { name: config.name, fileName: this._fistCharToUpper(config.name) } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 105 | ); |
| 106 | }, |
| 107 | template: function(){ |
| 108 | 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`)); |
| 109 | }, |
| 110 | gulp: function(){ |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 111 | this.fs.copyTpl( |
| 112 | this.templatePath('gulp/*.js'), |
| 113 | this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`), |
| 114 | {name:config.name, fileName: this._fistCharToUpper(config.name)} |
| 115 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 116 | 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] | 117 | }, |
| 118 | karma: function(){ |
| 119 | this.fs.copy( |
| 120 | this.templatePath('karma.conf.js'), |
| 121 | this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`) |
| 122 | ); |
| 123 | }, |
| 124 | spec: function(){ |
| 125 | const userName = user.git.name().split(' '); |
| 126 | this.fs.copyTpl( |
| 127 | this.templatePath('spec/sample.test.js'), |
| 128 | this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`), |
| 129 | { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } } |
| 130 | ); |
Matteo Scandolo | e3bc18d | 2015-11-05 18:36:10 +0100 | [diff] [blame] | 131 | }, |
| 132 | lint: function(){ |
| 133 | this.fs.copy( |
| 134 | this.templatePath('.eslintrc'), |
| 135 | this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`) |
| 136 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 137 | } |
| 138 | }, |
| 139 | install: function(){ |
| 140 | var done = this.async(); |
| 141 | this.prompt({ |
| 142 | type : 'confirm', |
| 143 | name : 'deps', |
| 144 | message : 'Install dependecies?', |
| 145 | default : false // value set in .yo-rc.json |
| 146 | }, function (answers) { |
| 147 | if(answers.deps){ |
| 148 | process.chdir(`${this.config.get('folder')}/${config.name}`); |
| 149 | this.installDependencies(); |
| 150 | } |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 151 | done(); |
| 152 | }.bind(this)); |
| 153 | } |
| 154 | }); |