Skip to content

Commit

Permalink
feat: introduce lerna-release plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Bekrin committed Apr 3, 2019
1 parent db36974 commit 1e46acf
Show file tree
Hide file tree
Showing 14 changed files with 620 additions and 357 deletions.
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ node_js:
- 8
- 10
cache: yarn
script:
- yarn lint
- yarn test
jobs:
include:
- stage: test
script:
- yarn lint
- yarn test
# Uncomment once all tokens are setup
# - stage: release
# node_js: 10
# if: branch = master
# script:
# - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
# - yarn release
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
"scripts": {
"lint": "spire lint",
"test": "spire test",
"prerelease": "yarn lint && yarn test",
"release": "lerna publish --no-verify-access --conventional-commits --allow-branch master --yes",
"release-next": "yarn release --npm-tag next --no-git-tag-version --no-push"
},
"devDependencies": {
"lerna": "^3.13.1"
"release": "spire release"
},
"spire": {
"extends": "spire-config-default",
"plugins": [
"spire-plugin-yarn"
"spire-plugin-yarn",
"spire-plugin-lerna-release"
]
}
}
5 changes: 2 additions & 3 deletions packages/spire-config-default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ This preset includes next plugins with their default options:
- [`spire-plugin-jest`](../spire-plugin-jest/README.md)
- [`spire-plugin-lint-staged`](../spire-plugin-lint-staged/README.md)
- [`spire-plugin-prettier`](../spire-plugin-prettier/README.md)
- [`spire-plugin-semantic-release`](../spire-plugin-semantic-release/README.md)

## Options

This preset allows to disable or override default options for plugins. To do so,
pass an option object with desired plugin keys (`clean`, `doctoc`, `eslint`,
`jest`, `lint-staged`, `prettier` or `semantic-release`). Setting option to
`false` will disable that plugin.
`jest`, `lint-staged` or `prettier`). Setting option to `false` will disable
that plugin.

