Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 1018 lines (862 sloc) 29.569 kb
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
1 // Load the basic Geddy toolkit
2 require('../lib/geddy')
3
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
4 // Dependencies
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
5 var cwd = process.cwd()
6 , fs = require('fs')
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
7 , path = require('path')
d278a7e Get example app working with external model lib
mde authored
8 , utils = require('../lib/utils')
7ae4e05 Added generator for auth
mde authored
9 , Adapter = require('../lib/template/adapters')
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
10 , geddyPassport = 'geddy-passport@0.0.x'
7ae4e05 Added generator for auth
mde authored
11 , getRouterPath
3900a2b @larzconwell Closes #215 Added a geddy routes command that takes an optional route
larzconwell authored
12 , getRoutes
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
13 , addRoute
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
14 , mixinJSONData;
7ae4e05 Added generator for auth
mde authored
15
16 getRouterPath = function () {
17 var beginPath
18 , jsRouter = path.normalize('config/router.js')
19 , coffeeRouter = path.normalize('config/router.coffee')
20 , routerPath;
21 // Check if the router file exists
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
22 beginPath = path.join(cwd, 'config');
7ae4e05 Added generator for auth
mde authored
23 utils.file.searchParentPath(jsRouter, function (err) {
24 if (err) {
25 var jsErr = err;
26 // If jsEnvironment wasn't found, try finding coffee variant
27 utils.file.searchParentPath(coffeeRouter, beginPath, function (err) {
28 if (err) {
29 throw jsErr;
30 } else {
31 routerPath = coffeeRouter;
32 }
33 });
34 } else {
35 routerPath = jsRouter;
36 }
37 });
38 return routerPath;
39 };
40
3900a2b @larzconwell Closes #215 Added a geddy routes command that takes an optional route
larzconwell authored
41 getRoutes = function (resource) {
42 if (!resource) {
43 return geddy.router.toString();
44 }
45
46 var rts = []
47 , _rt
48 , i;
49
50 // If a full route name was given add it to the list(e,g,. users.index)
51 if (resource.match(/.+\..+/)) {
52 var res = resource.split('.')
53 , cont = res[0]
54 , action = res[1];
55
56 for (i in geddy.router.routes) {
57 _rt = geddy.router.routes[i];
58
59 if (_rt.params.controller.match(cont) &&
60 _rt.params.action.match(action)) {
61 rts.push(_rt);
62 }
63 }
64 }
65 else {
66 for (i in geddy.router.routes) {
67 _rt = geddy.router.routes[i];
68
69 if (_rt.params.controller.match(resource) ||
70 _rt.params.action.match(resource)) {
71 rts.push(_rt);
72 }
73 }
74 }
75
76 return rts.map(function (rt) {
77 return rt.toString();
78 }).join('\n');
79 };
80
7ae4e05 Added generator for auth
mde authored
81 addRoute = function (routerPath, newRoute) {
82 var text = fs.readFileSync(routerPath, 'utf8')
83 , routerArr;
84 // Don't add the same route over and over
85 if (text.indexOf(newRoute) == -1) {
86 // Add the new resource route just above the export
87 routerArr = text.split('exports.router');
88 routerArr[0] += newRoute + '\n';
89
90 text = routerArr.join('exports.router');
91 fs.writeFileSync(routerPath, text, 'utf8');
92 return true;
93 }
94 else {
95 return false;
96 }
97 };
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
98
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
99 mixinJSONData = function (file, obj) {
100 var data = obj || {};
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
101
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
102 if (utils.file.existsSync(file)) {
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
103 try {
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
104 var content = JSON.parse(fs.readFileSync(file, 'utf8'));
105 utils.object.merge(content, data);
106 fs.writeFileSync(file, JSON.stringify(content, null, 2));
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
107 }
108 catch (e) {
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
109 throw new Error("Could not parse " + file);
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
110 }
111 }
112 else {
3620c04 @MiguelMadero Fixes typo
MiguelMadero authored
113 console.log("There is no file " + file + " to add data to.");
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
114 }
115 };
116
d278a7e Get example app working with external model lib
mde authored
117 namespace('env', function () {
e4ad4a1 Bandaid environment-setting for env:init
mde authored
118 task('init', function () {
119 var cfg = {};
120 if (process.env.environment) {
121 cfg.environment = process.env.environment;
122 }
123
d278a7e Get example app working with external model lib
mde authored
124 jake.addListener('complete', function (e) {
125 jake.Task['env:cleanup'].invoke();
126 });
9e1fe04 Got generators working.
mde authored
127
e4ad4a1 Bandaid environment-setting for env:init
mde authored
128 geddy.config = require('../lib/config').readConfig(cfg);
9e1fe04 Got generators working.
mde authored
129 geddy.model = require('model');
130
5da7b94 Cleaned up env init process a little more
mde authored
131 require('../lib/init').init(geddy, function () {
9e1fe04 Got generators working.
mde authored
132 complete();
133 });
134 }, {async: true});
d278a7e Get example app working with external model lib
mde authored
135
136 task('cleanup', function () {
137 // Disconnect all the adapters
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
138 var adapters = geddy.model.loadedAdapters
139 , adapter;
140
d278a7e Get example app working with external model lib
mde authored
141 for (var p in adapters) {
48fb464 Fixed DB adapter connect/disconnect
mde authored
142 adapter = adapters[p];
143 if (typeof adapter.disconnect == 'function') {
144 adapter.disconnect();
145 }
d278a7e Get example app working with external model lib
mde authored
146 }
147 });
148
3e0c059 Added basic console feature
mde authored
149 });
150
151 namespace('console', function () {
e4ad4a1 Bandaid environment-setting for env:init
mde authored
152 task('start', ['env:init'], {async: true}, function () {
153 var t = jake.Task['env:init'];
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
154
3e0c059 Added basic console feature
mde authored
155 t.addListener('complete', function () {
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
156 var repl = require('repl')
157 , rl;
158
159 rl = repl.start({
160 prompt: '>>> '
161 , input: process.stdin
162 , output: process.stdout
3e0c059 Added basic console feature
mde authored
163 });
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
164
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
165 rl.on('close', function () {
166 console.log('Exiting...');
f0c7bc1 @Techwraith added echo and capture helper funtions to the console
Techwraith authored
167 return complete();
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
168 })
f0c7bc1 @Techwraith added echo and capture helper funtions to the console
Techwraith authored
169
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
170 rl.context.capture = function (err, data) {
171 return rl.context.results = {
172 err: err
173 , data: data
174 };
f0c7bc1 @Techwraith added echo and capture helper funtions to the console
Techwraith authored
175 };
176
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
177 rl.context.echo = function (err, data) {
178 rl.context.capture(err, data);
179 if (err) {
180 console.log('Error: ', err);
181 }
182
183 if (data) {
184 if (data.length) {
185 for (var i in data) {
186 if (data[i] && data[i].toData) {
187 console.log(data[i].toData());
188 } else {
189 console.log(data[i]);
190 }
191 }
192 }
193 else {
194 if (data && data.toData) {
195 console.log(data.toData());
f0c7bc1 @Techwraith added echo and capture helper funtions to the console
Techwraith authored
196 } else {
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
197 console.log(data);
f0c7bc1 @Techwraith added echo and capture helper funtions to the console
Techwraith authored
198 }
199 }
200 } else {
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
201 console.log('No data');
f0c7bc1 @Techwraith added echo and capture helper funtions to the console
Techwraith authored
202 }
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
203 };
3900a2b @larzconwell Closes #215 Added a geddy routes command that takes an optional route
larzconwell authored
204
205 rl.context.routes = function (resource) {
206 console.log(getRoutes(resource));
207 };
bb90185 @larzconwell Closes #252, Replace readline REPL with repl REPL, which does autocom…
larzconwell authored
208 });
f0c7bc1 @Techwraith added echo and capture helper funtions to the console
Techwraith authored
209
e4ad4a1 Bandaid environment-setting for env:init
mde authored
210 t.invoke();
3e0c059 Added basic console feature
mde authored
211 });
212 });
d278a7e Get example app working with external model lib
mde authored
213
3900a2b @larzconwell Closes #215 Added a geddy routes command that takes an optional route
larzconwell authored
214 namespace('routes', function () {
215
216 task('show', ['env:init'], {async: true}, function (resource) {
217 console.log('Showing route results for "' + resource + '"');
218 console.log(getRoutes(resource));
219 });
220
221 });
222
d278a7e Get example app working with external model lib
mde authored
223 namespace('db', function () {
48fb464 Fixed DB adapter connect/disconnect
mde authored
224 task('createTable', ['env:init'], function (name) {
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
225
9e1fe04 Got generators working.
mde authored
226 var modelName
48fb464 Fixed DB adapter connect/disconnect
mde authored
227 , createTable
d278a7e Get example app working with external model lib
mde authored
228 , adapters
9e1fe04 Got generators working.
mde authored
229 , adapter;
230
231 if (typeof name == 'string') {
c7f64c5 Can't use commas with new embeddable Jake
mde authored
232 if (name.indexOf('%') > -1) {
233 modelNames = name.split('%');
9e1fe04 Got generators working.
mde authored
234 }
235 else {
236 modelNames = [name];
237 }
238 }
239 else {
240 modelNames = name;
241 }
242
d278a7e Get example app working with external model lib
mde authored
243 createTable = function () {
48fb464 Fixed DB adapter connect/disconnect
mde authored
244 if ((m = modelNames.shift())) {
9e1fe04 Got generators working.
mde authored
245
246 // Make sure this is a correct model-name
247 m = utils.string.getInflections(m).constructor.singular;
248 if (!geddy.model[m]) {
249 throw new Error(m + ' is not a known model.');
250 }
251
d278a7e Get example app working with external model lib
mde authored
252 adapter = geddy.model.adapters[m];
9e1fe04 Got generators working.
mde authored
253 if (adapter) {
254 console.log('Creating table for ' + m);
255 adapter.createTable(m, function (err, data) {
256 if (err) { throw err }
257 createTable();
258 });
259 }
260 else {
d278a7e Get example app working with external model lib
mde authored
261 createTable();
9e1fe04 Got generators working.
mde authored
262 }
d278a7e Get example app working with external model lib
mde authored
263 }
264 else {
265 complete();
266 }
267 };
b13d0e0 Defer table-creation until deferred association-creation
mde authored
268 // Defer until associations are set up
269 setTimeout(function () {
270 createTable();
271 }, 0);
48fb464 Fixed DB adapter connect/disconnect
mde authored
272 }, {async: true});
273
d192f14 'retrofit' task should just be init for SQL DBs
mde authored
274 task('init', ['env:init'], function () {
48fb464 Fixed DB adapter connect/disconnect
mde authored
275 var modelNames = Object.keys(geddy.model.descriptionRegistry)
276 , createTask = jake.Task['db:createTable'];
277 createTask.once('complete', function () {
278 complete();
279 });
280 createTask.invoke(modelNames);
d278a7e Get example app working with external model lib
mde authored
281 }, {async: true});
282
283 });
284
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
285 namespace('gen', function () {
286
b262b1c @larzconwell Default ID attribute is now 'int', if scaffold model template the def…
larzconwell authored
287 var _writeTemplate = function (name, filename, dirname, opts) {
288 var options = opts || {}
289 , names = utils.string.getInflections(name)
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
290 , text = fs.readFileSync(path.join(__dirname, filename + '.ejs'), 'utf8').toString()
cf999ea @larzconwell Deleted bare controller template
larzconwell authored
291 , bare = options.bare || false // Default to full controller
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
292 , adapter
293 , templContent
9ec7c3a @MiguelMadero Changed the generator to create the directory in case it doesn't exis…
MiguelMadero authored
294 , fileDir
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
295 , filePath;
296
297 // Render with the right model name
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
298 adapter = new Adapter({engine: 'ejs', template: text});
299 templContent = adapter.render({names: names, bare: bare, properties: options.properties});
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
300
301 // Write file
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
302 fileDir = dirname;
fc70402 @MiguelMadero Removed usage of fs.existsSync for compatibility with node 0.6 and ch…
MiguelMadero authored
303 if (!utils.file.existsSync(fileDir)) {
304 fs.mkdirSync(fileDir);
305 }
9ec7c3a @MiguelMadero Changed the generator to create the directory in case it doesn't exis…
MiguelMadero authored
306
307 filePath = path.join(fileDir, names.filename[options.inflection] + '.js');
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
308 fs.writeFileSync(filePath, templContent, 'utf8');
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
309
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
310 console.log('[Added] ' + filePath);
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
311 };
312
edf26c7 Formatting
mde authored
313 var _formatModelProperties = function (properties) {
515a929 @larzconwell Closes #259, Fix error where no properties at all would throw when co…
larzconwell authored
314 var obj = {default: {name: '', type: ''}};
9e1fe04 Got generators working.
mde authored
315 if (!properties) {
515a929 @larzconwell Closes #259, Fix error where no properties at all would throw when co…
larzconwell authored
316 return obj;
9e1fe04 Got generators working.
mde authored
317 }
515a929 @larzconwell Closes #259, Fix error where no properties at all would throw when co…
larzconwell authored
318 obj['default'].name = 'id';
89831d2 @larzconwell Default to string ID type instead of int for generators.
larzconwell authored
319 obj['default'].type = 'string';
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
320
d3f4d44 Spaces aren't legal inside passed Jake params.
mde authored
321 var itemsArr = properties.split('%')
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
322 , name
323 , type
9925793 @larzconwell Added default option to model property arguments as @TechWraith sugge…
larzconwell authored
324 , args
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
325 , i
326 , value;
327
26600c5 @larzconwell Just made a few loop optimizations for Array loops
larzconwell authored
328 i = -1;
d9fe3bb @larzconwell Get rid of all the syntax differences, well most of them.
larzconwell authored
329 while (++i < itemsArr.length) {
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
330 value = itemsArr[i];
dd3a65b @larzconwell Don't allow nodel property names to be CamelCased
larzconwell authored
331 name = utils.string.camelize(value.replace(/:.*/g, ''));
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
332 type = value.replace(/[a-zA-Z]*:?/, '');
9925793 @larzconwell Added default option to model property arguments as @TechWraith sugge…
larzconwell authored
333 args = type.replace(/[a-zA-Z]*:?/, '');
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
334
9925793 @larzconwell Added default option to model property arguments as @TechWraith sugge…
larzconwell authored
335 // Take off any args on the type
336 type = type.replace(/:.*/g, '');
337
9e1fe04 Got generators working.
mde authored
338 // Defaults and aliases
d9fe3bb @larzconwell Get rid of all the syntax differences, well most of them.
larzconwell authored
339 if (!type) {
9925793 @larzconwell Added default option to model property arguments as @TechWraith sugge…
larzconwell authored
340 type = 'string';
9e2a69d @larzconwell If text attribute is given it switches to string, also took out place…
larzconwell authored
341 }
d9489a2 @larzconwell Closes 210, Generators will use `name` and `title` properties as the …
larzconwell authored
342 if (args === 'def') {
343 args = 'default';
344 }
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
345
d9fe3bb @larzconwell Get rid of all the syntax differences, well most of them.
larzconwell authored
346 switch (type) {
f835d2f @larzconwell Move type checks for generatirs into a switch statement so can be eas…
larzconwell authored
347 case 'integer':
348 type = 'int';
349 break;
350 case 'bool':
351 type = 'boolean';
352 break;
353 case 'default':
354 case 'def':
355 type = 'string';
356 args = 'default';
357 break;
9925793 @larzconwell Added default option to model property arguments as @TechWraith sugge…
larzconwell authored
358 }
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
359
bc02170 @larzconwell Closes #230, Don't manually add the ID attribute into the model prope…
larzconwell authored
360 // Manage properties that deal with changing default properties
d9489a2 @larzconwell Closes 210, Generators will use `name` and `title` properties as the …
larzconwell authored
361 if (args === 'default') {
bc02170 @larzconwell Closes #230, Don't manually add the ID attribute into the model prope…
larzconwell authored
362 // Reset old default property to it's own property, only if it's not
363 // already the default
364 if (name !== obj['default'].name) {
365 // If the new default item already exists then delete it
366 if (obj[name]) {
367 delete obj[name];
368 }
369
370 obj[obj['default'].name] = obj[obj['default'].name] || obj['default'];
371 }
d9489a2 @larzconwell Closes 210, Generators will use `name` and `title` properties as the …
larzconwell authored
372
373 // Add new default property
374 obj['default'] = {name: name, type: type};
375 continue;
d9fe3bb @larzconwell Get rid of all the syntax differences, well most of them.
larzconwell authored
376 }
377
d9489a2 @larzconwell Closes 210, Generators will use `name` and `title` properties as the …
larzconwell authored
378 // If ID property is given and it matches the default
379 // then rewrite the default with the new ID property
380 if (name === 'id' && obj['default'].name === 'id') {
9925793 @larzconwell Added default option to model property arguments as @TechWraith sugge…
larzconwell authored
381 obj['default'] = {name: name, type: type};
d9489a2 @larzconwell Closes 210, Generators will use `name` and `title` properties as the …
larzconwell authored
382 continue;
9e1fe04 Got generators working.
mde authored
383 }
d9489a2 @larzconwell Closes 210, Generators will use `name` and `title` properties as the …
larzconwell authored
384
385 // If the name is name or title then set them to default, otherwise add
386 // the property normally
387 if (name === 'name' || name === 'title') {
388 // Reset old default to it's own property
389 obj[obj['default'].name] = obj[obj['default'].name] || obj['default'];
390
391 // Add new default property
392 obj['default'] = {name: name, type: type};
393 } else {
394 obj[name] = {name: name, type: type};
9925793 @larzconwell Added default option to model property arguments as @TechWraith sugge…
larzconwell authored
395 }
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
396 }
397
9925793 @larzconwell Added default option to model property arguments as @TechWraith sugge…
larzconwell authored
398 return obj;
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
399 };
400
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
401 // Creates a new Geddy app scaffold
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
402 task('app', function (name, engine, realtime) {
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
403 var basePath = path.join(__dirname, 'base')
404 , mkdirs
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
405 , cps
406 , text
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
407 , adapter;
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
408
9e1fe04 Got generators working.
mde authored
409 if (!name) {
410 throw new Error('No app name specified.');
411 }
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
412 if (!engine || engine == 'default') {
9e1fe04 Got generators working.
mde authored
413 engine = 'ejs';
414 }
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
415 if (realtime == 'default') {
416 realtime = false;
417 }
418
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
419 mkdirs = [
420 ''
421 , 'config'
422 , 'app/models'
423 , 'app/controllers'
424 , 'app/helpers'
425 , 'lib'
426 , 'log'
427 , 'node_modules'
428 , 'test'
429 ];
430 cps = [
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
431 (realtime) ? ['realtime/views/' + engine, 'app/views'] : ['views/' + engine, 'app/views']
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
432 , ['public', '']
433 , ['router.js', 'config']
434 , ['init.js', 'config']
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
435 , (realtime) ? ['realtime/environment.js', 'config'] : ['environment.js', 'config']
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
436 , ['development.js', 'config']
437 , ['production.js', 'config']
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
438 , ['secrets.json', 'config']
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
439 , ['main.js', 'app/controllers']
440 , ['application.js', 'app/controllers']
441 , ['favicon.ico', 'public']
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
442 , ['gitignore.txt', '.gitignore']
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
443 ];
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
444
edf26c7 Formatting
mde authored
445 mkdirs.forEach(function (dir) {
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
446 jake.mkdirP(path.join(name, dir));
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
447 });
edf26c7 Formatting
mde authored
448 cps.forEach(function (cp) {
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
449 jake.cpR(path.join(basePath, cp[0]), path.join(name, cp[1]), {silent: true});
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
450 });
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
451
944267c @Techwraith RT-MVC: added build init step, copied socket.io into all realtime app…
Techwraith authored
452 // one offs
453 if (realtime) {
454 jake.cpR(path.join(__dirname, '..', 'node_modules', 'socket.io' ), path.join(name, 'node_modules'), {silent: true});
455 }
456
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
457 // Compile Jakefile
458 text = fs.readFileSync(path.join(basePath, 'Jakefile.ejs'), 'utf8').toString();
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
459 adapter = new Adapter({engine: 'ejs', template: text});
460 fs.writeFileSync(path.join(name, 'Jakefile'), adapter.render({appName: name}), 'utf8');
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
461
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
462 // Compile package.json
463 text = fs.readFileSync(path.join(basePath, 'package.json.ejs'), 'utf8').toString();
464 adapter = new Adapter({engine: 'ejs', template: text});
465 fs.writeFileSync(path.join(name, 'package.json'), adapter.render({appName: name}), 'utf8');
466
467 // Add engine to package.json if it's not EJS
468 if (engine !== 'ejs') {
469 // Change to handlebars as we use it behind the scenes
470 if (engine === 'mustache') {
471 engine = 'handlebars';
472 }
473 var data = {dependencies: {}};
474 data.dependencies[engine] = "*";
475
476 mixinJSONData(path.join(name, 'package.json'), data);
477 }
478
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
479 console.log('Created app ' + name + '.');
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
480 });
481
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
482 // Creates a resource with a model, controller and a resource route
edf26c7 Formatting
mde authored
483 task('resource', function (name, modelProperties) {
9e1fe04 Got generators working.
mde authored
484 var names
485 , modelTask = jake.Task['gen:model'];
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
486
9e1fe04 Got generators working.
mde authored
487 if (!name) {
488 throw new Error('No resource name specified.');
489 }
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
490
9e1fe04 Got generators working.
mde authored
491 modelTask.on('complete', function () {
492 jake.Task['gen:controller'].invoke(name);
493 jake.Task['gen:route'].invoke(name);
494 names = utils.string.getInflections(name);
495 // Create views folder but not actions
496 jake.mkdirP(path.join('app', 'views', names.filename.plural));
497 console.log('[Added] ' + names.filename.plural + ' view directory');
498 complete();
499 });
500 modelTask.invoke(name, modelProperties);
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
501
9e1fe04 Got generators working.
mde authored
502 }, {async: true});
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
503
504 // Creates a full scaffold with views, a model, controller and a resource route
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
505 task('scaffold', function (name, realtime, engine, modelProperties) {
9e1fe04 Got generators working.
mde authored
506 var modelTask = jake.Task['gen:model'];
507
508 if (!name) {
509 throw new Error('No scaffold name specified.');
510 }
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
511 if (!engine || engine == 'default') {
9e1fe04 Got generators working.
mde authored
512 engine = 'ejs';
513 }
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
514 if (!realtime || realtime == 'default') {
515 realtime = false;
516 }
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
517
9e1fe04 Got generators working.
mde authored
518 modelTask.on('complete', function () {
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
519 jake.Task['gen:test'].invoke(name,
520 {properties: modelProperties});
9e1fe04 Got generators working.
mde authored
521 jake.Task['gen:controllerScaffold'].invoke(name,
522 {properties: modelProperties});
523 jake.Task['gen:route'].invoke(name);
524 jake.Task['gen:viewsScaffold'].invoke(name,
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
525 {engine: engine, properties: modelProperties, realtime: realtime});
9e1fe04 Got generators working.
mde authored
526 complete();
693a0fe @larzconwell Created a file utils function that will search for a dir/file in up t…
larzconwell authored
527 });
b262b1c @larzconwell Default ID attribute is now 'int', if scaffold model template the def…
larzconwell authored
528 modelTask.invoke(name, modelProperties, 'scaffold');
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
529
9e1fe04 Got generators working.
mde authored
530 }, {async: true});
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
531
b262b1c @larzconwell Default ID attribute is now 'int', if scaffold model template the def…
larzconwell authored
532 task('model', function (name, properties, modelPath) {
9e1fe04 Got generators working.
mde authored
533 var createTableTask;
534 if (!name) {
535 throw new Error('No model name specified.');
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
536 }
b262b1c @larzconwell Default ID attribute is now 'int', if scaffold model template the def…
larzconwell authored
537 if (!modelPath) {
538 modelPath = 'resource';
539 }
540 modelPath += '/model';
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
541
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
542 _writeTemplate(name, modelPath, path.join('app', 'models'), {
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
543 inflection: 'singular'
544 , properties: _formatModelProperties(properties)
545 });
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
546
9e1fe04 Got generators working.
mde authored
547 // Try to create a table -- should be a no-op if an
548 // appropriate DB adapter can't be found
549 createTableTask = jake.Task['db:createTable'];
550 createTableTask.on('complete', function () {
551 complete();
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
552 });
9e1fe04 Got generators working.
mde authored
553 createTableTask.invoke(name);
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
554
9e1fe04 Got generators working.
mde authored
555 }, {async: true});
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
556
9e1fe04 Got generators working.
mde authored
557 task('controller', function (name) {
558 if (!name) {
559 throw new Error('No controller name specified.');
560 }
561
e7a7bda @larzconwell Remove the require for child_process since we don't use it anymore
larzconwell authored
562
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
563 _writeTemplate(name, 'resource/controller', path.join('app', 'controllers'),
9e1fe04 Got generators working.
mde authored
564 {inflection: 'plural', bare: false});
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
565 });
566
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
567 task('test', function (name) {
568 if (!name) {
569 throw new Error('No test name specified.');
570 }
571
572 _writeTemplate(name, 'resource/test', 'test',
573 {inflection: 'singular'});
574 });
575
9e1fe04 Got generators working.
mde authored
576 task('controllerScaffold', function (name, options) {
577 if (!name) {
578 throw new Error('No controller name specified.');
579 }
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
580 options = options || {};
581
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
582 _writeTemplate(name, 'scaffold/controller', path.join('app', 'controllers'), {
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
583 inflection: 'plural'
584 , bare: false
585 , properties: _formatModelProperties(options.properties)
586 });
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
587 });
588
9e1fe04 Got generators working.
mde authored
589 task('bareController', function (name, engine) {
590 if (!name) {
591 throw new Error('No controller name specified.');
592 }
e7a7bda @larzconwell Remove the require for child_process since we don't use it anymore
larzconwell authored
593 if (!engine || engine == 'default') {
9e1fe04 Got generators working.
mde authored
594 engine = 'ejs';
595 }
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
596
109ee59 Added Jakefile, test dir to app, test stubs to scaffolds.
mde authored
597 _writeTemplate(name, 'resource/controller', path.join('app', 'controllers'),
598 {inflection: 'plural', bare: true});
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
599 jake.Task['gen:route'].invoke(name, {bare: true});
600 jake.Task['gen:views'].invoke(name, {bare: true, engine: engine});
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
601 });
602
9e1fe04 Got generators working.
mde authored
603 task('route', function (name, options) {
604 if (!name) {
605 throw new Error('No route name specified.');
606 }
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
607 options = options || {};
608
d92f157 Get generators working
mde authored
609 var names = utils.string.getInflections(name)
7ae4e05 Added generator for auth
mde authored
610 , routerPath = getRouterPath()
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
611 , routeType = options.bare ? 'Bare' : 'Resource'
7ae4e05 Added generator for auth
mde authored
612 , newRoute;
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
613
6967867 Misc. fixes to get generators working
mde authored
614 if (routerPath) {
615 if (routerPath.match('.coffee')) {
616 if (options.bare) {
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
617 newRoute = 'router.match(\'/' + names.filename.plural +
618 '\').to controller: \'' + names.constructor.plural +
619 '\', action: \'index\'';
baa8cdf @larzconwell Updated /site to reflect new features related to generators and templ…
larzconwell authored
620 } else {
621 newRoute = 'router.resource \'' + names.filename.plural + '\'';
622 }
6967867 Misc. fixes to get generators working
mde authored
623 } else if (routerPath.match('.js')) {
624 if (options.bare) {
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
625 newRoute = 'router.match(\'/' + names.filename.plural +
626 '\').to({controller: \'' + names.constructor.plural +
627 '\', action: \'index\'});';
baa8cdf @larzconwell Updated /site to reflect new features related to generators and templ…
larzconwell authored
628 } else {
629 newRoute = 'router.resource(\'' + names.filename.plural + '\');';
630 }
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
631 }
632
7ae4e05 Added generator for auth
mde authored
633 if (addRoute(routerPath, newRoute)) {
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
634 console.log('[Added] ' + routeType + ' ' + names.filename.plural +
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
635 ' route added to ' + routerPath);
636 }
637 else {
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
638 console.log(routeType + ' ' + names.filename.plural + ' route already defined in ' +
639 routerPath);
1282075 @larzconwell Fix old Fleegix lib code for template adapters
larzconwell authored
640 }
7ae4e05 Added generator for auth
mde authored
641 }
642 else {
baa8cdf @larzconwell Updated /site to reflect new features related to generators and templ…
larzconwell authored
643 console.log('There is no router file to add routes too');
644 }
7ae4e05 Added generator for auth
mde authored
645
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
646 });
647
9e1fe04 Got generators working.
mde authored
648 task('views', function (name, options) {
d9fe3bb @larzconwell Get rid of all the syntax differences, well most of them.
larzconwell authored
649 if (!name) {
650 throw new Error('No view name specified.');
651 }
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
652
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
653 options = options || {};
654
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
655 // Option defaults
656 options.engine = options.engine || 'ejs';
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
657
d92f157 Get generators working
mde authored
658 var names = utils.string.getInflections(name)
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
659 , engine = options.engine
660 , appViewDir = path.join('app', 'views', names.filename.plural)
661 , templateViewDir = path.join(__dirname, 'views', engine)
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
662 , cmds = []
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
663 , ext = '.html'
664 , appLayoutPath
665 , actions
666 , addActionView;
667
668 // Set extension based on engine option
d9fe3bb @larzconwell Get rid of all the syntax differences, well most of them.
larzconwell authored
669 switch (engine) {
670 case 'ejs':
671 ext += '.ejs';
672 break;
673 case 'jade':
674 ext += '.jade';
675 break;
676 case 'handlebars':
677 ext += '.hbs';
678 break;
679 case 'mustache':
680 ext += '.ms';
681 break;
682 }
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
683
684 // Set application layout path
685 appLayoutPath = path.join('app', 'views', 'layouts', 'application');
686 // Copy template view to application path
edf26c7 Formatting
mde authored
687 addActionView = function (action) {
dc80e70 @larzconwell Add ejs extension to copy and make it silent when copying over a new app
larzconwell authored
688 jake.cpR(path.join(templateViewDir, action + ext + '.ejs'), appViewDir, {silent: true});
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
689 };
690
691 jake.mkdirP(appViewDir);
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
692 jake.mkdirP('app/views/layouts');
693 addActionView('index');
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
694
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
695 // Add views for the other CRUD actions when doing a full-on resource
6967867 Misc. fixes to get generators working
mde authored
696 if (!options.bare) {
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
697 ['add', 'edit', 'show'].forEach(function (action) {
698 addActionView(action);
699 });
700 }
701
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
702 // Create default layout if one doesn't exist
703 // Hack: There should be a better way to detect if a application layout exists
6967867 Misc. fixes to get generators working
mde authored
704 if (!utils.file.existsSync(appLayoutPath + '.html.ejs') && !utils.file.existsSync(appLayoutPath + '.html.jade') &&
705 !utils.file.existsSync(appLayoutPath + '.html.hbs') && !utils.file.existsSync(appLayoutPath + '.html.ms')) {
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
706 // Copy template layout file to apps application layout file
dc80e70 @larzconwell Add ejs extension to copy and make it silent when copying over a new app
larzconwell authored
707 jake.cpR(path.join(templateViewDir, 'layout' + ext + '.ejs'), appLayoutPath + ext, {silent: true});
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
708 }
709
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
710 // Add engine to package.json if it's not EJS
711 if (engine !== 'ejs') {
712 // Change to handlebars as we use it behind the scenes
713 if (engine === 'mustache') {
714 engine = 'handlebars';
715 }
716 var data = {dependencies: {}};
717 data.dependencies[engine] = "*";
718
719 mixinJSONData('package.json', data);
720 }
721
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
722 console.log('[Added] View templates');
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
723 });
724
edf26c7 Formatting
mde authored
725 task('viewsScaffold', function (name, options) {
6967867 Misc. fixes to get generators working
mde authored
726 if (!name) {
693a0fe @larzconwell Created a file utils function that will search for a dir/file in up t…
larzconwell authored
727 throw new Error('No view name specified.');
728 }
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
729
730 options = options || {};
731
732 // Option defaults
733 options.engine = options.engine || 'ejs';
734
d92f157 Get generators working
mde authored
735 var names = utils.string.getInflections(name)
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
736 , engine = options.engine
737 , appViewDir = path.join('app', 'views', names.filename.plural)
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
738 , templateViewDir
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
739 , cmds = []
740 , ext = '.html'
741 , appLayoutPath
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
742 , layoutViewPath
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
743 , actions
744 , addActionView
ca35849 @larzconwell Closes #250, Add realtime code generation to the other template langu…
larzconwell authored
745 , viewPath
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
746 , text
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
747 , adapter
748 , templContent;
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
749
750 // Set extension based on engine option
d9fe3bb @larzconwell Get rid of all the syntax differences, well most of them.
larzconwell authored
751 switch (engine) {
752 case 'ejs':
753 ext += '.ejs';
754 break;
755 case 'jade':
756 ext += '.jade';
757 break;
758 case 'handlebars':
759 ext += '.hbs';
760 break;
761 case 'mustache':
762 ext += '.ms';
763 break;
764 }
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
765
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
766 // Get view path
057bd49 @Techwraith RT-MVC: Real time app generation and resource scaffolding is working
Techwraith authored
767 templateViewDir = options.realtime ?
768 path.join(__dirname, 'scaffold', 'realtime', 'views', engine) :
769 path.join(__dirname, 'scaffold', 'views', engine);
770
771
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
772 // Set application layout path
773 appLayoutPath = path.join('app', 'views', 'layouts', 'application');
774
775 // Function to compile the template
edf26c7 Formatting
mde authored
776 addActionView = function (action) {
ca35849 @larzconwell Closes #250, Add realtime code generation to the other template langu…
larzconwell authored
777 viewPath = path.join(templateViewDir, action + ext + '.ejs');
778 if (!utils.file.existsSync(viewPath)) {
779 return;
780 }
781 text = fs.readFileSync(viewPath).toString();
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
782
783 // Compile template text
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
784 adapter = new Adapter({engine: 'ejs', template: text});
785 templContent = adapter.render({names: names, properties: _formatModelProperties(options.properties)});
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
786
787 // Write file
788 fs.writeFileSync(path.join(appViewDir, action + ext),
2e8e3fb @larzconwell Remove the third party dependency Templato(which was rewritten in JS …
larzconwell authored
789 templContent.replace(/<@/g, '<%').replace(/@>/g, '%>'), 'utf8');
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
790 };
791
792 jake.mkdirP(appViewDir);
793 jake.mkdirP('app/views/layouts');
794
795 // Add views for the other CRUD actions when doing a full-on resource
9f7a384 @larzconwell Closes #246, Generator: Put form into a partial for add and edit acti…
larzconwell authored
796 ['index', 'add', 'show', 'edit', 'form'].forEach(function (action) {
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
797 addActionView(action);
798 });
799
800 // Create default layout if one doesn't exist
801 // Hack: There should be a better way to detect if a application layout exists
6967867 Misc. fixes to get generators working
mde authored
802 if (!utils.file.existsSync(appLayoutPath + '.html.ejs') && !utils.file.existsSync(appLayoutPath + '.html.jade') &&
803 !utils.file.existsSync(appLayoutPath + '.html.hbs') && !utils.file.existsSync(appLayoutPath + '.html.ms')) {
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
804 // Copy template layout file to apps application layout file
dc80e70 @larzconwell Add ejs extension to copy and make it silent when copying over a new app
larzconwell authored
805 jake.cpR(path.join(templateViewDir, 'layout' + ext + '.ejs'), appLayoutPath + ext, {silent: true});
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
806 }
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
807
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
808 // Add engine to package.json if it's not EJS
809 if (engine !== 'ejs') {
810 // Change to handlebars as we use it behind the scenes
811 if (engine === 'mustache') {
812 engine = 'handlebars';
813 }
814 var data = {dependencies: {}};
815 data.dependencies[engine] = "*";
816
817 mixinJSONData('package.json', data);
818 }
819
a082031 @larzconwell Updated readme to reflect new generators
larzconwell authored
820 console.log('[Added] View templates');
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
821 });
822
ae3f611 @larzconwell Created app and resource generators for Jade, Handlebars and Mustache
larzconwell authored
823 // Generate a new application secret in environment.js
9e1fe04 Got generators working.
mde authored
824 task('secret', function () {
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
825 var secretsFile = path.join(cwd, 'config', 'secrets.json')
826 , secret = utils.string.uuid(128);
827
828 mixinJSONData(secretsFile, {secret: secret});
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
829 console.log('Added app-secret to config/secrets.json.\n' +
830 'DO NOT add this file into your revision control.\n' +
831 'DO make a backup of it, keep it someplace safe.');
c389ea9 Move generator Jake tasks into a separate Jakefile.
mde authored
832 });
833
834 });
7ae4e05 Added generator for auth
mde authored
835
836 namespace('auth', function () {
837
aa49bd9 Added generator for auth:update
mde authored
838 task('update', {async: true}, function () {
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
839 var updatePath = path.join('geddy-passport', 'app', 'helpers', 'passport')
840 , from
841 , to;
842
843 console.log('Updating passport helpers from', geddyPassport);
844 jake.exec('npm uninstall ' + geddyPassport +
845 ' && npm install ' + geddyPassport, function () {
846 from = path.join(cwd, 'node_modules', updatePath);
847 to = path.join(cwd, 'app', 'helpers');
848
849 jake.rmRf(path.join(cwd, 'passport'), {silent: true});
aa49bd9 Added generator for auth:update
mde authored
850 jake.cpR(from, to, {silent: true});
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
851
852 console.log("\nCleaning up...");
853 jake.exec('npm uninstall ' + geddyPassport, function () {
aa49bd9 Added generator for auth:update
mde authored
854 complete();
855 });
856 }, {printStdout: true});
857 });
858
c189922 @larzconwell Include engine in auth:init, auth:init will now use the give engines
larzconwell authored
859 task('init', {async: true}, function (engine) {
3f8f8a5 Update `geddy auth` to work with changes to geddy-passport
mde authored
860 var env = process.env
861 , readline = require('readline')
862 , fromBase = env.srcDir ||
863 path.join(cwd, 'node_modules', 'geddy-passport')
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
864 , install = false
865 , rl, installPackages, passportCopy;
866
c189922 @larzconwell Include engine in auth:init, auth:init will now use the give engines
larzconwell authored
867 if (!engine || engine == 'default') {
868 engine = 'ejs';
869 }
870
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
871 // Create and start the prompt
872 rl = readline.createInterface({
873 input: process.stdin
874 , output: process.stdout
875 });
876 rl.setPrompt("WARNING: This command will create/overwrite files in your app.\n" +
877 "Do you wish to continue?(yes|no)\n\n");
7ae4e05 Added generator for auth
mde authored
878 rl.prompt();
879
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
880 rl.on('line', function (line) {
b786faf @larzconwell Closes #273 Add template engine to package.json if you change the
larzconwell authored
881 if (line === 'yes' || line === 'y') {
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
882 install = true;
7ae4e05 Added generator for auth
mde authored
883 }
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
884
7ae4e05 Added generator for auth
mde authored
885 rl.close();
886 });
887
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
888 rl.on('close', function () {
889 if (!install) {
890 return;
891 }
7ae4e05 Added generator for auth
mde authored
892
3f8f8a5 Update `geddy auth` to work with changes to geddy-passport
mde authored
893 if (env.srcDir) {
894 console.log('Installing from ' + fromBase);
895 installPackages();
896 }
897 else {
898 console.log('Installing', geddyPassport);
899 jake.exec('npm uninstall ' + geddyPassport +
900 ' && npm install ' + geddyPassport, installPackages, {printStdout: true});
901 }
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
902 });
7ae4e05 Added generator for auth
mde authored
903
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
904 // Gets the package versions from geddy-passport's package.json
905 // and installs them, then calls passportCopy
906 installPackages = function () {
907 var deps = require(path.join(fromBase, 'package')).dependencies
908 , packages = ''
909 , k;
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
910
dc80e70 @larzconwell Add ejs extension to copy and make it silent when copying over a new app
larzconwell authored
911 mixinJSONData(path.join(cwd, 'package.json'), {dependencies: deps});
912
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
913 for (k in deps) {
914 packages += k + '@' + deps[k] + ' ';
915 }
7dbdced Use secrets.json for secrets and keys, instead of environment.js
mde authored
916
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
917 console.log("\nInstalling", packages);
918 jake.exec('npm uninstall ' + packages +
919 ' && npm install ' + packages, passportCopy, {printStdout: true});
920 };
921
922 // Copy the contents of geddy-passport into the application
923 passportCopy = function () {
924 var list = require(path.join(fromBase, 'file_list'))
925 , routerPath = getRouterPath()
926 , newRoute
927 , from
c189922 @larzconwell Include engine in auth:init, auth:init will now use the give engines
larzconwell authored
928 , to
dc80e70 @larzconwell Add ejs extension to copy and make it silent when copying over a new app
larzconwell authored
929 , p
3f8f8a5 Update `geddy auth` to work with changes to geddy-passport
mde authored
930 , i
931 , engineExt = {
932 ejs: '.ejs'
933 , jade: '.jade'
934 , handlebars: '.hbs'
935 , mustache: '.ms'
936 };
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
937
938 // Copy files to the application
c189922 @larzconwell Include engine in auth:init, auth:init will now use the give engines
larzconwell authored
939 for (i = 0; i < list.length; i++) {
940 item = list[i];
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
941 from = path.join(fromBase, item);
942 to = path.dirname(path.join(cwd, item));
943
c189922 @larzconwell Include engine in auth:init, auth:init will now use the give engines
larzconwell authored
944 if (item.match('/app/views')) {
3f8f8a5 Update `geddy auth` to work with changes to geddy-passport
mde authored
945 from = from.replace('/app/views', '/app/views_' + engine);
946 from = from.replace(/\[\.ext\]$/, engineExt[engine]);
947 to = to.replace(/\[\.ext\]$/, engineExt[engine]);
c189922 @larzconwell Include engine in auth:init, auth:init will now use the give engines
larzconwell authored
948 }
949
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
950 jake.mkdirP(to);
3f8f8a5 Update `geddy auth` to work with changes to geddy-passport
mde authored
951 console.log('Creating file:', path.join(to, path.basename(from)));
dc80e70 @larzconwell Add ejs extension to copy and make it silent when copying over a new app
larzconwell authored
952
953 // Delete any existing interferring templates
954 if (item.match('/app/views')) {
955 ['.jade', '.ejs', '.ms', '.mustache', '.hbs', '.handlebars'].forEach(function (ext) {
956 p = path.basename(item, path.extname(item)) + ext;
957
958 jake.rmRf(path.join(to, p), {silent: true});
959 });
960 }
961
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
962 jake.cpR(from, to, {silent: true});
c189922 @larzconwell Include engine in auth:init, auth:init will now use the give engines
larzconwell authored
963 }
564357e Integrated generator with CLI, did some cleanup
mde authored
964
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
965 // Add new routes to router
966 if (routerPath) {
967 // CoffeeScript routes
968 if (routerPath.match('.coffee')) {
969 newRoute = "router.get('/login').to 'Main.login'\n" +
970 "router.get('/logout').to 'Main.logout'\n" +
971 "router.post('/auth/local').to 'Auth.local'\n" +
972 "router.get('/auth/twitter').to 'Auth.twitter'\n" +
973 "router.get('/auth/twitter/callback').to 'Auth.twitterCallback'\n" +
974 "router.get('/auth/facebook').to 'Auth.facebook'\n" +
975 "router.get('/auth/facebook/callback').to 'Auth.facebookCallback'\n" +
976 "router.get('/auth/yammer').to 'Auth.yammer'\n" +
977 "router.get('/auth/yammer/callback').to 'Auth.yammerCallback'\n" +
978 "router.resource 'users'";
979 } else {
980 newRoute = "router.get('/login').to('Main.login');\n" +
981 "router.get('/logout').to('Main.logout');\n" +
982 "router.post('/auth/local').to('Auth.local');\n" +
983 "router.get('/auth/twitter').to('Auth.twitter');\n" +
984 "router.get('/auth/twitter/callback').to('Auth.twitterCallback');\n" +
985 "router.get('/auth/facebook').to('Auth.facebook');\n" +
986 "router.get('/auth/facebook/callback').to('Auth.facebookCallback');\n" +
987 "router.get('/auth/yammer').to('Auth.yammer');\n" +
988 "router.get('/auth/yammer/callback').to('Auth.yammerCallback');\n" +
989 "router.resource('users');";
990 }
991
992 if (addRoute(routerPath, "\n" + newRoute)) {
993 console.log('\nAdded authentication routes:\n' + newRoute);
994 } else {
995 console.log('\nAuthentication routes already defined in', routerPath);
996 }
7ae4e05 Added generator for auth
mde authored
997 }
a9d96ec @larzconwell Include auth in usage dialog.
larzconwell authored
998 else {
999 console.log('\nThere is no router file to add routes too.');
1000 }
1001
1002 // Create secrets and copy the secrets template
1003 console.log("\nCreating secrets.json file with stubbed-out Passport config.");
1004 jake.cpR(path.join(fromBase, 'config', 'secrets.json.template'),
1005 path.join(cwd, 'config', 'secrets.json'), {silent: true});
1006 jake.Task['gen:secret'].invoke();
1007
1008 // Remove geddy-passport as it isn't needed anymore
1009 console.log('\nCleaning up...');
1010 jake.exec('npm uninstall geddy-passport', function () {
1011 console.log('Please set up your Passport config in config/secrets.json');
1012 complete();
1013 });
1014 };
7ae4e05 Added generator for auth
mde authored
1015 });
1016
1017 });
Something went wrong with that request. Please try again.