2022-05-09 09:15:45 +00:00
|
|
|
const { readFileSync, writeFileSync } = require('fs');
|
|
|
|
const glob = require('glob');
|
|
|
|
const recast = require('recast');
|
2022-10-31 14:31:51 +00:00
|
|
|
const tsParser = require('recast/parsers/babel-ts');
|
2022-05-09 09:15:45 +00:00
|
|
|
const util = require('util');
|
|
|
|
|
|
|
|
const queries = [];
|
2022-10-31 14:31:51 +00:00
|
|
|
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',
|
2023-01-24 16:06:46 +00:00
|
|
|
// any queries in libs/cypress run against capsule
|
|
|
|
'libs/cypress/**/*.ts',
|
|
|
|
'libs/cypress/**/*.js',
|
2022-10-31 14:31:51 +00:00
|
|
|
];
|
2022-05-09 09:15:45 +00:00
|
|
|
|
|
|
|
const globPromise = util.promisify(glob);
|
2023-01-24 16:06:46 +00:00
|
|
|
const globOptions = { ignore };
|
2022-05-09 09:15:45 +00:00
|
|
|
|
2022-10-31 14:31:51 +00:00
|
|
|
const processTsFiles = (files) => {
|
2022-05-09 09:15:45 +00:00
|
|
|
for (const file of files) {
|
|
|
|
const textContent = readFileSync(file, { encoding: 'utf-8' });
|
|
|
|
const ast = recast.parse(textContent, { parser: tsParser });
|
|
|
|
recast.visit(ast, {
|
|
|
|
visitTaggedTemplateExpression(path) {
|
|
|
|
const newQuasi = { ...path.value.quasi, expressions: [] };
|
|
|
|
if (path.value.tag.name === 'gql') {
|
|
|
|
queries.push(`# File: ${file}
|
|
|
|
# Query:
|
|
|
|
${recast.print(newQuasi).code.replace(/`/g, '')}`);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2022-10-31 14:31:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const processGraphQlFiles = (files) => {
|
|
|
|
for (const file of files) {
|
|
|
|
const textContent = readFileSync(file, { encoding: 'utf-8' });
|
|
|
|
const data = `
|
|
|
|
# File: ${file}
|
|
|
|
|
|
|
|
${textContent}
|
|
|
|
`;
|
|
|
|
queries.push(data);
|
|
|
|
}
|
2022-05-09 09:15:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const run = async () => {
|
2023-01-24 16:06:46 +00:00
|
|
|
const files1 = await globPromise('apps/**/*.ts', globOptions);
|
|
|
|
const files2 = await globPromise('libs/**/*.ts', globOptions);
|
|
|
|
const files3 = await globPromise('apps/**/*.tsx', globOptions);
|
|
|
|
const files4 = await globPromise('lib/**/*.tsx', globOptions);
|
|
|
|
processTsFiles([...files1, ...files2, ...files3, ...files4]);
|
2022-10-31 14:31:51 +00:00
|
|
|
const gqlFiles1 = await globPromise('lib/**/*.graphql');
|
|
|
|
const gqlFiles2 = await globPromise('apps/**/*.graphql');
|
|
|
|
processGraphQlFiles([...gqlFiles1, ...gqlFiles2]);
|
|
|
|
writeFileSync('./queries.graphql', queries.join('\n'), {
|
|
|
|
encoding: 'utf-8',
|
|
|
|
});
|
2022-05-09 09:15:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
run();
|