chore: relax loc check defaults
This commit is contained in:
parent
dd1e161f5a
commit
edf39d0a86
@ -140,7 +140,7 @@
|
||||
"protocol:gen:swift": "node --import tsx scripts/protocol-gen-swift.ts",
|
||||
"protocol:check": "pnpm protocol:gen && pnpm protocol:gen:swift && git diff --exit-code -- dist/protocol.schema.json apps/macos/Sources/ClawdbotProtocol/GatewayModels.swift",
|
||||
"canvas:a2ui:bundle": "bash scripts/bundle-a2ui.sh",
|
||||
"check:loc": "node --import tsx scripts/check-ts-max-loc.ts --max 500"
|
||||
"check:loc": "node --import tsx scripts/check-ts-max-loc.ts --max 3000"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
||||
@ -4,10 +4,13 @@ import { execFileSync } from "node:child_process";
|
||||
|
||||
type ParsedArgs = {
|
||||
maxLines: number;
|
||||
exclude: RegExp[];
|
||||
};
|
||||
|
||||
function parseArgs(argv: string[]): ParsedArgs {
|
||||
let maxLines = 500;
|
||||
const excludePatterns: string[] = [];
|
||||
const defaultExcludePatterns = ["^(vendor|dist|docs|extensions|ui|apps)/"];
|
||||
|
||||
for (let index = 0; index < argv.length; index++) {
|
||||
const arg = argv[index];
|
||||
@ -18,9 +21,25 @@ function parseArgs(argv: string[]): ParsedArgs {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--exclude") {
|
||||
const next = argv[index + 1];
|
||||
if (!next) throw new Error("Missing --exclude value");
|
||||
excludePatterns.push(next);
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return { maxLines };
|
||||
const combinedPatterns = [...defaultExcludePatterns, ...excludePatterns];
|
||||
const exclude = combinedPatterns.map((pattern) => {
|
||||
try {
|
||||
return new RegExp(pattern);
|
||||
} catch {
|
||||
throw new Error(`Invalid --exclude regex: ${pattern}`);
|
||||
}
|
||||
});
|
||||
|
||||
return { maxLines, exclude };
|
||||
}
|
||||
|
||||
function gitLsFilesAll(): string[] {
|
||||
@ -47,10 +66,11 @@ async function main() {
|
||||
throw error;
|
||||
});
|
||||
|
||||
const { maxLines } = parseArgs(process.argv.slice(2));
|
||||
const { maxLines, exclude } = parseArgs(process.argv.slice(2));
|
||||
const files = gitLsFilesAll()
|
||||
.filter((filePath) => existsSync(filePath))
|
||||
.filter((filePath) => filePath.endsWith(".ts") || filePath.endsWith(".tsx"));
|
||||
.filter((filePath) => filePath.endsWith(".ts") || filePath.endsWith(".tsx"))
|
||||
.filter((filePath) => !exclude.some((pattern) => pattern.test(filePath)));
|
||||
|
||||
const results = await Promise.all(
|
||||
files.map(async (filePath) => ({ filePath, lines: await countLines(filePath) })),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user