MCPcopy Create free account
hub / github.com/arktypeio/arktype / runInit

Function runInit

ark/type/cli.ts:459–598  ·  view source on GitHub ↗
(
	args: string[],
	cwd: string,
	stdout: (text: string) => void,
	stderr: (text: string) => void
)

Source from the content-addressed store, hash-verified

457 Object.prototype.hasOwnProperty.call(manifest.ark, "precompile")
458
459const 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

Callers 1

runCliFunction · 0.85

Calls 13

locateProjectRootFunction · 0.85
readManifestFunction · 0.85
detectedToolsOfFunction · 0.85
joinFunction · 0.85
hasArkPrecompileSettingFunction · 0.85
lstatIfExistsFunction · 0.85
prepareSkillInstallFunction · 0.85
reportExistingFunction · 0.85
applySkillInstallFunction · 0.85
resolveAotCliFunction · 0.85
detectPackageManagerFunction · 0.85
installDevCommandFunction · 0.85

Tested by

no test coverage detected