|
|
|
|
@@ -93,8 +93,8 @@ const CheckForUpdates = async () => {
|
|
|
|
|
|
|
|
|
|
const cachedVersion = fs.existsSync(path.join(tmpdir(), "rcz-server-version"))
|
|
|
|
|
? (await fs.promises.readFile(path.join(tmpdir(), "rcz-server-version")))
|
|
|
|
|
.toString()
|
|
|
|
|
.trim()
|
|
|
|
|
.toString()
|
|
|
|
|
.trim()
|
|
|
|
|
: null;
|
|
|
|
|
const localVersion = execSync("rcz --version").toString().trim();
|
|
|
|
|
|
|
|
|
|
@@ -123,7 +123,7 @@ const program = new Command();
|
|
|
|
|
program
|
|
|
|
|
.name("rcz")
|
|
|
|
|
.description("Resultium commit standardization command-line interface")
|
|
|
|
|
.version("1.10.0");
|
|
|
|
|
.version("1.11.0");
|
|
|
|
|
|
|
|
|
|
program
|
|
|
|
|
.command("commit")
|
|
|
|
|
@@ -131,6 +131,7 @@ program
|
|
|
|
|
.description("Create a conventional commit")
|
|
|
|
|
.option("-S, --sign", "sign the commit")
|
|
|
|
|
.option("--amend", "amend commit message to the last commit")
|
|
|
|
|
.option("--sudo", "remove any validation")
|
|
|
|
|
.action(async (options) => {
|
|
|
|
|
await CheckForUpdates();
|
|
|
|
|
|
|
|
|
|
@@ -138,6 +139,7 @@ program
|
|
|
|
|
|
|
|
|
|
const sign = config?.autoSignCommits || options.sign ? true : false;
|
|
|
|
|
const amend = options.amend ? true : false;
|
|
|
|
|
const sudo = options.sudo ? true : false;
|
|
|
|
|
|
|
|
|
|
intro("Creating a conventional commit");
|
|
|
|
|
|
|
|
|
|
@@ -149,11 +151,11 @@ program
|
|
|
|
|
const stageAll = amend
|
|
|
|
|
? null
|
|
|
|
|
: await confirm({
|
|
|
|
|
message: "Stage all changes?",
|
|
|
|
|
initialValue: (await simpleGit().diff(["--cached"])).toString()
|
|
|
|
|
? false
|
|
|
|
|
: true,
|
|
|
|
|
});
|
|
|
|
|
message: "Stage all changes?",
|
|
|
|
|
initialValue: (await simpleGit().diff(["--cached"])).toString()
|
|
|
|
|
? false
|
|
|
|
|
: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (isCancel(stageAll)) {
|
|
|
|
|
cancel("Commit creation cancelled");
|
|
|
|
|
@@ -166,7 +168,7 @@ program
|
|
|
|
|
).match(/\d+/gm) || []
|
|
|
|
|
).reduce((partialSum, num) => partialSum + Number(num), 0);
|
|
|
|
|
|
|
|
|
|
if (changedLines > 250) {
|
|
|
|
|
if (changedLines > 250 && !sudo) {
|
|
|
|
|
const proceedCommitting = await confirm({
|
|
|
|
|
message:
|
|
|
|
|
"You are about to commit changes to more than 250 lines, are you sure you want to proceed?",
|
|
|
|
|
@@ -177,6 +179,11 @@ program
|
|
|
|
|
cancel("Commit creation cancelled");
|
|
|
|
|
process.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!proceedCommitting) {
|
|
|
|
|
cancel("Cancelled, please split this commit into smaller ones");
|
|
|
|
|
process.exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const type: string | symbol = await select({
|
|
|
|
|
@@ -235,6 +242,10 @@ program
|
|
|
|
|
"Input a scope (subsystem which change is relevant to e.g. router, forms, core) or leave empty",
|
|
|
|
|
placeholder: "router",
|
|
|
|
|
validate: (value) => {
|
|
|
|
|
if (sudo) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config?.scopes && value) {
|
|
|
|
|
if (!config?.scopes.includes(value))
|
|
|
|
|
return "This scope is not allowed by local configuration";
|
|
|
|
|
@@ -255,6 +266,10 @@ program
|
|
|
|
|
message: `Briefly describe made changes in imperative tense, maximum length 50`,
|
|
|
|
|
placeholder: "warn upon suspicious router requests",
|
|
|
|
|
validate: (value) => {
|
|
|
|
|
if (sudo) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value.length > 50) {
|
|
|
|
|
return "Your message is too long";
|
|
|
|
|
}
|
|
|
|
|
@@ -316,11 +331,9 @@ program
|
|
|
|
|
process.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const commitMessage = `${type.toString()}${
|
|
|
|
|
scope ? `(${scope.toString()})` : ``
|
|
|
|
|
}${isBreaking ? "!" : ""}: ${message.toString()}${
|
|
|
|
|
resolvesIssue ? ` (${issue?.toString()})` : ``
|
|
|
|
|
}${body ? `\n\n${body}` : ``}${footer ? `\n\n${footer}` : ``}`;
|
|
|
|
|
const commitMessage = `${type.toString()}${scope ? `(${scope.toString()})` : ``
|
|
|
|
|
}${isBreaking ? "!" : ""}: ${message.toString()}${resolvesIssue ? ` (${issue?.toString()})` : ``
|
|
|
|
|
}${body ? `\n\n${body}` : ``}${footer ? `\n\n${footer}` : ``}`;
|
|
|
|
|
|
|
|
|
|
if (stageAll) {
|
|
|
|
|
await simpleGit()
|
|
|
|
|
@@ -339,8 +352,7 @@ program
|
|
|
|
|
note(commitMessage);
|
|
|
|
|
|
|
|
|
|
outro(
|
|
|
|
|
`Finished ${
|
|
|
|
|
amend ? "amending" : "creating"
|
|
|
|
|
`Finished ${amend ? "amending" : "creating"
|
|
|
|
|
} a conventional commit, feel free to push`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
@@ -462,8 +474,7 @@ program
|
|
|
|
|
: firstMessageLine[0];
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
`${showHashes ? `- [${shortHash}]` : ``} - ${
|
|
|
|
|
type ? `**${type}**: ${briefMessage}` : briefMessage
|
|
|
|
|
`${showHashes ? `- [${shortHash}]` : ``} - ${type ? `**${type}**: ${briefMessage}` : briefMessage
|
|
|
|
|
}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@@ -482,8 +493,7 @@ program
|
|
|
|
|
: firstMessageLine[0];
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
`${showHashes ? `- [${shortHash}]` : ``} - ${
|
|
|
|
|
type ? `**${type}**: ${briefMessage}` : briefMessage
|
|
|
|
|
`${showHashes ? `- [${shortHash}]` : ``} - ${type ? `**${type}**: ${briefMessage}` : briefMessage
|
|
|
|
|
}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@@ -502,8 +512,7 @@ program
|
|
|
|
|
: firstMessageLine[0];
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
`${showHashes ? `- [${shortHash}]` : ``} - ${
|
|
|
|
|
type ? `**${type}**: ${briefMessage}` : briefMessage
|
|
|
|
|
`${showHashes ? `- [${shortHash}]` : ``} - ${type ? `**${type}**: ${briefMessage}` : briefMessage
|
|
|
|
|
}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@@ -522,8 +531,7 @@ program
|
|
|
|
|
: firstMessageLine[0];
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
`${showHashes ? `- [${shortHash}]` : ``} - ${
|
|
|
|
|
type ? `**${type}**: ${briefMessage}` : briefMessage
|
|
|
|
|
`${showHashes ? `- [${shortHash}]` : ``} - ${type ? `**${type}**: ${briefMessage}` : briefMessage
|
|
|
|
|
}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@@ -611,11 +619,9 @@ program
|
|
|
|
|
// /(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("|") : "..*"
|
|
|
|
|
`(${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"
|
|
|
|
|
);
|
|
|
|
|
|