blob: 0368fd2d59875937975c945a79c0fda3d00b5a50 [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 Scandoloecc988d2016-04-28 16:20:53 -07007var userName;
Matteo Scandolo46485ac2015-11-03 10:48:01 +01008
9module.exports = generators.Base.extend({
Matteo Scandolodc88bf12015-11-03 16:27:07 +010010 _fistCharToUpper: function(string){
11 return string.replace(/^./, string[0].toUpperCase());
12 },
Matteo Scandolobbfc0622015-12-01 16:02:29 -080013 prompting: {
Matteo Scandolo881fed52016-05-23 15:31:25 -070014 name: function(){
Matteo Scandolobbfc0622015-12-01 16:02:29 -080015 var done = this.async();
16 this.prompt({
Matteo Scandolo881fed52016-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 Scandolobbfc0622015-12-01 16:02:29 -080021 }, function (answers) {
Matteo Scandolobbfc0622015-12-01 16:02:29 -080022 // TODO check if this view already exist
23 config.name = answers.name;
24 done();
25 }.bind(this));
Matteo Scandolobbfc0622015-12-01 16:02:29 -080026 }
Matteo Scandolof813b6a2015-11-03 14:32:00 +010027 },
28 writing: {
29 rcFiles: function(){
arpiagariuc959e4f2016-05-17 15:37:38 -070030 if (!user.git.name()){
Matteo Scandolo881fed52016-05-23 15:31:25 -070031 userName = ['', '']
arpiagariuc959e4f2016-05-17 15:37:38 -070032 }
33 else {
34 userName = user.git.name().split(' ');
35 }
Matteo Scandolof813b6a2015-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 Scandolo881fed52016-05-23 15:31:25 -070043 { name: config.name, author: {name: user.git.name()} }
Matteo Scandolof813b6a2015-11-03 14:32:00 +010044 );
45 },
46 bowerJson: function(){
47 this.fs.copyTpl(
48 this.templatePath('bower.json'),
49 this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`),
Matteo Scandolo881fed52016-05-23 15:31:25 -070050 { name: config.name, author: {name: user.git.name(), email: user.git.email()} }
Matteo Scandolof813b6a2015-11-03 14:32:00 +010051 );
52 },
Matteo Scandoloc7794962015-11-06 10:35:20 +010053 index: function(){
Matteo Scandolof813b6a2015-11-03 14:32:00 +010054 this.fs.copyTpl(
55 this.templatePath('src/index.html'),
56 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/index.html`),
Matteo Scandoloecc988d2016-04-28 16:20:53 -070057 { name: config.name, fileName: this._fistCharToUpper(config.name), user: {firstname: userName[0]}}
Matteo Scandolof813b6a2015-11-03 14:32:00 +010058 );
59 },
Matteo Scandoloc7794962015-11-06 10:35:20 +010060 css: function(){
Matteo Scandoloab91f432015-11-06 18:25:52 +010061 this.fs.copyTpl(
Matteo Scandoloc7794962015-11-06 10:35:20 +010062 this.templatePath('src/css/dev.css'),
Matteo Scandoloab91f432015-11-06 18:25:52 +010063 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/css/dev.css`),
64 {fileName: this._fistCharToUpper(config.name)}
Matteo Scandolodc88bf12015-11-03 16:27:07 +010065 );
66 },
Matteo Scandoloba1ed912016-03-29 14:23:20 -070067 css: function(){
68 this.fs.copyTpl(
69 this.templatePath('src/sass/main.scss'),
70 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/sass/main.scss`),
71 {fileName: this._fistCharToUpper(config.name)}
72 );
73 },
Matteo Scandolof813b6a2015-11-03 14:32:00 +010074 mainJs: function(){
75 this.fs.copyTpl(
76 this.templatePath('src/js/main.js'),
77 this.destinationPath(`${this.config.get('folder')}/${config.name}/src/js/main.js`),
Matteo Scandoloab91f432015-11-06 18:25:52 +010078 { name: config.name, fileName: this._fistCharToUpper(config.name) }
Matteo Scandolof813b6a2015-11-03 14:32:00 +010079 );
80 },
81 template: function(){
82 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`));
83 },
84 gulp: function(){
Matteo Scandolodc88bf12015-11-03 16:27:07 +010085 this.fs.copyTpl(
86 this.templatePath('gulp/*.js'),
87 this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
Matteo Scandolo881fed52016-05-23 15:31:25 -070088 {name: config.name, fileName: this._fistCharToUpper(config.name)}
Matteo Scandolodc88bf12015-11-03 16:27:07 +010089 );
Matteo Scandolof813b6a2015-11-03 14:32:00 +010090 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
Matteo Scandolo78a94332015-11-04 17:28:38 +010091 },
92 karma: function(){
93 this.fs.copy(
94 this.templatePath('karma.conf.js'),
95 this.destinationPath(`${this.config.get('folder')}/${config.name}/karma.conf.js`)
96 );
97 },
98 spec: function(){
Matteo Scandolo78a94332015-11-04 17:28:38 +010099 this.fs.copyTpl(
100 this.templatePath('spec/sample.test.js'),
101 this.destinationPath(`${this.config.get('folder')}/${config.name}/spec/sample.test.js`),
102 { name: config.name, user: {email: user.git.email(), firstname: userName[0], lastname: userName[1] } }
103 );
Matteo Scandolo7cf73ad2015-11-05 18:36:10 +0100104 },
105 lint: function(){
106 this.fs.copy(
107 this.templatePath('.eslintrc'),
108 this.destinationPath(`${this.config.get('folder')}/${config.name}/.eslintrc`)
109 );
Matteo Scandolof813b6a2015-11-03 14:32:00 +0100110 }
111 },
112 install: function(){
113 var done = this.async();
114 this.prompt({
Matteo Scandolo881fed52016-05-23 15:31:25 -0700115 type: 'confirm',
116 name: 'deps',
117 message: 'Install dependecies?',
118 default: false // value set in .yo-rc.json
Matteo Scandolof813b6a2015-11-03 14:32:00 +0100119 }, function (answers) {
120 if(answers.deps){
121 process.chdir(`${this.config.get('folder')}/${config.name}`);
122 this.installDependencies();
123 }
Matteo Scandolo46485ac2015-11-03 10:48:01 +0100124 done();
125 }.bind(this));
126 }
127});