Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9586a567de | |||
| 6c663cf7fc | |||
| 535a62857c | |||
| 03f68e2912 | |||
| 71925553c1 | |||
| 53bb1437a0 | |||
| 92f8126abf | |||
| 5080d71fb8 | |||
| 56ad837b82 | |||
| 003c943a74 | |||
| 77dfc9a73b | |||
| 8ab631549a | |||
| 2670f79e2f | |||
| 3afc2ed071 | |||
| 45458d14e2 | |||
| f3c55fac30 | |||
| 755da3bb57 | |||
| 9311be80b2 | |||
| d61c9ecf2e | |||
| 8816db86fe | |||
|
c69db8f4b9
|
|||
|
46a52ddebb
|
|||
| 37a1d0b25c | |||
| 2ac0307c87 | |||
| 66db269317 | |||
| d3cf78aacb | |||
| 605055eb76 | |||
| e4ba7dab53 | |||
| 85649a71a6 | |||
| d30071e3d7 | |||
| 06f349c75a | |||
| 7a5880d211 | |||
| b05591a316 | |||
| 8e51587260 |
9
.rczrc.json
Normal file
9
.rczrc.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"scopes": [
|
||||||
|
"commands",
|
||||||
|
"changelog",
|
||||||
|
"readme",
|
||||||
|
"release",
|
||||||
|
"config"
|
||||||
|
]
|
||||||
|
}
|
||||||
87
CHANGELOG.md
Normal file
87
CHANGELOG.md
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
Generation of this changelog is based on commits
|
||||||
|
|
||||||
|
## v1.5.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [92f8126ab] - **commands**: add --amend option to commit sub-command
|
||||||
|
- [5080d71fb] - **config**: allow more config file names
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- [53bb1437a] - **commands**: allow chore type (#7)
|
||||||
|
|
||||||
|
## v1.4.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [8ab631549] - **commands**: add the ability to return code only for validation command
|
||||||
|
|
||||||
|
## v1.3.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [755da3bb5] - **commands**: add ability to write a footer
|
||||||
|
- [9311be80b] - **commands**: add commit message validation command (#4)
|
||||||
|
|
||||||
|
## v1.2.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [46a52ddeb] - **commands**: add the ability to sign conventional commits (#2)
|
||||||
|
|
||||||
|
## v1.1.3
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- [d3cf78aac] - **commands**: incorrect formatting of changelog hashes
|
||||||
|
|
||||||
|
## v1.1.2
|
||||||
|
|
||||||
|
### Miscellaneous
|
||||||
|
|
||||||
|
- [85649a71a] - **commands**: change changelog output text
|
||||||
|
|
||||||
|
## v1.1.1
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- [7a5880d21] - **commands**: incorrect changelog version generation
|
||||||
|
|
||||||
|
## v1.1.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [8e5158726] - **commands**: add release and changelog commands
|
||||||
|
|
||||||
|
### Miscellaneous
|
||||||
|
|
||||||
|
- [b05591a31] - **release**: v1.1.0
|
||||||
|
|
||||||
|
## v1.0.0
|
||||||
|
|
||||||
|
### Breaking
|
||||||
|
|
||||||
|
- [7ef777bb2] - use commander for command management
|
||||||
|
|
||||||
|
### Miscellaneous
|
||||||
|
|
||||||
|
- [b07d9aaaa] - change question formatting, improve readme
|
||||||
|
|
||||||
|
## v1.0.0-alpha.1
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [b5ca3152c] - add support for body (#1)
|
||||||
|
- [ce0c01347] - initial commit
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- [2be2887ce] - make commit body wrap properly
|
||||||
|
- [e9d3c5e29] - incorrect config parsing
|
||||||
|
|
||||||
|
### Miscellaneous
|
||||||
|
|
||||||
|
- [4e16104d6] - change intro and outro messages
|
||||||
@@ -17,12 +17,13 @@ Resultium commit standardization library
|
|||||||
|
|
||||||
1. Make changes to your git initialized project
|
1. Make changes to your git initialized project
|
||||||
2. Run `rcz commit` in the root directory
|
2. Run `rcz commit` in the root directory
|
||||||
|
- if you wish to sign your commit use `--sign` option
|
||||||
3. Answer all the questions
|
3. Answer all the questions
|
||||||
4. Push to remote
|
4. Push to remote
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
You can create an `.rczrc` file in your root directory and specify available scopes and commit types
|
You can create an `.rczrc`, `.rczrc.json` or `rcz.config.json` file in your root directory and specify available scopes and commit types
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
"dictionaryDefinitions": [],
|
"dictionaryDefinitions": [],
|
||||||
"dictionaries": [],
|
"dictionaries": [],
|
||||||
"words": [
|
"words": [
|
||||||
|
"Acked",
|
||||||
|
"johndoe",
|
||||||
"outro",
|
"outro",
|
||||||
"rczrc"
|
"rczrc"
|
||||||
],
|
],
|
||||||
|
|||||||
72
package.json
72
package.json
@@ -1,37 +1,39 @@
|
|||||||
{
|
{
|
||||||
"name": "@resultium/rcz",
|
"name": "@resultium/rcz",
|
||||||
"version": "1.0.0",
|
"version": "1.5.1",
|
||||||
"description": "Resultium commit standardization library, based on conventional commits",
|
"description": "Resultium commit standardization library, based on conventional commits",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"rcz": "./dist/index.js"
|
"rcz": "./dist/index.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.resultium.net/technology/rcz.git"
|
"url": "https://git.resultium.net/technology/rcz.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"conventional",
|
"conventional",
|
||||||
"commits"
|
"commits"
|
||||||
],
|
],
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Resultium",
|
"name": "Resultium",
|
||||||
"email": "contact@resultium.io",
|
"email": "contact@resultium.io",
|
||||||
"url": "https://www.resultium.io"
|
"url": "https://www.resultium.io"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@clack/prompts": "^0.7.0",
|
"@clack/prompts": "^0.7.0",
|
||||||
"commander": "^11.0.0",
|
"commander": "^11.0.0",
|
||||||
"simple-git": "^3.19.1"
|
"semver": "^7.5.4",
|
||||||
},
|
"simple-git": "^3.19.1"
|
||||||
"devDependencies": {
|
},
|
||||||
"@types/node": "^20.5.1",
|
"devDependencies": {
|
||||||
"typescript": "^5.1.6"
|
"@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:
|
commander:
|
||||||
specifier: ^11.0.0
|
specifier: ^11.0.0
|
||||||
version: 11.0.0
|
version: 11.0.0
|
||||||
|
semver:
|
||||||
|
specifier: ^7.5.4
|
||||||
|
version: 7.5.4
|
||||||
simple-git:
|
simple-git:
|
||||||
specifier: ^3.19.1
|
specifier: ^3.19.1
|
||||||
version: 3.19.1
|
version: 3.19.1
|
||||||
@@ -19,6 +22,9 @@ devDependencies:
|
|||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^20.5.1
|
specifier: ^20.5.1
|
||||||
version: 20.5.1
|
version: 20.5.1
|
||||||
|
'@types/semver':
|
||||||
|
specifier: ^7.5.0
|
||||||
|
version: 7.5.0
|
||||||
typescript:
|
typescript:
|
||||||
specifier: ^5.1.6
|
specifier: ^5.1.6
|
||||||
version: 5.1.6
|
version: 5.1.6
|
||||||
@@ -58,6 +64,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==}
|
resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/@types/semver@7.5.0:
|
||||||
|
resolution: {integrity: sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/commander@11.0.0:
|
/commander@11.0.0:
|
||||||
resolution: {integrity: sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==}
|
resolution: {integrity: sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==}
|
||||||
engines: {node: '>=16'}
|
engines: {node: '>=16'}
|
||||||
@@ -75,6 +85,13 @@ packages:
|
|||||||
ms: 2.1.2
|
ms: 2.1.2
|
||||||
dev: false
|
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:
|
/ms@2.1.2:
|
||||||
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
||||||
dev: false
|
dev: false
|
||||||
@@ -83,6 +100,14 @@ packages:
|
|||||||
resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==}
|
resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==}
|
||||||
dev: false
|
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:
|
/simple-git@3.19.1:
|
||||||
resolution: {integrity: sha512-Ck+rcjVaE1HotraRAS8u/+xgTvToTuoMkT9/l9lvuP5jftwnYUp6DwuJzsKErHgfyRk8IB8pqGHWEbM3tLgV1w==}
|
resolution: {integrity: sha512-Ck+rcjVaE1HotraRAS8u/+xgTvToTuoMkT9/l9lvuP5jftwnYUp6DwuJzsKErHgfyRk8IB8pqGHWEbM3tLgV1w==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -102,3 +127,7 @@ packages:
|
|||||||
engines: {node: '>=14.17'}
|
engines: {node: '>=14.17'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/yallist@4.0.0:
|
||||||
|
resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}
|
||||||
|
dev: false
|
||||||
|
|||||||
321
src/index.ts
321
src/index.ts
@@ -12,9 +12,10 @@ import {
|
|||||||
} from "@clack/prompts";
|
} from "@clack/prompts";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { Config } from "./types";
|
import { CommitStack, Config } from "./types";
|
||||||
import simpleGit from "simple-git";
|
import simpleGit from "simple-git";
|
||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
|
import semver from "semver";
|
||||||
|
|
||||||
const GetConfig = async () => {
|
const GetConfig = async () => {
|
||||||
if (fs.existsSync(path.join(process.cwd(), ".rczrc"))) {
|
if (fs.existsSync(path.join(process.cwd(), ".rczrc"))) {
|
||||||
@@ -23,6 +24,18 @@ const GetConfig = async () => {
|
|||||||
await fs.promises.readFile(path.join(process.cwd(), ".rczrc"))
|
await fs.promises.readFile(path.join(process.cwd(), ".rczrc"))
|
||||||
).toString()
|
).toString()
|
||||||
) as Config;
|
) as Config;
|
||||||
|
} else if (fs.existsSync(path.join(process.cwd(), ".rczrc.json"))) {
|
||||||
|
return JSON.parse(
|
||||||
|
(
|
||||||
|
await fs.promises.readFile(path.join(process.cwd(), ".rczrc.json"))
|
||||||
|
).toString()
|
||||||
|
) as Config;
|
||||||
|
} else if (fs.existsSync(path.join(process.cwd(), "rcz.config.json"))) {
|
||||||
|
return JSON.parse(
|
||||||
|
(
|
||||||
|
await fs.promises.readFile(path.join(process.cwd(), "rcz.config.json"))
|
||||||
|
).toString()
|
||||||
|
) as Config;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -32,12 +45,17 @@ const program = new Command();
|
|||||||
program
|
program
|
||||||
.name("rcz")
|
.name("rcz")
|
||||||
.description("Resultium commit standardization command-line interface")
|
.description("Resultium commit standardization command-line interface")
|
||||||
.version("1.0.0");
|
.version("1.4.0");
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("commit")
|
.command("commit")
|
||||||
.description("Create a conventional commit")
|
.description("Create a conventional commit")
|
||||||
.action(async () => {
|
.option("-S, --sign", "sign the commit")
|
||||||
|
.option("--amend", "amend commit message to the last commit")
|
||||||
|
.action(async (options) => {
|
||||||
|
const sign = options.sign ? true : false;
|
||||||
|
const amend = options.amend ? true : false;
|
||||||
|
|
||||||
const config = await GetConfig();
|
const config = await GetConfig();
|
||||||
|
|
||||||
intro("Creating a conventional commit");
|
intro("Creating a conventional commit");
|
||||||
@@ -47,10 +65,12 @@ program
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const stageAll = await confirm({
|
const stageAll = amend
|
||||||
message: "Stage all changes?",
|
? null
|
||||||
initialValue: true,
|
: await confirm({
|
||||||
});
|
message: "Stage all changes?",
|
||||||
|
initialValue: true,
|
||||||
|
});
|
||||||
|
|
||||||
if (isCancel(stageAll)) {
|
if (isCancel(stageAll)) {
|
||||||
cancel("Commit creation cancelled");
|
cancel("Commit creation cancelled");
|
||||||
@@ -95,6 +115,11 @@ program
|
|||||||
value: "refactor",
|
value: "refactor",
|
||||||
hint: "code change that neither fixes a bug nor adds a feature",
|
hint: "code change that neither fixes a bug nor adds a feature",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "chore",
|
||||||
|
value: "chore",
|
||||||
|
hint: "changes that are routinely, e.g. dependency update or a release commit",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -141,6 +166,15 @@ program
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const footer = await text({
|
||||||
|
message: `Insert commit footer, can be left empty, e.g. Acked-by: @johndoe`,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isCancel(footer)) {
|
||||||
|
cancel("Commit creation cancelled");
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const isBreaking = await confirm({
|
const isBreaking = await confirm({
|
||||||
message: "Does this commit have breaking changes?",
|
message: "Does this commit have breaking changes?",
|
||||||
initialValue: false,
|
initialValue: false,
|
||||||
@@ -174,17 +208,282 @@ program
|
|||||||
scope ? `(${scope.toString()})` : ``
|
scope ? `(${scope.toString()})` : ``
|
||||||
}${isBreaking ? "!" : ""}: ${message.toString()}${
|
}${isBreaking ? "!" : ""}: ${message.toString()}${
|
||||||
resolvesIssue ? ` (${issue?.toString()})` : ``
|
resolvesIssue ? ` (${issue?.toString()})` : ``
|
||||||
}${body ? `\n\n${body}` : ``}`;
|
}${body ? `\n\n${body}` : ``}${footer ? `\n\n${footer}` : ``}`;
|
||||||
|
|
||||||
if (stageAll) {
|
if (stageAll) {
|
||||||
await simpleGit().add(".").commit(commitMessage);
|
await simpleGit()
|
||||||
|
.add(".")
|
||||||
|
.commit(
|
||||||
|
commitMessage,
|
||||||
|
sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : []
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await simpleGit().commit(commitMessage);
|
await simpleGit().commit(
|
||||||
|
commitMessage,
|
||||||
|
sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : []
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
note(commitMessage);
|
note(commitMessage);
|
||||||
|
|
||||||
outro("Finished creating a conventional commit, feel free to push");
|
outro(
|
||||||
|
`Finished ${
|
||||||
|
amend ? "amending" : "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");
|
||||||
|
console.log("Generation of this changelog is based on commits");
|
||||||
|
|
||||||
|
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")
|
||||||
|
.option("-S, --sign", "sign the release commit and tag")
|
||||||
|
.action(async (string: string, options) => {
|
||||||
|
const sign = options.sign ? true : false;
|
||||||
|
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}`, sign ? ["-S"] : [])
|
||||||
|
.tag(
|
||||||
|
sign
|
||||||
|
? [`-s`, `v${version}`, `-m`, `"Version ${version}"`]
|
||||||
|
: [`-a`, `v${version}`, `-m`, `"Version ${version}"`]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
program
|
||||||
|
.command("validate")
|
||||||
|
.description("Validate whether a string fits given commit conventions")
|
||||||
|
.argument("[message]", "string for validation")
|
||||||
|
.option("-C, --code-only", "return code only")
|
||||||
|
.action(async (string: string, options) => {
|
||||||
|
try {
|
||||||
|
const message = string || fs.readFileSync(0, "utf-8");
|
||||||
|
const codeOnly = options.codeOnly ? true : false;
|
||||||
|
|
||||||
|
const config = await GetConfig();
|
||||||
|
|
||||||
|
// Regex for testing:
|
||||||
|
// /(build|feat|docs)(\((commands|changelog)\))?!?: .* ?(\(..*\))?((\n\n..*)?(\n\n..*)?)?/gm
|
||||||
|
|
||||||
|
const testRegex = new RegExp(
|
||||||
|
`(${
|
||||||
|
config?.types?.map((type) => type.value).join("|") ||
|
||||||
|
"feat|fix|build|ci|docs|perf|refactor|chore"
|
||||||
|
})(\\((${
|
||||||
|
config?.scopes ? [...config?.scopes, "release"] : "..*"
|
||||||
|
})\\))?!?: .* ?(\\(..*\\))?((\n\n..*)?(\n\n..*)?)?`,
|
||||||
|
"gm"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (codeOnly) {
|
||||||
|
console.log(testRegex.test(message) ? 0 : 1);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
testRegex.test(message)
|
||||||
|
? "[rcz]: valid message"
|
||||||
|
: "[rcz]: invalid message"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[rcz]: no stdin found");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
program.parse();
|
program.parse();
|
||||||
|
|||||||
10
src/types.ts
10
src/types.ts
@@ -1,3 +1,5 @@
|
|||||||
|
import { DefaultLogFields, ListLogLine } from "simple-git";
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
types?: Array<Type>;
|
types?: Array<Type>;
|
||||||
scopes?: Array<string>;
|
scopes?: Array<string>;
|
||||||
@@ -8,3 +10,11 @@ export interface Type {
|
|||||||
value: string;
|
value: string;
|
||||||
hint: 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