fix(appium): ensure correct paths for schema declaration generation

- also convert script to ESM for fun
- transpiles appium just to be sure -- this generates the base schema `.json` file
This commit is contained in:
Christopher Hiller
2021-11-15 11:30:29 -08:00
parent f5ef3230eb
commit a56cba0b03
4 changed files with 53 additions and 46 deletions

View File

@@ -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",

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -13,8 +13,8 @@
"include": [
"packages/*/**/*.d.ts",
"packages/*/**/*.js",
"scripts/*.js",
"*.js"
"*.js",
"scripts/generate-schema-declarations.mjs"
],
"exclude": ["**/node_modules/**", "**/build/**"]
}