Skip to content

Commit

Permalink
feat: cleaner config options
Browse files Browse the repository at this point in the history
  • Loading branch information
psm14 committed Sep 7, 2024
1 parent c170d62 commit 9fba6bf
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# semantic-release-path-filter

A plugin for semantic-release that filters commits based on file paths before passing them to other semantic-release plugins.

## Installation

```bash
npm install --save-dev @psm14/semantic-release-path-filter
```

## Usage

This plugin wraps around other semantic-release plugins and filters the commits they receive based on file paths.

```json
{
"plugins": [
[
"@psm14/semantic-release-path-filter",
{
"path": "plugin",
"plugin": "@semantic-release/commit-analyzer"
}
],
[
"@psm14/semantic-release-path-filter",
{
"path": "plugin",
"plugin": "@semantic-release/release-notes-generator"
}
],
[
"@psm14/semantic-release-path-filter",
{
"path": "plugin",
"plugin": "@semantic-release/git"
}
],
[
"@psm14/semantic-release-path-filter",
{
"path": "plugin",
"plugin": "@semantic-release/github"
}
]
]
}
```

The `plugin` option may be a string or an array consisting of the name and a configuration object.
8 changes: 4 additions & 4 deletions plugin/.releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
"@psm14/semantic-release-path-filter",
{
"path": "plugin",
"originalPlugin": "@semantic-release/commit-analyzer"
"plugin": "@semantic-release/commit-analyzer"
}
],
[
"@psm14/semantic-release-path-filter",
{
"path": "plugin",
"originalPlugin": "@semantic-release/release-notes-generator"
"plugin": "@semantic-release/release-notes-generator"
}
],
[
"@psm14/semantic-release-path-filter",
{
"path": "plugin",
"originalPlugin": "@semantic-release/git"
"plugin": "@semantic-release/git"
}
],
[
"@psm14/semantic-release-path-filter",
{
"path": "plugin",
"originalPlugin": "@semantic-release/github"
"plugin": "@semantic-release/github"
}
]
]
Expand Down
8 changes: 4 additions & 4 deletions plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ function getChangedFiles(commitHash) {

function makePlugin(name) {
return async function (pluginConfig, context) {
const { path, originalPlugin, ...remainingConfig } = pluginConfig;
const { path, plugin, ...remainingConfig } = pluginConfig;

const originalPluginName =
typeof originalPlugin === "string" ? originalPlugin : originalPlugin[0];
const originalPluginConfig = Array.isArray(originalPlugin)
? { ...remainingConfig, ...originalPlugin[1] }
: remainingConfig;

const plugin = await import(originalPluginName);
if (!(name in plugin)) {
const pluginModule = await import(originalPluginName);
if (!(name in pluginModule)) {
return;
}

Expand All @@ -45,7 +45,7 @@ function makePlugin(name) {
commits: filterCommits(context.commits, path),
}
: context;
return plugin[name](originalPluginConfig, filteredContext);
return pluginModule[name](originalPluginConfig, filteredContext);
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/.releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@psm14/semantic-release-path-filter",
{
"path": "test",
"originalPlugin": "@semantic-release/commit-analyzer"
"plugin": "@semantic-release/commit-analyzer"
}
]
]
Expand Down

0 comments on commit 9fba6bf

Please sign in to comment.