Skip to content

Commit

Permalink
Fixes yui#33 - Allow serve, test and build to work on batches of gall…
Browse files Browse the repository at this point in the history
…ery modules
  • Loading branch information
davglass committed Dec 11, 2012
1 parent 67a3c67 commit fd08204
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 31 deletions.
2 changes: 1 addition & 1 deletion configs/yuidoc/yuidoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"attributesEmit": "true",
"outdir": "../api-js",
"paths": [
"./js/"
"."
]
}
}
7 changes: 6 additions & 1 deletion lib/cmds/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ mods = {
this.options.parsed.argv.original.unshift('--walk');
}
if (!mod) {
log.bail('yogi does not know what to do here..');
mod = {
name: 'gallery',
dir: process.cwd()
};
log.warn('guessing you want to use shifter --walk here');
this.options.parsed.argv.original.unshift('--walk');
}
}
this.dir = mod.dir;
Expand Down
88 changes: 70 additions & 18 deletions lib/cmds/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var util = require('../util'),
osenv = require('osenv'),
istanbulBase = path.join(osenv.tmpdir(), 'yogi-istanbul'),
portfinder = require('portfinder'),
findit = require('findit'),
ansispan = require('ansispan'),
mods;

Expand All @@ -30,6 +31,7 @@ config.register('yui', '<path> set the path to your local yui3 source tree');
mods = {
init: function(options) {
var port = options.parsed.port || 5000,
self = this,
module = util.findModule(true);

this.options = options;
Expand All @@ -49,15 +51,60 @@ mods = {
dir: path.join(git.findRoot(), '../src')
};
} else {
log.bail('could not locate the module you are attemping to serve, are you in the modules source directory?');
this._run = this.run;
this.run = function() {
log.debug('holding on to the run command for a bit');
};
this.scan(function() {
if (options.callback) {
options.callback();
} else {
self.run = self._run;
self.run();
}
});
}
}
this.module = module;
if (util.isYUI()) {
log.debug('this is yui, using global path for all docs');
this.module.dir = path.resolve(this.module.dir, '../');

if (module) {
this.module = module;
if (util.isYUI()) {
log.debug('this is yui, using global path for all docs');
this.module.dir = path.resolve(this.module.dir, '../');
}
if (options.callback) {
options.callback();
}
}
},
scan: function(callback) {
var finder = findit.find(process.cwd()),
mods = [],
self = this;

finder.on('path', function(file, stat) {
if (stat.isFile()) {
var name = path.basename(file);
if (name === 'build.json') {
mods.push(path.basename(path.dirname(file)));
}
}
});

finder.on('end', function() {
if (mods.length) {
log.info('using ' + mods.join(', '));
self.module = {
name: 'gallery',
dir: process.cwd()
};
self.modules = mods;
callback();
} else {
log.bail('could not locate the module you are attemping to serve, are you in the modules source directory?');
}
});
},
spawn: function(cmd, port, args, entry) {
var cwd = this.module.dir,
child;
Expand Down Expand Up @@ -337,12 +384,12 @@ mods = {
res.write('<p>You can add parameters to the query string to use shifter options: /shifter?istanbul&quiet&foo=bar</p>');


if (util.isYUI()) {
if (self.module.name === 'yui3') {
if (self.module.name === 'yui3' || self.module.name === 'gallery') {
if (util.isYUI()) {
cwd = path.join(self.module.dir, 'src');
args.push('--walk');
args.push('--cache');
}
args.push('--walk');
args.push('--cache');
}

Object.keys(req.query).forEach(function(key) {
Expand Down Expand Up @@ -760,7 +807,7 @@ mods = {
index = index.replace(/\{\{tests\}\}/gi, t.join('\n'));
index = index.replace(/\{\{covertests\}\}/gi, c.join('\n'));
} else {
if (util.isYUI()) {
if (util.isYUI() || self.module.name === 'gallery') {
batch = fs.readdirSync(base);
batch.forEach(function(mod) {

Expand Down Expand Up @@ -804,14 +851,19 @@ mods = {
});
});

if (util.isYUI()) {
this.app.get('/docs/yui3/', function(req, res) {
res.redirect('/docs/');
});
this.app.get('/api/modules/yui3.html', function(req, res) {
res.redirect('/api/');
});
}
this.app.get('/docs/yui3/', function(req, res) {
res.redirect('/docs/');
});
this.app.get('/api/modules/yui3.html', function(req, res) {
res.redirect('/api/');
});

this.app.get('/docs/gallery/', function(req, res) {
res.redirect('/docs/');
});
this.app.get('/api/modules/gallery.html', function(req, res) {
res.redirect('/api/');
});

this.app.get('/yogi/' + '*', function(req, res) {
res.header('Yogi-Served', 'Yes');
Expand Down
68 changes: 58 additions & 10 deletions lib/cmds/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var log = require('../log'),
portfinder = require('portfinder'),
fs = require('fs'),
server = require('./serve'),
findit = require('findit'),
fork = require('child_process').fork,
spawn = require('win-spawn'), //comma
mods = {
Expand Down Expand Up @@ -46,12 +47,25 @@ mods = {
name: 'yui3',
dir: path.join(git.findRoot(), '../src')
};
this.module = module;
this.afterInit();
} else {
log.bail('not in a module directory');
this.scan(function(mods) {
if (mods.length) {
self.modules = mods;
self.afterInit();
} else {
log.bail('not in a module directory');
}
});
}
} else {
this.module = module;
this.afterInit();
}

this.module = module;
},
afterInit: function() {
var self = this;
if (this.yetiHub && this.useYeti) {
if (this.yetiAgents) {
this.agents();
Expand All @@ -60,13 +74,13 @@ mods = {
}
} else {
this.prepServer(function(port) {
if (options.parsed.cli) {
if (self.options.parsed.cli) {
self.cli(port, function() {
self.stopServer();
self.done();
});
} else {
if (options.parsed.cli === false) {
if (self.options.parsed.cli === false) {
self.grover();
} else {
self.cli(port, function() {
Expand All @@ -77,6 +91,31 @@ mods = {
});
}
},
scan: function(callback) {
log.debug('scanning for gallery modules..');
var finder = findit.find(process.cwd()),
mods = [],
self = this;

finder.on('path', function(file, stat) {
if (stat.isFile()) {
var name = path.basename(file);
if (name === 'build.json') {
mods.push(path.basename(path.dirname(file)));
}
}
});

finder.on('end', function() {
if (mods.length) {
self.module = {
name: 'gallery',
dir: process.cwd()
};
}
callback(mods);
});
},
done: function() {
if (this.options.callback) {
this.options.callback();
Expand Down Expand Up @@ -298,6 +337,7 @@ mods = {
var tests = [], base,
self = this, batch,
exclude = {},
canBatch = false,
testPath = path.join(this.module.dir, 'tests', 'unit');

if (this.options.parsed.x) {
Expand All @@ -318,7 +358,11 @@ mods = {
if (util.exists(testPath)) {
tests = util.getTests(testPath, self.coverage);
} else {
if (util.isYUI() && (this.module.name === 'yui3' || this.modules)) {
canBatch = (util.isYUI() && (this.module.name === 'yui3' || this.modules));
if (this.module.name === 'gallery') {
canBatch = true;
}
if (canBatch) {
base = path.join(git.findRoot(), '../src');
if (!this.modules) {
this.modules = [];
Expand Down Expand Up @@ -373,11 +417,15 @@ mods = {
self.options.tests.forEach(function(val, key) {
self.options.tests[key] = val.replace(gbase, 'tests/').split(path.sep).join('/');
});
self.options.callback = function() {
//delete the options callback so that it never fires again
delete self.options.callback;
server.port = port;
server.startServer();
self.yogiServer = server;
callback(port);
};
server.init(self.options);
server.port = port;
server.startServer();
self.yogiServer = server;
callback(port);
});
},
startGrover: function() {
Expand Down
2 changes: 1 addition & 1 deletion web/assets/yogi.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ YUI().use('jsonp', 'node', function(Y) {
return 0;
};

if (YOGI.yui) {
if (YOGI.yui || YOGI.module.name === 'gallery') {
Y.one('body').addClass('yui');
} else {
Y.one('body').addClass('gallery');
Expand Down

0 comments on commit fd08204

Please sign in to comment.