Permalink
Browse files

Get basic app-scaffold generation working.

  • Loading branch information...
1 parent db9ad82 commit d46b18c430cd64f233f719620269d6c64d32b4e7 @mde mde committed Nov 14, 2011
Showing with 144 additions and 19 deletions.
  1. +90 −2 Jakefile
  2. +51 −11 bin/cli.js
  3. 0 {old/geddy-core/scripts/gen → templates}/bare_controller.ejs
  4. 0 {old/geddy-core/scripts/gen → templates/base}/application.js
  5. +1 −2 {old/geddy-core/scripts/gen → templates/base}/development.js
  6. BIN {old/geddy-core/scripts/gen → templates/base}/favicon.ico
  7. 0 {old/geddy-core/scripts/gen → templates/base}/inflections.js
  8. 0 {old/geddy-core/scripts/gen → templates/base}/init.js
  9. 0 {old/geddy-core/scripts/gen → templates/base}/main.js
  10. 0 {old/geddy-core/scripts/gen → templates/base}/master.css
  11. +1 −2 {old/geddy-core/scripts/gen → templates/base}/production.js
  12. +1 −2 {old/geddy-core/scripts/gen → templates/base}/router.js
  13. 0 {old/geddy-core/scripts/gen → templates}/resource_controller.ejs
  14. 0 {old/geddy-core/scripts/gen → templates}/resource_controller_scaffold.ejs
  15. 0 {old/geddy-core/scripts/gen → templates}/resource_model.ejs
  16. 0 {old/geddy-core/scripts/gen → templates}/views/add.html.ejs
  17. 0 {old/geddy-core/scripts/gen → templates}/views/add_scaffold.html.ejs
  18. 0 {old/geddy-core/scripts/gen → templates}/views/edit.html.ejs
  19. 0 {old/geddy-core/scripts/gen → templates}/views/edit_scaffold.html.ejs
  20. 0 {old/geddy-core/scripts/gen → templates}/views/index.html.ejs
  21. 0 {old/geddy-core/scripts/gen → templates}/views/index_scaffold.html.ejs
  22. 0 {old/geddy-core/scripts/gen → templates}/views/layout.html.ejs
  23. 0 {old/geddy-core/scripts/gen → templates}/views/show.html.ejs
