refactor: foramt the code with prettier

This commit is contained in:
2024-01-27 23:30:21 +02:00
parent 444a957724
commit afc4f76c4a

View File

@@ -24,27 +24,27 @@ const GetConfig = async () => {
return JSON.parse(
(
await fs.promises.readFile(path.join(process.cwd(), ".rczrc"))
).toString()
).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()
).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()
).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")
path.join(process.cwd(), ".rcz", "config.json"),
)
).toString()
).toString(),
) as Config;
} else {
return null;
@@ -59,7 +59,7 @@ const GetOnReleaseScript = async () => {
} else if (fs.existsSync(path.join(process.cwd(), ".rcz", "onrelease.js"))) {
return (
await fs.promises.readFile(
path.join(process.cwd(), ".rcz", "onrelease.js")
path.join(process.cwd(), ".rcz", "onrelease.js"),
)
).toString();
} else {
@@ -71,7 +71,7 @@ const GetPostReleaseScript = async () => {
if (fs.existsSync(path.join(process.cwd(), ".rcz.postrelease.js"))) {
return (
await fs.promises.readFile(
path.join(process.cwd(), ".rcz.postrelease.js")
path.join(process.cwd(), ".rcz.postrelease.js"),
)
).toString();
} else if (
@@ -79,7 +79,7 @@ const GetPostReleaseScript = async () => {
) {
return (
await fs.promises.readFile(
path.join(process.cwd(), ".rcz", "postrelease.js")
path.join(process.cwd(), ".rcz", "postrelease.js"),
)
).toString();
} else {
@@ -109,7 +109,7 @@ const CheckForUpdates = async () => {
fs.promises.writeFile(
path.join(tmpdir(), "rcz-server-version"),
serverVersion
serverVersion,
);
if (semver.gt(serverVersion, localVersion)) note(updateText);
@@ -243,7 +243,7 @@ program
placeholder: "router",
validate: (value) => {
if (sudo) {
return
return;
}
if (config?.scopes && value) {
@@ -267,7 +267,7 @@ program
placeholder: "warn upon suspicious router requests",
validate: (value) => {
if (sudo) {
return
return;
}
if (value.length > 50) {
@@ -331,8 +331,10 @@ program
process.exit(0);
}
const commitMessage = `${type.toString()}${scope ? `(${scope.toString()})` : ``
}${isBreaking ? "!" : ""}: ${message.toString()}${resolvesIssue ? ` (${issue?.toString()})` : ``
const commitMessage = `${type.toString()}${
scope ? `(${scope.toString()})` : ``
}${isBreaking ? "!" : ""}: ${message.toString()}${
resolvesIssue ? ` (${issue?.toString()})` : ``
}${body ? `\n\n${body}` : ``}${footer ? `\n\n${footer}` : ``}`;
if (stageAll) {
@@ -340,20 +342,27 @@ program
.add(".")
.commit(
commitMessage,
sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : []
sign
? amend
? ["-S", "--amend"]
: ["-S"]
: amend
? ["--amend"]
: [],
);
} else {
await simpleGit().commit(
commitMessage,
sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : []
sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : [],
);
}
note(commitMessage);
outro(
`Finished ${amend ? "amending" : "creating"
} a conventional commit, feel free to push`
`Finished ${
amend ? "amending" : "creating"
} a conventional commit, feel free to push`,
);
});
@@ -365,7 +374,7 @@ program
.option("--last-only", "display only latest release changes")
.option(
"--unreleased-as <version>",
"show unreleased changes as different version"
"show unreleased changes as different version",
)
.action(async (options) => {
const showHashes = options.showHashes ? true : false;
@@ -374,7 +383,7 @@ program
if ((await simpleGit().tags()).all.length === 0) {
return console.log(
"[rcz]: not even one release has yet been made, cannot make a changelog"
"[rcz]: not even one release has yet been made, cannot make a changelog",
);
}
@@ -388,11 +397,11 @@ program
for (const commit of commits) {
const tag =
semver.sort(
(await simpleGit().tags([`--contains=${commit.hash}`])).all
(await simpleGit().tags([`--contains=${commit.hash}`])).all,
)[0]! || unreleased;
const currentCommitStack = parsedCommitStacks.find(
(commitStack) => commitStack.version === tag
(commitStack) => commitStack.version === tag,
) || {
version: tag || unreleased,
breaking: [],
@@ -412,7 +421,7 @@ program
breaking: [...currentCommitStack.breaking, commit],
},
...parsedCommitStacks.filter(
(commitStack) => commitStack.version !== tag
(commitStack) => commitStack.version !== tag,
),
];
} else if (commit.message.startsWith("feat")) {
@@ -422,7 +431,7 @@ program
features: [...currentCommitStack.features, commit],
},
...parsedCommitStacks.filter(
(commitStack) => commitStack.version !== tag
(commitStack) => commitStack.version !== tag,
),
];
} else if (commit.message.startsWith("fix")) {
@@ -432,7 +441,7 @@ program
fixes: [...currentCommitStack.fixes, commit],
},
...parsedCommitStacks.filter(
(commitStack) => commitStack.version !== tag
(commitStack) => commitStack.version !== tag,
),
];
} else {
@@ -442,7 +451,7 @@ program
miscellaneous: [...currentCommitStack.miscellaneous, commit],
},
...parsedCommitStacks.filter(
(commitStack) => commitStack.version !== tag
(commitStack) => commitStack.version !== tag,
),
];
}
@@ -474,8 +483,9 @@ program
: firstMessageLine[0];
console.log(
`${showHashes ? `- [${shortHash}]` : ``} - ${type ? `**${type}**: ${briefMessage}` : briefMessage
}`
`${showHashes ? `- [${shortHash}]` : ``} - ${
type ? `**${type}**: ${briefMessage}` : briefMessage
}`,
);
}
}
@@ -493,8 +503,9 @@ program
: firstMessageLine[0];
console.log(
`${showHashes ? `- [${shortHash}]` : ``} - ${type ? `**${type}**: ${briefMessage}` : briefMessage
}`
`${showHashes ? `- [${shortHash}]` : ``} - ${
type ? `**${type}**: ${briefMessage}` : briefMessage
}`,
);
}
}
@@ -512,8 +523,9 @@ program
: firstMessageLine[0];
console.log(
`${showHashes ? `- [${shortHash}]` : ``} - ${type ? `**${type}**: ${briefMessage}` : briefMessage
}`
`${showHashes ? `- [${shortHash}]` : ``} - ${
type ? `**${type}**: ${briefMessage}` : briefMessage
}`,
);
}
}
@@ -531,8 +543,9 @@ program
: firstMessageLine[0];
console.log(
`${showHashes ? `- [${shortHash}]` : ``} - ${type ? `**${type}**: ${briefMessage}` : briefMessage
}`
`${showHashes ? `- [${shortHash}]` : ``} - ${
type ? `**${type}**: ${briefMessage}` : briefMessage
}`,
);
}
}
@@ -543,7 +556,7 @@ program
.command("release")
.alias("rel")
.description(
"Changes package.json version and creates a new commit with a tag"
"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")
@@ -567,7 +580,7 @@ program
const packageFile = JSON.parse(
(
await fs.promises.readFile(path.join(process.cwd(), "package.json"))
).toString()
).toString(),
);
if (!packageFile) {
@@ -577,7 +590,7 @@ program
packageFile.version = version;
await fs.promises.writeFile(
path.join(process.cwd(), "package.json"),
JSON.stringify(packageFile, null, 4)
JSON.stringify(packageFile, null, 4),
);
}
@@ -587,7 +600,7 @@ program
.tag(
sign
? [`-s`, `v${version}`, `-m`, `"v${version}"`]
: [`-a`, `v${version}`, `-m`, `"v${version}"`]
: [`-a`, `v${version}`, `-m`, `"v${version}"`],
);
const postReleaseFile = await GetPostReleaseScript();
@@ -619,11 +632,13 @@ program
// /(build|feat|docs)(\((commands|changelog)\))?!?: .* ?(\(..*\))?((\n\n..*)?(\n\n..*)?)?/gm
const testRegex = new RegExp(
`(${config?.types?.map((type) => type.value).join("|") ||
`(${
config?.types?.map((type) => type.value).join("|") ||
"feat|fix|build|ci|docs|perf|refactor|chore"
})(\\((${config?.scopes ? [...config?.scopes, "release"].join("|") : "..*"
})(\\((${
config?.scopes ? [...config?.scopes, "release"].join("|") : "..*"
})\\))?!?: .* ?(\\(..*\\))?((\n\n..*)?(\n\n..*)?)?`,
"gm"
"gm",
);
if (codeOnly) {
@@ -632,7 +647,7 @@ program
console.log(
testRegex.test(message)
? "[rcz]: valid message"
: "[rcz]: invalid message"
: "[rcz]: invalid message",
);
}
} catch (err) {