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: { |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 14 | name: function(){ |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 15 | var done = this.async(); |
| 16 | this.prompt({ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 17 | type: 'input', |
| 18 | name: 'name', |
| 19 | message: 'Your project name', |
| 20 | default: this.config.get('name') // value set in .yo-rc.json |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 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)); |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 26 | } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 27 | }, |
| 28 | writing: { |
| 29 | rcFiles: function(){ |
arpiagariu | 4bb9e5b | 2016-05-17 15:37:38 -0700 | [diff] [blame] | 30 | if (!user.git.name()){ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 31 | userName = ['', ''] |
arpiagariu | 4bb9e5b | 2016-05-17 15:37:38 -0700 | [diff] [blame] | 32 | } |
| 33 | else { |
| 34 | userName = user.git.name().split(' '); |
| 35 | } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 36 | this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`)); |
| 37 | this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`)); |
| 38 | }, |
| 39 | packageJson: function(){ |
| 40 | this.fs.copyTpl( |
| 41 | this.templatePath('package.json'), |
| 42 | this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`), |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 43 | { name: config.name, author: {name: user.git.name()} } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 44 | ); |
| 45 | }, |
| 46 | bowerJson: function(){ |
| 47 | this.fs.copyTpl( |
| 48 | this.templatePath('bower.json'), |
| 49 | this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`), |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 50 | { name: config.name, author: {name: user.git.name(), email: user.git.email()} } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 51 | ); |
| 52 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 53 | index: function(){ |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 54 | this.fs.copyTpl( |
| 55 | this.templatePath('src/index.html'), |
| 56 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`), |
Matteo Scandolo | a3839e3 | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 57 | { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}} |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 58 | ); |
| 59 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 60 | css: function(){ |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 61 | this.fs.copyTpl( |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 62 | this.templatePath('src/css/dev.css'), |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 63 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`), |
| 64 | {fileName: this._fistCharToUpper(config.name)} |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 65 | ); |
| 66 | }, |
Arpit Agarwal | 03fcec3 | 2016-07-18 17:30:32 -0700 | [diff] [blame^] | 67 | scss: function(){ |
Matteo Scandolo | b7c91cf | 2016-03-29 14:23:20 -0700 | [diff] [blame] | 68 | this.fs.copyTpl( |
| 69 | this.templatePath('src/sass/main.scss'), |
| 70 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`), |
| 71 | {fileName: this._fistCharToUpper(config.name)} |
| 72 | ); |
| 73 | }, |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 74 | mainJs: function(){ |
| 75 | this.fs.copyTpl( |
| 76 | this.templatePath('src/js/main.js'), |
| 77 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`), |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 78 | { name: config.name, fileName: this._fistCharToUpper(config.name) } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 79 | ); |
| 80 | }, |
Arpit Agarwal | 03fcec3 | 2016-07-18 17:30:32 -0700 | [diff] [blame^] | 81 | image: function(){ |
| 82 | this.fs.copyTpl( |
| 83 | this.templatePath('src/icons/README.md'), |
| 84 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/icons/README.md`)); |
| 85 | }, |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 86 | template: function(){ |
| 87 | 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`)); |
| 88 | }, |
| 89 | gulp: function(){ |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 90 | this.fs.copyTpl( |
| 91 | this.templatePath('gulp/*.js'), |
| 92 | this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`), |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 93 | {name: config.name, fileName: this._fistCharToUpper(config.name)} |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 94 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 95 | 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] | 96 | }, |
| 97 | karma: function(){ |
| 98 | this.fs.copy( |
| 99 | this.templatePath('karma.conf.js'), |
| 100 | this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`) |
| 101 | ); |
| 102 | }, |
| 103 | spec: function(){ |
Matteo Scandolo | b165a3f | 2015-11-04 17:28:38 +0100 | [diff] [blame] | 104 | this.fs.copyTpl( |
| 105 | this.templatePath('spec/sample.test.js'), |
| 106 | this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`), |
| 107 | { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } } |
| 108 | ); |
Matteo Scandolo | e3bc18d | 2015-11-05 18:36:10 +0100 | [diff] [blame] | 109 | }, |
| 110 | lint: function(){ |
| 111 | this.fs.copy( |
| 112 | this.templatePath('.eslintrc'), |
| 113 | this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`) |
| 114 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 115 | } |
| 116 | }, |
| 117 | install: function(){ |
| 118 | var done = this.async(); |
| 119 | this.prompt({ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 120 | type: 'confirm', |
| 121 | name: 'deps', |
| 122 | message: 'Install dependecies?', |
| 123 | default: false // value set in .yo-rc.json |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 124 | }, function (answers) { |
| 125 | if(answers.deps){ |
| 126 | process.chdir(`${this.config.get('folder')}/${config.name}`); |
| 127 | this.installDependencies(); |
| 128 | } |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 129 | done(); |
| 130 | }.bind(this)); |
| 131 | } |
| 132 | }); |