View
@@ -1,9 +1,45 @@
var child_process = require('child_process')
, exec = child_process.exec;
+namespace('app', function () {
+ desc('Creates a new Geddy app scaffold.');
+ task('create', [], function (appName) {
+ if (!appName) {
+ throw new Error('No app-name specified.');
+ }
+ var dir = appName
+ , templateDir = __dirname + '/templates/base'
+ , cmds = [
+ 'mkdir -p ./' + dir
+ , 'mkdir -p ./' + dir + '/config'
+ , 'mkdir -p ./' + dir + '/app/models'
+ , 'mkdir -p ./' + dir + '/app/controllers'
+ , 'mkdir -p ./' + dir + '/app/views'
+ , 'mkdir -p ./' + dir + '/public'
+ , 'mkdir -p ./' + dir + '/public/js'
+ , 'mkdir -p ./' + dir + '/public/css'
+ , 'mkdir -p ./' + dir + '/log'
+ , 'cp ' + templateDir + '/router.js ' + dir + '/config/'
+ , 'cp ' + templateDir + '/init.js ' + dir + '/config/'
+ , 'cp ' + templateDir + '/environment.js ' + dir + '/config/'
+ , 'cp ' + templateDir + '/development.js ' + dir + '/config/'
+ , 'cp ' + templateDir + '/production.js ' + dir + '/config/'
+ , 'cp ' + templateDir + '/main.js ' + dir + '/app/controllers/'
+ , 'cp ' + templateDir + '/application.js ' + dir + '/app/controllers/'
+ , 'cp ' + templateDir + '/master.css ' + dir + '/public/css/'
+ , 'cp ' + templateDir + '/favicon.ico ' + dir + '/public/'
+ ];
+ runCmds(cmds, function () {
+ console.log('Created app ' + dir + '.');
+ });
+ });
+});
+
namespace('doc', function () {
- task('generate', function () {
- var cmd = '../node-jsdoc-toolkit/app/run.js -n -t=../node-jsdoc-toolkit/templates/codeview -d=./doc/ ./lib';
+ desc('Generate docs for Geddy');
+ task('generate', ['doc:clobber'], function () {
+ var cmd = '../node-jsdoc-toolkit/app/run.js -n -r=100 ' +
+ '-t=../node-jsdoc-toolkit/templates/codeview -d=./doc/ ./lib';
console.log('Generating docs ...');
exec(cmd, function (err, stdout, stderr) {
if (err) {
@@ -19,5 +55,57 @@ namespace('doc', function () {
complete();
});
}, true);
+
+ desc('Clobber the generated docs.');
+ task('clobber', function () {
+ var cmd = 'rm -fr ./doc/*';
+ exec(cmd, function (err, stdout, stderr) {
+ if (err) {
+ throw err;
+ }
+ if (stderr) {
+ console.log(stderr);
+ }
+ if (stdout) {
+ console.log(stdout);
+ }
+ console.log('Clobbered old docs.');
+ complete();
+ });
+ }, true);
+
});
+// Runs an array of shell commands asynchronously, calling the
+// next command off the queue inside the callback from child_process.exec.
+// When the queue is done, call the final callback function.
+var runCmds = function (arr, callback, printStdout) {
+ var run = function (cmd) {
+ child_process.exec(cmd, function (err, stdout, stderr) {
+ if (err) {
+ console.log('Error: ' + JSON.stringify(err));
+ }
+ else if (stderr) {
+ console.log('Error: ' + stderr);
+ }
+ else {
+ if (printStdout) {
+ console.log(stdout);
+ }
+ if (arr.length) {
+ var next = arr.shift();
+ run(next);
+ }
+ else {
+ if (callback) {
+ callback();
+ }
+ }
+ }
+ });
+ };
+ run(arr.shift());
+};
+
+
+
View
@@ -1,15 +1,22 @@
#!/usr/bin/env node
-// TODO: add start/stop/restart commands
-// command to create new project layout too
+// TODO: add start/stop/restart commands, commands to create new app-layout
-var Server = require(__dirname + '/../lib/server')
- , parseopts = require(__dirname + '/../lib/parseopts')
+var childProcess = require('child_process')
+ , fs = require('fs')
+ , exec = require('child_process').exec
+ , Server = require('../lib/server')
+ , parseopts = require('../lib/parseopts')
+ , utils = require('../lib/utils/index')
+ , parser
, args = process.argv.slice(2)
- , childProcess = require('child_process')
- , fs = require('fs');
+ , optsReg
+ , cmds
+ , opts
+ , usage
+ , cmd;
-var usage = ''
+usage = ''
+ 'Geddy web framework for Node.js\n'
+ '*********************************************************************************************\n'
+ 'With no flags, server starts running on port 4000, accepting requests from http://localhost.\n'
@@ -51,9 +58,10 @@ optsReg = [
}
];
-Parser = new parseopts.Parser(optsReg);
-parsed = Parser.parse(args);
-opts = Parser.opts;
+parser = new parseopts.Parser(optsReg);
+parser.parse(args);
+cmds = parser.cmds;
+opts = parser.opts;
function start() {
/*
@@ -93,6 +101,38 @@ function start() {
if (typeof opts.help != 'undefined') {
Server.die(usage);
}
+else {
+ // `geddy app foo` or `geddy resource bar` etc. -- run generators
+ if (cmds.length) {
+ cmd = 'jake -f /' + __dirname + '/../Jakefile ';
+ if (!cmds[1]) {
+ throw new Error(cmds[0] + ' command requires another argument.');
+ }
+ switch (cmds[0]) {
+ case 'app':
+ cmd += 'app:create[' + cmds[1] + ']'
+ break;
+ case 'resource':
+ break;
+ default:
+ Server.die(cmds[0] + ' is not a Geddy command.');
+ }
+ exec(cmd, function (err, stdout, stderr) {
+ if (err) {
+ throw err;
+ }
+ else if (stderr) {
+ console.log(stderr);
+ }
+ else {
+ console.log(utils.string.trim(stdout));
+ }
+ });
+ }
+ // Just `geddy` -- start the server
+ else {
+ start();
+ }
+}
-start();
@@ -50,6 +50,5 @@ var config = new function () {
//*/
}();
-
-module.exports = config;
+config;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -49,7 +49,6 @@ var config = new function () {
};
//*/
}();
-
-module.exports = config;
+config;
@@ -16,9 +16,8 @@
*
*/
-var Router = require('geddy-core/lib/router').Router;
-var router = new Router();
+var router = new geddy.RegExpRouter();
router.match('/').to({controller: 'Main', action: 'index'});
// Basic routes

0 comments on commit d46b18c

Please sign in to comment.