()
| 571 | } |
| 572 | |
| 573 | async function taskNewSchema() { |
| 574 | const rl = readline.createInterface({ |
| 575 | input: process.stdin, |
| 576 | output: process.stdout, |
| 577 | }) |
| 578 | |
| 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 | |
| 628 | async function taskLint() { |
| 629 | const /** @type {{count: number, file: string}[]} */ entries = [] |
nothing calls this directly
no test coverage detected