From bdd42ebfc67b8f38b605b133e91879e9a05092f9 Mon Sep 17 00:00:00 2001 From: AllanZhengYP Date: Wed, 13 Apr 2022 08:05:51 +0000 Subject: [PATCH] chore: attempt to migrate generate-clients script --- package.json | 2 +- scripts/copy-models/index.js | 5 +---- scripts/generate-clients/code-eslint-fix.js | 7 +------ scripts/generate-clients/code-prettify.js | 11 ++--------- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 86d052b294b50..3fa9a35130f7d 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "clear-build-cache": "rimraf ./packages/*/dist-* ./clients/*/dist-* ./lib/*/dist-* ./private/*/dist-*", "clear-build-info": "rimraf ./packages/**/*.tsbuildinfo ./clients/**/*.tsbuildinfo ./lib/**/*.tsbuildinfo ./private/**/*.tsbuildinfo", "copy-models": "node ./scripts/copy-models", - "generate-clients": "node ./scripts/generate-clients", + "generate-clients": "yarn node ./scripts/generate-clients", "generate:clients:generic": "node ./scripts/generate-clients/generic", "generate:defaults-mode-provider": "./scripts/generate-defaults-mode-provider/index.js", "lerna:version": "lerna version --exact --conventional-commits --no-push --no-git-tag-version --no-commit-hooks --loglevel silent --yes", diff --git a/scripts/copy-models/index.js b/scripts/copy-models/index.js index ec26db04a3efd..58fe44d1ce764 100644 --- a/scripts/copy-models/index.js +++ b/scripts/copy-models/index.js @@ -49,8 +49,5 @@ const { models } = yargs } // Prettify copied models - await spawnProcess(join(__dirname, "..", "..", "node_modules", ".bin", "prettier"), [ - "--write", - `${OUTPUT_DIR}/*.json`, - ]); + await spawnProcess("yarn", ["exec", "prettier", "--write", `${OUTPUT_DIR}/*.json`]); })(); diff --git a/scripts/generate-clients/code-eslint-fix.js b/scripts/generate-clients/code-eslint-fix.js index 5aaa8933d53c0..7c5f73fcf18a8 100644 --- a/scripts/generate-clients/code-eslint-fix.js +++ b/scripts/generate-clients/code-eslint-fix.js @@ -1,14 +1,9 @@ // @ts-check const { spawnProcess } = require("../utils/spawn-process"); -const path = require("path"); const eslintFixCode = async () => { try { - await spawnProcess(path.join(__dirname, "..", "..", "node_modules", ".bin", "esprint"), [ - "check", - "--fix", - "--quiet", - ]); + await spawnProcess("yarn", ["exec", "esprint", "check", "--fix", "--quiet"]); } catch (error) { // esprint throws error as the clients source code does not follow 'prefer-const' rule. // And esprint does not have a way to override rules written in .eslintrc diff --git a/scripts/generate-clients/code-prettify.js b/scripts/generate-clients/code-prettify.js index 610442509d0ff..c0e3b9f1b96eb 100644 --- a/scripts/generate-clients/code-prettify.js +++ b/scripts/generate-clients/code-prettify.js @@ -1,16 +1,9 @@ // @ts-check const { spawnProcess } = require("../utils/spawn-process"); -const path = require("path"); const prettifyCode = async (dir) => { - await spawnProcess(path.join(__dirname, "..", "..", "node_modules", ".bin", "pprettier"), [ - "--write", - `${dir}/*/typescript-codegen/**/*.{ts,js,md,json}`, - ]); - await spawnProcess(path.join(__dirname, "..", "..", "node_modules", ".bin", "pprettier"), [ - "--write", - `${dir}/*/typescript-ssdk-codegen/**/*.{ts,js,md,json}`, - ]); + await spawnProcess("yarn", ["exec", "prettier", "--write", `${dir}/*/typescript-codegen/**/*.{ts,js,md,json}`]); + await spawnProcess("yarn", ["exec", "prettier", "--write", `${dir}/*/typescript-ssdk-codegen/**/*.{ts,js,md,json}`]); }; module.exports = {