blob: 009550aed417c65518faea90484cb424545699f3 [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 Scandolo46485ac2015-11-03 10:48:01 +01007
8module.exports = generators.Base.extend({
Matteo Scandolodc88bf12015-11-03 16:27:07 +01009 _fistCharToUpper: function(string){
10 return string.replace(/^./, string[0].toUpperCase());
11 },
Matteo Scandolo46485ac2015-11-03 10:48:01 +010012 prompting: function(){
13 var done = this.async();
14 this.prompt({
15 type : 'input',
16 name : 'name',
17 message : 'Your project name',
18 default : this.config.get('name') // value set in .yo-rc.json
19 }, function (answers) {
Matteo Scandolof813b6a2015-11-03 14:32:00 +010020 // TODO check if this view already exist
21 config.name = answers.name;
22 done();
23 }.bind(this));
24 },
25 writing: {
26 rcFiles: function(){
27 this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`));
28 this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`));
29 },
30 packageJson: function(){
31 this.fs.copyTpl(
32 this.templatePath('package.json'),
33 this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`),
34 { name: config.name, author: {name:user.git.name()} }
35 );
36 },
37 bowerJson: function(){
38 this.fs.copyTpl(
39 this.templatePath('bower.json'),
40 this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`),
41 { name: config.name, author: {name:user.git.name(), email: user.git.email()} }
42 );
43 },
Matteo Scandolodc88bf12015-11-03 16:27:07 +010044 indexDev: function(){
Matteo Scandolof813b6a2015-11-03 14:32:00 +010045 this.fs.copyTpl(
46 this.templatePath('src/index.html'),
47 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`),
48 { name: config.name }
49 );
50 },
Matteo Scandolodc88bf12015-11-03 16:27:07 +010051 indexProd: function(){
52 this.fs.copyTpl(
53 this.templatePath('src/prod.html'),
54 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/xos${this._fistCharToUpper(config.name)}.html`),
55 { name: config.name, fileName: this._fistCharToUpper(config.name) }
56 );
57 },
Matteo Scandolof813b6a2015-11-03 14:32:00 +010058 mainJs: function(){
59 this.fs.copyTpl(
60 this.templatePath('src/js/main.js'),
61 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`),
62 { name: config.name }
63 );
64 },
65 template: function(){
66 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`));
67 },
68 gulp: function(){
Matteo Scandolodc88bf12015-11-03 16:27:07 +010069 this.fs.copyTpl(
70 this.templatePath('gulp/*.js'),
71 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
72 {name:config.name, fileName: this._fistCharToUpper(config.name)}
73 );
Matteo Scandolof813b6a2015-11-03 14:32:00 +010074 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolo78a94332015-11-04 17:28:38 +010075 },
76 karma: function(){
77 this.fs.copy(
78 this.templatePath('karma.conf.js'),
79 this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
80 );
81 },
82 spec: function(){
83 const userName = user.git.name().split(' ');
84 this.fs.copyTpl(
85 this.templatePath('spec/sample.test.js'),
86 this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
87 { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
88 );
Matteo Scandolof813b6a2015-11-03 14:32:00 +010089 }
90 },
91 install: function(){
92 var done = this.async();
93 this.prompt({
94 type : 'confirm',
95 name : 'deps',
96 message : 'Install dependecies?',
97 default : false // value set in .yo-rc.json
98 }, function (answers) {
99 if(answers.deps){
100 process.chdir(`${this.config.get('folder')}/${config.name}`);
101 this.installDependencies();
102 }
Matteo Scandolo46485ac2015-11-03 10:48:01 +0100103 done();
104 }.bind(this));
105 }
106});