scripts: update graphql-update script

This commit is contained in:
vchikalkin 2023-01-10 18:54:18 +03:00
parent 7968bf7194
commit 09061c16fa
8 changed files with 45 additions and 25 deletions

View File

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

View File

@ -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...');

View File

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

View File

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

19
packages/tools/scripts.js Normal file
View File

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

View File

@ -1,5 +1,6 @@
{
"extends": "tsconfig/common.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
"include": ["./**/*"],
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": { "outDir": "./build" }
}

View File

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

View File

@ -0,0 +1,5 @@
const run = require('tools/scripts');
const command = ['yarn', 'workspace', 'web', 'graphql:update'].join(' ');
run(command, '*** Update GraphQL files ***');