blob: f17ad3ccefaddcc2d5199a0e9dd26e5e9d0c7dc3 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
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 Scandoloa0449cd2015-11-03 10:48:01 +010019'use strict';
20
21var generators = require('yeoman-generator');
Matteo Scandoloe53ee052015-11-03 14:32:00 +010022var user = require('../node_modules/yeoman-generator/lib/actions/user');
23
24var config = {};
Matteo Scandoloa3839e32016-04-28 16:20:53 -070025var userName;
Matteo Scandoloa0449cd2015-11-03 10:48:01 +010026
27module.exports = generators.Base.extend({
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010028 _fistCharToUpper: function(string){
29 return string.replace(/^./, string[0].toUpperCase());
30 },
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080031 prompting: {
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070032 name: function(){
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080033 var done = this.async();
34 this.prompt({
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070035 type: 'input',
36 name: 'name',
37 message: 'Your project name',
38 default: this.config.get('name') // value set in .yo-rc.json
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080039 }, function (answers) {
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080040 // TODO check if this view already exist
41 config.name = answers.name;
42 done();
43 }.bind(this));
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080044 }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010045 },
46 writing: {
47 rcFiles: function(){
arpiagariu4bb9e5b2016-05-17 15:37:38 -070048 if (!user.git.name()){
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070049 userName = ['', '']
arpiagariu4bb9e5b2016-05-17 15:37:38 -070050 }
51 else {
52 userName = user.git.name().split(' ');
53 }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010054 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 Scandolo4ac9a0b2016-05-23 15:31:25 -070061 { name: config.name, author: {name: user.git.name()} }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010062 );
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 Scandolo4ac9a0b2016-05-23 15:31:25 -070068 { name: config.name, author: {name: user.git.name(), email: user.git.email()} }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010069 );
70 },
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010071 index: function(){
Matteo Scandoloe53ee052015-11-03 14:32:00 +010072 this.fs.copyTpl(
73 this.templatePath('src/index.html'),
74 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`),
Matteo Scandoloa3839e32016-04-28 16:20:53 -070075 { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}}
Matteo Scandoloe53ee052015-11-03 14:32:00 +010076 );
77 },
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010078 css: function(){
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010079 this.fs.copyTpl(
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010080 this.templatePath('src/css/dev.css'),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010081 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`),
82 {fileName: this._fistCharToUpper(config.name)}
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010083 );
84 },
Arpit Agarwalfecac782016-07-18 17:30:32 -070085 scss: function(){
Matteo Scandolob7c91cf2016-03-29 14:23:20 -070086 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 Scandoloe53ee052015-11-03 14:32:00 +010092 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 Scandoloba5e19d2015-11-06 18:25:52 +010096 { name: config.name, fileName: this._fistCharToUpper(config.name) }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010097 );
98 },
Arpit Agarwalfecac782016-07-18 17:30:32 -070099 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 Scandoloe53ee052015-11-03 14:32:00 +0100104 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 Scandolo6be0cd22015-11-03 16:27:07 +0100108 this.fs.copyTpl(
109 this.templatePath('gulp/*.js'),
110 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -0700111 {name: config.name, fileName: this._fistCharToUpper(config.name)}
Matteo Scandolo6be0cd22015-11-03 16:27:07 +0100112 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100113 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolob165a3f2015-11-04 17:28:38 +0100114 },
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 Scandolob165a3f2015-11-04 17:28:38 +0100122 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 Scandoloe3bc18d2015-11-05 18:36:10 +0100127 },
128 lint: function(){
129 this.fs.copy(
130 this.templatePath('.eslintrc'),
131 this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`)
132 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100133 }
134 },
135 install: function(){
136 var done = this.async();
137 this.prompt({
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -0700138 type: 'confirm',
139 name: 'deps',
140 message: 'Install dependecies?',
141 default: false // value set in .yo-rc.json
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100142 }, function (answers) {
143 if(answers.deps){
144 process.chdir(`${this.config.get('folder')}/${config.name}`);
145 this.installDependencies();
146 }
Matteo Scandoloa0449cd2015-11-03 10:48:01 +0100147 done();
148 }.bind(this));
149 }
150});