blob: 9fab96fd980f296b81870f15207f18604069def1 [file] [log] [blame]
Matteo Scandoloa0449cd2015-11-03 10:48:01 +01001'use strict';
2
3var generators = require('yeoman-generator');
Matteo Scandoloe53ee052015-11-03 14:32:00 +01004var user = require('../node_modules/yeoman-generator/lib/actions/user');
5
6var config = {};
Matteo Scandoloa0449cd2015-11-03 10:48:01 +01007
8module.exports = generators.Base.extend({
Matteo Scandolo6be0cd22015-11-03 16:27:07 +01009 _fistCharToUpper: function(string){
10 return string.replace(/^./, string[0].toUpperCase());
11 },
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080012 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 Scandolod05ac6c2015-12-01 16:02:29 -080021 // 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 Scandoloe53ee052015-11-03 14:32:00 +010059 },
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 Scandolod05ac6c2015-12-01 16:02:29 -080072 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 Scandoloe53ee052015-11-03 14:32:00 +010079 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 Scandoloba2af3d2015-11-06 10:35:20 +010086 index: function(){
Matteo Scandoloe53ee052015-11-03 14:32:00 +010087 this.fs.copyTpl(
88 this.templatePath('src/index.html'),
89 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010090 { name: config.name, fileName: this._fistCharToUpper(config.name) }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010091 );
92 },
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010093 css: function(){
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010094 this.fs.copyTpl(
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010095 this.templatePath('src/css/dev.css'),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010096 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`),
97 {fileName: this._fistCharToUpper(config.name)}
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010098 );
99 },
Matteo Scandolob7c91cf2016-03-29 14:23:20 -0700100 css: function(){
101 this.fs.copyTpl(
102 this.templatePath('src/sass/main.scss'),
103 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`),
104 {fileName: this._fistCharToUpper(config.name)}
105 );
106 },
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100107 mainJs: function(){
108 this.fs.copyTpl(
109 this.templatePath('src/js/main.js'),
110 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +0100111 { name: config.name, fileName: this._fistCharToUpper(config.name) }
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100112 );
113 },
114 template: function(){
115 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`));
116 },
117 gulp: function(){
Matteo Scandolo6be0cd22015-11-03 16:27:07 +0100118 this.fs.copyTpl(
119 this.templatePath('gulp/*.js'),
120 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
121 {name:config.name, fileName: this._fistCharToUpper(config.name)}
122 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100123 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolob165a3f2015-11-04 17:28:38 +0100124 },
125 karma: function(){
126 this.fs.copy(
127 this.templatePath('karma.conf.js'),
128 this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
129 );
130 },
131 spec: function(){
132 const userName = user.git.name().split(' ');
133 this.fs.copyTpl(
134 this.templatePath('spec/sample.test.js'),
135 this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
136 { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
137 );
Matteo Scandoloe3bc18d2015-11-05 18:36:10 +0100138 },
139 lint: function(){
140 this.fs.copy(
141 this.templatePath('.eslintrc'),
142 this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`)
143 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100144 }
145 },
146 install: function(){
147 var done = this.async();
148 this.prompt({
149 type : 'confirm',
150 name : 'deps',
151 message : 'Install dependecies?',
152 default : false // value set in .yo-rc.json
153 }, function (answers) {
154 if(answers.deps){
155 process.chdir(`${this.config.get('folder')}/${config.name}`);
156 this.installDependencies();
157 }
Matteo Scandoloa0449cd2015-11-03 10:48:01 +0100158 done();
159 }.bind(this));
160 }
161});