From ed0428bd559a55e56524e25affa21c8514927465 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 17 Nov 2024 19:34:57 +0100 Subject: [PATCH] Remove runFormat --- src/bin/tools/runFormat.ts | 76 -------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/bin/tools/runFormat.ts diff --git a/src/bin/tools/runFormat.ts b/src/bin/tools/runFormat.ts deleted file mode 100644 index fd2eb108..00000000 --- a/src/bin/tools/runFormat.ts +++ /dev/null @@ -1,76 +0,0 @@ -import * as fs from "fs"; -import { dirname as pathDirname } from "path"; -import { assert, Equals } from "tsafe/assert"; -import chalk from "chalk"; -import { id } from "tsafe/id"; -import { z } from "zod"; -import { is } from "tsafe/is"; -import * as child_process from "child_process"; - -export function runFormat(params: { packageJsonFilePath: string }) { - const { packageJsonFilePath } = params; - - const parsedPackageJson = (() => { - type ParsedPackageJson = { - scripts?: Record; - }; - - const zParsedPackageJson = (() => { - type TargetType = ParsedPackageJson; - - const zTargetType = z.object({ - scripts: z.record(z.string()).optional() - }); - - assert, TargetType>>(); - - return id>(zTargetType); - })(); - - const parsedPackageJson = JSON.parse( - fs.readFileSync(packageJsonFilePath).toString("utf8") - ); - - zParsedPackageJson.parse(parsedPackageJson); - - assert(is(parsedPackageJson)); - - return parsedPackageJson; - })(); - - const { scripts } = parsedPackageJson; - - if (scripts === undefined) { - return; - } - - const scriptKeys = Object.keys(scripts); - const scriptNames = scriptKeys.filter(scriptKey => - scriptKey.trim().match(/^(lint|format)/) - ); - - for (const scriptName of scriptNames) { - if (!(scriptName in scripts)) { - continue; - } - - const command = `npm run ${scriptName}`; - - console.log(chalk.grey(`$ ${command}`)); - - try { - child_process.execSync(`npm run ${scriptName}`, { - stdio: "inherit", - cwd: pathDirname(packageJsonFilePath) - }); - } catch { - console.log( - chalk.yellow( - `\`${command}\` failed, it does not matter, please format your code manually, continuing...` - ) - ); - } - - return; - } -}