Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 06f349c75a | |||
| 7a5880d211 | |||
| b05591a316 | |||
| 8e51587260 |
74
package.json
74
package.json
@@ -1,37 +1,39 @@
|
||||
{
|
||||
"name": "@resultium/rcz",
|
||||
"version": "1.0.0",
|
||||
"description": "Resultium commit standardization library, based on conventional commits",
|
||||
"main": "./dist/index.js",
|
||||
"bin": {
|
||||
"rcz": "./dist/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.resultium.net/technology/rcz.git"
|
||||
},
|
||||
"keywords": [
|
||||
"conventional",
|
||||
"commits"
|
||||
],
|
||||
"author": {
|
||||
"name": "Resultium",
|
||||
"email": "contact@resultium.io",
|
||||
"url": "https://www.resultium.io"
|
||||
},
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.7.0",
|
||||
"commander": "^11.0.0",
|
||||
"simple-git": "^3.19.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.5.1",
|
||||
"typescript": "^5.1.6"
|
||||
}
|
||||
}
|
||||
"name": "@resultium/rcz",
|
||||
"version": "1.1.1",
|
||||
"description": "Resultium commit standardization library, based on conventional commits",
|
||||
"main": "./dist/index.js",
|
||||
"bin": {
|
||||
"rcz": "./dist/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.resultium.net/technology/rcz.git"
|
||||
},
|
||||
"keywords": [
|
||||
"conventional",
|
||||
"commits"
|
||||
],
|
||||
"author": {
|
||||
"name": "Resultium",
|
||||
"email": "contact@resultium.io",
|
||||
"url": "https://www.resultium.io"
|
||||
},
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.7.0",
|
||||
"commander": "^11.0.0",
|
||||
"semver": "^7.5.4",
|
||||
"simple-git": "^3.19.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.5.1",
|
||||
"@types/semver": "^7.5.0",
|
||||
"typescript": "^5.1.6"
|
||||
}
|
||||
}
|
||||
29
pnpm-lock.yaml
generated
29
pnpm-lock.yaml
generated
@@ -11,6 +11,9 @@ dependencies:
|
||||
commander:
|
||||
specifier: ^11.0.0
|
||||
version: 11.0.0
|
||||
semver:
|
||||
specifier: ^7.5.4
|
||||
version: 7.5.4
|
||||
simple-git:
|
||||
specifier: ^3.19.1
|
||||
version: 3.19.1
|
||||
@@ -19,6 +22,9 @@ devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^20.5.1
|
||||
version: 20.5.1
|
||||
'@types/semver':
|
||||
specifier: ^7.5.0
|
||||
version: 7.5.0
|
||||
typescript:
|
||||
specifier: ^5.1.6
|
||||
version: 5.1.6
|
||||
@@ -58,6 +64,10 @@ packages:
|
||||
resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==}
|
||||
dev: true
|
||||
|
||||
/@types/semver@7.5.0:
|
||||
resolution: {integrity: sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==}
|
||||
dev: true
|
||||
|
||||
/commander@11.0.0:
|
||||
resolution: {integrity: sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==}
|
||||
engines: {node: '>=16'}
|
||||
@@ -75,6 +85,13 @@ packages:
|
||||
ms: 2.1.2
|
||||
dev: false
|
||||
|
||||
/lru-cache@6.0.0:
|
||||
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
yallist: 4.0.0
|
||||
dev: false
|
||||
|
||||
/ms@2.1.2:
|
||||
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
||||
dev: false
|
||||
@@ -83,6 +100,14 @@ packages:
|
||||
resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==}
|
||||
dev: false
|
||||
|
||||
/semver@7.5.4:
|
||||
resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==}
|
||||
engines: {node: '>=10'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
lru-cache: 6.0.0
|
||||
dev: false
|
||||
|
||||
/simple-git@3.19.1:
|
||||
resolution: {integrity: sha512-Ck+rcjVaE1HotraRAS8u/+xgTvToTuoMkT9/l9lvuP5jftwnYUp6DwuJzsKErHgfyRk8IB8pqGHWEbM3tLgV1w==}
|
||||
dependencies:
|
||||
@@ -102,3 +127,7 @@ packages:
|
||||
engines: {node: '>=14.17'}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/yallist@4.0.0:
|
||||
resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}
|
||||
dev: false
|
||||
|
||||
210
src/index.ts
210
src/index.ts
@@ -12,9 +12,10 @@ import {
|
||||
} from "@clack/prompts";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { Config } from "./types";
|
||||
import { CommitStack, Config } from "./types";
|
||||
import simpleGit from "simple-git";
|
||||
import { Command } from "commander";
|
||||
import semver from "semver";
|
||||
|
||||
const GetConfig = async () => {
|
||||
if (fs.existsSync(path.join(process.cwd(), ".rczrc"))) {
|
||||
@@ -187,4 +188,211 @@ program
|
||||
outro("Finished creating a conventional commit, feel free to push");
|
||||
});
|
||||
|
||||
program
|
||||
.command("changelog")
|
||||
.description("Outputs a markdown formatted changelog")
|
||||
.option("--show-hashes", "show first 9 characters of commit hashes")
|
||||
.option("--last-only", "display only latest release changes")
|
||||
.action(async (options) => {
|
||||
const showHashes = options.showHashes ? true : false;
|
||||
const lastOnly = options.lastOnly ? true : false;
|
||||
|
||||
if ((await simpleGit().tags()).all.length === 0) {
|
||||
return console.log(
|
||||
"[rcz]: not even one release has yet been made, cannot make a changelog"
|
||||
);
|
||||
}
|
||||
|
||||
const commits = (await simpleGit().log()).all;
|
||||
let lastTag = "";
|
||||
let parsedCommitStacks: Array<CommitStack> = [];
|
||||
|
||||
console.log("# Changelog");
|
||||
|
||||
for (const commit of commits) {
|
||||
const tag = semver.sort(
|
||||
(await simpleGit().tags([`--contains=${commit.hash}`])).all
|
||||
)[0]!;
|
||||
const currentCommitStack = parsedCommitStacks.find(
|
||||
(commitStack) => commitStack.version === tag
|
||||
) || {
|
||||
version: tag || "",
|
||||
breaking: [],
|
||||
features: [],
|
||||
fixes: [],
|
||||
miscellaneous: [],
|
||||
};
|
||||
|
||||
if (lastTag !== tag) {
|
||||
parsedCommitStacks = [currentCommitStack, ...parsedCommitStacks];
|
||||
}
|
||||
|
||||
if (commit.message.includes("!:")) {
|
||||
parsedCommitStacks = [
|
||||
{
|
||||
...currentCommitStack,
|
||||
breaking: [...currentCommitStack.breaking, commit],
|
||||
},
|
||||
...parsedCommitStacks.filter(
|
||||
(commitStack) => commitStack.version !== tag
|
||||
),
|
||||
];
|
||||
} else if (commit.message.startsWith("feat")) {
|
||||
parsedCommitStacks = [
|
||||
{
|
||||
...currentCommitStack,
|
||||
features: [...currentCommitStack.features, commit],
|
||||
},
|
||||
...parsedCommitStacks.filter(
|
||||
(commitStack) => commitStack.version !== tag
|
||||
),
|
||||
];
|
||||
} else if (commit.message.startsWith("fix")) {
|
||||
parsedCommitStacks = [
|
||||
{
|
||||
...currentCommitStack,
|
||||
fixes: [...currentCommitStack.fixes, commit],
|
||||
},
|
||||
...parsedCommitStacks.filter(
|
||||
(commitStack) => commitStack.version !== tag
|
||||
),
|
||||
];
|
||||
} else {
|
||||
parsedCommitStacks = [
|
||||
{
|
||||
...currentCommitStack,
|
||||
miscellaneous: [...currentCommitStack.miscellaneous, commit],
|
||||
},
|
||||
...parsedCommitStacks.filter(
|
||||
(commitStack) => commitStack.version !== tag
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
lastTag = tag;
|
||||
}
|
||||
|
||||
parsedCommitStacks = parsedCommitStacks.reverse();
|
||||
|
||||
if (lastOnly) {
|
||||
parsedCommitStacks = [parsedCommitStacks[0]];
|
||||
}
|
||||
|
||||
for (const commitStack of parsedCommitStacks) {
|
||||
console.log(`## ${commitStack.version}`);
|
||||
|
||||
if (commitStack.breaking.length > 0) {
|
||||
console.log(`### Breaking`);
|
||||
for (const commit of commitStack.breaking) {
|
||||
const shortHash = commit.hash.slice(0, 9);
|
||||
|
||||
// Selects contents between parenthesis and a semicolon, via https://stackoverflow.com/a/17779833/14544732
|
||||
const type = /\(([^)]+)\):/.exec(commit.message)
|
||||
? /\(([^)]+)\):/.exec(commit.message)![1]
|
||||
: null;
|
||||
const firstMessageLine = commit.message.split("\n");
|
||||
const briefMessage = firstMessageLine[0].includes(":")
|
||||
? firstMessageLine[0].split(":")[1].trim()
|
||||
: firstMessageLine[0];
|
||||
|
||||
console.log(
|
||||
`${showHashes ? `- [${"`"}${shortHash}${"`"}]` : ``} - ${
|
||||
type ? `**${type}**: ${briefMessage}` : briefMessage
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (commitStack.features.length > 0) {
|
||||
console.log(`### Features`);
|
||||
for (const commit of commitStack.features) {
|
||||
const shortHash = commit.hash.slice(0, 9);
|
||||
const type = /\(([^)]+)\):/.exec(commit.message)
|
||||
? /\(([^)]+)\):/.exec(commit.message)![1]
|
||||
: null;
|
||||
const firstMessageLine = commit.message.split("\n");
|
||||
const briefMessage = firstMessageLine[0].includes(":")
|
||||
? firstMessageLine[0].split(":")[1].trim()
|
||||
: firstMessageLine[0];
|
||||
|
||||
console.log(
|
||||
`${showHashes ? `- [${"`"}${shortHash}${"`"}]` : ``} - ${
|
||||
type ? `**${type}**: ${briefMessage}` : briefMessage
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (commitStack.fixes.length > 0) {
|
||||
console.log(`### Fixes`);
|
||||
for (const commit of commitStack.fixes) {
|
||||
const shortHash = commit.hash.slice(0, 9);
|
||||
const type = /\(([^)]+)\):/.exec(commit.message)
|
||||
? /\(([^)]+)\):/.exec(commit.message)![1]
|
||||
: null;
|
||||
const firstMessageLine = commit.message.split("\n");
|
||||
const briefMessage = firstMessageLine[0].includes(":")
|
||||
? firstMessageLine[0].split(":")[1].trim()
|
||||
: firstMessageLine[0];
|
||||
|
||||
console.log(
|
||||
`${showHashes ? `- [${"`"}${shortHash}${"`"}]` : ``} - ${
|
||||
type ? `**${type}**: ${briefMessage}` : briefMessage
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (commitStack.miscellaneous.length > 0) {
|
||||
console.log(`### Miscellaneous`);
|
||||
for (const commit of commitStack.miscellaneous) {
|
||||
const shortHash = commit.hash.slice(0, 9);
|
||||
const type = /\(([^)]+)\):/.exec(commit.message)
|
||||
? /\(([^)]+)\):/.exec(commit.message)![1]
|
||||
: null;
|
||||
const firstMessageLine = commit.message.split("\n");
|
||||
const briefMessage = firstMessageLine[0].includes(":")
|
||||
? firstMessageLine[0].split(":")[1].trim()
|
||||
: firstMessageLine[0];
|
||||
|
||||
console.log(
|
||||
`${showHashes ? `- [${"`"}${shortHash}${"`"}]` : ``} - ${
|
||||
type ? `**${type}**: ${briefMessage}` : briefMessage
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
program
|
||||
.command("release")
|
||||
.description(
|
||||
"Changes package.json version and creates a new commit with a tag"
|
||||
)
|
||||
.argument("<version>", "new version formatted in SemVer")
|
||||
.action(async (string: string) => {
|
||||
const version = string.replace("v", "");
|
||||
const packageFile = JSON.parse(
|
||||
(
|
||||
await fs.promises.readFile(path.join(process.cwd(), "package.json"))
|
||||
).toString()
|
||||
);
|
||||
|
||||
if (!packageFile) {
|
||||
console.log("[rcz]: this directory does not have a package.json file");
|
||||
}
|
||||
|
||||
packageFile.version = version;
|
||||
await fs.promises.writeFile(
|
||||
path.join(process.cwd(), "package.json"),
|
||||
JSON.stringify(packageFile, null, 4)
|
||||
);
|
||||
|
||||
await simpleGit()
|
||||
.add(".")
|
||||
.commit(`chore(release): v${version}`)
|
||||
.addTag(`v${version}`);
|
||||
});
|
||||
|
||||
program.parse();
|
||||
|
||||
10
src/types.ts
10
src/types.ts
@@ -1,3 +1,5 @@
|
||||
import { DefaultLogFields, ListLogLine } from "simple-git";
|
||||
|
||||
export interface Config {
|
||||
types?: Array<Type>;
|
||||
scopes?: Array<string>;
|
||||
@@ -8,3 +10,11 @@ export interface Type {
|
||||
value: string;
|
||||
hint: string;
|
||||
}
|
||||
|
||||
export interface CommitStack {
|
||||
version: string;
|
||||
breaking: Array<DefaultLogFields & ListLogLine>;
|
||||
features: Array<DefaultLogFields & ListLogLine>;
|
||||
fixes: Array<DefaultLogFields & ListLogLine>;
|
||||
miscellaneous: Array<DefaultLogFields & ListLogLine>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user