( args: string[], cwd: string, stdout: (text: string) => void, stderr: (text: string) => void )
| 710 | } |
| 711 | |
| 712 | const runMigrate = ( |
| 713 | args: string[], |
| 714 | cwd: string, |
| 715 | stdout: (text: string) => void, |
| 716 | stderr: (text: string) => void |
| 717 | ): number => { |
| 718 | let parsed: ReturnType<typeof parseArgs> |
| 719 | try { |
| 720 | parsed = parseArgs({ |
| 721 | args, |
| 722 | options: { |
| 723 | run: { type: "boolean", default: false }, |
| 724 | agent: { type: "string" }, |
| 725 | "no-skill": { type: "boolean", default: false }, |
| 726 | "allow-outside": { type: "boolean", default: false }, |
| 727 | help: { type: "boolean", short: "h", default: false } |
| 728 | }, |
| 729 | allowPositionals: true |
| 730 | }) |
| 731 | } catch (e) { |
| 732 | stderr(`${(e as Error).message}\n`) |
| 733 | return 1 |
| 734 | } |
| 735 | if (parsed.values.help) { |
| 736 | stdout( |
| 737 | `Usage: ark migrate [${migrationSources.join("|")}] [--run] [--agent claude|codex] [--no-skill] [--allow-outside]\n\nDetects your existing validator, installs the bundled ArkType skill, and prints (or launches) a migration prompt.\n` |
| 738 | ) |
| 739 | return 0 |
| 740 | } |
| 741 | const foundRoot = locateProjectRoot(cwd) |
| 742 | if (!parsed.values["no-skill"] && !foundRoot) { |
| 743 | stderr( |
| 744 | `No package.json found in ${resolve(cwd)} or any parent directory. Run \`ark migrate\` inside a project, or pass --no-skill.\n` |
| 745 | ) |
| 746 | return 1 |
| 747 | } |
| 748 | const projectRoot = foundRoot ?? resolve(cwd) |
| 749 | const manifest = readManifest(projectRoot) |
| 750 | const argSource = parsed.positionals[0] |
| 751 | let source: MigrationSource | undefined |
| 752 | if (argSource !== undefined) { |
| 753 | if (!migrationSources.includes(argSource as MigrationSource)) { |
| 754 | stderr( |
| 755 | `Unknown migration source "${argSource}". Expected one of: ${migrationSources.join(", ")}\n` |
| 756 | ) |
| 757 | return 1 |
| 758 | } |
| 759 | source = argSource as MigrationSource |
| 760 | } else source = detectMigrationSource(manifest) |
| 761 | |
| 762 | let skillDir: string |
| 763 | if (parsed.values["no-skill"]) skillDir = bundledSkillPath() |
| 764 | else { |
| 765 | try { |
| 766 | skillDir = installBundledSkill(projectRoot, undefined, { |
| 767 | allowOutside: Boolean(parsed.values["allow-outside"]) |
| 768 | }) |
| 769 | } catch (e) { |
no test coverage detected