Skip to content

Commit

Permalink
feat: semantic-release plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hongaar committed Nov 24, 2022
1 parent bb8652d commit b61c4b4
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ yarn moker add --template cra client
- [Use plugins](#use-plugins)
- [Add workspace](#add-workspace)
- [Available plugins](#available-plugins)
- [`dependabot` _monorepo_](#dependabot-_monorepo_)
- [`devcontainer` _monorepo_](#devcontainer-_monorepo_)
- [`github-actions` _monorepo_](#github-actions-_monorepo_)
- [`husky` _monorepo_](#husky-_monorepo_)
- [`lint-staged` _monorepo_](#lint-staged-_monorepo_)
- [`prettier` _monorepo_](#prettier-_monorepo_)
- [`jest` _workspace_](#jest-_workspace_)
- [`semantic-release` _workspace_](#semantic-release-_workspace_)
- [`typescript` _workspace_](#typescript-_workspace_)
- [Available templates](#available-templates)
- [`common` _monorepo_](#common-_monorepo_)
Expand Down Expand Up @@ -142,6 +144,14 @@ options.

# Available plugins

## `dependabot` _monorepo_

**🚧 This plugin is a work in progress**

This plugin adds a
[Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates)
configuration to your monorepo.

## `devcontainer` _monorepo_

**🚧 This plugin is a work in progress**
Expand Down Expand Up @@ -191,6 +201,15 @@ This plugin sets up [Prettier](https://prettier.io).
This plugin sets up [Jest](https://jestjs.io) and adds a `test` and `watch:test`
script to both the workspace and the monorepo.

## `semantic-release` _workspace_

This plugin sets up
[semantic-release](https://semantic-release.gitbook.io/semantic-release/).

> ⚠️ The semantic-release plugin in our monorepo configuration is currently
> broken due to
> [this issue with their npm plugin](https://github.com/semantic-release/npm/pull/529)

## `typescript` _workspace_

This plugin sets up [TypeScript](https://www.typescriptlang.org) and adds a
Expand Down Expand Up @@ -238,6 +257,9 @@ Contributions are very welcome!

- [ ] github-actions plugin
- [ ] devcontainer plugin
- [ ] semantic-release plugin
- [ ] leasot (todos) plugin
- [ ] doctoc plugin
- [ ] Add LICENSE file to monorepo
- [ ] Support for `swc`/`esbuild`
- [ ] A compat lib (which builds cjs and mjs targets)
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"postinstall": "husky install && node scripts/postinstall.js",
"format": "prettier --write --ignore-unknown .",
"doctoc": "doctoc README.md",
"leasot": "leasot --exit-nicely --reporter markdown --ignore \"**/node_modules\" \"**/*.ts\" > TODO.md",
"publish-all": "yarn workspaces foreach --topological --verbose npm publish"
"leasot": "leasot --exit-nicely --reporter markdown --ignore \"**/node_modules\" \"**/*.ts\" > TODO.md"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CORE_PLUGINS = [
"github-actions",
"typescript",
"jest",
"semantic-release",
];

export function isPlugin(plugin: unknown): plugin is Plugin {
Expand Down
19 changes: 19 additions & 0 deletions packages/plugins/src/githubActions/githubActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { PluginType } from "@mokr/core";

async function install() {
// jest -> test workflow
// semanticRelease -> release workflow
// prettier -> lint workflow
// typescript -> build workflow
}

async function remove() {}

async function load() {}

export const githubActions = {
type: PluginType.Monorepo,
install,
remove,
load,
};
1 change: 1 addition & 0 deletions packages/plugins/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from "./husky/husky.js";
export * from "./jest/jest.js";
export * from "./lintStaged/lintStaged.js";
export * from "./prettier/prettier.js";
export * from "./semanticRelease/semanticRelease.js";
export * from "./typescript/typescript.js";
91 changes: 91 additions & 0 deletions packages/plugins/src/semanticRelease/semanticRelease.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {
enqueueInstallDependency,
enqueueRemoveDependency,
logInfo,
PluginArgs,
PluginType,
removeFile,
writeFile,
writeJson,
} from "@mokr/core";
import { join } from "node:path";

const CONFIG_FILENAME = ".releaserc.json";
const CONFIG = {
branches: ["main"],
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/git",
{
assets: ["CHANGELOG.md", "package.json", "packages/*/package.json"],
message:
"chore(release): ${nextRelease.version}\n\n${nextRelease.notes}\n\n[skip ci]",
},
],
],
};

const NPMRC_FILENAME = ".npmrc";
const NPMRC = `
workspaces = true
workspaces-update = false
`;

async function install({ directory }: PluginArgs) {
enqueueInstallDependency({
directory,
identifier: [
"@semantic-release/changelog",
"@semantic-release/git",
"semantic-release",
],
dev: true,
});

await writeJson({
path: join(directory, CONFIG_FILENAME),
data: CONFIG,
});

await writeFile({
path: join(directory, NPMRC_FILENAME),
contents: NPMRC,
});

logInfo(
`semantic-release in our monorepo configuration is currently broken due to https://github.com/semantic-release/npm/pull/529`
);
}

async function remove({ directory }: PluginArgs) {
enqueueRemoveDependency({
directory,
identifier: [
"@semantic-release/changelog",
"@semantic-release/git",
"semantic-release",
],
});

await removeFile({
path: join(directory, CONFIG_FILENAME),
});

await removeFile({
path: join(directory, NPMRC_FILENAME),
});
}

async function load() {}

export const semanticRelease = {
type: PluginType.Monorepo,
install,
remove,
load,
};

0 comments on commit b61c4b4

Please sign in to comment.