( args: string[], cwd: string, stdout: (text: string) => void, stderr: (text: string) => void )
| 457 | Object.prototype.hasOwnProperty.call(manifest.ark, "precompile") |
| 458 | |
| 459 | const runInit = ( |
| 460 | args: string[], |
| 461 | cwd: string, |
| 462 | stdout: (text: string) => void, |
| 463 | stderr: (text: string) => void |
| 464 | ): number => { |
| 465 | let parsed: ReturnType<typeof parseArgs> |
| 466 | try { |
| 467 | parsed = parseArgs({ |
| 468 | args, |
| 469 | options: { |
| 470 | force: { type: "boolean", default: false }, |
| 471 | "no-skill": { type: "boolean", default: false }, |
| 472 | "allow-outside": { type: "boolean", default: false }, |
| 473 | help: { type: "boolean", short: "h", default: false } |
| 474 | }, |
| 475 | allowPositionals: false |
| 476 | }) |
| 477 | } catch (e) { |
| 478 | stderr(`${(e as Error).message}\n`) |
| 479 | return 1 |
| 480 | } |
| 481 | if (parsed.values.help) { |
| 482 | stdout( |
| 483 | "Usage: ark init [--force] [--no-skill] [--allow-outside]\n\nDetects your bundler/test runner, writes ark.json, and installs the bundled ArkType skill.\n" |
| 484 | ) |
| 485 | return 0 |
| 486 | } |
| 487 | const projectRoot = locateProjectRoot(cwd) |
| 488 | if (!projectRoot) { |
| 489 | stderr( |
| 490 | `No package.json found in ${resolve(cwd)} or any parent directory. Run \`ark init\` inside a JavaScript/TypeScript project.\n` |
| 491 | ) |
| 492 | return 1 |
| 493 | } |
| 494 | const manifest = readManifest(projectRoot) |
| 495 | const tools = detectedToolsOf(manifest, projectRoot) |
| 496 | const settingsPath = join(projectRoot, "ark.json") |
| 497 | const settingsContent = `${JSON.stringify( |
| 498 | { |
| 499 | $schema: "./node_modules/@ark/aot/ark.schema.json", |
| 500 | precompile: {} |
| 501 | }, |
| 502 | null, |
| 503 | "\t" |
| 504 | )}\n` |
| 505 | const hasSettings = hasArkPrecompileSetting(manifest) |
| 506 | |
| 507 | let existingSettings: Stats | undefined |
| 508 | if (!hasSettings && parsed.values.force) { |
| 509 | existingSettings = lstatIfExists(settingsPath) |
| 510 | if (existingSettings?.isSymbolicLink()) { |
| 511 | stderr(`Refusing to overwrite symlink at ${settingsPath}.\n`) |
| 512 | return 1 |
| 513 | } |
| 514 | if (existingSettings && !existingSettings.isFile()) { |
| 515 | stderr(`Cannot write ${settingsPath}: path is not a regular file.\n`) |
| 516 | return 1 |
no test coverage detected