Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d1099c1e69 | |||
| f4a7a0d2bc | |||
| c80d763259 | |||
| 498c830e34 | |||
| f51bb88de4 | |||
| a5626dbc54 | |||
| 4c892e8b11 | |||
| 63a6c9feab | |||
| 8cb67f2cfd | |||
| 8dbe266e39 | |||
| 58f4dde9c9 | |||
| 9586a567de | |||
| 6c663cf7fc | |||
| 535a62857c | |||
| 03f68e2912 | |||
| 71925553c1 | |||
| 53bb1437a0 | |||
| 92f8126abf | |||
| 5080d71fb8 | |||
| 56ad837b82 | |||
| 003c943a74 | |||
| 77dfc9a73b | |||
| 8ab631549a | |||
| 2670f79e2f | |||
| 3afc2ed071 | |||
| 45458d14e2 | |||
| f3c55fac30 | |||
| 755da3bb57 | |||
| 9311be80b2 | |||
| d61c9ecf2e | |||
| 8816db86fe | |||
|
c69db8f4b9
|
|||
|
46a52ddebb
|
|||
| 37a1d0b25c | |||
| 2ac0307c87 |
3
.rczrc.json
Normal file
3
.rczrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"scopes": ["commands", "changelog", "readme", "release", "config"]
|
||||
}
|
||||
17
.rczrc.onrelease.js
Normal file
17
.rczrc.onrelease.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const fs = require("fs");
|
||||
|
||||
const packageFile = fs.readFileSync("./package.json").toString();
|
||||
const newPackageFile = packageFile.replace(
|
||||
/"version": "[0-9]+.[0-9]+.[0-9]+"/,
|
||||
`"version": "${__NEW_VERSION__}"`
|
||||
);
|
||||
|
||||
fs.writeFileSync("./package.json", newPackageFile);
|
||||
|
||||
const indexFile = fs.readFileSync("./src/index.ts").toString();
|
||||
const newIndexFile = indexFile.replace(
|
||||
/version\("[0-9]+\.[0-9]+\.[0-9]+"\)/,
|
||||
`version("${__NEW_VERSION__}")`
|
||||
);
|
||||
|
||||
fs.writeFileSync("./src/index.ts", newIndexFile);
|
||||
10
.vscode/settings.json
vendored
Normal file
10
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"Acked",
|
||||
"johndoe",
|
||||
"onrelease",
|
||||
"outro",
|
||||
"rczrc",
|
||||
"Resultium"
|
||||
]
|
||||
}
|
||||
76
CHANGELOG.md
76
CHANGELOG.md
@@ -2,6 +2,72 @@
|
||||
|
||||
Generation of this changelog is based on commits
|
||||
|
||||
## v1.7.0
|
||||
|
||||
### Features
|
||||
|
||||
- [f4a7a0d2b] - **commands**: add release script customizability (#12)
|
||||
- [c80d76325] - **config**: add auto-signing options
|
||||
- [498c830e3] - change tag message schema (#11)
|
||||
|
||||
## v1.6.0
|
||||
|
||||
### Features
|
||||
|
||||
- [a5626dbc5] - improve default 'stage all changes' behavior
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- [4c892e8b1] - **changelog**: generate for v1.5.2
|
||||
|
||||
## v1.5.2
|
||||
|
||||
### Fixes
|
||||
|
||||
- [8cb67f2cf] - **commands**: incorrect regex generation with specified scopes
|
||||
|
||||
## v1.5.1
|
||||
|
||||
### Fixes
|
||||
|
||||
- [6c663cf7f] - **commands**: allow chore type in validation regex
|
||||
|
||||
## 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
|
||||
@@ -18,7 +84,11 @@ Generation of this changelog is based on commits
|
||||
|
||||
### Features
|
||||
|
||||
- [`8e5158726`] - **commands**: add release and changelog commands
|
||||
- [8e5158726] - **commands**: add release and changelog commands
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- [b05591a31] - **release**: v1.1.0
|
||||
|
||||
## v1.0.0
|
||||
|
||||
@@ -34,8 +104,8 @@ Generation of this changelog is based on commits
|
||||
|
||||
### Features
|
||||
|
||||
- [`b5ca3152c`] - add support for body (#1)
|
||||
- [`ce0c01347`] - initial commit
|
||||
- [b5ca3152c] - add support for body (#1)
|
||||
- [ce0c01347] - initial commit
|
||||
|
||||
### Fixes
|
||||
|
||||
|
||||
30
README.md
30
README.md
@@ -17,12 +17,13 @@ Resultium commit standardization library
|
||||
|
||||
1. Make changes to your git initialized project
|
||||
2. Run `rcz commit` in the root directory
|
||||
- if you wish to sign your commit use `--sign` option
|
||||
3. Answer all the questions
|
||||
4. Push to remote
|
||||
|
||||
## 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
|
||||
{
|
||||
@@ -33,6 +34,31 @@ You can create an `.rczrc` file in your root directory and specify available sco
|
||||
"value": "chore",
|
||||
"hint": "a routine action"
|
||||
}
|
||||
]
|
||||
],
|
||||
"autoSignCommits": false,
|
||||
"autoSignReleases": true
|
||||
}
|
||||
```
|
||||
|
||||
You are also able to create an onRelease event file, that is going to run before creation of a git tag and a release commit, when `rcz release` is run. The file is to be named `.rczrc.onrelease.js`. A sample can be seen below.
|
||||
|
||||
```js
|
||||
const fs = require("fs"); // Require fileSystem
|
||||
|
||||
const packageFile = fs.readFileSync("./package.json").toString(); // Get package.json contents from the current working directory
|
||||
const newPackageFile = packageFile.replace(
|
||||
/"version": "[0-9]+.[0-9]+.[0-9]+"/,
|
||||
`"version": "${__NEW_VERSION__}"`
|
||||
); // Use RegExp to replace package.json version
|
||||
|
||||
fs.writeFileSync("./package.json", newPackageFile); // Write to package.json file its new content
|
||||
|
||||
const indexFile = fs.readFileSync("./src/index.ts").toString(); // Get index.ts file from source code directory
|
||||
const newIndexFile = indexFile.replace(/version\("[0-9]+\.[0-9]+\.[0-9]+"\)/); // Replace class function call content with the new version
|
||||
|
||||
fs.writeFileSync("./src/index.ts", newIndexFile); // Write to source code index file
|
||||
```
|
||||
|
||||
In your onRelease file you are provided with `__NEW_VERSION__` constant string which is the new version submitted in `rcz release` and `__IS_SIGNED__` constant which is a boolean telling whether the release (it's commit and tag) is going to be signed.
|
||||
|
||||
Bear in mind, **this script is going to be executed through `eval()` with no sanitation**, be careful with whatever you write.
|
||||
|
||||
12
cspell.json
12
cspell.json
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": "0.2",
|
||||
"ignorePaths": [],
|
||||
"dictionaryDefinitions": [],
|
||||
"dictionaries": [],
|
||||
"words": [
|
||||
"outro",
|
||||
"rczrc"
|
||||
],
|
||||
"ignoreWords": [],
|
||||
"import": []
|
||||
}
|
||||
76
package.json
76
package.json
@@ -1,39 +1,39 @@
|
||||
{
|
||||
"name": "@resultium/rcz",
|
||||
"version": "1.1.3",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
"name": "@resultium/rcz",
|
||||
"version": "1.7.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",
|
||||
"semver": "^7.5.4",
|
||||
"simple-git": "^3.19.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.5.1",
|
||||
"@types/semver": "^7.5.0",
|
||||
"typescript": "^5.1.6"
|
||||
}
|
||||
}
|
||||
|
||||
163
src/index.ts
163
src/index.ts
@@ -24,6 +24,18 @@ const GetConfig = async () => {
|
||||
await fs.promises.readFile(path.join(process.cwd(), ".rczrc"))
|
||||
).toString()
|
||||
) 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 {
|
||||
return null;
|
||||
}
|
||||
@@ -33,14 +45,19 @@ const program = new Command();
|
||||
program
|
||||
.name("rcz")
|
||||
.description("Resultium commit standardization command-line interface")
|
||||
.version("1.0.0");
|
||||
.version("1.7.0");
|
||||
|
||||
program
|
||||
.command("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 config = await GetConfig();
|
||||
|
||||
const sign = config?.autoSignCommits || options.sign ? true : false;
|
||||
const amend = options.amend ? true : false;
|
||||
|
||||
intro("Creating a conventional commit");
|
||||
|
||||
if (!fs.existsSync(path.join(process.cwd(), ".git"))) {
|
||||
@@ -48,10 +65,14 @@ program
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const stageAll = await confirm({
|
||||
message: "Stage all changes?",
|
||||
initialValue: true,
|
||||
});
|
||||
const stageAll = amend
|
||||
? null
|
||||
: await confirm({
|
||||
message: "Stage all changes?",
|
||||
initialValue: (await simpleGit().diff(["--cached"])).toString()
|
||||
? false
|
||||
: true,
|
||||
});
|
||||
|
||||
if (isCancel(stageAll)) {
|
||||
cancel("Commit creation cancelled");
|
||||
@@ -96,6 +117,11 @@ program
|
||||
value: "refactor",
|
||||
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",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -142,6 +168,15 @@ program
|
||||
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({
|
||||
message: "Does this commit have breaking changes?",
|
||||
initialValue: false,
|
||||
@@ -175,17 +210,29 @@ program
|
||||
scope ? `(${scope.toString()})` : ``
|
||||
}${isBreaking ? "!" : ""}: ${message.toString()}${
|
||||
resolvesIssue ? ` (${issue?.toString()})` : ``
|
||||
}${body ? `\n\n${body}` : ``}`;
|
||||
}${body ? `\n\n${body}` : ``}${footer ? `\n\n${footer}` : ``}`;
|
||||
|
||||
if (stageAll) {
|
||||
await simpleGit().add(".").commit(commitMessage);
|
||||
await simpleGit()
|
||||
.add(".")
|
||||
.commit(
|
||||
commitMessage,
|
||||
sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : []
|
||||
);
|
||||
} else {
|
||||
await simpleGit().commit(commitMessage);
|
||||
await simpleGit().commit(
|
||||
commitMessage,
|
||||
sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : []
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
@@ -372,28 +419,92 @@ program
|
||||
"Changes package.json version and creates a new commit with a tag"
|
||||
)
|
||||
.argument("<version>", "new version formatted in SemVer")
|
||||
.action(async (string: string) => {
|
||||
.option("-S, --sign", "sign the release commit and tag")
|
||||
.action(async (string: string, options) => {
|
||||
const config = await GetConfig();
|
||||
|
||||
const sign = config?.autoSignReleases || 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");
|
||||
const onReleaseFile = (
|
||||
await fs.promises.readFile(
|
||||
path.join(process.cwd(), ".rczrc.onrelease.js")
|
||||
)
|
||||
).toString();
|
||||
|
||||
if (onReleaseFile) {
|
||||
const releaseScript = `
|
||||
const __NEW_VERSION__ = "${version}";
|
||||
const __IS_SIGNED__ = ${sign};
|
||||
|
||||
${onReleaseFile}`;
|
||||
|
||||
eval(releaseScript);
|
||||
} else {
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
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}`);
|
||||
.commit(`chore(release): v${version}`, sign ? ["-S"] : [])
|
||||
.tag(
|
||||
sign
|
||||
? [`-s`, `v${version}`, `-m`, `"v${version}"`]
|
||||
: [`-a`, `v${version}`, `-m`, `"v${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"].join("|") : "..*"
|
||||
})\\))?!?: .* ?(\\(..*\\))?((\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();
|
||||
|
||||
@@ -3,6 +3,8 @@ import { DefaultLogFields, ListLogLine } from "simple-git";
|
||||
export interface Config {
|
||||
types?: Array<Type>;
|
||||
scopes?: Array<string>;
|
||||
autoSignCommits?: boolean;
|
||||
autoSignReleases?: boolean;
|
||||
}
|
||||
|
||||
export interface Type {
|
||||
|
||||
Reference in New Issue
Block a user