From 850f492d6edb54057af8d0d682f1bf1673b540ed Mon Sep 17 00:00:00 2001 From: Anthony Dodd Date: Sun, 1 Feb 2015 11:27:55 -0600 Subject: [PATCH] -d|--dest might be working. Need to test. --- index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3a3afd3..31e9b27 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,7 @@ function printHelp($0, prn) { prn(' --scripts If installing, run scripts (to build addons).'); prn(' -b,--bundle Modify package to bundle deployment dependencies.'); prn(' -p,--pack Pack into a publishable archive (with dependencies).'); + prn(' -d,--dest A destination directory to move the final artifact to.'); prn(''); prn('Git specific options:'); prn(' -c,--commit Commit build output (branch specified by --onto).'); @@ -88,6 +89,7 @@ exports.build = function build(argv, callback) { 's(scripts)', 'i(install)', 'b(bundle)', + 'd:(dest)', 'p(pack)', 'O:(onto)', 'c(commit)', @@ -99,6 +101,7 @@ exports.build = function build(argv, callback) { var install; var scripts; var bundle; + var dest; var pack; var commit; @@ -119,6 +122,9 @@ exports.build = function build(argv, callback) { case 'b': bundle = true; break; + case 'd': + dest = option.optarg; + break; case 'p': pack = true; break; @@ -172,6 +178,10 @@ exports.build = function build(argv, callback) { steps.push(doNpmInstall); } + if (dest) { + steps.push(doDest); + } + if (bundle) { steps.push(doBundle); } @@ -227,6 +237,17 @@ exports.build = function build(argv, callback) { }); } + function doDest(_, callback) { + // Ensure the destination specified on the command-line exists and can be + // written to. + fs.existsSync(dest, function(exists) { + // Attempt to create dest if it does not exist. + if (exists !== true) { + fs.mkdirSync(dest); + } + }); + } + function doBundle(_, callback) { // Build output won't get packed if it is .npmignored (a configuration // error, don't .npmignore your build output) or if there is no .npmignore, @@ -297,7 +318,7 @@ exports.build = function build(argv, callback) { // npm pack output is a single line with the pack file name var src = output.split('\n')[0]; - var dst = path.join('..', src); + var dst = (dest !== "undefined") ? path.join(dest, src) : path.join('..', src); console.log('Running `mv -f %s %s`', src, dst);