| 42 | const OUTPUT_PATH = path.join(OUTPUT_DIR, JSON_FILENAME); |
| 43 | |
| 44 | async function write() { |
| 45 | /** @type {typeof import('../lib/appium-config-schema.js').AppiumConfigJsonSchema} */ |
| 46 | let schema; |
| 47 | try { |
| 48 | ({AppiumConfigJsonSchema: schema} = await import(pathToFileURL(SCHEMA_SRC).href)); |
| 49 | } catch (e) { |
| 50 | throw new Error(`${error} Failed to read ${SCHEMA_SRC}; did you execute \`npm run build\` first?`, {cause: e}); |
| 51 | } |
| 52 | |
| 53 | const json = `${JSON.stringify(schema, null, 2)}\n`; |
| 54 | |
| 55 | try { |
| 56 | await mkdir(OUTPUT_DIR, {recursive: true}); |
| 57 | await writeFile(OUTPUT_PATH, json); |
| 58 | console.log(`${info} Wrote JSON schema to ${OUTPUT_PATH}`); |
| 59 | } catch (err) { |
| 60 | const message = err instanceof Error ? err.message : String(err); |
| 61 | throw new Error(`${error} Failed to write JSON schema to ${OUTPUT_PATH}: ${message}`, { |
| 62 | cause: err, |
| 63 | }); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | async function main() { |
| 68 | try { |