Skip to content

Commit

Permalink
Updated distil CLI task: Packages are now created synchronously so th…
Browse files Browse the repository at this point in the history
…at the result is deterministic.
  • Loading branch information
paulcuth committed Jul 8, 2014
1 parent 428ad0e commit 0d96c75
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions bin/commands/distil.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,20 @@ function distilFile (source, destination, switches, callback) {


function distilPackage (files, root, switches, callback) {
var outstanding = 0,
var fileQueue = [].concat(files),
outputFilename = switches.outputFilename,
packageMain = pathLib.relative('.', pathLib.resolve(switches.packageMain)),
packageData = {
format: 'moonshine.package',
files: {},
main: files[0][1]
},
i, l;
};


function processNextFile () {
var file, source, destination;

function checkDone () {
if (!outstanding) {
if (!fileQueue.length) {
createPath(outputFilename);

fs.writeFile(outputFilename, JSON.stringify(packageData), function (err) {
Expand All @@ -237,30 +238,28 @@ function distilPackage (files, root, switches, callback) {

callback();
});
}
}

for (i = 0, l = files.length; i < l; i++) {
outstanding++;
return;
}

(function (source, destination) {
var main = (packageMain == source);
if (main) packageData.main = destination;
file = fileQueue.shift();
source = file[0];
destination = file[1];

distil(source, switches, function (tree) {
tree.sourcePath = getRelativePath(source, root + '/' + pathLib.dirname(destination));
var main = (packageMain == source);
if (main) packageData.main = destination;

packageData.files[destination] = tree;
console.log(COLORS.WHITE + 'Added to package: ' + source + (main? ' [main]' : '') + COLORS.RESET);
distil(source, switches, function (tree) {
tree.sourcePath = getRelativePath(source, root + '/' + pathLib.dirname(destination));

outstanding--;
checkDone();
});
packageData.files[destination] = tree;
console.log(COLORS.WHITE + 'Added to package: ' + source + (main? ' [main]' : '') + COLORS.RESET);

})(files[i][0], files[i][1]);
processNextFile();
});
}

checkDone();
processNextFile();
}


Expand Down

0 comments on commit 0d96c75

Please sign in to comment.