Skip to content

Commit

Permalink
feat(run): add run command to help run workspace script in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Feb 9, 2022
1 parent 59b7147 commit a71191b
Show file tree
Hide file tree
Showing 22 changed files with 1,017 additions and 23 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
### Why and when to use this lib?
You would use this lib when your project is an NPM/Yarn Workspace monorepo structure and you wish to automate Versioning and Publishing of all your packages by following the [Conventional Commits](https://www.conventionalcommits.org/) and also automatically create [Conventional-Changelog](https://github.com/conventional-changelog/conventional-changelog) for each of your package (and also a main changelog in the root).

This lib will help you to
#### This lib will help you to:
- Automate the rolling of new Versions (independent or fixed) for all your packages
- it will automatically add Commit & Tag your new Version in Git & create new Release in GitHub when enabled
- Automate the creation of Changelogs for all your packages by reading all [Conventional Commits](https://www.conventionalcommits.org/)
- each package will get its own changelog and a combined changelog will also be created in the root
- Automate the repository Publish of your new versions for all your packages
- it could push to NPM or any other repository platform

#### Extras:
- [@ws-conventional-version-roller/run](https://github.com/ghiscoding/ws-conventional-version-roller/tree/main/packages/run) is an optional package that will help you run npm script in parallel and in topological order.

### Project Demo?
You want to see a demo project? Well, you're looking at it 😉

Expand Down Expand Up @@ -60,8 +63,6 @@ Add the following NPM Scripts or simply run the following NodeJS command in your
### Configuration
This lib requires a config file in order to do its job properly. It could come from a separate file (read [`roller.json` - Wiki](https://github.com/ghiscoding/ws-conventional-version-roller/wiki/Roller.json), recommended approach) in the root of your project OR a `"roller": {}` property directly under your `package.json`.

**Note:** make sure to reference your workspace packages via the `packages: []` in the [roller.json](https://github.com/ghiscoding/ws-conventional-version-roller/blob/main/roller.json) config file, because at the moment the lib will **not** read the `workspaces` property yet (it might, probably will, in the future).

#### Command Options
- `version` same as Lerna [version options](https://github.com/lerna/lerna/tree/main/commands/version#readme)
- `publish` same as Lerna [publish options](https://github.com/lerna/lerna/tree/main/commands/publish#readme)
Expand All @@ -88,3 +89,13 @@ On top of Lerna's existing options, we added a few more options that might be us

### 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)

### Available Public Packages

| Package Name | Version | Description | Changes |
| -------------| ------- | ----------- | ------- |
| [@ws-conventional-version-roller/cli](https://github.com/ghiscoding/ws-conventional-version-roller/tree/main/packages/cli) | [![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) | Roller Version/Publish comands CLI | [changelog](https://github.com/ghiscoding/ws-conventional-version-roller/blob/main/packages/cli/CHANGELOG.md) |
| [@ws-conventional-version-roller/core](https://github.com/ghiscoding/ws-conventional-version-roller/tree/main/packages/core) | [![npm](https://img.shields.io/npm/v/@ws-conventional-version-roller/core.svg?color=forest)](https://www.npmjs.com/package/@ws-conventional-version-roller/core) | Roller core & utils methods | [changelog](https://github.com/ghiscoding/ws-conventional-version-roller/blob/main/packages/core/CHANGELOG.md) |
| [@ws-conventional-version-roller/publish](https://github.com/ghiscoding/ws-conventional-version-roller/tree/main/packages/publish) | [![npm](https://img.shields.io/npm/v/@ws-conventional-version-roller/publish.svg?color=forest)](https://www.npmjs.com/package/@ws-conventional-version-roller/publish) | Publish packages in the current workspace | [changelog](https://github.com/ghiscoding/ws-conventional-version-roller/blob/main/packages/publish/CHANGELOG.md) |
| [@ws-conventional-version-roller/run](https://github.com/ghiscoding/ws-conventional-version-roller/tree/main/packages/run) | [![npm](https://img.shields.io/npm/v/@ws-conventional-version-roller/run.svg?color=forest)](https://www.npmjs.com/package/@ws-conventional-version-roller/run) | CLI to help running npm script in the workspace | [changelog](https://github.com/ghiscoding/ws-conventional-version-roller/blob/main/packages/run/CHANGELOG.md) |
| [@ws-conventional-version-roller/version](https://github.com/ghiscoding/ws-conventional-version-roller/tree/main/packages/version) | [![npm](https://img.shields.io/npm/v/@ws-conventional-version-roller/version.svg?color=forest)](https://www.npmjs.com/package/@ws-conventional-version-roller/version) | Bump Version & write Changelogs | [changelog](https://github.com/ghiscoding/ws-conventional-version-roller/blob/main/packages/version/CHANGELOG.md) |
142 changes: 139 additions & 3 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"./packages/core",
"./packages/version",
"./packages/publish",
"./packages/cli"
"./packages/cli",
"./packages/run"
]
}
18 changes: 9 additions & 9 deletions packages/core/src/child-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const NUM_COLORS = colorWheel.length;
// ever-increasing index ensures colors are always sequential
let currentColor = 0;

export function exec(command, args, opts, gitDryRun = false) {
export function exec(command, args, opts, cmdDryRun = false) {
const options = Object.assign({ stdio: 'pipe' }, opts);
const spawned = spawnProcess(command, args, options, gitDryRun);
const spawned = spawnProcess(command, args, options, cmdDryRun);

return gitDryRun ? Promise.resolve() : wrapError(spawned);
return cmdDryRun ? Promise.resolve() : wrapError(spawned);
}

// resultCallback?: (processResult: ChildProcessResult) => void
Expand All @@ -28,19 +28,19 @@ export function execSync(command: string, args?: string[], opts?: any, cmdDryRun
: execa.sync(command, args, opts).stdout;
}

export function spawn(command, args, opts) {
export function spawn(command, args, opts, cmdDryRun = false) {
const options = Object.assign({}, opts, { stdio: 'inherit' });
const spawned = spawnProcess(command, args, options);
const spawned = spawnProcess(command, args, options, cmdDryRun);

return wrapError(spawned);
}

// istanbul ignore next
export function spawnStreaming(command, args, opts, prefix) {
export function spawnStreaming(command, args, opts, prefix, cmdDryRun = false) {
const options = Object.assign({}, opts);
options.stdio = ['ignore', 'pipe', 'pipe'];

const spawned = spawnProcess(command, args, options) as execa.ExecaChildProcess<string>;
const spawned = spawnProcess(command, args, options, cmdDryRun) as execa.ExecaChildProcess<string>;

const stdoutOpts: any = {};
const stderrOpts: any = {}; // mergeMultiline causes escaped newlines :P
Expand Down Expand Up @@ -87,8 +87,8 @@ export function getExitCode(result) {
throw new TypeError(`Received unexpected exit code value ${JSON.stringify(result.code)}`);
}

export function spawnProcess(command, args, opts, gitDryRun = false) {
if (gitDryRun) {
export function spawnProcess(command, args, opts, cmdDryRun = false) {
if (cmdDryRun) {
return logExecCommand(command, args);
}
const child: any = execa(command, args, opts);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DEFAULT_CONCURRENCY = os.cpus().length;

export class Command {
argv: any;
concurrency?: number;
concurrency!: number;
envDefaults: any;
libVersion = '';
sort: any;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ export class Project {
);
}

log.verbose('project workspaces packages', (workspaces.packages || workspaces).join(' '));
return workspaces.packages || workspaces;
}

log.verbose('project packages', (this.config.packages || [Project.PACKAGE_GLOB]).join(' '));
return this.config.packages || [Project.PACKAGE_GLOB];
}

Expand Down

0 comments on commit a71191b

Please sign in to comment.