@kors/generate-changelog 0.1.11 → 0.2.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/distribution/cli.js +36 -2
- package/distribution/lib/fetchGitHubCommits.d.ts +1 -0
- package/distribution/lib/fetchGitHubCommits.js +13 -0
- package/distribution/lib/getLocalCommits.d.ts +1 -0
- package/distribution/lib/getLocalCommits.js +6 -0
- package/distribution/lib/index.d.ts +3 -1
- package/distribution/lib/index.js +12 -6
- package/package.json +13 -3
package/distribution/cli.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { generateChangelog } from "./lib/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import meow from 'meow';
|
|
4
|
+
const cli = meow(`
|
|
5
|
+
Usage
|
|
6
|
+
$ generate-changelog <input>
|
|
7
|
+
|
|
8
|
+
Options
|
|
9
|
+
--write, -w Write output to changelog.json
|
|
10
|
+
--owner, -o Fetch commits from github owner (used with --repo)
|
|
11
|
+
--repo, -r Fetch commit from github repo (used with --owner)
|
|
12
|
+
--version Print current version
|
|
13
|
+
--help Print help message
|
|
14
|
+
|
|
15
|
+
Examples:
|
|
16
|
+
Generate from local repo:
|
|
17
|
+
$ generate-changelog --write
|
|
18
|
+
|
|
19
|
+
Generate from remote repo:
|
|
20
|
+
$ generate-changelog --owner="StefKors" --repo="generate-changelog"
|
|
21
|
+
`, {
|
|
22
|
+
importMeta: import.meta,
|
|
23
|
+
flags: {
|
|
24
|
+
write: {
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
shortFlag: 'w'
|
|
27
|
+
},
|
|
28
|
+
owner: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
shortFlag: 'o'
|
|
31
|
+
},
|
|
32
|
+
repo: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
shortFlag: 'r'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
generateChangelog(cli.flags);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fetchGitHubCommits: (owner: string, repo: string) => Promise<string[]>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Octokit } from 'octokit';
|
|
2
|
+
export const fetchGitHubCommits = async (owner, repo) => {
|
|
3
|
+
const octokit = new Octokit({});
|
|
4
|
+
const data = await octokit.paginate('GET /repos/{owner}/{repo}/commits', {
|
|
5
|
+
owner: owner,
|
|
6
|
+
repo: repo,
|
|
7
|
+
per_page: 100,
|
|
8
|
+
});
|
|
9
|
+
return data?.map((item) => {
|
|
10
|
+
// add short sha and commit message together
|
|
11
|
+
return `${item.sha.substring(0, 7)} ${item.commit.message}`;
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getLocalCommits: () => string[];
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
// run with `npx tsx scripts/generate-changelog.ts` or something
|
|
2
|
-
import { execSync } from 'node:child_process';
|
|
3
1
|
import * as fs from 'node:fs';
|
|
4
|
-
|
|
2
|
+
import { getLocalCommits } from './getLocalCommits.js';
|
|
3
|
+
import { fetchGitHubCommits } from './fetchGitHubCommits.js';
|
|
4
|
+
const generateChangelog = async ({ write, owner, repo }) => {
|
|
5
5
|
try {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
let lines = [];
|
|
7
|
+
if (repo && owner) {
|
|
8
|
+
console.log("fetching from remote", owner, repo);
|
|
9
|
+
lines = await fetchGitHubCommits(owner, repo);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
console.log("reading local commits");
|
|
13
|
+
lines = getLocalCommits();
|
|
14
|
+
}
|
|
9
15
|
// Initialize changelog object
|
|
10
16
|
const changelog = {
|
|
11
17
|
releases: {},
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kors/generate-changelog",
|
|
3
3
|
"description": "Generate a changelog json from a git commit history",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"generate-changelog": "./distribution/cli.js"
|
|
@@ -16,7 +16,13 @@
|
|
|
16
16
|
"email": "stef.kors+npmpackage@gmail.com",
|
|
17
17
|
"url": "https://github.com/StefKors"
|
|
18
18
|
},
|
|
19
|
-
"repository":
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/StefKors/generate-changelog.git"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"registry": "https://registry.npmjs.org"
|
|
25
|
+
},
|
|
20
26
|
"files": [
|
|
21
27
|
"distribution"
|
|
22
28
|
],
|
|
@@ -57,5 +63,9 @@
|
|
|
57
63
|
"command-line tool",
|
|
58
64
|
"open source",
|
|
59
65
|
"developer tools"
|
|
60
|
-
]
|
|
66
|
+
],
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"meow": "^13.2.0",
|
|
69
|
+
"octokit": "^4.0.2"
|
|
70
|
+
}
|
|
61
71
|
}
|