Skip to content

Commit

Permalink
Fixed connection error occurring due to package dependency on http re…
Browse files Browse the repository at this point in the history
…direct.

Changed default command line behaviour so that recursive building is only available via an option, not implicit.
  • Loading branch information
mosen committed Oct 11, 2011
1 parent bbf1e93 commit b1028f6
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 67 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -7,4 +7,6 @@
/.idea/
/example/component/build/
/example/build/
/example/
/example/
npm-debug.log
yuibuild.iml
172 changes: 108 additions & 64 deletions bin/cli.js
@@ -1,59 +1,103 @@
#!/usr/bin/env node

var path = require('path'),
fs = require('fs'),
util = require('util'),
events = require('events'),
/*
* yuibuild
* https://github.com/mosen/yuibuild
*/

var path = require('path'),
fs = require('fs'),
util = require('util'),
events = require('events'),
component = require('../lib/component.js'),
Builder = require('../lib/builder.js').Builder;
Builder = require('../lib/builder.js').Builder;

var buildFileName = /build\.json$/;
var buildFileName = "build.json";

var help = [
"usage: yuibuild [DIR, ...] [options]",
var header = "yuibuild v0.0.1";
var usage = [
"usage: yuibuild [options] <component directory ...>",
"",
"options:",
" -v, --verbose Verbose output",
" -h, --help This is the help",
"",
" -h, --help Display this help message",
" -r, --recursive Search recursively for components to build",
" -v, -vv, -vvv Verbosity level (Warnings, Info, Debug)",
""
].join('\n');

var arg,
args = [], // DIRs
buildDirs = [], // Any non matching arg becomes build directory
argv = process.argv.slice(2),
options = {};
options = {
recursive : false,
logging : {
warnings : true,
info : true,
debug : false,
ludicrous : false
}
};

while (arg = argv.shift()) {
if (arg === __filename) { continue }

if (arg[0] !== '-') {
args.push(arg);
} else {
switch(arg) {
case 'v':
case 'verbose':
options.verbose = true;
break;

case 'help':
case 'h':
console.log(help);
process.exit(0);
break;
}
if (arg === __filename) { continue; }

switch(arg) {
case '-h':
case '--help':
console.log(usage);
process.exit(1);
break;

case '-r':
case '--recursive':
// recurse into subdirectories to discover more build files.
options.recursive = true;
break;

case '-v':
// display warnings

case '-vv':
// display info

case '-vvv':
// display debug

case '-vvvv':
// rediculous dump of information

default:
buildDirs.push(arg);
}
}

if (args.length === 0) {
console.log('yuibuild alpha');

var buildPaths = paths('.');
buildPaths.forEach(function(f) {
var buildComponent = component.factory('json', { buildFile: f });
var builder = new Builder(buildComponent);
builder.run();
})
console.log(header);

if (buildDirs.length === 0) {
console.log(usage);
process.exit(0);

} else {
console.log('Attempting to build components in: ' + buildDirs.join(', '));

if (options.recursive === true) {
// recurse into subdirectories, looking for buildFileName
console.log('Recursive option not yet supported.')
} else {
buildDirs.forEach(function(dir) {
var buildFilePath = path.join(dir, buildFileName);

path.exists(buildFilePath, function(exists) {
if (exists) {
var buildComponent = component.factory('json', { buildFile: buildFilePath });
var builder = new Builder(buildComponent);
builder.run();
} else {
console.log('Couldnt find a build file at ' + buildFilePath + ', skipping...');
}
});
}, this);
}
}


Expand All @@ -62,28 +106,28 @@ if (args.length === 0) {
// Recursively traverse a hierarchy, returning
// a list of all relevant .js files.
//
function paths(dir) {
var paths = [];

try { fs.statSync(dir) }
catch (e) { return [] }

(function traverse(dir, stack) {
stack.push(dir);
fs.readdirSync(stack.join('/')).forEach(function (file) {
var path = stack.concat([file]).join('/'),
stat = fs.statSync(path);

if (file[0] == '.' || file === 'vendor') {
return;
} else if (stat.isFile() && buildFileName.test(file)) {
paths.push(path);
} else if (stat.isDirectory()) {
traverse(file, stack);
}
});
stack.pop();
})(dir || '.', []);

return paths;
}
//function paths(dir) {
// var paths = [];
//
// try { fs.statSync(dir) }
// catch (e) { return [] }
//
// (function traverse(dir, stack) {
// stack.push(dir);
// fs.readdirSync(stack.join('/')).forEach(function (file) {
// var path = stack.concat([file]).join('/'),
// stat = fs.statSync(path);
//
// if (file[0] == '.' || file === 'vendor') {
// return;
// } else if (stat.isFile() && file === buildFileName) {
// paths.push(path);
// } else if (stat.isDirectory()) {
// traverse(file, stack);
// }
// });
// stack.pop();
// })(dir || '.', []);
//
// return paths;
//}
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -21,10 +21,10 @@
},
"repository" : {
"type" : "git",
"url" : "http://github.com/mosen/yuibuild.git"
"url" : "https://github.com/mosen/yuibuild.git"
},
"dependencies" : {
"buildy" : "http://github.com/mosen/buildy/tarball/master"
"buildy" : "https://github.com/mosen/buildy/tarball/master"
},
"preferGlobal" : true,
"private" : true
Expand Down

0 comments on commit b1028f6

Please sign in to comment.