MCPcopy Index your code
hub / github.com/SchemaStore/schemastore / handleInput

Function handleInput

cli.js:581–625  ·  view source on GitHub ↗
(/** @type {string} */ schemaName = '')

Source from the content-addressed store, hash-verified

579 console.log('Enter the name of the schema (without .json extension)')
580 await handleInput()
581 async function handleInput(/** @type {string} */ schemaName = '') {
582 if (!schemaName || schemaName.endsWith('.json')) {
583 rl.question('input: ', handleInput)
584 return
585 }
586
587 const schemaFile = path.join(SchemaDir, schemaName + '.json')
588 const testDir = path.join(TestPositiveDir, schemaName)
589 const testFile = path.join(testDir, `${schemaName}.json`)
590
591 if (await exists(schemaFile)) {
592 throw new Error(`Schema file already exists: ${schemaFile}`)
593 }
594
595 console.info(`Creating schema file at 'src/${schemaFile}'...`)
596 console.info(`Creating positive test file at 'src/${testFile}'...`)
597
598 await fs.mkdir(path.dirname(schemaFile), { recursive: true })
599 await fs.writeFile(
600 schemaFile,
601 `{
602 "$id": "https://www.schemastore.org/${schemaName}.json",
603 "$schema": "http://json-schema.org/draft-07/schema#",
604 "additionalProperties": true,
605 "properties": {
606
607 },
608 "type": "object"
609}\n`,
610 )
611 await fs.mkdir(testDir, { recursive: true })
612 await fs.writeFile(
613 testFile,
614 `"Replace this file with an example/test that passes schema validation. Supported formats are JSON, YAML, and TOML. We recommend adding as many files as possible to make your schema most robust."\n`,
615 )
616
617 console.info(`Please add the following to 'src/api/json/catalog.json':
618{
619 "name": "",
620 "description": "",
621 "fileMatch": ["${schemaName}.yml", "${schemaName}.yaml"],
622 "url": "https://www.schemastore.org/${schemaName}.json"
623}`)
624 process.exit(0)
625 }
626}
627
628async function taskLint() {

Callers 1

taskNewSchemaFunction · 0.85

Calls 1

existsFunction · 0.70

Tested by

no test coverage detected