From 09061c16faf089e455525adbddca8533dcfc4771 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Tue, 10 Jan 2023 18:54:18 +0300 Subject: [PATCH] scripts: update graphql-update script --- apps/web/package.json | 3 ++- apps/web/scripts/graphql-update.js | 11 +++++++++++ package.json | 8 ++++---- packages/eslint-config-custom/index.js | 1 + packages/tools/scripts.js | 19 +++++++++++++++++++ packages/tools/tsconfig.json | 5 +++-- scripts/graphql-download-schema.js | 18 ------------------ scripts/graphql-update.js | 5 +++++ 8 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 apps/web/scripts/graphql-update.js create mode 100644 packages/tools/scripts.js delete mode 100644 scripts/graphql-download-schema.js create mode 100644 scripts/graphql-update.js diff --git a/apps/web/package.json b/apps/web/package.json index 11bd832..e6ccaaf 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -8,7 +8,7 @@ "lint": "next lint", "lint:fix": "next lint -- --fix", "start": "next start", - "graphql:codegen": "graphql-codegen --config .graphqlrc.yml", + "graphql:update": "node ./scripts/graphql-update.js", "test": "jest" }, "dependencies": { @@ -52,6 +52,7 @@ "@types/styled-components": "^5.1.26", "eslint": "^8.31.0", "eslint-config-custom": "*", + "gql-sdl": "^1.0.0", "jest": "^29.3.1", "jest-environment-jsdom": "^29.3.1", "msw": "^0.49.2", diff --git a/apps/web/scripts/graphql-update.js b/apps/web/scripts/graphql-update.js new file mode 100644 index 0000000..92d9e03 --- /dev/null +++ b/apps/web/scripts/graphql-update.js @@ -0,0 +1,11 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const run = require('tools/scripts'); + +const { URL_CRM_GRAPHQL_DIRECT } = process.env; +const PATH_CRM_GRAPHQL_SCHEMA = './graphql/crm.schema.graphql'; + +const command1 = ['gql-sdl', URL_CRM_GRAPHQL_DIRECT, '-o', PATH_CRM_GRAPHQL_SCHEMA].join(' '); +run(command1, 'Download GraphQL Schema...'); + +const command2 = ['graphql-codegen,', '--config', '.graphqlrc.yml'].join(' '); +run(command2, 'Generating TypeScript code...'); diff --git a/package.json b/package.json index ab27618..d63159d 100644 --- a/package.json +++ b/package.json @@ -11,20 +11,20 @@ "clean": "turbo run clean", "dev": "dotenv -e .env.local turbo run dev --parallel", "format": "prettier --write \"**/*.{js,jsx,ts,tsx}\"", - "lint": "turbo run lint", - "lint:fix": "turbo run lint:fix", + "lint": "dotenv -e .env.local turbo run lint", + "lint:fix": "dotenv -e .env.local turbo run lint:fix", "test": "dotenv -e .env.local turbo run test", "prepare": "husky install", "precommit": "yarn format && yarn lint:fix && yarn test", - "graphql:download-schema": "dotenv -e .env.local node ./scripts/graphql-download-schema.js" + "graphql:update": "dotenv -e .env.local node ./scripts/graphql-update.js" }, "dependencies": {}, "devDependencies": { "dotenv-cli": "^6.0.0", "eslint-config-custom": "*", - "gql-sdl": "^1.0.0", "husky": "^8.0.3", "prettier": "^2.8.2", + "tools": "*", "turbo": "latest" }, "packageManager": "yarn@1.22.17", diff --git a/packages/eslint-config-custom/index.js b/packages/eslint-config-custom/index.js index 53305bb..b35dabf 100644 --- a/packages/eslint-config-custom/index.js +++ b/packages/eslint-config-custom/index.js @@ -83,6 +83,7 @@ module.exports = { 'implicit-arrow-linebreak': 'warn', 'operator-linebreak': 'warn', 'function-paren-newline': 'warn', + 'turbo/no-undeclared-env-vars': 'warn', }, overrides: [ // Only uses Testing Library lint rules in test files diff --git a/packages/tools/scripts.js b/packages/tools/scripts.js new file mode 100644 index 0000000..a30dff3 --- /dev/null +++ b/packages/tools/scripts.js @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const { exec } = require('child_process'); + +module.exports = function run(command, message) { + console.log(message); + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`${error.message}`); + + return; + } + if (stderr) { + console.error(`${stderr}`); + + return; + } + console.info(`${stdout}`); + }); +}; diff --git a/packages/tools/tsconfig.json b/packages/tools/tsconfig.json index bdd435a..af2ec7d 100644 --- a/packages/tools/tsconfig.json +++ b/packages/tools/tsconfig.json @@ -1,5 +1,6 @@ { "extends": "tsconfig/common.json", - "include": ["."], - "exclude": ["dist", "build", "node_modules"] + "include": ["./**/*"], + "exclude": ["dist", "build", "node_modules"], + "compilerOptions": { "outDir": "./build" } } diff --git a/scripts/graphql-download-schema.js b/scripts/graphql-download-schema.js deleted file mode 100644 index e1d5554..0000000 --- a/scripts/graphql-download-schema.js +++ /dev/null @@ -1,18 +0,0 @@ -const { exec } = require('child_process'); - -const { URL_CRM_GRAPHQL_DIRECT } = process.env; -const PATH_CRM_GRAPHQL_SCHEMA = './apps/web/graphql/crm.schema.graphql'; - -const command = ['gql-sdl ', URL_CRM_GRAPHQL_DIRECT, ' ', '-o', PATH_CRM_GRAPHQL_SCHEMA].join(''); - -exec(command, (error, stdout, stderr) => { - if (error) { - console.log(`error: ${error.message}`); - return; - } - if (stderr) { - console.log(`stderr: ${stderr}`); - return; - } - console.log(`stdout: ${stdout}`); -}); diff --git a/scripts/graphql-update.js b/scripts/graphql-update.js new file mode 100644 index 0000000..9bcb446 --- /dev/null +++ b/scripts/graphql-update.js @@ -0,0 +1,5 @@ +const run = require('tools/scripts'); + +const command = ['yarn', 'workspace', 'web', 'graphql:update'].join(' '); + +run(command, '*** Update GraphQL files ***');