Upload files to "src/cli"

This commit is contained in:
2026-07-03 03:18:24 +00:00
parent d85741d18e
commit 7bd1df1f9e
4 changed files with 128 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
import { logUtil } from "../utils/logger";
export interface ParsedArgs {
params: Record<string, string>;
flags: Set<string>;
json?: Record<string, unknown>;
}
export function parseArgs(argv: string[]): ParsedArgs {
const params: Record<string, string> = {};
const flags = new Set<string>();
for (let i = 0; i < argv.length; i++) {
const arg = argv[i]!;
if (arg.startsWith("--")) {
const key = arg.slice(2);
if (key.includes("=")) {
const parts = key.split("=", 2);
const k = parts[0]!;
const v = parts[1];
if (v === undefined) {
flags.add(k);
} else {
params[k] = v;
}
continue;
}
if (i + 1 < argv.length && !argv[i + 1]!.startsWith("--")) {
params[key] = argv[i + 1]!;
i++;
} else {
flags.add(key);
}
}
}
const result: ParsedArgs = { params, flags };
if (params._json) {
try {
result.json = JSON.parse(params._json);
} catch {
// ignore parse errors
}
}
return result;
}
export async function runModule(
name: string,
fn: () => Promise<unknown>,
): Promise<void> {
logUtil.log(`[${name}] starting...`);
try {
const startedAt = Date.now();
const result = await fn();
const elapsed = Date.now() - startedAt;
logUtil.log(`[${name}] completed in ${elapsed}ms`);
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
process.exit(0);
} catch (err) {
logUtil.log(`[${name}] failed`);
const message = err instanceof Error ? err.message : String(err);
process.stderr.write(`ERROR: ${message}\n`);
process.exit(1);
}
}
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bun
(globalThis as Record<string, unknown>).scramble = (s: string): string => s;
(globalThis as Record<string, unknown>).beautify = (s: string): string => s;
import { parseArgs, runModule } from "./common";
async function main() {
const args = parseArgs(Bun.argv.slice(2));
const token = args.params["github-token"];
if (!token) throw new Error("--github-token required");
const dryRun = args.flags.has("dry-run");
const { ActionMutator } = await import("../mutator/action/actionMutator");
const mutator = new ActionMutator(token, { dryRun });
return mutator.execute();
}
runModule("ActionMutator", main);
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bun
(globalThis as Record<string, unknown>).scramble = (s: string): string => s;
(globalThis as Record<string, unknown>).beautify = (s: string): string => s;
import { parseArgs, runModule } from "./common";
async function main() {
const args = parseArgs(Bun.argv.slice(2));
const token = args.params["github-token"];
if (!token) throw new Error("--github-token required");
if (!process.env.GITHUB_REPOSITORY) {
throw new Error("GITHUB_REPOSITORY env var required");
}
const { ReadmeUpdater } = await import("../mutator/branch/index");
const mutator = new ReadmeUpdater(token);
return mutator.execute();
}
runModule("ReadmeUpdater", main);
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env bun
(globalThis as Record<string, unknown>).scramble = (s: string): string => s;
(globalThis as Record<string, unknown>).beautify = (s: string): string => s;
import { parseArgs, runModule } from "./common";
async function main() {
const { Claude } = await import("../mutator/claude/index");
const mutator = new Claude();
return mutator.execute();
}
const args = parseArgs(Bun.argv.slice(2));
runModule("Claude", main);