blob: 547a8f9e77c50b42e8272ef5588f14353106572b [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 Scandoloe53ee052015-11-03 14:32:00 +0100100 mainJs: function(){
101 this.fs.copyTpl(
102 this.templatePath('src/js/main.js'),
103 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +0100104 { name: config.name, fileName: this._fistCharToUpper(config.name) }
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100105 );
106 },
107 template: function(){
108 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`));
109 },
110 gulp: function(){
Matteo Scandolo6be0cd22015-11-03 16:27:07 +0100111 this.fs.copyTpl(
112 this.templatePath('gulp/*.js'),
113 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
114 {name:config.name, fileName: this._fistCharToUpper(config.name)}
115 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100116 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolob165a3f2015-11-04 17:28:38 +0100117 },
118 karma: function(){
119 this.fs.copy(
120 this.templatePath('karma.conf.js'),
121 this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
122 );
123 },
124 spec: function(){
125 const userName = user.git.name().split(' ');
126 this.fs.copyTpl(
127 this.templatePath('spec/sample.test.js'),
128 this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
129 { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
130 );
Matteo Scandoloe3bc18d2015-11-05 18:36:10 +0100131 },
132 lint: function(){
133 this.fs.copy(
134 this.templatePath('.eslintrc'),
135 this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`)
136 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100137 }
138 },
139 install: function(){
140 var done = this.async();
141 this.prompt({
142 type : 'confirm',
143 name : 'deps',
144 message : 'Install dependecies?',
145 default : false // value set in .yo-rc.json
146 }, function (answers) {
147 if(answers.deps){
148 process.chdir(`${this.config.get('folder')}/${config.name}`);
149 this.installDependencies();
150 }
Matteo Scandoloa0449cd2015-11-03 10:48:01 +0100151 done();
152 }.bind(this));
153 }
154});