githublogen 0.3.25 → 0.4.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/README.md +1 -1
- package/dist/cli.mjs +103 -0
- package/package.json +11 -10
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -1237
- package/dist/prompt-X7YDA36E.js +0 -756
package/README.md
CHANGED
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { getChangelogMarkdown } from "@soybeanjs/changelog";
|
|
4
|
+
import cac from "cac";
|
|
5
|
+
import { consola } from "consola";
|
|
6
|
+
import { blue, bold, cyan, dim, green, red, yellow } from "kolorist";
|
|
7
|
+
import { ofetch } from "ofetch";
|
|
8
|
+
|
|
9
|
+
//#region package.json
|
|
10
|
+
var version = "0.4.0";
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/github.ts
|
|
14
|
+
function getHeaders(githubToken) {
|
|
15
|
+
return {
|
|
16
|
+
accept: "application/vnd.github.v3+json",
|
|
17
|
+
authorization: `token ${githubToken}`
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async function hasTagOnGitHub(tag, repo, githubToken) {
|
|
21
|
+
try {
|
|
22
|
+
await ofetch(`https://api.github.com/repos/${repo}/git/ref/tags/${tag}`, { headers: getHeaders(githubToken) });
|
|
23
|
+
return true;
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function sendRelease(options, content) {
|
|
29
|
+
const headers = getHeaders(options.github.token);
|
|
30
|
+
const github = options.github.repo;
|
|
31
|
+
let url = `https://api.github.com/repos/${github}/releases`;
|
|
32
|
+
let method = "POST";
|
|
33
|
+
try {
|
|
34
|
+
const exists = await ofetch(`https://api.github.com/repos/${github}/releases/tags/${options.to}`, { headers });
|
|
35
|
+
if (exists.url) {
|
|
36
|
+
url = exists.url;
|
|
37
|
+
method = "PATCH";
|
|
38
|
+
}
|
|
39
|
+
} catch {}
|
|
40
|
+
const body = {
|
|
41
|
+
body: content,
|
|
42
|
+
draft: false,
|
|
43
|
+
name: options.to,
|
|
44
|
+
prerelease: options.prerelease,
|
|
45
|
+
tag_name: options.to
|
|
46
|
+
};
|
|
47
|
+
const webUrl = `https://github.com/${github}/releases/new?title=${encodeURIComponent(String(body.name))}&body=${encodeURIComponent(String(body.body))}&tag=${encodeURIComponent(String(options.to))}&prerelease=${options.prerelease}`;
|
|
48
|
+
try {
|
|
49
|
+
consola.log(cyan(method === "POST" ? "Creating release notes..." : "Updating release notes..."));
|
|
50
|
+
const res = await ofetch(url, {
|
|
51
|
+
method,
|
|
52
|
+
body: JSON.stringify(body),
|
|
53
|
+
headers
|
|
54
|
+
});
|
|
55
|
+
consola.log(green(`Released on ${res.html_url}`));
|
|
56
|
+
} catch (e) {
|
|
57
|
+
consola.error(red("Failed to create the release. Using the following link to create it manually:"));
|
|
58
|
+
consola.error(yellow(webUrl));
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function execCommand(cmd, args) {
|
|
63
|
+
const { execa } = await import("execa");
|
|
64
|
+
return (await execa(cmd, args)).stdout.trim();
|
|
65
|
+
}
|
|
66
|
+
async function isRepoShallow() {
|
|
67
|
+
return (await execCommand("git", ["rev-parse", "--is-shallow-repository"])).trim() === "true";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/cli.ts
|
|
72
|
+
function setupCli() {
|
|
73
|
+
const cli = cac("githublogen");
|
|
74
|
+
cli.version(version).option("-t, --token <path>", "GitHub Token").help();
|
|
75
|
+
cli.command("").action(async (args) => {
|
|
76
|
+
try {
|
|
77
|
+
const { options, commits, markdown } = await getChangelogMarkdown({
|
|
78
|
+
cwd: process.cwd(),
|
|
79
|
+
...args
|
|
80
|
+
}, false);
|
|
81
|
+
consola.log(cyan(options.from) + dim(" -> ") + blue(options.to) + dim(` (${commits.length} commits)`));
|
|
82
|
+
if (!await hasTagOnGitHub(options.to, options.github.repo, options.github.token)) {
|
|
83
|
+
consola.error(yellow(`Current ref "${bold(options.to)}" is not available as tags on GitHub. Release skipped.`));
|
|
84
|
+
if (process.exitCode) process.exitCode = 1;
|
|
85
|
+
}
|
|
86
|
+
if (!commits.length && await isRepoShallow()) {
|
|
87
|
+
consola.error(yellow("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."));
|
|
88
|
+
if (process.exitCode) process.exitCode = 1;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
await sendRelease(options, markdown);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
consola.error(red(String(e)));
|
|
94
|
+
if (e?.stack) consola.error(dim(e.stack?.split("\n").slice(1).join("\n")));
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
cli.parse();
|
|
99
|
+
}
|
|
100
|
+
setupCli();
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "githublogen",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Soybean",
|
|
7
7
|
"email": "soybeanjs@outlook.com",
|
|
@@ -34,24 +34,25 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
37
|
+
"node": ">=18",
|
|
38
38
|
"pnpm": ">=9"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"c12": "3.
|
|
41
|
+
"c12": "3.3.3",
|
|
42
42
|
"cac": "6.7.14",
|
|
43
|
-
"execa": "9.6.
|
|
43
|
+
"execa": "9.6.1",
|
|
44
44
|
"kolorist": "1.8.0",
|
|
45
|
-
"ofetch": "1.
|
|
46
|
-
"@soybeanjs/changelog": "0.
|
|
45
|
+
"ofetch": "1.5.1",
|
|
46
|
+
"@soybeanjs/changelog": "0.4.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@soybeanjs/cli": "1.
|
|
50
|
-
"@types/node": "
|
|
51
|
-
"
|
|
49
|
+
"@soybeanjs/cli": "1.4.1",
|
|
50
|
+
"@types/node": "25.0.3",
|
|
51
|
+
"tsdown": "0.18.2",
|
|
52
|
+
"typescript": "5.9.3"
|
|
52
53
|
},
|
|
53
54
|
"scripts": {
|
|
54
|
-
"build": "
|
|
55
|
+
"build": "tsdown",
|
|
55
56
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
56
57
|
}
|
|
57
58
|
}
|
package/dist/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|