blob: 115797311b67a86a583831d6e671bd08cc4f0f46 [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 Scandoloa3839e32016-04-28 16:20:53 -07007var userName;
Matteo Scandoloa0449cd2015-11-03 10:48:01 +01008
9module.exports = generators.Base.extend({
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010010 _fistCharToUpper: function(string){
11 return string.replace(/^./, string[0].toUpperCase());
12 },
Matteo Scandolod05ac6c2015-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 Scandolod05ac6c2015-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 Scandoloe53ee052015-11-03 14:32:00 +010060 },
61 writing: {
62 rcFiles: function(){
Matteo Scandoloa3839e32016-04-28 16:20:53 -070063 userName = user.git.name().split(' ');
Matteo Scandoloe53ee052015-11-03 14:32:00 +010064 this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`));
65 this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`));
66 },
67 packageJson: function(){
68 this.fs.copyTpl(
69 this.templatePath('package.json'),
70 this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`),
71 { name: config.name, author: {name:user.git.name()} }
72 );
73 },
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080074 envConfig: function(){
75 this.fs.copyTpl(
76 this.templatePath('env/default.js'),
77 this.destinationPath(`${this.config.get('folder')}/${config.name}/env/default.js`),
78 { host: config.host, token: config.token, session: config.session }
79 );
80 },
Matteo Scandoloe53ee052015-11-03 14:32:00 +010081 bowerJson: function(){
82 this.fs.copyTpl(
83 this.templatePath('bower.json'),
84 this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`),
85 { name: config.name, author: {name:user.git.name(), email: user.git.email()} }
86 );
87 },
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010088 index: function(){
Matteo Scandoloe53ee052015-11-03 14:32:00 +010089 this.fs.copyTpl(
90 this.templatePath('src/index.html'),
91 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`),
Matteo Scandoloa3839e32016-04-28 16:20:53 -070092 { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}}
Matteo Scandoloe53ee052015-11-03 14:32:00 +010093 );
94 },
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010095 css: function(){
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010096 this.fs.copyTpl(
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010097 this.templatePath('src/css/dev.css'),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010098 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`),
99 {fileName: this._fistCharToUpper(config.name)}
Matteo Scandolo6be0cd22015-11-03 16:27:07 +0100100 );
101 },
Matteo Scandolob7c91cf2016-03-29 14:23:20 -0700102 css: function(){
103 this.fs.copyTpl(
104 this.templatePath('src/sass/main.scss'),
105 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`),
106 {fileName: this._fistCharToUpper(config.name)}
107 );
108 },
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100109 mainJs: function(){
110 this.fs.copyTpl(
111 this.templatePath('src/js/main.js'),
112 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +0100113 { name: config.name, fileName: this._fistCharToUpper(config.name) }
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100114 );
115 },
116 template: function(){
117 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`));
118 },
119 gulp: function(){
Matteo Scandolo6be0cd22015-11-03 16:27:07 +0100120 this.fs.copyTpl(
121 this.templatePath('gulp/*.js'),
122 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
123 {name:config.name, fileName: this._fistCharToUpper(config.name)}
124 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100125 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolob165a3f2015-11-04 17:28:38 +0100126 },
127 karma: function(){
128 this.fs.copy(
129 this.templatePath('karma.conf.js'),
130 this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
131 );
132 },
133 spec: function(){
Matteo Scandolob165a3f2015-11-04 17:28:38 +0100134 this.fs.copyTpl(
135 this.templatePath('spec/sample.test.js'),
136 this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
137 { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
138 );
Matteo Scandoloe3bc18d2015-11-05 18:36:10 +0100139 },
140 lint: function(){
141 this.fs.copy(
142 this.templatePath('.eslintrc'),
143 this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`)
144 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100145 }
146 },
147 install: function(){
148 var done = this.async();
149 this.prompt({
150 type : 'confirm',
151 name : 'deps',
152 message : 'Install dependecies?',
153 default : false // value set in .yo-rc.json
154 }, function (answers) {
155 if(answers.deps){
156 process.chdir(`${this.config.get('folder')}/${config.name}`);
157 this.installDependencies();
158 }
Matteo Scandoloa0449cd2015-11-03 10:48:01 +0100159 done();
160 }.bind(this));
161 }
162});