@kors/generate-changelog 0.1.11 → 0.2.1

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.
@@ -1,4 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
  import { generateChangelog } from "./lib/index.js";
3
- const write = process.argv[2];
4
- console.log(generateChangelog({ write: write ? true : false }));
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[];
@@ -0,0 +1,6 @@
1
+ import { execSync } from 'node:child_process';
2
+ export const getLocalCommits = () => {
3
+ // Get git log output
4
+ const gitLog = execSync('git log --oneline --no-color').toString();
5
+ return gitLog.split('\n');
6
+ };
@@ -1,5 +1,7 @@
1
1
  export interface Options {
2
2
  write?: boolean;
3
+ repo?: string;
4
+ owner?: string;
3
5
  }
4
- declare const generateChangelog: ({ write }: Options) => {};
6
+ declare const generateChangelog: ({ write, owner, repo }: Options) => Promise<{}>;
5
7
  export { generateChangelog };
@@ -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
- const generateChangelog = ({ write }) => {
2
+ import { getLocalCommits } from './getLocalCommits.js';
3
+ import { fetchGitHubCommits } from './fetchGitHubCommits.js';
4
+ const generateChangelog = async ({ write, owner, repo }) => {
5
5
  try {
6
- // Get git log output
7
- const gitLog = execSync('git log --oneline --no-color').toString();
8
- const lines = gitLog.split('\n');
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,11 +1,12 @@
1
1
  {
2
2
  "name": "@kors/generate-changelog",
3
3
  "description": "Generate a changelog json from a git commit history",
4
- "version": "0.1.11",
4
+ "version": "0.2.1",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "generate-changelog": "./distribution/cli.js"
8
8
  },
9
+ "main": "./distribution/index.js",
9
10
  "scripts": {
10
11
  "dev": "vite",
11
12
  "build": "tsc",
@@ -16,7 +17,13 @@
16
17
  "email": "stef.kors+npmpackage@gmail.com",
17
18
  "url": "https://github.com/StefKors"
18
19
  },
19
- "repository": "https://github.com/StefKors/generate-changelog",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/StefKors/generate-changelog.git"
23
+ },
24
+ "publishConfig": {
25
+ "registry": "https://registry.npmjs.org"
26
+ },
20
27
  "files": [
21
28
  "distribution"
22
29
  ],
@@ -57,5 +64,9 @@
57
64
  "command-line tool",
58
65
  "open source",
59
66
  "developer tools"
60
- ]
67
+ ],
68
+ "dependencies": {
69
+ "meow": "^13.2.0",
70
+ "octokit": "^4.0.2"
71
+ }
61
72
  }