Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 19 | 'use strict'; |
| 20 | |
| 21 | var generators = require('yeoman-generator'); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 22 | var user = require('../node_modules/yeoman-generator/lib/actions/user'); |
| 23 | |
| 24 | var config = {}; |
Matteo Scandolo | a3839e3 | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 25 | var userName; |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 26 | |
| 27 | module.exports = generators.Base.extend({ |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 28 | _fistCharToUpper: function(string){ |
| 29 | return string.replace(/^./, string[0].toUpperCase()); |
| 30 | }, |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 31 | prompting: { |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 32 | name: function(){ |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 33 | var done = this.async(); |
| 34 | this.prompt({ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 35 | type: 'input', |
| 36 | name: 'name', |
| 37 | message: 'Your project name', |
| 38 | default: this.config.get('name') // value set in .yo-rc.json |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 39 | }, function (answers) { |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 40 | // TODO check if this view already exist |
| 41 | config.name = answers.name; |
| 42 | done(); |
| 43 | }.bind(this)); |
Matteo Scandolo | d05ac6c | 2015-12-01 16:02:29 -0800 | [diff] [blame] | 44 | } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 45 | }, |
| 46 | writing: { |
| 47 | rcFiles: function(){ |
arpiagariu | 4bb9e5b | 2016-05-17 15:37:38 -0700 | [diff] [blame] | 48 | if (!user.git.name()){ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 49 | userName = ['', ''] |
arpiagariu | 4bb9e5b | 2016-05-17 15:37:38 -0700 | [diff] [blame] | 50 | } |
| 51 | else { |
| 52 | userName = user.git.name().split(' '); |
| 53 | } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 54 | this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`)); |
| 55 | this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`)); |
| 56 | }, |
| 57 | packageJson: function(){ |
| 58 | this.fs.copyTpl( |
| 59 | this.templatePath('package.json'), |
| 60 | this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`), |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 61 | { name: config.name, author: {name: user.git.name()} } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 62 | ); |
| 63 | }, |
| 64 | bowerJson: function(){ |
| 65 | this.fs.copyTpl( |
| 66 | this.templatePath('bower.json'), |
| 67 | this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`), |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 68 | { name: config.name, author: {name: user.git.name(), email: user.git.email()} } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 69 | ); |
| 70 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 71 | index: function(){ |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 72 | this.fs.copyTpl( |
| 73 | this.templatePath('src/index.html'), |
| 74 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`), |
Matteo Scandolo | a3839e3 | 2016-04-28 16:20:53 -0700 | [diff] [blame] | 75 | { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}} |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 76 | ); |
| 77 | }, |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 78 | css: function(){ |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 79 | this.fs.copyTpl( |
Matteo Scandolo | ba2af3d | 2015-11-06 10:35:20 +0100 | [diff] [blame] | 80 | this.templatePath('src/css/dev.css'), |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 81 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`), |
| 82 | {fileName: this._fistCharToUpper(config.name)} |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 83 | ); |
| 84 | }, |
Arpit Agarwal | fecac78 | 2016-07-18 17:30:32 -0700 | [diff] [blame] | 85 | scss: function(){ |
Matteo Scandolo | b7c91cf | 2016-03-29 14:23:20 -0700 | [diff] [blame] | 86 | this.fs.copyTpl( |
| 87 | this.templatePath('src/sass/main.scss'), |
| 88 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`), |
| 89 | {fileName: this._fistCharToUpper(config.name)} |
| 90 | ); |
| 91 | }, |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 92 | mainJs: function(){ |
| 93 | this.fs.copyTpl( |
| 94 | this.templatePath('src/js/main.js'), |
| 95 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`), |
Matteo Scandolo | ba5e19d | 2015-11-06 18:25:52 +0100 | [diff] [blame] | 96 | { name: config.name, fileName: this._fistCharToUpper(config.name) } |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 97 | ); |
| 98 | }, |
Arpit Agarwal | fecac78 | 2016-07-18 17:30:32 -0700 | [diff] [blame] | 99 | image: function(){ |
| 100 | this.fs.copyTpl( |
| 101 | this.templatePath('src/icons/README.md'), |
| 102 | this.destinationPath(`${this.config.get('folder')}/${config.name}/src/icons/README.md`)); |
| 103 | }, |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 104 | template: function(){ |
| 105 | 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`)); |
| 106 | }, |
| 107 | gulp: function(){ |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 108 | this.fs.copyTpl( |
| 109 | this.templatePath('gulp/*.js'), |
| 110 | this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`), |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 111 | {name: config.name, fileName: this._fistCharToUpper(config.name)} |
Matteo Scandolo | 6be0cd2 | 2015-11-03 16:27:07 +0100 | [diff] [blame] | 112 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 113 | 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] | 114 | }, |
| 115 | karma: function(){ |
| 116 | this.fs.copy( |
| 117 | this.templatePath('karma.conf.js'), |
| 118 | this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`) |
| 119 | ); |
| 120 | }, |
| 121 | spec: function(){ |
Matteo Scandolo | b165a3f | 2015-11-04 17:28:38 +0100 | [diff] [blame] | 122 | this.fs.copyTpl( |
| 123 | this.templatePath('spec/sample.test.js'), |
| 124 | this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`), |
| 125 | { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } } |
| 126 | ); |
Matteo Scandolo | e3bc18d | 2015-11-05 18:36:10 +0100 | [diff] [blame] | 127 | }, |
| 128 | lint: function(){ |
| 129 | this.fs.copy( |
| 130 | this.templatePath('.eslintrc'), |
| 131 | this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`) |
| 132 | ); |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 133 | } |
| 134 | }, |
| 135 | install: function(){ |
| 136 | var done = this.async(); |
| 137 | this.prompt({ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 138 | type: 'confirm', |
| 139 | name: 'deps', |
| 140 | message: 'Install dependecies?', |
| 141 | default: false // value set in .yo-rc.json |
Matteo Scandolo | e53ee05 | 2015-11-03 14:32:00 +0100 | [diff] [blame] | 142 | }, function (answers) { |
| 143 | if(answers.deps){ |
| 144 | process.chdir(`${this.config.get('folder')}/${config.name}`); |
| 145 | this.installDependencies(); |
| 146 | } |
Matteo Scandolo | a0449cd | 2015-11-03 10:48:01 +0100 | [diff] [blame] | 147 | done(); |
| 148 | }.bind(this)); |
| 149 | } |
| 150 | }); |