Prettier had never been run in --check mode here before, so this had drifted across most files (markdown tables, long option() chains, line wrapping). Purely formatting, no logic changes - needed so a CI format:check gate can actually pass. Adds .prettierignore for pnpm-lock.yaml specifically: prettier's YAML formatter rewrites every quoted key (single -> double quotes) producing an ~8700-line diff of pure noise on a file pnpm itself owns the formatting of. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
import path from "node:path";
|
|
import { ConfigError, loadConfig } from "../../lib/config/load";
|
|
import type { ScriptConfig } from "../../lib/config/schema";
|
|
import { loadDotenv } from "../lib/env-file";
|
|
import { resolveConfigPath } from "../lib/paths";
|
|
|
|
export interface ScriptsOptions {
|
|
config?: string;
|
|
}
|
|
|
|
function loadScripts(opts: ScriptsOptions): ScriptConfig[] | null {
|
|
const configPath = resolveConfigPath(opts.config);
|
|
loadDotenv(path.join(path.dirname(configPath), ".env"));
|
|
|
|
try {
|
|
return loadConfig(configPath).config.scripts;
|
|
} catch (error) {
|
|
if (error instanceof ConfigError) {
|
|
console.error(`Config error: ${error.message}`);
|
|
for (const issue of error.issues) console.error(` - ${issue}`);
|
|
process.exitCode = 1;
|
|
return null;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export async function scriptsListCommand(opts: ScriptsOptions): Promise<void> {
|
|
const scripts = loadScripts(opts);
|
|
if (!scripts) return;
|
|
|
|
if (scripts.length === 0) {
|
|
console.log("No scripts configured.");
|
|
return;
|
|
}
|
|
|
|
const idWidth = Math.max(...scripts.map((s) => s.id.length));
|
|
for (const script of scripts) {
|
|
const description = script.description ? ` - ${script.description}` : "";
|
|
console.log(`${script.id.padEnd(idWidth)} ${script.name}${description}`);
|
|
}
|
|
}
|
|
|
|
export async function scriptsShowCommand(
|
|
scriptId: string,
|
|
opts: ScriptsOptions,
|
|
): Promise<void> {
|
|
const scripts = loadScripts(opts);
|
|
if (!scripts) return;
|
|
|
|
const script = scripts.find((s) => s.id === scriptId);
|
|
if (!script) {
|
|
console.error(`No script '${scriptId}' configured.`);
|
|
if (scripts.length > 0) {
|
|
console.error(
|
|
`Available scripts: ${scripts.map((s) => s.id).join(", ")}`,
|
|
);
|
|
}
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
console.log(script.name);
|
|
if (script.description) console.log(script.description);
|
|
console.log(
|
|
`\ncommand: ${script.command} ${script.args.join(" ")}`.trimEnd(),
|
|
);
|
|
|
|
if (script.variables.length === 0) {
|
|
console.log("\nThis script takes no parameters.");
|
|
return;
|
|
}
|
|
|
|
console.log("\nvariables:");
|
|
for (const variable of script.variables) {
|
|
const parts: string[] = [variable.type];
|
|
if (variable.required) parts.push("required");
|
|
if (variable.type === "enum" || variable.type === "multiselect") {
|
|
parts.push(`choices: ${variable.choices.join(", ")}`);
|
|
}
|
|
if (variable.default !== undefined) {
|
|
parts.push(`default: ${JSON.stringify(variable.default)}`);
|
|
}
|
|
console.log(` ${variable.name} (${parts.join(", ")})`);
|
|
}
|
|
}
|