var includeDir = exports.includeDir = function(dir, callback) { var on = outcome.error(callback); step( /** * first scan for all the scripts in the given directory recursively */ function() { var inc = [], self = this; findJsFiles(dir, this); }, /** * next include all the scripts loaded in */ on.success(function(include) { //after async.forEach(include, includeScript, this); }), /** */ callback ) }
var includeScript = function(script, callback) { //script already used? skip. if(isUsed(script) || !script.path) return callback(); //script is core, and platform is node? if(script.core && ops.platform == "node") { script.alias = script.moduleName; return callback(); } use(script); var on = outcome.e(function(e) { callback(new Error("unable to include script " + script.path + " from "+script.source+", e: " + e.stack)) }); step( /** * first get the dependencies */ function() { findDeps(script.path, this); }, /** * deps found? load THOSE in! */ on.s(function(deps) { script.dependencies = deps; async.forEach(deps, includeScript, this); }), /** */ callback ) }
var findDeps = module.exports.findDeps = function(entry, callback) { //incase getPathInfo stuff is passed... if(entry.path) entry = entry.path; var cwd = path.dirname(entry), on = outcome.e(callback), content = null; step( /** */ function() { fs.readFile(entry, "utf8", this); }, /** */ on.s(function(cn) { content = cn; var next = this, d; scanRequired(content, cwd, on.s(function(deps) { scanInclude(content, cwd, on.s(function(incDeps) { next(null, deps.concat(incDeps)); })); })); }), /** */ on.success(function(deps) { deps.forEach(function(dep) { dep.source = entry; }); callback(null, deps); }) ); }
var includeEntry = function(dirOrScript, callback) { var on = outcome.e(callback); step( /** */ function() { fs.lstat(dirOrScript, this); }, /** */ on.s(function(stats) { //dir specified? scan EVERYTHING if(stats.isDirectory()) { includeDir(dirOrScript, this); //otherwise scan for require() statements } else { var script = this.script = pathInfo.getPathInfo(dirOrScript); includeScript(script, this); } }), /** */ on.s(function() { this(null, this.script); }), /** */ callback ) }
exports.run = function(ops, next) { var output = ops.cwd, platforms = ops.platforms = ops.platforms.split('+'), bootstrapDir = ops.directories.bootstrap; bootstrapSrcDir = bootstrapDir + "/src"; step( /** */ function() { mergeDirs(bootstrapSrcDir, platforms). filterFile(mergeDirs.parseTemplate(ops)). copyEach(output + "/src"). complete(this); }, /** */ function() { walkr(bootstrapDir, output). filter(function(options, next) { next(options.source == bootstrapDir || !options.stat.isDirectory()) }). filterFile(walkr.parseTemplate(ops)). filter(walkr.copy). start(this); }, /** */ next ); };
//scans for #include file.js or/path function scanInclude(content, cwd, callback) { var include = String(content).match(/\/\/#include\s([^\n]+)/g) || []; step( function() { var next = this; async.map(include, function(fn, next) { inc = fn.split(/\s+/g); inc.shift(); async.map(inc, function(path, next) { findJsFiles(cwd+"/"+path, next); }, next); }, function(err, inc) { next(null, flatten(inc)); }); }, callback ) }