Skip to content

Commit

Permalink
feat(cli): add ws-roller CLI for publish & version commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Feb 10, 2022
1 parent 0aaba0d commit 6201c1d
Show file tree
Hide file tree
Showing 20 changed files with 1,357 additions and 24 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"**/dist/**/*.*",
"**/packages/**/*.js",
"**/**/*.json",
"**/**/*.tgz",
"**/__tests__/*.ts"
],
"rules": {
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ dist

# Environment variables
.env

# tarball
**/*.tgz
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ On top of Lerna's existing options, we added a few more options that might be us
- Note: it will still create the changelogs (when enabled), so it could be useful to see what gets created (however, make sure to discard the changes and roll back your version in `roller.json` once you're done)
- "Version" command only options
- `--changelog-header-message "My Custom Header Message"`
- only writes to the root changelog (sub-packages will not receive this text)
- this will be written, only once, at the top of all your changelog files (e.g.: a good example is to add reference to your website)
- this will be written, only once, at the top of your changelog file located in the root (e.g.: a good example is to add reference to your website)
- you can see a live example from our very own [changelog](https://github.com/ghiscoding/ws-conventional-version-roller/blob/main/CHANGELOG.md)
- `--changelog-version-message "My custom version message"`
- only writes to the root changelog (sub-packages will not receive this text)
- this will be written as a prefix to your version change (e.g.: for example, provide more info about the new version changes)
- this will be written as a prefix to your each new version change (e.g.: for example, provide more info about the new version changes)

### Troubleshooting
If you have problems running the lib and your problems are with Git then you should first try the `--git-dry-run` option to see if that helps in finding the error. Another great, and possibly much more useful suggestion, is to search in the Lerna [issues](https://github.com/lerna/lerna/issues) because most of the code came from that library. Lastly if it that is not enough and you wish to troubleshoot yourself, then read this [Troubleshooting - Wiki](https://github.com/ghiscoding/ws-conventional-version-roller/wiki/Troubleshooting)
Expand Down
14 changes: 11 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"prebuild": "run-s clean lint",
"build": "npm run build --ws",
"lint": "eslint packages/** --ext .ts",
"pack-tarball": "npm run pack-tarball --ws --if-present",
"preroll-version": "echo MAKE SURE TO RUN A BUILD BEFORE RELEASING A NEW VERSION",
"roll-version": "node ./packages/cli/dist/index.js --roll-version",
"roll-publish": "node ./packages/cli/dist/index.js --roll-publish --bump from-package"
Expand Down
1 change: 1 addition & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
[![npm](https://img.shields.io/npm/v/@ws-conventional-version-roller/cli.svg?color=forest)](https://www.npmjs.com/package/@ws-conventional-version-roller/cli)
[![npm](https://img.shields.io/npm/dy/@ws-conventional-version-roller/cli?color=forest)](https://www.npmjs.com/package/@ws-conventional-version-roller/cli)
[![Actions Status](https://github.com/ghiscoding/ws-conventional-version-roller/workflows/CI%20Build/badge.svg)](https://github.com/ghiscoding/ws-conventional-version-roller/actions)

## Roller Version/Publish comands CLI
#### @ws-conventional-version-roller/cli
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "@ws-conventional-version-roller/cli",
"description": "CLI for Version/Publish roller commands",
"description": "Roller CLI for the Version/Publish commands",
"version": "0.1.8",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"bin": {
"ws-roller": "dist/cli.js"
},
"files": [
"/dist"
],
Expand Down Expand Up @@ -33,6 +36,7 @@
"@ws-conventional-version-roller/core": "^0.1.8",
"@ws-conventional-version-roller/publish": "^0.1.8",
"@ws-conventional-version-roller/version": "^0.1.8",
"dedent": "^0.7.0",
"dotenv": "^14.2.0",
"npmlog": "^6.0.0",
"yargs": "^17.3.1"
Expand Down
74 changes: 74 additions & 0 deletions packages/cli/src/cli.ts
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;

1 change: 1 addition & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { VersionCommand } from '@ws-conventional-version-roller/version';
try {
const pkg = require('../package.json');
log.notice('cli', `version ${pkg?.version ?? ''}`);
log.warn('deprecated', 'Calling publish or version command this way is now deprecated and will be removed in the next version. Please use "ws-roller" CLI instead.');

if ((argv as CommandOptions).rollPublish) {
new PublishCommand(argv);
Expand Down
123 changes: 123 additions & 0 deletions packages/cli/src/publishCommandOptions.ts
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',
// },
};
Loading

0 comments on commit 6201c1d

Please sign in to comment.