Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
3
.rczrc.json
Normal file
3
.rczrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"scopes": ["commands", "changelog", "readme", "release", "config"]
|
||||
}
|
||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"cSpell.words": ["Resultium", "Acked", "johndoe", "outro", "rczrc"]
|
||||
}
|
||||
52
CHANGELOG.md
52
CHANGELOG.md
@@ -2,6 +2,58 @@
|
||||
|
||||
Generation of this changelog is based on commits
|
||||
|
||||
## 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
|
||||
|
||||
@@ -23,7 +23,7 @@ Resultium commit standardization library
|
||||
|
||||
## 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
|
||||
{
|
||||
|
||||
12
cspell.json
12
cspell.json
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": "0.2",
|
||||
"ignorePaths": [],
|
||||
"dictionaryDefinitions": [],
|
||||
"dictionaries": [],
|
||||
"words": [
|
||||
"outro",
|
||||
"rczrc"
|
||||
],
|
||||
"ignoreWords": [],
|
||||
"import": []
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@resultium/rcz",
|
||||
"version": "1.2.0",
|
||||
"version": "1.6.0",
|
||||
"description": "Resultium commit standardization library, based on conventional commits",
|
||||
"main": "./dist/index.js",
|
||||
"bin": {
|
||||
|
||||
101
src/index.ts
101
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,16 @@ const program = new Command();
|
||||
program
|
||||
.name("rcz")
|
||||
.description("Resultium commit standardization command-line interface")
|
||||
.version("1.0.0");
|
||||
.version("1.6.0");
|
||||
|
||||
program
|
||||
.command("commit")
|
||||
.description("Create a conventional commit")
|
||||
.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();
|
||||
|
||||
@@ -51,10 +65,16 @@ 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(["--name-only", "--cached"])
|
||||
).toString()
|
||||
? false
|
||||
: true,
|
||||
});
|
||||
|
||||
if (isCancel(stageAll)) {
|
||||
cancel("Commit creation cancelled");
|
||||
@@ -99,6 +119,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",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -145,6 +170,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,
|
||||
@@ -178,19 +212,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, sign ? ["-S"] : []);
|
||||
.commit(
|
||||
commitMessage,
|
||||
sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : []
|
||||
);
|
||||
} else {
|
||||
await simpleGit().commit(commitMessage, sign ? ["-S"] : []);
|
||||
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
|
||||
@@ -407,4 +451,43 @@ program
|
||||
);
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user