UNPKG

radashi-helper

Version:
73 lines (71 loc) 1.73 kB
import { stdio } from "./chunk-GGEXN2BI.js"; import { getEnv } from "./chunk-DSXY7YVB.js"; import { exec } from "./chunk-JLKIE3A2.js"; import "./chunk-VOEQFXI5.js"; // src/format.ts import glob from "fast-glob"; async function format(filter, options) { const env = options.env ?? getEnv(options.dir); const { stdout: uncommittedChanges } = await exec( "git", ["status", "--porcelain", "-uno"], { cwd: env.root } ); const biomeGlobs = ["src/**/*", "tests/**/*", "benchmarks/**/*"]; let biomeFiles = await glob(biomeGlobs, { cwd: env.root }); const prettierGlobs = [ "package.json", "README.md", "docs/**/*", "scripts/**/*" ]; let prettierFiles = await glob(prettierGlobs, { cwd: env.root }); if (filter.length > 0) { const filterRE = new RegExp(`^(${filter.join("|")}).*`); biomeFiles = biomeFiles.filter((file) => filterRE.test(file)); prettierFiles = prettierFiles.filter((file) => filterRE.test(file)); } if (biomeFiles.length > 0) { await exec( "pnpm", [ "biome", "check", "--diagnostic-level", "info", "--fix", "--unsafe", ...biomeFiles ], { cwd: env.root, stdio } ); } if (prettierFiles.length > 0) { await exec("pnpm", ["prettier", "--write", ...prettierFiles], { cwd: env.root, stdio }); } const { stdout: currentChanges } = await exec( "git", ["status", "--porcelain", "-uno"], { cwd: env.root } ); if (!uncommittedChanges && currentChanges) { await exec("git", ["add", "-u"], { cwd: env.root }); await exec("git", ["commit", "-m", "chore: format"], { cwd: env.root }); } } export { format };