diff --git a/README.md b/README.md index b9dc6d46..5e9e50ec 100644 --- a/README.md +++ b/README.md @@ -38,17 +38,17 @@ Lerna-Lite differs from the original [Lerna](https://github.com/lerna/lerna) in Mainly for the following reasons: 1. the original Lerna is no longer maintained (dependencies are out of date) 2. create a lighter lib that still provide Lerna's approach of Versioning and Publishing by following the [Conventional Commits](https://www.conventionalcommits.org/) and also automatically create [Conventional-Changelog](https://github.com/conventional-changelog/conventional-changelog) for each package of the workspace. We don't need all packages of Lerna anymore since NPM Workspaces came out. -3. add some little extras +3. add some little extras while keeping the lib light. ### This lib will help you with -##### [Version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version) & [Publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish) commands -- Automate the rolling of new Versions (independent or fixed) for all your workspace packages - - it will automatically add Commit & Tag your new Version in Git & create new Release in GitHub when enabled +#### [Version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version) & [Publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish) commands +- Automate the rolling of new Versions (`independent` or `fixed`) for all your workspace packages + - it will automatically add Commit & Tag your new Version in Git & create new GitHub or GitLab Release 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 (NPM or other platform) -##### [Run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) command (optional) +#### [Run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) command (optional) - [Run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) is an optional package that will help you run npm script in parallel and in topological order. ## Lerna-Lite Packages @@ -94,7 +94,7 @@ Using Lerna-Lite? Add a README badge to show it off: [![lerna--lite](https://img # Lerna CLI which includes publish/version commands npm install @lerna-lite/cli # OR yard add @lerna-lite/cli -# optional run command +# install optional `run` command npm install @lerna-lite/run # OR yarn add @lerna-lite/run ``` @@ -110,7 +110,7 @@ Add custom NPM Scripts or simply run the following NodeJS commands in a shell. ``` ### Configuration -This lib requires a config file in order to do its job properly. It could come from a separate config file in the root (read [`lerna.json` - Wiki](https://github.com/ghiscoding/lerna-lite/wiki/lerna.json) OR a `"lerna": {}` property directly under your `package.json`. +You could configure Lerna via a `lerna.json` file, via a `"lerna": {}` property directly under your `package.json` or lastly by passing arguments directly when calling the shell commands. You can read the [`lerna.json` - Wiki](https://github.com/ghiscoding/lerna-lite/wiki/lerna.json) for more info. ### Migration for [Lerna](https://github.com/lerna/lerna) Users If you are migrating from Lerna, it should be fairly easy to just replace Lerna with Lerna-Lite and that should be it, the CLI commands are the same, take a look at the quick steps below: @@ -125,7 +125,7 @@ npm uninstall -g lerna # OR yarn global remove lerna # Lerna CLI (`version`/`publish` commands) npm install @lerna-lite/cli -# optionally install the `run` command +# install optional `run` command npm install @lerna-lite/run ``` diff --git a/lerna.json b/lerna.json index 4e5ac8d0..d2c804a2 100644 --- a/lerna.json +++ b/lerna.json @@ -9,6 +9,7 @@ }, "version": { "conventionalCommits": true, + "createRelease": "github", "gitDryRun": false, "noPrivate": true, "message": "chore(release): publish new version %v", diff --git a/packages/core/src/git-clients/__tests__/github-client.spec.ts b/packages/core/src/git-clients/__tests__/github-client.spec.ts index 234624e9..1474de8e 100644 --- a/packages/core/src/git-clients/__tests__/github-client.spec.ts +++ b/packages/core/src/git-clients/__tests__/github-client.spec.ts @@ -62,8 +62,7 @@ describe('parseGitRepo', () => { expect(childProcess.execSync).toHaveBeenCalledWith( 'git', ['config', '--get', 'remote.origin.url'], - undefined, - false + undefined ); expect(repo).toEqual( @@ -82,8 +81,7 @@ describe('parseGitRepo', () => { expect(childProcess.execSync).toHaveBeenCalledWith( 'git', ['config', '--get', 'remote.upstream.url'], - undefined, - false + undefined ); }); diff --git a/packages/core/src/git-clients/github-client.ts b/packages/core/src/git-clients/github-client.ts index 3c318782..8241f70f 100644 --- a/packages/core/src/git-clients/github-client.ts +++ b/packages/core/src/git-clients/github-client.ts @@ -30,15 +30,15 @@ export function createGitHubClient() { return new Octokit(options); } -export function parseGitRepo(remote = 'origin', opts?: SyncOptions, gitDryRun = false): parseGitUrl.GitUrl { +export function parseGitRepo(remote = 'origin', opts?: SyncOptions): parseGitUrl.GitUrl { log.silly('parseGitRepo', ''); const args = ['config', '--get', `remote.${remote}.url`]; log.verbose('git', args.join(' ')); - const url = execSync('git', args, opts, gitDryRun); + const url = execSync('git', args, opts); - if (!url && !gitDryRun) { + if (!url) { throw new Error(`Git remote URL could not be found using "${remote}".`); } - return gitDryRun ? {} as parseGitUrl.GitUrl : parseGitUrl(url); + return parseGitUrl(url); } diff --git a/packages/version/README.md b/packages/version/README.md index fe39106d..58f692bf 100644 --- a/packages/version/README.md +++ b/packages/version/README.md @@ -286,7 +286,7 @@ When run with this flag, `lerna version` will force publish the specified packag Displays the git command that would be performed without actually executing it, however please note that it will still create all the changelogs. This could be helpful for troubleshooting and also to see changelog changes without commiting them to Git. -**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 `lerna.json` once you're done) +**Note:** changelogs will still be created (when enabled) even in dry-run mode, so it could be useful to see what gets created without them being committed (however, make sure to discard the changes and roll back your version in `lerna.json` once you're done). ```sh $ lerna run watch --git-dry-run diff --git a/packages/version/src/lib/create-release.ts b/packages/version/src/lib/create-release.ts index c6016682..c414555c 100644 --- a/packages/version/src/lib/create-release.ts +++ b/packages/version/src/lib/create-release.ts @@ -31,7 +31,7 @@ export function createReleaseClient(type: 'github' | 'gitlab') { * @param {{ gitRemote: string; execOpts: import('@lerna/child-process').ExecOpts }} opts */ export function createRelease(client, { tags, releaseNotes }: ReleaseCommandProps, { gitRemote, execOpts }: ReleaseOptions, gitDryRun = false) { - const repo = parseGitRepo(gitRemote, execOpts, gitDryRun); + const repo = parseGitRepo(gitRemote, execOpts); return Promise.all( releaseNotes.map(({ notes, name }) => { @@ -43,13 +43,7 @@ export function createRelease(client, { tags, releaseNotes }: ReleaseCommandProp } const prereleaseParts = semver.prerelease(tag.replace(`${name}@`, '')) || []; - - if (gitDryRun) { - log.info('dry-run>', `Release Created`); - return {}; - } - - return client.repos.createRelease({ + const releaseOptions = { owner: repo.owner, repo: repo.name, tag_name: tag, @@ -57,7 +51,14 @@ export function createRelease(client, { tags, releaseNotes }: ReleaseCommandProp body: notes, draft: false, prerelease: prereleaseParts.length > 0, - }); + }; + + if (gitDryRun) { + log.info('dry-run>', `Create Release with repo options: `, JSON.stringify(releaseOptions)); + return Promise.resolve(); + } + + return client.repos.createRelease(releaseOptions); }) ); }