MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / updateCommand

Function updateCommand

ts/workflow-cli/cli/update.ts:17–63  ·  view source on GitHub ↗
(filePath?: string, outPath?: string)

Source from the content-addressed store, hash-verified

15 * and no output path is given.
16 */
17export async function updateCommand(filePath?: string, outPath?: string): Promise<void> {
18 if (!filePath) {
19 process.stderr.write("Usage: fh-workflow update <file.json> [out.json]\n");
20 process.exit(1);
21 }
22
23 const abs = path.resolve(process.cwd(), filePath);
24 let raw: string;
25 try {
26 raw = await fs.readFile(abs, "utf-8");
27 } catch (err: unknown) {
28 const code = (err as NodeJS.ErrnoException).code;
29 if (code === "ENOENT") {
30 process.stderr.write(`File not found: ${abs}\n`);
31 process.exit(1);
32 }
33 throw err;
34 }
35
36 let parsed: unknown;
37 try {
38 parsed = JSON.parse(raw);
39 } catch (err) {
40 process.stderr.write(`Invalid JSON: ${err instanceof Error ? err.message : String(err)}\n`);
41 process.exit(1);
42 }
43
44 let migrated: ApiWorkflow;
45 try {
46 migrated = migrate(parsed);
47 } catch (err) {
48 process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
49 process.exit(1);
50 }
51
52 const from = readSchemaVersion(parsed as Record<string, unknown>);
53 const dest = outPath ? path.resolve(process.cwd(), outPath) : abs;
54
55 if (from === CURRENT_SCHEMA_VERSION && dest === abs) {
56 process.stdout.write(`✓ ${abs}: already at schemaVersion ${CURRENT_SCHEMA_VERSION}\n`);
57 return;
58 }
59
60 await fs.writeFile(dest, JSON.stringify(migrated, null, 2) + "\n", "utf-8");
61 const where = dest === abs ? "" : ` → ${dest}`;
62 process.stdout.write(`✓ ${abs}: schemaVersion ${from} → ${CURRENT_SCHEMA_VERSION}${where}\n`);
63}

Callers 1

index.tsFile · 0.90

Calls 3

migrateFunction · 0.90
readSchemaVersionFunction · 0.90
writeMethod · 0.80

Tested by

no test coverage detected