forked from angular-fullstack/generator-angular-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
267 lines (236 loc) · 7.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
'use strict';
var fs = require('fs');
var path = require('path');
var util = require('util');
var genUtils = require('../util.js');
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var wiredep = require('wiredep');
var AngularFullstackGenerator = yeoman.generators.Base.extend({
init: function () {
this.argument('name', { type: String, required: false });
this.appname = this.name || path.basename(process.cwd());
this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname)));
this.option('app-suffix', {
desc: 'Allow a custom suffix to be added to the module name',
type: String,
required: 'false'
});
this.scriptAppName = this.appname + genUtils.appName(this);
this.appPath = this.env.options.appPath;
this.pkg = require('../package.json');
this.filters = {};
},
info: function () {
this.log(this.yeoman);
this.log('Out of the box I create an AngularJS app with an Express server.\n');
},
checkForConfig: function() {
var cb = this.async();
if(this.config.get('filters')) {
this.prompt([{
type: "confirm",
name: "skipConfig",
message: "Existing .yo-rc configuration found, would you like to use it?",
default: true,
}], function (answers) {
this.skipConfig = answers.skipConfig;
// NOTE: temp(?) fix for #403
if(typeof this.oauth==='undefined') {
var strategies = Object.keys(this.filters).filter(function(key) {
return key.match(/Auth$/) && key;
});
if(strategies.length) this.config.set('oauth', true);
}
cb();
}.bind(this));
} else {
cb();
}
},
clientPrompts: function() {
if(this.skipConfig) return;
var cb = this.async();
this.log('# Client\n');
this.prompt([{
type: "list",
name: "script",
message: "What would you like to write scripts with?",
choices: [ "JavaScript", "CoffeeScript"],
filter: function( val ) {
var filterMap = {
'JavaScript': 'js',
'CoffeeScript': 'coffee'
};
return filterMap[val];
}
}, {
type: "list",
name: "markup",
message: "What would you like to write markup with?",
choices: [ "HTML", "Jade"],
filter: function( val ) { return val.toLowerCase(); }
}, {
type: "list",
name: "stylesheet",
default: 1,
message: "What would you like to write stylesheets with?",
choices: [ "CSS", "Sass", "Stylus", "Less"],
filter: function( val ) { return val.toLowerCase(); }
}, {
type: "list",
name: "router",
default: 1,
message: "What Angular router would you like to use?",
choices: [ "ngRoute", "uiRouter"],
filter: function( val ) { return val.toLowerCase(); }
}, {
type: "confirm",
name: "bootstrap",
message: "Would you like to include Bootstrap?"
}, {
type: "confirm",
name: "uibootstrap",
message: "Would you like to include UI Bootstrap?",
when: function (answers) {
return answers.bootstrap;
}
}], function (answers) {
this.filters[answers.script] = true;
this.filters[answers.markup] = true;
this.filters[answers.stylesheet] = true;
this.filters[answers.router] = true;
this.filters.bootstrap = !!answers.bootstrap;
this.filters.uibootstrap = !!answers.uibootstrap;
cb();
}.bind(this));
},
serverPrompts: function() {
if(this.skipConfig) return;
var cb = this.async();
var self = this;
this.log('\n# Server\n');
this.prompt([{
type: "confirm",
name: "mongoose",
message: "Would you like to use mongoDB with Mongoose for data modeling?"
}, {
type: "confirm",
name: "auth",
message: "Would you scaffold out an authentication boilerplate?",
when: function (answers) {
return answers.mongoose;
}
}, {
type: 'checkbox',
name: 'oauth',
message: 'Would you like to include additional oAuth strategies?',
when: function (answers) {
return answers.auth;
},
choices: [
{
value: 'googleAuth',
name: 'Google',
checked: false
},
{
value: 'facebookAuth',
name: 'Facebook',
checked: false
},
{
value: 'twitterAuth',
name: 'Twitter',
checked: false
}
]
}, {
type: "confirm",
name: "socketio",
message: "Would you like to use socket.io?",
// to-do: should not be dependent on mongoose
when: function (answers) {
return answers.mongoose;
},
default: true
}], function (answers) {
if(answers.socketio) this.filters.socketio = true;
if(answers.mongoose) this.filters.mongoose = true;
if(answers.auth) this.filters.auth = true;
if(answers.oauth) {
if(answers.oauth.length) this.filters.oauth = true;
answers.oauth.forEach(function(oauthStrategy) {
this.filters[oauthStrategy] = true;
}.bind(this));
}
cb();
}.bind(this));
},
saveSettings: function() {
if(this.skipConfig) return;
this.config.set('insertRoutes', true);
this.config.set('registerRoutesFile', 'server/routes.js');
this.config.set('routesNeedle', '// Insert routes below');
this.config.set('routesBase', '/api/');
this.config.set('pluralizeRoutes', true);
this.config.set('insertSockets', true);
this.config.set('registerSocketsFile', 'server/config/socketio.js');
this.config.set('socketsNeedle', '// Insert sockets below');
this.config.set('filters', this.filters);
this.config.forceSave();
},
compose: function() {
if(this.skipConfig) return;
var appPath = 'client/app/';
var extensions = [];
var filters = [];
if(this.filters.ngroute) filters.push('ngroute');
if(this.filters.uirouter) filters.push('uirouter');
if(this.filters.coffee) extensions.push('coffee');
if(this.filters.js) extensions.push('js');
if(this.filters.html) extensions.push('html');
if(this.filters.jade) extensions.push('jade');
if(this.filters.css) extensions.push('css');
if(this.filters.stylus) extensions.push('styl');
if(this.filters.sass) extensions.push('scss');
if(this.filters.less) extensions.push('less');
this.composeWith('ng-component', {
options: {
'routeDirectory': appPath,
'directiveDirectory': appPath,
'filterDirectory': appPath,
'serviceDirectory': appPath,
'filters': filters,
'extensions': extensions,
'basePath': 'client'
}
}, { local: require.resolve('generator-ng-component/app/index.js') });
},
ngModules: function() {
this.filters = this._.defaults(this.config.get('filters'), {
bootstrap: true,
uibootstrap: true
});
var angModules = [
"'ngCookies'",
"'ngResource'",
"'ngSanitize'"
];
if(this.filters.ngroute) angModules.push("'ngRoute'");
if(this.filters.socketio) angModules.push("'btford.socket-io'");
if(this.filters.uirouter) angModules.push("'ui.router'");
if(this.filters.uibootstrap) angModules.push("'ui.bootstrap'");
this.angularModules = "\n " + angModules.join(",\n ") +"\n";
},
generate: function() {
this.sourceRoot(path.join(__dirname, './templates'));
genUtils.processDirectory(this, '.', '.');
},
end: function() {
this.installDependencies({
skipInstall: this.options['skip-install']
});
}
});
module.exports = AngularFullstackGenerator;