#!/usr/bin/env node import { existsSync } from "node:fs"; import { dirname, join } from "node:path"; import { type CheckerOptions, checkDirectory } from "./checker.js"; function findMonorepoRoot(startDirectory: string): string | null { let current = startDirectory; while (current !== dirname(current)) { const packagesPath = join(current, "packages"); const packageJsonPath = join(current, "package.json"); if (existsSync(packagesPath) && existsSync(packageJsonPath)) { return current; } current = dirname(current); } return null; } function parseArguments(arguments_: string[]): { directory?: string; options: CheckerOptions; } { const options: CheckerOptions = { noComments: true, }; let directory: string | undefined; for (const argument of arguments_) { if (argument === "--allow-comments") { options.noComments = false; } else if (!argument.startsWith("-")) { directory = argument; } } return { directory, options }; } const monorepoRoot = findMonorepoRoot(process.cwd()); if (!monorepoRoot) { console.error("Could not find monorepo root"); process.exit(1); } const { directory, options } = parseArguments(process.argv.slice(2)); const targetDirectory = directory ?? join(monorepoRoot, "packages"); const { errors, hasErrors } = checkDirectory(targetDirectory, options); for (const error of errors) { console.error(error); } if (hasErrors) { process.exit(1); } else { console.log("Iku formatting check passed"); }