From 03e39e8323c5d502826f02a26abc4f7da47607be Mon Sep 17 00:00:00 2001 From: Dexter Edwards Date: Mon, 31 Oct 2022 14:31:51 +0000 Subject: [PATCH] fix: get queries script (#1911) --- scripts/get-queries.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/scripts/get-queries.js b/scripts/get-queries.js index c3a3ec40b..17e2c56f1 100644 --- a/scripts/get-queries.js +++ b/scripts/get-queries.js @@ -1,14 +1,19 @@ const { readFileSync, writeFileSync } = require('fs'); const glob = require('glob'); const recast = require('recast'); -const tsParser = require('recast/parsers/typescript'); +const tsParser = require('recast/parsers/babel-ts'); const util = require('util'); const queries = []; +const ignore = [ + 'libs/fills/src/lib/fills-data-provider.ts', + 'libs/orders/src/lib/components/order-data-provider/order-data-provider.ts', + 'libs/trades/src/lib/trades-data-provider.ts', +]; const globPromise = util.promisify(glob); -const processFiles = (files) => { +const processTsFiles = (files) => { for (const file of files) { const textContent = readFileSync(file, { encoding: 'utf-8' }); const ast = recast.parse(textContent, { parser: tsParser }); @@ -24,15 +29,36 @@ ${recast.print(newQuasi).code.replace(/`/g, '')}`); }, }); } - writeFileSync('./queries.graphql', queries.join('\n'), { - encoding: 'utf-8', - }); +}; + +const processGraphQlFiles = (files) => { + for (const file of files) { + const textContent = readFileSync(file, { encoding: 'utf-8' }); + const data = ` +# File: ${file} + +${textContent} + `; + queries.push(data); + } }; const run = async () => { const files1 = await globPromise('apps/**/*.ts'); const files2 = await globPromise('libs/**/*.ts'); - processFiles([...files1, ...files2]); + const files3 = await globPromise('apps/**/*.tsx'); + const files4 = await globPromise('lib/**/*.tsx'); + processTsFiles( + [...files1, ...files2, ...files3, ...files4].filter( + (f) => !ignore.includes(f) + ) + ); + const gqlFiles1 = await globPromise('lib/**/*.graphql'); + const gqlFiles2 = await globPromise('apps/**/*.graphql'); + processGraphQlFiles([...gqlFiles1, ...gqlFiles2]); + writeFileSync('./queries.graphql', queries.join('\n'), { + encoding: 'utf-8', + }); }; run();