```js
module.exports = () => ({
Expand Down
2 changes: 0 additions & 2 deletions packages/spire-config-default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = (
eslint = {},
jest = {},
prettier = {},
'semantic-release': semanticRelease = {},
'lint-staged': lintStaged = {},
}
) => ({
Expand All @@ -16,7 +15,6 @@ module.exports = (
['spire-plugin-eslint', eslint],
['spire-plugin-jest', jest],
['spire-plugin-prettier', prettier],
['spire-plugin-semantic-release', semanticRelease],
['spire-plugin-lint-staged', lintStaged],
]
.filter(entry => {
Expand Down
2 changes: 1 addition & 1 deletion packages/spire-plugin-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"dependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.15.3",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.1.0",
"eslint-config-unobtrusive": "^1.2.2",
"eslint-plugin-prettier": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/spire-plugin-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"dependencies": {
"execa": "^1.0.0",
"jest": "^24.5.0"
"jest": "^24.7.0"
},
"devDependencies": {
"spire-test-utils": "^1.3.0"
Expand Down
68 changes: 68 additions & 0 deletions packages/spire-plugin-lerna-release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# spire-plugin-lerna-release

[lerna publish](https://github.com/lerna/lerna/tree/master/commands/publish)
plugin for [Spire](../spire/README.md).

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Quick start](#quick-start)
- [Hooks](#hooks)
- [Options](#options)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Quick start

1. Install `spire-plugin-lerna-release`

```sh
yarn add --dev spire-plugin-lerna-release
```

2. Add `spire-plugin-lerna-release` to list of plugins

```json
{
"spire": {
"plugins": ["spire-plugin-lerna-release"]
}
}
```

## Hooks

- `setup` Adds `release` command and prepares lerna arguments.
- `run` Runs `lerna publish`.

## Options

- Plugin `['spire-plugin-lerna-release', options]`

- `command` \<[string]\> Command to run semantic-release on. Defaults to
`release`.
- `gitAuthorName` \<[string]\> Git author and commiter name. Defaults to
`undefined`, which falls back to default value of [lerna].
- `gitAuthorEmail` \<[string]\> Git author and commiter email. Defaults to
`undefined`, which falls back to default value of [lerna].
- `allowBranch` \<[string]\> Allowed branch to be released. Defaults to
`master`.
- `githubRelease` \<[boolean]\> Whether to create a GitHub release or not.
- `extraArgs` \<[Array]\<[string]\>\> Array of extra argumnets to pass to
`lerna publish`. Defaults to `[]`.

- CLI `npx spire release`
- Passes all arguments after `--` as-is to lerna.

## License

MIT &copy; [ResearchGate](https://github.com/researchgate)

[lerna]: https://github.com/lerna/lerna
[boolean]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
[string]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
[array]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
62 changes: 62 additions & 0 deletions packages/spire-plugin-lerna-release/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const execa = require('execa');

function lernaRelease(
{ setCommand, getCommand, setState, getState },
{
command = 'release',
gitAuthorName = undefined,
gitAuthorEmail = undefined,
allowBranch = 'master',
githubRelease = true,
extraArgs = [],
}
) {
const RELEASE_COMMAND = Symbol.for(`lerna-${command}`);
return {
name: 'spire-plugin-lerna-release',
async setup({ cli }) {
cli.command(
command,
'run lerna publish',
() => {},
() => setCommand(RELEASE_COMMAND)
);
setState({
lernaPublishArgs: [
'--conventional-commits',
'--allow-branch',
allowBranch,
'--github-release',
githubRelease,
'--yes',
...extraArgs,
],
});
},
async skip() {
return getCommand() !== RELEASE_COMMAND;
},
async run({ options, cwd, logger }) {
const { lernaPublishArgs } = getState();
const userProvidedArgs = options._.slice(1);
const finalLernaPublishArgs = [...lernaPublishArgs, ...userProvidedArgs];
logger.debug(
'Using lerna publish arguments: %s',
finalLernaPublishArgs.join(' ')
);
const env = {
GIT_AUTHOR_NAME: gitAuthorName,
GIT_AUTHOR_EMAIL: gitAuthorEmail,
GIT_COMMITTER_NAME: gitAuthorName,
GIT_COMMITTER_EMAIL: gitAuthorEmail,
};
await execa('lerna', ['publish', ...finalLernaPublishArgs], {
env,
cwd,
stdio: 'inherit',
});
},
};
}

module.exports = lernaRelease;
14 changes: 14 additions & 0 deletions packages/spire-plugin-lerna-release/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "spire-plugin-lerna-release",
"version": "1.4.1",
"description": "Lerna publish plugin for Spire",
"repository": "researchgate/spire",
"author": "Sergey Bekrin <sergey@bekrin.me> (https://bekrin.me)",
"license": "MIT",
"dependencies": {
"lerna": "^3.13.1"
},
"peerDependencies": {
"spire": "^1.0.0"
}
}
49 changes: 40 additions & 9 deletions packages/spire-plugin-semantic-release/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# spire-plugin-semantic-release

[semantic-release](https://github.com/semantic-release/semantic-release) plugin
for [Spire](../spire/README.md).
[semantic-release] plugin for [Spire](../spire/README.md).

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Quick start](#quick-start)
- [Hooks](#hooks)
- [Options](#options)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Quick start

1. Install `spire-plugin-semantic-release`

```sh
yarn add --dev spire-plugin-semantic-release
```

2. Add `spire-plugin-semantic-release` to list of plugins

```json
{
"spire": {
"plugins": ["spire-plugin-semantic-release"]
}
}
```

## Hooks

- `setup` Adds `release` command and prepares semantic-release arguments.
Expand All @@ -20,19 +39,31 @@ for [Spire](../spire/README.md).

- Plugin `['spire-plugin-semantic-release', options]`

- `command` \<string\> Command to run semantic-release on. Defaults to
- `command` \<[string]\> Command to run semantic-release on. Defaults to
`release`.
- `semanticReleaseConfig` \<string\> Default [semantic-release] configuration.
Defaults to [`./config.js`](./config.js).
- `allowCustomConfig` \<boolean\> Whether to allow user-provided config. If
- `semanticReleaseConfig` \<[string]\> Default [semantic-release]
configuration. Defaults to [`./config.js`](./config.js).
- `allowCustomConfig` \<[boolean]\> Whether to allow user-provided config. If
this option is `false` and there's custom semantic-release config found it
will throw an error. Defaults to `true`.
- `changelogName` \<string\> Case-sensitive changelog name. Defaults to
- `changelogName` \<[string]\> Case-sensitive changelog name. Defaults to
`changelog.md`.
- `gitAuthorName` \<string\> Git author and commiter name. Defaults to
- `gitAuthorName` \<[string]\> Git author and commiter name. Defaults to
`undefined`, which falls back to default value of [semantic-release].
- `gitAuthorEmail` \<string\> Git author and commiter email. Defaults to
- `gitAuthorEmail` \<[string]\> Git author and commiter email. Defaults to
`undefined`, which falls back to default value of [semantic-release].

- CLI `npx spire release`
- Passes all arguments after `--` as-is to semantic-release.

## License

MIT &copy; [ResearchGate](https://github.com/researchgate)

[semantic-release]: https://github.com/semantic-release/semantic-release
[boolean]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
[string]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
[array]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
33 changes: 30 additions & 3 deletions packages/spire-plugin-yarn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,46 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Quick start](#quick-start)
- [Hooks](#hooks)
- [Options](#options)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Quick start

1. Install `spire-plugin-yarn`

```sh
yarn add --dev spire-plugin-yarn
```

2. Add `spire-plugin-yarn` to list of plugins

```json
{
"spire": {
"plugins": ["spire-plugin-yarn"]
}
}
```

## Hooks

- `preinstall` Ensures what `yarn` is used instead of `npm`.
- `postinstall` Runs
[`yarn-deduplicate`](https://github.com/atlassian/yarn-deduplicate).
- `postinstall` Runs [yarn-deduplicate].

## Options

- Plugin `['spire-plugin-yarn', options]`
- `deduplicateStrategy` \<string\> Deduplication strategy. Valid values:
- `deduplicateStrategy` \<[string]\> Deduplication strategy. Valid values:
`fewer`, `highest`. Defaults to `highest`.

## License

MIT &copy; [ResearchGate](https://github.com/researchgate)

[yarn-deduplicate]: https://github.com/atlassian/yarn-deduplicate
[string]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
Loading

0 comments on commit 1e46acf

Please sign in to comment.