-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add
ws-roller
CLI for publish & version commands
- Loading branch information
1 parent
0aaba0d
commit 6201c1d
Showing
20 changed files
with
1,357 additions
and
24 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
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 |
---|---|---|
|
@@ -35,3 +35,6 @@ dist | |
|
||
# Environment variables | ||
.env | ||
|
||
# tarball | ||
**/*.tgz |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env node | ||
import dedent from 'dedent'; | ||
import log from 'npmlog'; | ||
import yargs from 'yargs/yargs'; | ||
import { PublishCommand } from '@ws-conventional-version-roller/publish'; | ||
import { VersionCommand } from '@ws-conventional-version-roller/version'; | ||
import { publishCommandOptions } from './publishCommandOptions'; | ||
import { versionCommandOptions } from './versionCommandOptions'; | ||
|
||
function logCliVersion() { | ||
const pkg = require('../package.json'); | ||
log.notice('cli', `version ${pkg?.version ?? ''}`); | ||
} | ||
|
||
function publishHandler(argv: any) { | ||
logCliVersion(); | ||
new PublishCommand(argv); | ||
} | ||
|
||
function versionHandler(argv: any) { | ||
logCliVersion(); | ||
new VersionCommand(argv); | ||
} | ||
|
||
const cli = yargs(process.argv, process.cwd()); | ||
|
||
yargs(process.argv.slice(2)) | ||
.example('$0 version build -- --silent', '# `npm version build --silent` in all packages with a build script') | ||
.command({ | ||
command: 'publish [script]', | ||
describe: 'publish a new version', | ||
handler: publishHandler, | ||
}) | ||
.command({ | ||
command: 'version [script]', | ||
describe: 'roll a new version', | ||
handler: versionHandler, | ||
}) | ||
.parserConfiguration({ | ||
'populate--': true, | ||
}) | ||
.positional('script', { | ||
describe: 'The npm script to run. Pass flags to send to the npm client after --', | ||
type: 'string', | ||
}) | ||
.options({ ...versionCommandOptions, ...publishCommandOptions } as any) | ||
.demandCommand(1, 'A command is required. Pass --help to see all available commands and options.') | ||
.usage('Usage: $0 <command> [options]') | ||
.recommendCommands() | ||
.help() | ||
.wrap(null) | ||
.fail((msg, err) => { | ||
// certain yargs validations throw strings :P | ||
const actual: any = err || new Error(msg); | ||
|
||
// ValidationErrors are already logged, as are package errors | ||
if (actual.name !== 'ValidationError' && !actual.pkg) { | ||
// the recommendCommands() message is too terse | ||
if (/Did you mean/.test(actual.message)) { | ||
log.error('roller', `Unknown command "${(cli.parsed as any).argv._[0]}"`); | ||
} | ||
|
||
log.error('roller', actual.message); | ||
} | ||
|
||
// exit non-zero so the CLI can be usefully chained | ||
cli.exit(actual.exitCode > 0 ? actual.exitCode : 1, actual); | ||
}) | ||
.wrap(cli.terminalWidth()).epilogue(dedent` | ||
When a command fails, all logs are written to roller-debug.log in the current working directory. | ||
For more information, find our manual at https://github.com/ghiscoding/ws-conventional-version-roller | ||
`) | ||
.argv; | ||
|
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,123 @@ | ||
export const publishCommandOptions = { | ||
c: { | ||
describe: 'Publish packages after every successful merge using the sha as part of the tag.', | ||
group: 'Version Command Options:', | ||
alias: 'canary', | ||
type: 'boolean', | ||
}, | ||
// preid is copied from ../version/command because a whitelist for one option isn't worth it | ||
preid: { | ||
describe: 'Specify the prerelease identifier when publishing a prerelease', | ||
group: 'Version Command Options:', | ||
type: 'string', | ||
requiresArg: true, | ||
defaultDescription: 'alpha', | ||
}, | ||
contents: { | ||
describe: 'Subdirectory to publish. Must apply to ALL packages.', | ||
group: 'Version Command Options:', | ||
type: 'string', | ||
requiresArg: true, | ||
defaultDescription: '.', | ||
}, | ||
'dist-tag': { | ||
describe: 'Publish packages with the specified npm dist-tag', | ||
group: 'Version Command Options:', | ||
type: 'string', | ||
requiresArg: true, | ||
}, | ||
'legacy-auth': { | ||
describe: 'Legacy Base64 Encoded username and password.', | ||
group: 'Version Command Options:', | ||
type: 'string', | ||
}, | ||
'pre-dist-tag': { | ||
describe: 'Publish prerelease packages with the specified npm dist-tag', | ||
group: 'Version Command Options:', | ||
type: 'string', | ||
requiresArg: true, | ||
}, | ||
'git-head': { | ||
describe: 'Explicit SHA to set as gitHead when packing tarballs, only allowed with "from- package" positional.', | ||
group: 'Version Command Options:', | ||
type: 'string', | ||
requiresArg: true, | ||
}, | ||
'graph-type': { | ||
describe: 'Type of dependency to use when determining package hierarchy.', | ||
group: 'Version Command Options:', | ||
choices: ['all', 'dependencies'], | ||
defaultDescription: 'dependencies', | ||
}, | ||
'ignore-prepublish': { | ||
describe: 'Disable deprecated "prepublish" lifecycle script', | ||
group: 'Version Command Options:', | ||
type: 'boolean', | ||
}, | ||
'ignore-scripts': { | ||
describe: 'Disable all lifecycle scripts', | ||
group: 'Version Command Options:', | ||
type: 'boolean', | ||
}, | ||
// TODO: (major) make --no-granular-pathspec the default | ||
'no-granular-pathspec': { | ||
describe: 'Do not reset changes file-by-file, but globally.', | ||
group: 'Version Command Options:', | ||
type: 'boolean', | ||
}, | ||
'granular-pathspec': { | ||
// proxy for --no-granular-pathspec | ||
hidden: true, | ||
// describe: 'Reset changes file-by-file, not globally.', | ||
group: 'Version Command Options:', | ||
type: 'boolean', | ||
}, | ||
otp: { | ||
describe: 'Supply a one-time password for publishing with two-factor authentication.', | ||
group: 'Version Command Options:', | ||
type: 'string', | ||
requiresArg: true, | ||
}, | ||
registry: { | ||
describe: 'Use the specified registry for all npm client operations.', | ||
group: 'Version Command Options:', | ||
type: 'string', | ||
requiresArg: true, | ||
}, | ||
'require-scripts': { | ||
describe: 'Execute ./scripts/prepublish.js and ./scripts/postpublish.js, relative to package root.', | ||
group: 'Version Command Options:', | ||
type: 'boolean', | ||
}, | ||
'no-git-reset': { | ||
describe: 'Do not reset changes to working tree after publishing is complete.', | ||
group: 'Version Command Options:', | ||
type: 'boolean', | ||
}, | ||
'git-reset': { | ||
// proxy for --no-git-reset | ||
hidden: true, | ||
type: 'boolean', | ||
}, | ||
'temp-tag': { | ||
describe: 'Create a temporary tag while publishing.', | ||
group: 'Version Command Options:', | ||
type: 'boolean', | ||
}, | ||
'no-verify-access': { | ||
describe: 'Do not verify package read-write access for current npm user.', | ||
group: 'Version Command Options:', | ||
type: 'boolean', | ||
}, | ||
'verify-access': { | ||
// proxy for --no-verify-access | ||
hidden: true, | ||
type: 'boolean', | ||
}, | ||
// y: { | ||
// describe: 'Skip all confirmation prompts.', | ||
group: 'Version Command Options:', | ||
// alias: 'yes', | ||
// type: 'boolean', | ||
// }, | ||
}; |
Oops, something went wrong.