Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Jakefile, test dir to app, test stubs to scaffolds.

  • Loading branch information...
commit 109ee5928a746b0787f563629614db03b624cd27 1 parent 33d17ba
mde authored
View
30 bin/cli.js
@@ -128,7 +128,9 @@ if (cmds.length) {
// Some commands take only one arg
if (!(cmds[0] == 'secret' ||
cmds[0] == 'db:init' ||
- cmds[0] == 'console') && !cmds[1]) {
+ cmds[0].indexOf('test') === 0 ||
+ cmds[0] == 'console')
+ && !cmds[1]) {
throw new Error(cmds[0] + ' command requires another argument.');
}
@@ -156,6 +158,12 @@ if (cmds.length) {
// Create DBs
cmd += 'db:init';
break;
+ case 'test':
+ cmd = 'test';
+ if (cmds[1]) {
+ cmd += '[' + cmds[1] + ']'
+ }
+ break;
case 'db:createTable':
// Create DBs
cmd += 'db:createTable[' + cmds[1] + ']';
@@ -189,12 +197,22 @@ if (cmds.length) {
}
jake = require('jake');
- jake.program.init({
- quiet: !opts.debug
- , trace: true
- });
jake.loader.loadFile(filepath);
- jake.program.setTaskNames([cmd]);
+ if (cmd.indexOf('test') === 0) {
+ jake.loader.loadFile(path.join(process.cwd(), 'Jakefile'));
+ // Load up the Geddy env before running
+ jake.program.setTaskNames(['env:init', cmd]);
+ jake.program.init({
+ trace: true
+ });
+ }
+ else {
+ jake.program.init({
+ quiet: !opts.debug
+ , trace: true
+ });
+ jake.program.setTaskNames([cmd]);
+ }
jake.program.run();
}
// Just `geddy` -- start the server
View
77 templates/Jakefile
@@ -181,7 +181,7 @@ namespace('gen', function () {
templ.process({names: names, bare: bare, properties: options.properties});
// Write file
- fileDir = path.join('app', dirname);
+ fileDir = dirname;
if (!utils.file.existsSync(fileDir)) {
fs.mkdirSync(fileDir);
}
@@ -265,6 +265,11 @@ namespace('gen', function () {
// Creates a new Geddy app scaffold
task('app', function (name, engine) {
+ var mkdirs
+ , cps
+ , text
+ , tpl;
+
if (!name) {
throw new Error('No app name specified.');
}
@@ -272,28 +277,29 @@ namespace('gen', function () {
engine = 'ejs';
}
- var mkdirs = [
- ''
- , 'config'
- , 'app/models'
- , 'app/controllers'
- , 'app/helpers'
- , 'lib'
- , 'log'
- , 'node_modules'
- ]
- , cps = [
- ['views/' + engine, 'app/views']
- , ['public', '']
- , ['router.js', 'config']
- , ['init.js', 'config']
- , ['environment.js', 'config']
- , ['development.js', 'config']
- , ['production.js', 'config']
- , ['main.js', 'app/controllers']
- , ['application.js', 'app/controllers']
- , ['favicon.ico', 'public']
- ];
+ mkdirs = [
+ ''
+ , 'config'
+ , 'app/models'
+ , 'app/controllers'
+ , 'app/helpers'
+ , 'lib'
+ , 'log'
+ , 'node_modules'
+ , 'test'
+ ];
+ cps = [
+ ['views/' + engine, 'app/views']
+ , ['public', '']
+ , ['router.js', 'config']
+ , ['init.js', 'config']
+ , ['environment.js', 'config']
+ , ['development.js', 'config']
+ , ['production.js', 'config']
+ , ['main.js', 'app/controllers']
+ , ['application.js', 'app/controllers']
+ , ['favicon.ico', 'public']
+ ];
mkdirs.forEach(function (dir) {
jake.mkdirP(path.join(name, dir));
@@ -302,6 +308,11 @@ namespace('gen', function () {
jake.cpR(path.join(__dirname, 'base', cp[0]), path.join(name, cp[1]), {silent: true});
});
+ text = fs.readFileSync(path.join(__dirname, 'base', 'Jakefile.ejs'), 'utf8').toString()
+ templ = new adapter({data: {ext: '.ejs'}, text: text, templato: templato});
+ templ.process({appName: name});
+ fs.writeFileSync(path.join(name, 'Jakefile'), templ.markup, 'utf8');
+
console.log('Created app ' + name + '.');
});
@@ -344,6 +355,8 @@ namespace('gen', function () {
}
modelTask.on('complete', function () {
+ jake.Task['gen:test'].invoke(name,
+ {properties: modelProperties});
jake.Task['gen:controllerScaffold'].invoke(name,
{properties: modelProperties});
jake.Task['gen:route'].invoke(name);
@@ -365,7 +378,7 @@ namespace('gen', function () {
}
modelPath += '/model';
- _writeTemplate(name, modelPath, 'models', {
+ _writeTemplate(name, modelPath, path.join('app', 'models'), {
inflection: 'singular'
, properties: _formatModelProperties(properties)
});
@@ -385,17 +398,26 @@ namespace('gen', function () {
throw new Error('No controller name specified.');
}
- _writeTemplate(name, 'resource/controller', 'controllers',
+ _writeTemplate(name, 'resource/controller', path.join('app', 'controllers'),
{inflection: 'plural', bare: false});
});
+ task('test', function (name) {
+ if (!name) {
+ throw new Error('No test name specified.');
+ }
+
+ _writeTemplate(name, 'resource/test', 'test',
+ {inflection: 'singular'});
+ });
+
task('controllerScaffold', function (name, options) {
if (!name) {
throw new Error('No controller name specified.');
}
options = options || {};
- _writeTemplate(name, 'scaffold/controller', 'controllers', {
+ _writeTemplate(name, 'scaffold/controller', path.join('app', 'controllers'), {
inflection: 'plural'
, bare: false
, properties: _formatModelProperties(options.properties)
@@ -410,7 +432,8 @@ namespace('gen', function () {
engine = 'ejs';
}
- _writeTemplate(name, 'resource/controller', 'controllers', {inflection: 'plural', bare: true});
+ _writeTemplate(name, 'resource/controller', path.join('app', 'controllers'),
+ {inflection: 'plural', bare: true});
jake.Task['gen:route'].invoke(name, {bare: true});
jake.Task['gen:views'].invoke(name, {bare: true, engine: engine});
});
View
6 templates/base/Jakefile.ejs
@@ -0,0 +1,6 @@
+
+var t = new jake.TestTask('<%= appName %>', function () {
+ this.testFiles.include('test/*.js');
+ this.testFiles.include('test/**/*.js');
+});
+
View
12 templates/resource/test.ejs
@@ -0,0 +1,12 @@
+var assert = require('assert')
+ , tests
+ , <%= names.constructor.singular %> = geddy.model.<%= names.constructor.singular %>;
+
+tests = {
+ 'test stub, replace with your own passing test': function () {
+ assert.equal(true, false);
+ }
+
+};
+
+module.exports = tests;
Please sign in to comment.
Something went wrong with that request. Please try again.