Skip to content

Commit

Permalink
Get basic app-scaffold generation working.
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Nov 14, 2011
1 parent db9ad82 commit d46b18c
Show file tree
Hide file tree
Showing 23 changed files with 144 additions and 19 deletions.
92 changes: 90 additions & 2 deletions Jakefile
@@ -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) {
Expand All @@ -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());
};



62 changes: 51 additions & 11 deletions bin/cli.js
@@ -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'
Expand Down Expand Up @@ -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() {
/*
Expand Down Expand Up @@ -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();

File renamed without changes.
File renamed without changes.
Expand Up @@ -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.
File renamed without changes.
Expand Up @@ -49,7 +49,6 @@ var config = new function () {
};
//*/
}();

module.exports = config;
config;


Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d46b18c

Please sign in to comment.