-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from hdorgeval/pr-npx
Be able to run publish-please with npx
- Loading branch information
Showing
19 changed files
with
995 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,7 @@ node_js: | |
- '8' | ||
- '9' | ||
- '10' | ||
|
||
|
||
before_install: | ||
- if [[ `node -v` = v6* ]]; then npm i -g npx; fi | ||
- npx --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,48 @@ | ||
'use strict'; | ||
|
||
const getNpmArgs = require('./utils/get-npm-args'); | ||
const getNpxArgs = require('./utils/get-npx-args'); | ||
|
||
module.exports = function() { | ||
if (process.argv.indexOf('guard') > -1) { | ||
return require('./guard')(process.env); | ||
} | ||
const npmArgs = getNpmArgs(process.env); | ||
if (npmArgs && npmArgs['config']) { | ||
|
||
if (shouldRunConfigurationWizard()) { | ||
const config = require('./config'); | ||
return config.configurePublishPlease.inCurrentProject(); | ||
} | ||
|
||
if (npmArgs && npmArgs['--dry-run']) { | ||
if (shouldRunInDryMode()) { | ||
return require('./publish/dry-run-workflow')(); | ||
} | ||
|
||
return require('./publish/publish-workflow')(); | ||
}; | ||
|
||
function shouldRunInDryMode() { | ||
const npmArgs = getNpmArgs(process.env); | ||
if (npmArgs && npmArgs['--dry-run']) { | ||
return true; | ||
} | ||
|
||
const npxArgs = getNpxArgs(process); | ||
if (npxArgs && npxArgs['--dry-run']) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
function shouldRunConfigurationWizard() { | ||
const npmArgs = getNpmArgs(process.env); | ||
if (npmArgs && npmArgs['config']) { | ||
return true; | ||
} | ||
|
||
const npxArgs = getNpxArgs(process); | ||
if (npxArgs && npxArgs['config']) { | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
module.exports.arg = function(input) { | ||
return { | ||
is: (predicate) => { | ||
return predicate(input); | ||
}, | ||
}; | ||
}; | ||
|
||
module.exports.npmCommand = function(args) { | ||
const isValidArgs = args && args.cooked && Array.isArray(args.cooked); | ||
return { | ||
hasArg: (arg) => { | ||
return isValidArgs | ||
? args.cooked.filter((a) => a === arg).length > 0 | ||
: false; | ||
}, | ||
hasArgThatContains: (substring) => { | ||
/* prettier-ignore */ | ||
return isValidArgs | ||
? args.cooked.filter((a) => a && a.includes(substring)).length > 0 | ||
: false; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,58 @@ | ||
'use strict'; | ||
const pathSeparator = require('path').sep; | ||
const npmCommand = require('./fluent-syntax').npmCommand; | ||
const arg = require('./fluent-syntax').arg; | ||
|
||
// NOTE: the following code was partially adopted from https://github.com/iarna/in-publish | ||
module.exports = function getNpmArgs(processEnv) { | ||
if (arg(processEnv).is(notValid)) { | ||
return {}; | ||
} | ||
const npmArgs = {}; | ||
if (processEnv && processEnv['npm_config_argv']) { | ||
try { | ||
const args = JSON.parse(processEnv['npm_config_argv']); | ||
npmArgs.install = | ||
npmCommand(args).hasArg('install') || | ||
npmCommand(args).hasArg('i'); | ||
npmArgs.publish = npmCommand(args).hasArg('publish'); | ||
npmArgs.runScript = npmCommand(args).hasArg('run'); | ||
npmArgs['--save-dev'] = npmCommand(args).hasArg('--save-dev'); | ||
npmArgs['--save'] = npmCommand(args).hasArg('--save'); | ||
npmArgs['--global'] = npmCommand(args).hasArg('--global'); | ||
npmArgs['--dry-run'] = npmCommand(args).hasArg('--dry-run'); | ||
npmArgs['config'] = npmCommand(args).hasArg('config'); | ||
// prettier-ignore | ||
npmArgs['--with-publish-please'] = npmCommand(args).hasArg('--with-publish-please'); | ||
} catch (err) { | ||
console.warn( | ||
"[Publish-please] Cannot parse property 'npm_config_argv' in process.env " | ||
); | ||
// prettier-ignore | ||
console.warn( | ||
`[Publish-please] process.env['npm_config_argv']= '${processEnv['npm_config_argv']}'` | ||
try { | ||
const args = JSON.parse(processEnv['npm_config_argv']); | ||
npmArgs.install = | ||
npmCommand(args).hasArg('install') || npmCommand(args).hasArg('i'); | ||
npmArgs.publish = npmCommand(args).hasArg('publish'); | ||
npmArgs.runScript = npmCommand(args).hasArg('run'); | ||
npmArgs['--save-dev'] = npmCommand(args).hasArg('--save-dev'); | ||
npmArgs['--save'] = npmCommand(args).hasArg('--save'); | ||
npmArgs['--global'] = npmCommand(args).hasArg('--global'); | ||
npmArgs['--dry-run'] = npmCommand(args).hasArg('--dry-run'); | ||
npmArgs['config'] = npmCommand(args).hasArg('config'); | ||
npmArgs.npx = | ||
npmCommand(args).hasArg('--prefix') && | ||
npmCommand(args).hasArgThatContains( | ||
`${pathSeparator}_npx${pathSeparator}` | ||
); | ||
} | ||
// prettier-ignore | ||
npmArgs['--with-publish-please'] = npmCommand(args).hasArg('--with-publish-please'); | ||
} catch (err) { | ||
console.error( | ||
"[Publish-please] Cannot parse property 'npm_config_argv' in process.env " | ||
); | ||
// prettier-ignore | ||
console.error( | ||
`[Publish-please] process.env['npm_config_argv']= '${processEnv['npm_config_argv']}'` | ||
); | ||
console.error(`[Publish-please] ${err.message}`); | ||
} | ||
|
||
return npmArgs; | ||
}; | ||
|
||
function npmCommand(args) { | ||
const isValidArgs = args && args.cooked && Array.isArray(args.cooked); | ||
return { | ||
hasArg: (arg) => { | ||
return isValidArgs | ||
? args.cooked.filter((a) => a === arg).length > 0 | ||
: false; | ||
}, | ||
}; | ||
function notValid(processEnv) { | ||
if (processEnv === null || processEnv === undefined) { | ||
return true; | ||
} | ||
|
||
if (processEnv['npm_config_argv'] === undefined) { | ||
return true; | ||
} | ||
|
||
if (processEnv['npm_config_argv'] === 'undefined') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
const pathSeparator = require('path').sep; | ||
|
||
module.exports = function getNpxArgs(process) { | ||
const npxArgs = {}; | ||
|
||
const args = process && process.argv ? process.argv : []; | ||
|
||
npxArgs['--dry-run'] = | ||
npxCommand(args).hasArg('--dry-run') && | ||
npxCommand(args).hasArgThatContains( | ||
`${pathSeparator}_npx${pathSeparator}` | ||
); | ||
npxArgs['config'] = | ||
npxCommand(args).hasArg('config') && | ||
npxCommand(args).hasArgThatContains( | ||
`${pathSeparator}_npx${pathSeparator}` | ||
); | ||
return npxArgs; | ||
}; | ||
|
||
function npxCommand(args) { | ||
const isValidArgs = args && Array.isArray(args); | ||
return { | ||
hasArg: (arg) => { | ||
return isValidArgs | ||
? args.filter((a) => a === arg).length > 0 | ||
: false; | ||
}, | ||
hasArgThatContains: (substring) => { | ||
/* prettier-ignore */ | ||
return isValidArgs ? | ||
args.filter((a) => a && a.includes(substring)).length > 0 : | ||
false; | ||
}, | ||
}; | ||
} |
Oops, something went wrong.