From 0d96c75747cb962aa330f2d1a68f6640f641ec68 Mon Sep 17 00:00:00 2001 From: Paul Cuthbertson Date: Tue, 8 Jul 2014 13:58:46 +0100 Subject: [PATCH] Updated distil CLI task: Packages are now created synchronously so that the result is deterministic. --- bin/commands/distil.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/bin/commands/distil.js b/bin/commands/distil.js index 97f7f36..5508398 100644 --- a/bin/commands/distil.js +++ b/bin/commands/distil.js @@ -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) { @@ -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(); }