blob: 57eee8c8d3a9700885aff779b858445e62221aba [file] [log] [blame]
Matteo Scandolo46485ac2015-11-03 10:48:01 +01001'use strict';
2
3var generators = require('yeoman-generator');
Matteo Scandolof813b6a2015-11-03 14:32:00 +01004var user = require('../node_modules/yeoman-generator/lib/actions/user');
5
6var config = {};
Matteo Scandoloecc988d2016-04-28 16:20:53 -07007var userName;
Matteo Scandolo46485ac2015-11-03 10:48:01 +01008
9module.exports = generators.Base.extend({
Matteo Scandolodc88bf12015-11-03 16:27:07 +010010 _fistCharToUpper: function(string){
11 return string.replace(/^./, string[0].toUpperCase());
12 },
Matteo Scandolobbfc0622015-12-01 16:02:29 -080013 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 Scandolobbfc0622015-12-01 16:02:29 -080022 // 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 Scandolof813b6a2015-11-03 14:32:00 +010060 },
61 writing: {
62 rcFiles: function(){
arpiagariuc959e4f2016-05-17 15:37:38 -070063 if (!user.git.name()){
64 userName = ['','']
65 }
66 else {
67 userName = user.git.name().split(' ');
68 }
Matteo Scandolof813b6a2015-11-03 14:32:00 +010069 this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`));
70 this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`));
71 },
72 packageJson: function(){
73 this.fs.copyTpl(
74 this.templatePath('package.json'),
75 this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`),
76 { name: config.name, author: {name:user.git.name()} }
77 );
78 },
Matteo Scandolobbfc0622015-12-01 16:02:29 -080079 envConfig: function(){
80 this.fs.copyTpl(
81 this.templatePath('env/default.js'),
82 this.destinationPath(`${this.config.get('folder')}/${config.name}/env/default.js`),
83 { host: config.host, token: config.token, session: config.session }
84 );
85 },
Matteo Scandolof813b6a2015-11-03 14:32:00 +010086 bowerJson: function(){
87 this.fs.copyTpl(
88 this.templatePath('bower.json'),
89 this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`),
90 { name: config.name, author: {name:user.git.name(), email: user.git.email()} }
91 );
92 },
Matteo Scandoloc7794962015-11-06 10:35:20 +010093 index: function(){
Matteo Scandolof813b6a2015-11-03 14:32:00 +010094 this.fs.copyTpl(
95 this.templatePath('src/index.html'),
96 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`),
Matteo Scandoloecc988d2016-04-28 16:20:53 -070097 { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}}
Matteo Scandolof813b6a2015-11-03 14:32:00 +010098 );
99 },
Matteo Scandoloc7794962015-11-06 10:35:20 +0100100 css: function(){
Matteo Scandoloab91f432015-11-06 18:25:52 +0100101 this.fs.copyTpl(
Matteo Scandoloc7794962015-11-06 10:35:20 +0100102 this.templatePath('src/css/dev.css'),
Matteo Scandoloab91f432015-11-06 18:25:52 +0100103 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`),
104 {fileName: this._fistCharToUpper(config.name)}
Matteo Scandolodc88bf12015-11-03 16:27:07 +0100105 );
106 },
Matteo Scandoloba1ed912016-03-29 14:23:20 -0700107 css: function(){
108 this.fs.copyTpl(
109 this.templatePath('src/sass/main.scss'),
110 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`),
111 {fileName: this._fistCharToUpper(config.name)}
112 );
113 },
Matteo Scandolof813b6a2015-11-03 14:32:00 +0100114 mainJs: function(){
115 this.fs.copyTpl(
116 this.templatePath('src/js/main.js'),
117 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`),
Matteo Scandoloab91f432015-11-06 18:25:52 +0100118 { name: config.name, fileName: this._fistCharToUpper(config.name) }
Matteo Scandolof813b6a2015-11-03 14:32:00 +0100119 );
120 },
121 template: function(){
122 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`));
123 },
124 gulp: function(){
Matteo Scandolodc88bf12015-11-03 16:27:07 +0100125 this.fs.copyTpl(
126 this.templatePath('gulp/*.js'),
127 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
128 {name:config.name, fileName: this._fistCharToUpper(config.name)}
129 );
Matteo Scandolof813b6a2015-11-03 14:32:00 +0100130 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolo78a94332015-11-04 17:28:38 +0100131 },
132 karma: function(){
133 this.fs.copy(
134 this.templatePath('karma.conf.js'),
135 this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
136 );
137 },
138 spec: function(){
Matteo Scandolo78a94332015-11-04 17:28:38 +0100139 this.fs.copyTpl(
140 this.templatePath('spec/sample.test.js'),
141 this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
142 { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
143 );
Matteo Scandolo7cf73ad2015-11-05 18:36:10 +0100144 },
145 lint: function(){
146 this.fs.copy(
147 this.templatePath('.eslintrc'),
148 this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`)
149 );
Matteo Scandolof813b6a2015-11-03 14:32:00 +0100150 }
151 },
152 install: function(){
153 var done = this.async();
154 this.prompt({
155 type : 'confirm',
156 name : 'deps',
157 message : 'Install dependecies?',
158 default : false // value set in .yo-rc.json
159 }, function (answers) {
160 if(answers.deps){
161 process.chdir(`${this.config.get('folder')}/${config.name}`);
162 this.installDependencies();
163 }
Matteo Scandolo46485ac2015-11-03 10:48:01 +0100164 done();
165 }.bind(this));
166 }
167});