diff --git a/package.json b/package.json index b97c662f3..474dacff1 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,7 @@ "doctor": "node ./packages/doctor", "e2e-test": "lerna exec \"gulp e2e-test\"", "generate-docs": "lerna run --scope=appium generate-docs", - "pregenerate-schema-declarations": "lerna exec --scope=appium \"gulp transpile\"", - "generate-schema-declarations": "node ./scripts/generate-schema-declarations.js", + "generate-schema-declarations": "node ./scripts/generate-schema-declarations.mjs", "postinstall": "lerna bootstrap && lerna exec --parallel \"gulp prepublish\"", "install-fake-driver": "lerna run --scope=appium install-fake-driver", "lint": "lerna exec --parallel \"gulp lint\" && lerna run --scope=@appium/eslint-config-appium lint", diff --git a/scripts/generate-schema-declarations.js b/scripts/generate-schema-declarations.js deleted file mode 100644 index 5999141a4..000000000 --- a/scripts/generate-schema-declarations.js +++ /dev/null @@ -1,42 +0,0 @@ -/* eslint-disable no-console */ -'use strict'; - -/* - * This module reads in the config file JSON schema and outputs a TypeScript declaration file (`.d.ts`). - */ - -const path = require('path'); -const {compileFromFile} = require('json-schema-to-typescript'); -const {fs} = require('../packages/support'); -const {execSync} = require('child_process'); - -const SCHEMA_PATH = require.resolve( - '../packages/appium/build/lib/appium-config.schema.json', -); - -const DECLARATIONS_PATH = path.join( - __dirname, - '..', - 'packages', - 'appium', - 'types', - 'appium-config.d.ts', -); - -async function main () { - try { - const ts = await compileFromFile(SCHEMA_PATH); - await fs.writeFile(DECLARATIONS_PATH, ts); - console.log(`wrote to ${DECLARATIONS_PATH}`); - execSync(`git add -A "${DECLARATIONS_PATH}"`); - console.log(`added ${DECLARATIONS_PATH} to the stage`); - } catch (err) { - console.error('Be sure to build the project first!'); - console.error(err); - process.exitCode = 1; - } -} - -if (require.main === module) { - main(); -} diff --git a/scripts/generate-schema-declarations.mjs b/scripts/generate-schema-declarations.mjs new file mode 100644 index 000000000..7a7a322d4 --- /dev/null +++ b/scripts/generate-schema-declarations.mjs @@ -0,0 +1,50 @@ +/* eslint-disable no-console */ +/* + * This module reads in the config file JSON schema and outputs a TypeScript declaration file (`.d.ts`). + * + * WARNING: This will add `../packages/appium/types/appium-config.d.ts` to the Git stage! + */ + +import { execSync } from 'child_process'; +import { compileFromFile } from 'json-schema-to-typescript'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { promises as fs } from 'fs'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +const SCHEMA_PATH = path.join( + __dirname, + '..', + 'packages', + 'appium', + 'lib', + 'appium-config.schema.json', +); + +const DECLARATIONS_PATH = path.join( + __dirname, + '..', + 'packages', + 'appium', + 'types', + 'appium-config.d.ts', +); + +// no top-level await in node v12 +async function main () { + try { + console.log('transpiling appium...'); + execSync('../node_modules/.bin/gulp -f ../packages/appium/gulpfile.js transpile', {stdio: 'inherit', cwd: __dirname}); + const ts = await compileFromFile(SCHEMA_PATH); + await fs.writeFile(DECLARATIONS_PATH, ts); + console.log(`wrote to ${DECLARATIONS_PATH}`); + execSync(`git add -A "${DECLARATIONS_PATH}"`, {stdio: 'inherit'}); + console.log(`added ${DECLARATIONS_PATH} to the stage`); + } catch (err) { + console.error(err); + process.exitCode = 1; + } +} + +main(); diff --git a/tsconfig.json b/tsconfig.json index 384ca2077..4e7902278 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,8 +13,8 @@ "include": [ "packages/*/**/*.d.ts", "packages/*/**/*.js", - "scripts/*.js", - "*.js" + "*.js", + "scripts/generate-schema-declarations.mjs" ], "exclude": ["**/node_modules/**", "**/build/**"] }