blob: 43b82e4d2fd052ff25f18d620eb5f563ca397dd7 [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: {
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070014 name: function(){
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080015 var done = this.async();
16 this.prompt({
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070017 type: 'input',
18 name: 'name',
19 message: 'Your project name',
20 default: this.config.get('name') // value set in .yo-rc.json
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080021 }, 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));
Matteo Scandolod05ac6c2015-12-01 16:02:29 -080026 }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010027 },
28 writing: {
29 rcFiles: function(){
arpiagariu4bb9e5b2016-05-17 15:37:38 -070030 if (!user.git.name()){
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070031 userName = ['', '']
arpiagariu4bb9e5b2016-05-17 15:37:38 -070032 }
33 else {
34 userName = user.git.name().split(' ');
35 }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010036 this.fs.copy(this.templatePath('.bowerrc'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.bowerrc`));
37 this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${this.config.get('folder')}/${config.name}/.gitignore`));
38 },
39 packageJson: function(){
40 this.fs.copyTpl(
41 this.templatePath('package.json'),
42 this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`),
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070043 { name: config.name, author: {name: user.git.name()} }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010044 );
45 },
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070046 // envConfig: function(){
47 // this.fs.copyTpl(
48 // this.templatePath('env/default.js'),
49 // this.destinationPath(`${this.config.get('folder')}/${config.name}/env/default.js`),
50 // { host: config.host, token: config.token, session: config.session }
51 // );
52 // },
Matteo Scandoloe53ee052015-11-03 14:32:00 +010053 bowerJson: function(){
54 this.fs.copyTpl(
55 this.templatePath('bower.json'),
56 this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`),
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070057 { name: config.name, author: {name: user.git.name(), email: user.git.email()} }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010058 );
59 },
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010060 index: function(){
Matteo Scandoloe53ee052015-11-03 14:32:00 +010061 this.fs.copyTpl(
62 this.templatePath('src/index.html'),
63 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`),
Matteo Scandoloa3839e32016-04-28 16:20:53 -070064 { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}}
Matteo Scandoloe53ee052015-11-03 14:32:00 +010065 );
66 },
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010067 css: function(){
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010068 this.fs.copyTpl(
Matteo Scandoloba2af3d2015-11-06 10:35:20 +010069 this.templatePath('src/css/dev.css'),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010070 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`),
71 {fileName: this._fistCharToUpper(config.name)}
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010072 );
73 },
Matteo Scandolob7c91cf2016-03-29 14:23:20 -070074 css: function(){
75 this.fs.copyTpl(
76 this.templatePath('src/sass/main.scss'),
77 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`),
78 {fileName: this._fistCharToUpper(config.name)}
79 );
80 },
Matteo Scandoloe53ee052015-11-03 14:32:00 +010081 mainJs: function(){
82 this.fs.copyTpl(
83 this.templatePath('src/js/main.js'),
84 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`),
Matteo Scandoloba5e19d2015-11-06 18:25:52 +010085 { name: config.name, fileName: this._fistCharToUpper(config.name) }
Matteo Scandoloe53ee052015-11-03 14:32:00 +010086 );
87 },
88 template: function(){
89 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`));
90 },
91 gulp: function(){
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010092 this.fs.copyTpl(
93 this.templatePath('gulp/*.js'),
94 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070095 {name: config.name, fileName: this._fistCharToUpper(config.name)}
Matteo Scandolo6be0cd22015-11-03 16:27:07 +010096 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +010097 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolob165a3f2015-11-04 17:28:38 +010098 },
99 karma: function(){
100 this.fs.copy(
101 this.templatePath('karma.conf.js'),
102 this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
103 );
104 },
105 spec: function(){
Matteo Scandolob165a3f2015-11-04 17:28:38 +0100106 this.fs.copyTpl(
107 this.templatePath('spec/sample.test.js'),
108 this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
109 { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
110 );
Matteo Scandoloe3bc18d2015-11-05 18:36:10 +0100111 },
112 lint: function(){
113 this.fs.copy(
114 this.templatePath('.eslintrc'),
115 this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`)
116 );
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100117 }
118 },
119 install: function(){
120 var done = this.async();
121 this.prompt({
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -0700122 type: 'confirm',
123 name: 'deps',
124 message: 'Install dependecies?',
125 default: false // value set in .yo-rc.json
Matteo Scandoloe53ee052015-11-03 14:32:00 +0100126 }, function (answers) {
127 if(answers.deps){
128 process.chdir(`${this.config.get('folder')}/${config.name}`);
129 this.installDependencies();
130 }
Matteo Scandoloa0449cd2015-11-03 10:48:01 +0100131 done();
132 }.bind(this));
133 }
134});