Ci/generate queries (#336)

* generate GQL queries as an artefact

* rename artefact

* only run on master

* remove uneeded file
This commit is contained in:
Dexter Edwards 2022-05-09 10:15:45 +01:00 committed by GitHub
parent 6eb52c9a65
commit f9c8178412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 0 deletions

30
.github/workflows/generate-queries.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: Generate queries
on:
push:
branches:
- master
jobs:
master:
name: Generate Queries
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js 16
id: Node
uses: actions/setup-node@v2
with:
node-version: 16.14.0
- name: Install root dependencies
run: yarn install
- name: Generate queries
run: node ./scripts/get-queries.js
- uses: actions/upload-artifact@v2
with:
name: queries
path: ./queries.graphql

View File

@ -121,6 +121,7 @@
"eslint-plugin-react": "7.27.0",
"eslint-plugin-react-hooks": "4.3.0",
"eslint-plugin-unicorn": "^41.0.0",
"glob": "^8.0.1",
"husky": "^7.0.4",
"jest": "27.2.3",
"jest-canvas-mock": "^2.3.1",
@ -128,6 +129,7 @@
"nx": "13.10.1",
"prettier": "^2.5.1",
"react-test-renderer": "17.0.2",
"recast": "^0.21.1",
"resize-observer-polyfill": "^1.5.1",
"sass": "1.49.9",
"storybook-addon-themes": "^6.1.0",

38
scripts/get-queries.js Normal file
View File

@ -0,0 +1,38 @@
const { readFileSync, writeFileSync } = require('fs');
const glob = require('glob');
const recast = require('recast');
const tsParser = require('recast/parsers/typescript');
const util = require('util');
const queries = [];
const globPromise = util.promisify(glob);
const processFiles = (files) => {
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;
},
});
}
writeFileSync('./queries.graphql', queries.join('\n'), {
encoding: 'utf-8',
});
};
const run = async () => {
const files1 = await globPromise('apps/**/*.ts');
const files2 = await globPromise('libs/**/*.ts');
processFiles([...files1, ...files2]);
};
run();

View File

@ -7078,6 +7078,13 @@ ast-types@0.14.2, ast-types@^0.14.0, ast-types@^0.14.2:
dependencies:
tslib "^2.0.1"
ast-types@0.15.2:
version "0.15.2"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.15.2.tgz#39ae4809393c4b16df751ee563411423e85fb49d"
integrity sha512-c27loCv9QkZinsa5ProX751khO9DJl/AcB5c2KNtA6NRvHKS0PgLfcftz72KVq504vB0Gku5s2kUZzDBvQWvHg==
dependencies:
tslib "^2.0.1"
astral-regex@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
@ -7622,6 +7629,13 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"
brace-expansion@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
dependencies:
balanced-match "^1.0.0"
braces@^2.3.1, braces@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729"
@ -11967,6 +11981,18 @@ glob@7.2.0, glob@^7.0.0, glob@^7.1.0, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glo
once "^1.3.0"
path-is-absolute "^1.0.0"
glob@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.1.tgz#00308f5c035aa0b2a447cd37ead267ddff1577d3"
integrity sha512-cF7FYZZ47YzmCu7dDy50xSRRfO3ErRfrXuLZcNIuyiJEco0XSrGtuilG19L5xp3NcwTx7Gn+X6Tv3fmsUPTbow==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^5.0.1"
once "^1.3.0"
path-is-absolute "^1.0.0"
global-agent@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/global-agent/-/global-agent-2.2.0.tgz#566331b0646e6bf79429a16877685c4a1fbf76dc"
@ -15059,6 +15085,13 @@ minimatch@^3.0.2, minimatch@^3.0.4, minimatch@^3.1.2:
dependencies:
brace-expansion "^1.1.7"
minimatch@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.0.1.tgz#fb9022f7528125187c92bd9e9b6366be1cf3415b"
integrity sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==
dependencies:
brace-expansion "^2.0.1"
minimatch@~3.0.2:
version "3.0.8"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.8.tgz#5e6a59bd11e2ab0de1cfb843eb2d82e546c321c1"
@ -17635,6 +17668,16 @@ recast@^0.20.0:
source-map "~0.6.1"
tslib "^2.0.1"
recast@^0.21.1:
version "0.21.1"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.21.1.tgz#9b3f4f68c1fe9c1513a1c02ff572fdef02231de2"
integrity sha512-PF61BHLaOGF5oIKTpSrDM6Qfy2d7DIx5qblgqG+wjqHuFH97OgAqBYFIJwEuHTrM6pQGT17IJ8D0C/jVu/0tig==
dependencies:
ast-types "0.15.2"
esprima "~4.0.0"
source-map "~0.6.1"
tslib "^2.0.1"
recharts-scale@^0.4.4:
version "0.4.5"
resolved "https://registry.yarnpkg.com/recharts-scale/-/recharts-scale-0.4.5.tgz#0969271f14e732e642fcc5bd4ab270d6e87dd1d9"