Skip to content

Commit

Permalink
Initial test migration to buster. Update command handling with latest…
Browse files Browse the repository at this point in the history
… bagofholding. Upgrade deps.
  • Loading branch information
cliffano committed Feb 13, 2013
1 parent 2321ff2 commit a47bf6f
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 131 deletions.
19 changes: 19 additions & 0 deletions conf/commands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"commands": {
"init": {
"desc": "Create example AE86 project files\nUsage: ae86 init"
},
"gen": {
"desc": "Generate website\nUsage: ae86 gen"
},
"watch": {
"desc": "Watch for changes and automatically regenerate website\nUsage: ae86 watch"
},
"drift": {
"desc": "Alias for watch\nUsage: ae86 drift"
},
"clean": {
"desc": "Remove website\nUsage: ae86 clean"
}
}
}
31 changes: 15 additions & 16 deletions lib/ae86.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,26 @@ AE86.prototype.generate = function (cb) {

console.log('Generating website');

function _params() {

// initial userland params
var params = require(p.join(process.cwd(), 'params')).params;

// set defaults
params.sitemap = params.sitemap || {};
params.__genId = dateformat('yyyymmddHHMMssLl');

return params;
}

function _static(cb) {

// copy static files as-is
ncp.ncp('static', 'out', cb);
}

function _pages(cb) {

function _params() {

// initialise userland params
var params = require(p.join(process.cwd(), 'params')).params;

// add website info
params.sitemap = params.sitemap || {};
params.__genId = dateformat('yyyymmddHHMMssLl');

return params;
}

var _engine = new engine('html'),
tasks = {};

Expand All @@ -71,11 +72,9 @@ AE86.prototype.generate = function (cb) {

/**
* Watch for any file changes in AE86 project files.
* A detected change means the project needs to be regenerated.
*
* @param {Function} cb: standard cb(err, result) callback, this callback is never called because watch is not meant to exit
* A change means the project website will automatically be regenerated.
*/
AE86.prototype.watch = function (cb) {
AE86.prototype.watch = function () {

console.log('Watching for changes and automatically regenerating website');

Expand Down
66 changes: 26 additions & 40 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
var _ = require('underscore'),
ae86 = require('./ae86'),
var ae86 = require('./ae86'),
bag = require('bagofholding');

function _init() {
new ae86().init(bag.cli.exit);
}

function _gen() {
new ae86().generate(bag.cli.exit);
}

function _watch() {
new ae86().watch(bag.cli.exit);
}

function _clean() {
new ae86().clean(bag.cli.exit);
}

/**
* Execute AE86 using template files in the current directory.
* Execute AE86 CLI.
*/
function exec() {

function _init() {
new ae86().init(bag.cli.exit);
}

function _generate() {
new ae86().generate(bag.cli.exit);
}

function _watch() {
new ae86().watch(bag.cli.exit);
}

function _clean() {
new ae86().clean(bag.cli.exit);
}

var commands = {
init: {
desc: 'Create example AE86 project files',
action: _init
},
gen: {
desc: 'Generate website',
action: _generate
},
watch: {
desc: 'Watch for changes and automatically regenerate website',
action: _watch
},
drift: {
desc: 'Alias for watch',
action: _watch
},
clean: {
desc: 'Remove website',
action: _clean
var actions = {
commands: {
init: { action: _init },
gen: { action: _gen },
watch: { action: _watch },
drift: { action: _watch },
clean: { action: _clean }
}
};

bag.cli.parse(commands, __dirname);
bag.cli.command(__dirname, actions);
}

exports.exec = exec;
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
"test": "./test"
},
"dependencies": {
"async": "0.1.22",
"bagofholding": "0.0.12",
"dateformat": "1.0.2-1.2.3",
"async": "0.2.5",
"bagofholding": "0.1.1",
"dateformat": "1.0.4-1.2.3",
"file": "0.2.1",
"jazz": "0.0.18",
"mkdirp": "0.3.3",
"ncp": "0.2.6",
"underscore": "1.3.3",
"mkdirp": "0.3.4",
"ncp": "0.3.0",
"underscore": "1.4.4",
"watch-tree-maintained": "0.1.2",
"wrench": "1.3.9"
"wrench": "1.4.4"
},
"devDependencies": {
"buster": "0.6.12"
Expand Down
2 changes: 2 additions & 0 deletions test/ae86.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
var bag = require('bagofholding'),
_jscov = require('../lib/ae86'),
sandbox = require('sandboxed-module'),
Expand Down Expand Up @@ -269,3 +270,4 @@ describe('ae86', function () {
});
});
});
*/
149 changes: 83 additions & 66 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,100 @@
var bag = require('bagofholding'),
sandbox = require('sandboxed-module'),
should = require('should'),
checks, mocks,
cli;
buster = require('buster'),
cli = require('../lib/cli'),
AE86 = new require('../lib/ae86');

describe('cli', function () {
buster.testCase('cli - exec', {
'should contain commands with actions': function (done) {
var mockCommand = function (base, actions) {
assert.defined(base);
assert.defined(actions.commands.init.action);
assert.defined(actions.commands.gen.action);
assert.defined(actions.commands.watch.action);
assert.defined(actions.commands.drift.action);
assert.defined(actions.commands.clean.action);
done();
};
this.stub(bag, 'cli', { command: mockCommand });
cli.exec();
}
});

function create(checks, mocks) {
return sandbox.require('../lib/cli', {
requires: {
bagofholding: {
cli: {
exit: bag.cli.exit,
parse: function (commands, dir) {
checks.bag_parse_commands = commands;
checks.bag_parse_dir = dir;
}
}
},
'./ae86': function () {
return {
init: function (exit) {
checks.ae86_init_exit = exit;
},
generate: function (exit) {
checks.ae86_gen_exit = exit;
},
watch: function (exit) {
checks.ae86_watch_exit = exit;
},
clean: function (exit) {
checks.ae86_clean_exit = exit;
}
};
}
buster.testCase('cli - init', {
'should contain init command and delegate to ae86 init when exec is called': function (done) {
this.stub(bag, 'cli', {
command: function (base, actions) {
actions.commands.init.action();
},
globals: {
process: bag.mock.process(checks, mocks)
}
exit: bag.cli.exit
});
this.stub(AE86.prototype, 'init', function (cb) {
assert.equals(typeof bag.cli.exit, 'function');
done();
});
cli.exec();
}
});

beforeEach(function () {
checks = {};
mocks = {};
cli = create(checks, mocks);
buster.testCase('cli - gen', {
'should contain gen command and delegate to ae86 generate when exec is called': function (done) {
this.stub(bag, 'cli', {
command: function (base, actions) {
actions.commands.gen.action();
},
exit: bag.cli.exit
});
this.stub(AE86.prototype, 'generate', function (cb) {
assert.equals(typeof bag.cli.exit, 'function');
done();
});
cli.exec();
});

describe('exec', function () {
}
});

it('should contain init command and delegate to ae86 init when exec is called', function () {
checks.bag_parse_commands.init.desc.should.equal('Create example AE86 project files');
checks.bag_parse_commands.init.action();
checks.ae86_init_exit.should.be.a('function');
buster.testCase('cli - watch', {
'should contain watch command and delegate to ae86 watch when exec is called': function (done) {
this.stub(bag, 'cli', {
command: function (base, actions) {
actions.commands.watch.action();
},
exit: bag.cli.exit
});

it('should contain gen command and delegate to ae86 gen when exec is called', function () {
checks.bag_parse_commands.gen.desc.should.equal('Generate website');
checks.bag_parse_commands.gen.action();
checks.ae86_gen_exit.should.be.a('function');
this.stub(AE86.prototype, 'watch', function (cb) {
assert.equals(typeof bag.cli.exit, 'function');
done();
});
cli.exec();
}
});

it('should contain watch command and delegate to ae86 watch when exec is called', function () {
checks.bag_parse_commands.watch.desc.should.equal('Watch for changes and automatically regenerate website');
checks.bag_parse_commands.watch.action();
checks.ae86_watch_exit.should.be.a('function');
buster.testCase('cli - drift', {
'should contain drift command and delegate to ae86 watch when exec is called': function (done) {
this.stub(bag, 'cli', {
command: function (base, actions) {
actions.commands.watch.action();
},
exit: bag.cli.exit
});

it('should contain drift command and delegate to ae86 watch when exec is called', function () {
checks.bag_parse_commands.drift.desc.should.equal('Alias for watch');
checks.bag_parse_commands.drift.action();
checks.ae86_watch_exit.should.be.a('function');
this.stub(AE86.prototype, 'watch', function (cb) {
assert.equals(typeof bag.cli.exit, 'function');
done();
});
cli.exec();
}
});

it('should contain clean command and delegate to ae86 clean when exec is called', function () {
checks.bag_parse_commands.clean.desc.should.equal('Remove website');
checks.bag_parse_commands.clean.action();
checks.ae86_clean_exit.should.be.a('function');
buster.testCase('cli - clean', {
'should contain clean command and delegate to ae86 clean when exec is called': function (done) {
this.stub(bag, 'cli', {
command: function (base, actions) {
actions.commands.clean.action();
},
exit: bag.cli.exit
});
this.stub(AE86.prototype, 'clean', function (cb) {
assert.equals(typeof bag.cli.exit, 'function');
done();
});
});
cli.exec();
}
});
3 changes: 2 additions & 1 deletion test/engine.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
var bag = require('bagofholding'),
jazz = require('jazz'),
sandbox = require('sandboxed-module'),
Expand Down Expand Up @@ -258,4 +259,4 @@ describe('engine', function () {
});
});
});
*/
4 changes: 3 additions & 1 deletion test/functions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
var bag = require('bagofholding'),
sandbox = require('sandboxed-module'),
should = require('should'),
Expand Down Expand Up @@ -132,4 +133,5 @@ describe('functions', function () {
checks.data.should.equal('[error] page somepage.html does not have any sitemap title');
});
});
});
});
*/

0 comments on commit a47bf6f

Please sign in to comment.