Skip to content

Commit

Permalink
feat: contributors generator
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 20, 2024
1 parent 91bb79a commit f627d63
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ Your automated markdown maintainer!

</details>


<!-- /automd -->

## License

Made with 💛 Published under the [MIT License](./LICENSE).
<!-- automd:contributors license=MIT author="pi0" -->

Published under the [MIT](https://github.com/unjs/automd/blob/main/LICENSE) license.
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/automd/graphs/contributors) 💛
<br><br>
<a href="https://github.com/unjs/automd/graphs/contributors">
<img src="https://contrib.rocks/image?repo=unjs/automd" />
</a>

<!-- /automd -->

---

<!-- automd:with-automd -->

Expand Down
2 changes: 2 additions & 0 deletions docs/2.generators/badges.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The `badges` generator generates badges for the latest npm version, npm download
[![npm downloads](https://flat.badgen.net/npm/dm/defu?color=yellow)](https://npmjs.com/package/defu)
[![bundle size](https://flat.badgen.net/bundlephobia/minzip/defu?color=yellow)](https://bundlephobia.com/package/defu)
[![install size](https://flat.badgen.net/packagephobia/publish/defu?color=yellow)](https://packagephobia.com/result?p=defu)
[![codecov](https://flat.badgen.net/codecov/c/github/unjs/automd?color=yellow)](https://codecov.io/gh/unjs/automd)
[![license](https://flat.badgen.net/github/license/unjs/automd?color=yellow)](https://github.com/unjs/automd/blob/main/LICENSE)

<!-- /automd -->

Expand Down
35 changes: 35 additions & 0 deletions docs/2.generators/contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# contributors

The `contributors` generator generates an image of contributors using [contrib.rocks](https://contrib.rocks/) service plus additional data about authors and license.

<!-- automd:example generator=contributors author=pi0 license=MIT -->

## Example

### Input

<!-- automd:contributors author=pi0 license=MIT -->
<!-- /automd -->

### Output

<!-- automd:contributors author=pi0 license=MIT -->

Published under the [MIT](https://github.com/unjs/automd/blob/main/LICENSE) license.
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/automd/graphs/contributors) 💛
<br><br>
<a href="https://github.com/unjs/automd/graphs/contributors">
<img src="https://contrib.rocks/image?repo=unjs/automd" />
</a>

<!-- /automd -->

<!-- /automd -->

## Arguments

- `github`: Github repository name (by default tries to read from `package.json`)
- `max`: Max contributor count (100 by default)
- `anon` Include anonymous users (false by default)
- `author`: Comma separated list of github usersnames.
- `license`: Name of license.
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"name": "docs",
"repository": "unjs/automd",
"scripts": {
"dev": "undocs dev",
"build": "undocs build"
Expand Down
56 changes: 56 additions & 0 deletions src/generators/contributors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { getPkg } from "../_utils";
import { defineGenerator } from "../generator";

export const contributors = defineGenerator({
name: "contributors",
async generate({ config, args }) {
const { github } = await getPkg(config.dir, args);

if (!github) {
throw new Error("`github` is required!");
}

const lines: string[] = [];

// License
if (typeof args.license === "string") {
lines.push(
`Published under the [${args.license.toUpperCase()}](https://github.com/${github}/blob/main/LICENSE) license.`,
);
}

// Made by
let madeBy = `[community](https://github.com/${github}/graphs/contributors) 💛`;
if (typeof args.author === "string") {
const authors = args.author
.split(",")
.map((author) => author.trim())
.map((user) => `[@${user}](https://github.com/${user})`)
.join(", ");
if (authors.length > 0) {
madeBy = `${authors} and ${madeBy}`;
}
}
lines.push(`Made by ${madeBy}`);

// Contributors
const params = [["repo", github]];
if (args.max) {
params.push(["max", args.max]);
}
if (args.anon) {
params.push(["anon", args.anon]);
}
const paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&");
lines.push(
`<br><br>`,
`<a href="https://github.com/${github}/graphs/contributors">`,
`<img src="https://contrib.rocks/image?${paramsStr}" />`,
`</a>`,
);

return {
contents: lines.join("\n"),
};
},
});
2 changes: 2 additions & 0 deletions src/generators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { fetch as _fetch } from "./fetch";
import { jsimport } from "./jsimport";
import { withAutomd } from "./with-automd";
import { file } from "./file";
import { contributors } from "./contributors";

export default {
jsdocs,
Expand All @@ -17,4 +18,5 @@ export default {
file,
jsimport,
"with-automd": withAutomd,
contributors,
} as Record<string, Generator>;
5 changes: 5 additions & 0 deletions test/fixture/INPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@

<!-- automd:file src="./TEST.md" -->
<!-- /automd -->

## `contributors`

<!-- automd:contributors author=pi0 license=MIT -->
<!-- /automd -->
13 changes: 13 additions & 0 deletions test/fixture/OUTPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,16 @@ When your code doesn't work, don't blame yourself. It's clearly the compiler's f
Why waste time solving problems when someone else has already done it for you? Stack Overflow is your best friend, your mentor, and your savior. Just make sure to upvote the answers that save your bacon.

<!-- /automd -->

## `contributors`

<!-- automd:contributors author=pi0 license=MIT -->

Published under the [MIT](https://github.com/unjs/automd/blob/main/LICENSE) license.
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/automd/graphs/contributors) 💛
<br><br>
<a href="https://github.com/unjs/automd/graphs/contributors">
<img src="https://contrib.rocks/image?repo=unjs/automd" />
</a>

<!-- /automd -->

0 comments on commit f627d63

Please sign in to comment.