Skip to content

Commit

Permalink
Cleanup of GraphQL codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
timowestnosto committed Nov 15, 2023
1 parent 1d2a39f commit f7f8693
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 504 deletions.
14 changes: 14 additions & 0 deletions cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fs from "fs"

const fileName = "src/api/search/generated.ts"
let fileContents = fs.readFileSync(fileName, "utf8")

fileContents = fileContents.replaceAll(/export type (Maybe|InputMaybe|Exact|Make|Incremental).*$/gm, "")
fileContents = fileContents.replaceAll(/InputMaybe<(.+)>;$/gm, "$1")
fileContents = fileContents.replaceAll(/Maybe<(.+)>;$/gm, "$1")
fileContents = fileContents.replaceAll(/Scalars\['(ID|String)'\]\['\w+'\]/gm, "string")
fileContents = fileContents.replaceAll(/Scalars\['Boolean'\]\['\w+'\]/gm, "boolean")
fileContents = fileContents.replaceAll(/Scalars\['(Int|Float)'\]\['\w+'\]/gm, "number")
fileContents = fileContents.replaceAll(/Scalars\['Json'\]\['\w+'\]/gm, "unknown")
fileContents = fileContents.replaceAll(/Array<(\w+)>/gm, "$1[]")
fs.writeFileSync(fileName, fileContents.trim())
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"build:docs": "typedoc src/index.ts",
"build:site": "npm run build:docs && npm run test:cov && rm -rf site && cp -r./docs ./site && cp -r./examples ./site/examples && cp -r./coverage ./site/coverage",
"lint": "eslint 'src/**/*.{ts,tsx}' --cache",
"prettify": "prettier --write \"{src,spec}/**/*.ts\"",
"prettify": "node cleanup.js && prettier --write \"{src,spec}/**/*.ts\"",
"test": "jest spec",
"test:cov": "jest --coverage spec && make-coverage-badge",
"codegen": "graphql-codegen",
Expand Down
Loading

0 comments on commit f7f8693

Please sign in to comment.