Skip to content

Commit 6d209c2

Browse files
committed
refactors
1 parent cd8272c commit 6d209c2

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env node
2-
import nanoSpawn, {SubprocessError} from "nano-spawn";
2+
import nanoSpawn, {SubprocessError, type Result} from "nano-spawn";
33
import {parseArgs} from "node:util";
44
import {basename, dirname, join, relative} from "node:path";
55
import {cwd, exit, stdout} from "node:process";
66
import {EOL, platform} from "node:os";
77
import {readFileSync, writeFileSync, accessSync, truncateSync, statSync} from "node:fs";
88
import pkg from "./package.json" with {type: "json"};
99
import {parse} from "smol-toml";
10-
import type {Result} from "nano-spawn";
1110

1211
export type SemverLevel = "patch" | "minor" | "major";
1312

@@ -32,7 +31,7 @@ function replaceTokens(str: string, newVersion: string): string {
3231
.replace(/_PATCH_/g, patch);
3332
}
3433

35-
function incrementSemver(str: string, level: SemverLevel): string {
34+
function incrementSemver(str: string, level: string): string {
3635
if (!isSemver(str)) throw new Error(`Invalid semver: ${str}`);
3736
if (level === "major") return str.replace(/([0-9]+)\.[0-9]+\.[0-9]+(.*)/, (_, m1, m2) => {
3837
return `${Number(m1) + 1}.0.0${m2}`;
@@ -45,7 +44,7 @@ function incrementSemver(str: string, level: SemverLevel): string {
4544
});
4645
}
4746

48-
function find(filename: string, dir: string, stopDir?: string): string | null {
47+
function findUp(filename: string, dir: string, stopDir?: string): string | null {
4948
const path = join(dir, filename);
5049

5150
try {
@@ -57,7 +56,7 @@ function find(filename: string, dir: string, stopDir?: string): string | null {
5756
if ((stopDir && path === stopDir) || parent === dir) {
5857
return null;
5958
} else {
60-
return find(filename, parent, stopDir);
59+
return findUp(filename, parent, stopDir);
6160
}
6261
}
6362

@@ -232,7 +231,7 @@ async function main(): Promise<void> {
232231
}
233232

234233
const pwd = cwd();
235-
const gitDir = find(".git", pwd);
234+
const gitDir = findUp(".git", pwd);
236235
let projectRoot = gitDir ? dirname(gitDir) : null;
237236
if (!projectRoot) projectRoot = pwd;
238237

@@ -269,7 +268,7 @@ async function main(): Promise<void> {
269268
files = files.map(file => relative(pwd, file));
270269

271270
// set new version
272-
const newVersion = incrementSemver(baseVersion, level as SemverLevel);
271+
const newVersion = incrementSemver(baseVersion, level);
273272

274273
const replacements: Array<{re: RegExp, replacement: string}> = [];
275274
if (args.replace?.length) {

0 commit comments

Comments
 (0)