mirror of
https://github.com/appium/appium.git
synced 2026-02-25 04:39:56 -06:00
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:
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
50
scripts/generate-schema-declarations.mjs
Normal file
50
scripts/generate-schema-declarations.mjs
Normal 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();
|
||||
@@ -13,8 +13,8 @@
|
||||
"include": [
|
||||
"packages/*/**/*.d.ts",
|
||||
"packages/*/**/*.js",
|
||||
"scripts/*.js",
|
||||
"*.js"
|
||||
"*.js",
|
||||
"scripts/generate-schema-declarations.mjs"
|
||||
],
|
||||
"exclude": ["**/node_modules/**", "**/build/**"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user