blob: 6ddbc6e02dc8bdef0b923b95445bead48728529b [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 Scandoloa0449cd2015-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 Scandoloe53ee052015-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 Scandoloba2af3d2015-11-06 10:35:20 +010044 index: function(){
Matteo Scandoloe53ee052015-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 Scandoloba2af3d2015-11-06 10:35:20 +010051 css: function(){
52 this.fs.copy(
53 this.templatePath('src/css/dev.css'),
54 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`)
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010055 );
56 },
Matteo Scandoloe53ee052015-11-03 14:32:00 +010057 mainJs: function(){
58 this.fs.copyTpl(
59 this.templatePath('src/js/main.js'),
60 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`),
61 { name: config.name }
62 );
63 },
64 template: function(){
65 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`));
66 },
67 gulp: function(){
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010068 this.fs.copyTpl(
69 this.templatePath('gulp/*.js'),
70 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
71 {name:config.name, fileName: this._fistCharToUpper(config.name)}
72 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +010073 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolob165a3f2015-11-04 17:28:38 +010074 },
75 karma: function(){
76 this.fs.copy(
77 this.templatePath('karma.conf.js'),
78 this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
79 );
80 },
81 spec: function(){
82 const userName = user.git.name().split(' ');
83 this.fs.copyTpl(
84 this.templatePath('spec/sample.test.js'),
85 this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
86 { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
87 );
Matteo Scandoloe3bc18d2015-11-05 18:36:10 +010088 },
89 lint: function(){
90 this.fs.copy(
91 this.templatePath('.eslintrc'),
92 this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`)
93 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +010094 }
95 },
96 install: function(){
97 var done = this.async();
98 this.prompt({
99 type : 'confirm',
100 name : 'deps',
101 message : 'Install dependecies?',
102 default : false // value set in .yo-rc.json
103 }, function (answers) {
104 if(answers.deps){
105 process.chdir(`${this.config.get('folder')}/${config.name}`);
106 this.installDependencies();
107 }
Matteo Scandoloa0449cd2015-11-03 10:48:01 +0100108 done();
109 }.bind(this));
110 }
111});