githublogen 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -107
- package/dist/cli.d.ts +2 -2
- package/dist/cli.mjs +4 -99
- package/package.json +13 -46
- package/README.md +0 -51
- package/dist/index.cjs +0 -8444
- package/dist/index.d.ts +0 -146
- package/dist/index.mjs +0 -8414
package/dist/cli.cjs
CHANGED
|
@@ -1,107 +1 @@
|
|
|
1
|
-
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const fs = require('node:fs');
|
|
5
|
-
const kolorist = require('kolorist');
|
|
6
|
-
const execa = require('execa');
|
|
7
|
-
const cac = require('cac');
|
|
8
|
-
const index = require('./index.cjs');
|
|
9
|
-
require('ohmyfetch');
|
|
10
|
-
require('convert-gitmoji');
|
|
11
|
-
require('node:module');
|
|
12
|
-
require('node:url');
|
|
13
|
-
require('node:assert');
|
|
14
|
-
require('node:process');
|
|
15
|
-
require('node:path');
|
|
16
|
-
require('node:v8');
|
|
17
|
-
require('node:util');
|
|
18
|
-
|
|
19
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
20
|
-
|
|
21
|
-
const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
|
|
22
|
-
|
|
23
|
-
const version = "0.2.1";
|
|
24
|
-
|
|
25
|
-
const cli = cac__default("githublogen");
|
|
26
|
-
cli.version(version).option("-t, --token <path>", "GitHub Token").option("--from <ref>", "From tag").option("--to <ref>", "To tag").option("--github <path>", "GitHub Repository, e.g. soybeanjs/githublogen").option("--name <name>", "Name of the release").option("--contributors", "Show contributors section").option("--prerelease", "Mark release as prerelease").option("-d, --draft", "Mark release as draft").option("--output <path>", "Output to file instead of sending to GitHub").option("--capitalize", "Should capitalize for each comment message").option("--emoji", "Use emojis in section titles", { default: true }).option("--group", "Nest commit messages under their scopes").option("--dry", "Dry run").help();
|
|
27
|
-
cli.command("").action(async (args) => {
|
|
28
|
-
try {
|
|
29
|
-
console.log();
|
|
30
|
-
console.log(kolorist.dim(`${kolorist.bold("github")}logen `) + kolorist.dim(`v${version}`));
|
|
31
|
-
const cwd = process.cwd();
|
|
32
|
-
const { config, md, changelog, commits } = await index.generate(cwd, args);
|
|
33
|
-
const markdown = md.replace(/ /g, "");
|
|
34
|
-
console.log(kolorist.cyan(config.from) + kolorist.dim(" -> ") + kolorist.blue(config.to) + kolorist.dim(` (${commits.length} commits)`));
|
|
35
|
-
console.log(kolorist.dim("--------------"));
|
|
36
|
-
console.log();
|
|
37
|
-
console.log(markdown);
|
|
38
|
-
console.log();
|
|
39
|
-
console.log(kolorist.dim("--------------"));
|
|
40
|
-
if (config.dry) {
|
|
41
|
-
console.log(kolorist.yellow("Dry run. Release skipped."));
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (typeof config.output === "string") {
|
|
45
|
-
const pushUrl = index.getGitPushUrl(config.repo, config.tokens.github);
|
|
46
|
-
if (!pushUrl) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
let changelogMD;
|
|
50
|
-
const changelogPrefix = "# Changelog";
|
|
51
|
-
if (fs.existsSync(config.output)) {
|
|
52
|
-
console.info(`Updating ${config.output}`);
|
|
53
|
-
changelogMD = await fs.promises.readFile(config.output, "utf8");
|
|
54
|
-
if (!changelogMD.startsWith(changelogPrefix)) {
|
|
55
|
-
changelogMD = `${changelogPrefix}
|
|
56
|
-
|
|
57
|
-
${changelogMD}`;
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
console.info(`Creating ${config.output}`);
|
|
61
|
-
changelogMD = `${changelogPrefix}
|
|
62
|
-
|
|
63
|
-
`;
|
|
64
|
-
}
|
|
65
|
-
const lastEntry = changelogMD.match(/^###?\s+.*$/m);
|
|
66
|
-
if (lastEntry) {
|
|
67
|
-
changelogMD = `${changelogMD.slice(0, lastEntry.index) + changelog}
|
|
68
|
-
|
|
69
|
-
${changelogMD.slice(lastEntry.index)}`;
|
|
70
|
-
} else {
|
|
71
|
-
changelogMD += `
|
|
72
|
-
${changelog}
|
|
73
|
-
|
|
74
|
-
`;
|
|
75
|
-
}
|
|
76
|
-
await fs.promises.writeFile(config.output, changelogMD);
|
|
77
|
-
const { email = "unknow@unknow.com", name = "unknow" } = commits[0]?.author || {};
|
|
78
|
-
await execa.execa("git", ["config", "--global", "user.email", `"${email}"`]);
|
|
79
|
-
await execa.execa("git", ["config", "--global", "user.name", `"${name}"`]);
|
|
80
|
-
await execa.execa("git", ["add", "."]);
|
|
81
|
-
await execa.execa("git", ["commit", "-m docs(projects): CHANGELOG.md"], { cwd });
|
|
82
|
-
await execa.execa("git", ["push", pushUrl, `HEAD:${config.gitMainBranch}`], { cwd });
|
|
83
|
-
}
|
|
84
|
-
if (!await index.hasTagOnGitHub(config.to, config)) {
|
|
85
|
-
console.error(kolorist.yellow(`Current ref "${kolorist.bold(config.to)}" is not available as tags on GitHub. Release skipped.`));
|
|
86
|
-
process.exitCode = 1;
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (!commits.length && await index.isRepoShallow()) {
|
|
90
|
-
console.error(
|
|
91
|
-
kolorist.yellow(
|
|
92
|
-
"The repo seems to be clone shallowly, which make changelog failed to generate. You might want to specify `fetch-depth: 0` in your CI config."
|
|
93
|
-
)
|
|
94
|
-
);
|
|
95
|
-
process.exitCode = 1;
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
await index.sendRelease(config, md);
|
|
99
|
-
} catch (e) {
|
|
100
|
-
console.error(kolorist.red(String(e)));
|
|
101
|
-
if (e?.stack) {
|
|
102
|
-
console.error(kolorist.dim(e.stack?.split("\n").slice(1).join("\n")));
|
|
103
|
-
}
|
|
104
|
-
process.exit(1);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
cli.parse();
|
|
1
|
+
module.exports = require("/Users/soybean/Web/Projects/SoybeanJS/changelog/node_modules/.pnpm/jiti@1.19.3/node_modules/jiti/lib/index.js")(null, { interopDefault: true, esmResolve: true })("/Users/soybean/Web/Projects/SoybeanJS/changelog/packages/githublogen/src/cli.ts")
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
export * from "/Users/soybean/Web/Projects/SoybeanJS/changelog/packages/githublogen/src/cli";
|
|
2
|
+
export { default } from "/Users/soybean/Web/Projects/SoybeanJS/changelog/packages/githublogen/src/cli";
|
package/dist/cli.mjs
CHANGED
|
@@ -1,101 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { existsSync, promises } from 'node:fs';
|
|
3
|
-
import { dim, bold, cyan, blue, yellow, red } from 'kolorist';
|
|
4
|
-
import { execa } from 'execa';
|
|
5
|
-
import cac from 'cac';
|
|
6
|
-
import { generate, getGitPushUrl, hasTagOnGitHub, isRepoShallow, sendRelease } from './index.mjs';
|
|
7
|
-
import 'ohmyfetch';
|
|
8
|
-
import 'convert-gitmoji';
|
|
9
|
-
import 'node:module';
|
|
10
|
-
import 'node:url';
|
|
11
|
-
import 'node:assert';
|
|
12
|
-
import 'node:process';
|
|
13
|
-
import 'node:path';
|
|
14
|
-
import 'node:v8';
|
|
15
|
-
import 'node:util';
|
|
1
|
+
import jiti from "file:///Users/soybean/Web/Projects/SoybeanJS/changelog/node_modules/.pnpm/jiti@1.19.3/node_modules/jiti/lib/index.js";
|
|
16
2
|
|
|
17
|
-
|
|
3
|
+
/** @type {import("/Users/soybean/Web/Projects/SoybeanJS/changelog/packages/githublogen/src/cli")} */
|
|
4
|
+
const _module = jiti(null, { interopDefault: true, esmResolve: true })("/Users/soybean/Web/Projects/SoybeanJS/changelog/packages/githublogen/src/cli.ts");
|
|
18
5
|
|
|
19
|
-
|
|
20
|
-
cli.version(version).option("-t, --token <path>", "GitHub Token").option("--from <ref>", "From tag").option("--to <ref>", "To tag").option("--github <path>", "GitHub Repository, e.g. soybeanjs/githublogen").option("--name <name>", "Name of the release").option("--contributors", "Show contributors section").option("--prerelease", "Mark release as prerelease").option("-d, --draft", "Mark release as draft").option("--output <path>", "Output to file instead of sending to GitHub").option("--capitalize", "Should capitalize for each comment message").option("--emoji", "Use emojis in section titles", { default: true }).option("--group", "Nest commit messages under their scopes").option("--dry", "Dry run").help();
|
|
21
|
-
cli.command("").action(async (args) => {
|
|
22
|
-
try {
|
|
23
|
-
console.log();
|
|
24
|
-
console.log(dim(`${bold("github")}logen `) + dim(`v${version}`));
|
|
25
|
-
const cwd = process.cwd();
|
|
26
|
-
const { config, md, changelog, commits } = await generate(cwd, args);
|
|
27
|
-
const markdown = md.replace(/ /g, "");
|
|
28
|
-
console.log(cyan(config.from) + dim(" -> ") + blue(config.to) + dim(` (${commits.length} commits)`));
|
|
29
|
-
console.log(dim("--------------"));
|
|
30
|
-
console.log();
|
|
31
|
-
console.log(markdown);
|
|
32
|
-
console.log();
|
|
33
|
-
console.log(dim("--------------"));
|
|
34
|
-
if (config.dry) {
|
|
35
|
-
console.log(yellow("Dry run. Release skipped."));
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (typeof config.output === "string") {
|
|
39
|
-
const pushUrl = getGitPushUrl(config.repo, config.tokens.github);
|
|
40
|
-
if (!pushUrl) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
let changelogMD;
|
|
44
|
-
const changelogPrefix = "# Changelog";
|
|
45
|
-
if (existsSync(config.output)) {
|
|
46
|
-
console.info(`Updating ${config.output}`);
|
|
47
|
-
changelogMD = await promises.readFile(config.output, "utf8");
|
|
48
|
-
if (!changelogMD.startsWith(changelogPrefix)) {
|
|
49
|
-
changelogMD = `${changelogPrefix}
|
|
50
|
-
|
|
51
|
-
${changelogMD}`;
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
console.info(`Creating ${config.output}`);
|
|
55
|
-
changelogMD = `${changelogPrefix}
|
|
56
|
-
|
|
57
|
-
`;
|
|
58
|
-
}
|
|
59
|
-
const lastEntry = changelogMD.match(/^###?\s+.*$/m);
|
|
60
|
-
if (lastEntry) {
|
|
61
|
-
changelogMD = `${changelogMD.slice(0, lastEntry.index) + changelog}
|
|
62
|
-
|
|
63
|
-
${changelogMD.slice(lastEntry.index)}`;
|
|
64
|
-
} else {
|
|
65
|
-
changelogMD += `
|
|
66
|
-
${changelog}
|
|
67
|
-
|
|
68
|
-
`;
|
|
69
|
-
}
|
|
70
|
-
await promises.writeFile(config.output, changelogMD);
|
|
71
|
-
const { email = "unknow@unknow.com", name = "unknow" } = commits[0]?.author || {};
|
|
72
|
-
await execa("git", ["config", "--global", "user.email", `"${email}"`]);
|
|
73
|
-
await execa("git", ["config", "--global", "user.name", `"${name}"`]);
|
|
74
|
-
await execa("git", ["add", "."]);
|
|
75
|
-
await execa("git", ["commit", "-m docs(projects): CHANGELOG.md"], { cwd });
|
|
76
|
-
await execa("git", ["push", pushUrl, `HEAD:${config.gitMainBranch}`], { cwd });
|
|
77
|
-
}
|
|
78
|
-
if (!await hasTagOnGitHub(config.to, config)) {
|
|
79
|
-
console.error(yellow(`Current ref "${bold(config.to)}" is not available as tags on GitHub. Release skipped.`));
|
|
80
|
-
process.exitCode = 1;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (!commits.length && await isRepoShallow()) {
|
|
84
|
-
console.error(
|
|
85
|
-
yellow(
|
|
86
|
-
"The repo seems to be clone shallowly, which make changelog failed to generate. You might want to specify `fetch-depth: 0` in your CI config."
|
|
87
|
-
)
|
|
88
|
-
);
|
|
89
|
-
process.exitCode = 1;
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
await sendRelease(config, md);
|
|
93
|
-
} catch (e) {
|
|
94
|
-
console.error(red(String(e)));
|
|
95
|
-
if (e?.stack) {
|
|
96
|
-
console.error(dim(e.stack?.split("\n").slice(1).join("\n")));
|
|
97
|
-
}
|
|
98
|
-
process.exit(1);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
cli.parse();
|
|
6
|
+
export default _module;
|
package/package.json
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "githublogen",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"author": {
|
|
7
|
-
"name": "
|
|
8
|
-
"email": "
|
|
7
|
+
"name": "Soybean",
|
|
8
|
+
"email": "soybeanjs@outlook.com",
|
|
9
9
|
"url": "https://github.com/soybeanjs"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"homepage": "https://github.com/soybeanjs/githublogen#readme",
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/soybeanjs/githublogen.git"
|
|
16
|
-
},
|
|
17
|
-
"bugs": "https://github.com/soybeanjs/githublogen/issues",
|
|
18
12
|
"publishConfig": {
|
|
19
13
|
"registry": "https://registry.npmjs.org/"
|
|
20
14
|
},
|
|
@@ -26,16 +20,6 @@
|
|
|
26
20
|
"changelog",
|
|
27
21
|
"log"
|
|
28
22
|
],
|
|
29
|
-
"exports": {
|
|
30
|
-
".": {
|
|
31
|
-
"types": "./dist/index.d.ts",
|
|
32
|
-
"require": "./dist/index.cjs",
|
|
33
|
-
"import": "./dist/index.mjs"
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"main": "./dist/index.mjs",
|
|
37
|
-
"module": "./dist/index.mjs",
|
|
38
|
-
"types": "./dist/index.d.ts",
|
|
39
23
|
"bin": {
|
|
40
24
|
"githublogen": "./dist/cli.mjs"
|
|
41
25
|
},
|
|
@@ -46,39 +30,22 @@
|
|
|
46
30
|
"node": ">=12.0.0"
|
|
47
31
|
},
|
|
48
32
|
"dependencies": {
|
|
49
|
-
"c12": "1.4.
|
|
33
|
+
"c12": "1.4.2",
|
|
50
34
|
"cac": "6.7.14",
|
|
51
|
-
"
|
|
52
|
-
"execa": "7.1.1",
|
|
35
|
+
"execa": "8.0.1",
|
|
53
36
|
"kolorist": "1.8.0",
|
|
54
|
-
"
|
|
37
|
+
"ofetch": "1.2.0",
|
|
38
|
+
"@soybeanjs/changelog": "0.3.0"
|
|
55
39
|
},
|
|
56
40
|
"devDependencies": {
|
|
57
|
-
"@soybeanjs/cli": "0.
|
|
58
|
-
"@types/node": "20.2
|
|
59
|
-
"
|
|
60
|
-
"changelogen": "^0.5.3",
|
|
61
|
-
"eslint": "8.41.0",
|
|
62
|
-
"eslint-config-soybeanjs": "0.4.8",
|
|
63
|
-
"simple-git-hooks": "2.8.1",
|
|
64
|
-
"tsx": "^3.12.7",
|
|
65
|
-
"typescript": "5.0.4",
|
|
41
|
+
"@soybeanjs/cli": "0.6.7",
|
|
42
|
+
"@types/node": "20.5.2",
|
|
43
|
+
"typescript": "5.1.6",
|
|
66
44
|
"unbuild": "1.2.1"
|
|
67
45
|
},
|
|
68
|
-
"simple-git-hooks": {
|
|
69
|
-
"commit-msg": "pnpm soy git-commit-verify",
|
|
70
|
-
"pre-commit": "pnpm soy lint-staged"
|
|
71
|
-
},
|
|
72
46
|
"scripts": {
|
|
73
|
-
"build": "unbuild",
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"commit": "soy git-commit",
|
|
77
|
-
"cleanup": "soy cleanup",
|
|
78
|
-
"update-pkg": "soy update-pkg",
|
|
79
|
-
"update-version": "bumpp --commit --push --tag",
|
|
80
|
-
"publish-pkg": "pnpm -r publish --access public",
|
|
81
|
-
"release": "pnpm update-version && pnpm build && pnpm publish-pkg",
|
|
82
|
-
"typecheck": "tsc --noEmit"
|
|
47
|
+
"build": "pnpm typecheck && unbuild",
|
|
48
|
+
"stub": "pnpm unbuild --stub",
|
|
49
|
+
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
83
50
|
}
|
|
84
51
|
}
|
package/README.md
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# githublogen
|
|
2
|
-
|
|
3
|
-
Generate changelog for GitHub releases from [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), powered by [changelogithub](https://github.com/antfu/changelogithub).
|
|
4
|
-
|
|
5
|
-
Auto Generate CHANGELOG.md from [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), powered by [changelogen](https://github.com/unjs/changelogen).
|
|
6
|
-
|
|
7
|
-
## Usage
|
|
8
|
-
|
|
9
|
-
In GitHub Actions:
|
|
10
|
-
|
|
11
|
-
```yml
|
|
12
|
-
# .github/workflows/release.yml
|
|
13
|
-
|
|
14
|
-
name: Release
|
|
15
|
-
|
|
16
|
-
permissions:
|
|
17
|
-
contents: write
|
|
18
|
-
|
|
19
|
-
on:
|
|
20
|
-
push:
|
|
21
|
-
tags:
|
|
22
|
-
- "v*"
|
|
23
|
-
|
|
24
|
-
jobs:
|
|
25
|
-
release:
|
|
26
|
-
runs-on: ubuntu-latest
|
|
27
|
-
steps:
|
|
28
|
-
- uses: actions/checkout@v3
|
|
29
|
-
with:
|
|
30
|
-
fetch-depth: 0
|
|
31
|
-
|
|
32
|
-
- uses: actions/setup-node@v3
|
|
33
|
-
with:
|
|
34
|
-
node-version: 16.x
|
|
35
|
-
|
|
36
|
-
- run: npx githublogen
|
|
37
|
-
env:
|
|
38
|
-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
It will be trigged whenever you push a tag to GitHub that starts with `v`.
|
|
42
|
-
|
|
43
|
-
## Configuration
|
|
44
|
-
|
|
45
|
-
You can put a configuration file in the project root, named as `githublogen.config.{json,ts,js,mjs,cjs}`, `.githublogenrc` or use the `githublogen` field in `package.json`.
|
|
46
|
-
|
|
47
|
-
## Preview Locally
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
npx githublogen --dry
|
|
51
|
-
```
|