diff --git a/index.js b/index.js index 60ca7ba..b91b221 100644 --- a/index.js +++ b/index.js @@ -41,8 +41,8 @@ function spawnNpmWithOutput(args, options) { }); } -async function packWithNpm({ sourceDir, targetDir, verbose }) { - const output = (await spawnNpmWithOutput(['pack', sourceDir], { +async function packWithNpm({ packageSpec, targetDir, verbose }) { + const output = (await spawnNpmWithOutput(['pack', packageSpec], { cwd: targetDir, verbose })).trim().split(/\n/); @@ -60,7 +60,7 @@ async function packWithNpm({ sourceDir, targetDir, verbose }) { } } -async function publish({tag, branch, version, push, packOptions}, pack = packWithNpm) { +async function publish({tag, branch, version, push, packageSpec, packOptions}, pack = packWithNpm) { if (!tag) { tag = `v${version}`; } @@ -86,7 +86,7 @@ async function publish({tag, branch, version, push, packOptions}, pack = packWit } await pack(Object.assign({ - sourceDir: process.cwd(), + packageSpec: packageSpec, targetDir: tmpDir, }, packOptions)); diff --git a/main.js b/main.js index 8b3aa38..b92b6e3 100644 --- a/main.js +++ b/main.js @@ -12,6 +12,8 @@ const argv = yargs .describe('branch', "Branch name to append this new release to - none by default") .describe('push', 'Push update to the git remote (pass --no-push to disable)') .describe('force', 'Override any existing tag on the remote as well as locally (git tag -f, git push -f)') + .parserConfiguration({ 'populate--': true }) + .describe('--', 'All arguments after -- are passed to npm pack command') .boolean('push') .boolean('force') .default('push', 'true') @@ -21,6 +23,16 @@ const argv = yargs const path = require('path'); const packageJson = require(path.join(process.cwd(), '/package.json')); +// packageSpec is the first non-option token after `--`. +// Remaining forwarded tokens are forwarded. +const forwarded = yargs(argv['--'] || []) + .default('verbose', 'true') + .wrap(yargs.terminalWidth()) + .argv; + +const packageSpec = forwarded._.length > 0 ? forwarded._ : process.cwd(); +console.log('Using packageSpec:', packageSpec); + publish({ tag: argv.tag, branch: argv.branch, @@ -30,8 +42,9 @@ publish({ remote: argv.remote, force: argv.force, }, + packageSpec, packOptions: { - verbose: true + ...forwarded } }).catch(err => { if (err.cmd) {