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