Permalink
Browse files

Fixes #33 - Allow serve, test and build to work on batches of gallery…

… modules
  • Loading branch information...
1 parent 67a3c67 commit fd08204d32f2718550fcbe3f9d7640223a1d681d @davglass davglass committed Dec 11, 2012
Showing with 136 additions and 31 deletions.
  1. +1 −1 configs/yuidoc/yuidoc.json
  2. +6 −1 lib/cmds/build.js
  3. +70 −18 lib/cmds/serve.js
  4. +58 −10 lib/cmds/test.js
  5. +1 −1 web/assets/yogi.js
View
2 configs/yuidoc/yuidoc.json
@@ -8,7 +8,7 @@
"attributesEmit": "true",
"outdir": "../api-js",
"paths": [
- "./js/"
+ "."
]
}
}
View
7 lib/cmds/build.js
@@ -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;
View
88 lib/cmds/serve.js
@@ -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;
@@ -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;
@@ -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;
@@ -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) {
@@ -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) {
@@ -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');
View
68 lib/cmds/test.js
@@ -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 = {
@@ -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();
@@ -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() {
@@ -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();
@@ -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) {
@@ -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 = [];
@@ -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() {
View
2 web/assets/yogi.js
@@ -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');

0 comments on commit fd08204

Please sign in to comment.