Files
appium/packages/schema/scripts/generate-schema-json.mjs
Edgars Eglītis 298b09cdbf chore: apply oxlint correctness fixes (#22896)
* chore: fix some correctness issues

* chore: fix more correctness issues

* chore: more correctness fixes

* chore: remove unnecessary eslint-disable directives

* chore: more correctness fixes

* chore: apply remaining fixes

* chore: minor tuning

* chore: explicitly disable rule

* chore: handle TS error

* chore: tune

* chore: tune more

* chore: address comments

* chore: address some comments

* chore: address remaining comments

* chore: address previously missed copilot commens
2026-10-05 20:52:17 +03:00

82 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
// @ts-check
/* eslint-disable no-console */
/**
* This script takes the JSON schema `.js` artifact and converts it to JSON proper,
* then outputs the result.
*/
import {mkdir, writeFile} from 'node:fs/promises';
import path from 'node:path';
import {fileURLToPath, pathToFileURL} from 'node:url';
const info = 'ℹ';
const success = '✔';
const error = '✖';
/**
* `@appium/schema` package root.
*/
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const SCHEMA_ROOT = path.join(__dirname, '..');
/**
* Dir which will contain output `.json`
*/
const OUTPUT_DIR = path.join(SCHEMA_ROOT, 'lib');
/**
* Basename of exported `.json` file.
*/
const JSON_FILENAME = 'appium-config.schema.json';
/**
* Path to the schema artifact.
*/
const SCHEMA_SRC = path.join(SCHEMA_ROOT, 'build', 'lib', 'appium-config-schema.js');
/**
* Full path to output `.json`
*/
const OUTPUT_PATH = path.join(OUTPUT_DIR, JSON_FILENAME);
async function write() {
/** @type {typeof import('../lib/appium-config-schema.js').AppiumConfigJsonSchema} */
let schema;
try {
({AppiumConfigJsonSchema: schema} = await import(pathToFileURL(SCHEMA_SRC).href));
} catch (e) {
throw new Error(`${error} Failed to read ${SCHEMA_SRC}; did you execute \`npm run build\` first?`, {cause: e});
}
const json = `${JSON.stringify(schema, null, 2)}\n`;
try {
await mkdir(OUTPUT_DIR, {recursive: true});
await writeFile(OUTPUT_PATH, json);
console.log(`${info} Wrote JSON schema to ${OUTPUT_PATH}`);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
throw new Error(`${error} Failed to write JSON schema to ${OUTPUT_PATH}: ${message}`, {
cause: err,
});
}
}
async function main() {
try {
await write();
} catch (err) {
console.log(err);
process.exitCode = 1;
return;
}
console.log(`${success} Done.`);
}
// Check if this module is being run directly
if (import.meta.main) {
void main();
}