postCodegen.ts 1.2 KB

1234567891011121314151617181920
  1. // A script to be executed post hydra codegen, that may include modifications to autogenerated files
  2. import fs from 'fs'
  3. import path from 'path'
  4. // TS4 useUnknownInCatchVariables is not compatible with auto-generated code inside generated/graphql-server
  5. const serverTsConfigPath = path.resolve(__dirname, '../../generated/graphql-server/tsconfig.json')
  6. const serverTsConfig = JSON.parse(fs.readFileSync(serverTsConfigPath).toString())
  7. serverTsConfig.compilerOptions.useUnknownInCatchVariables = false
  8. fs.writeFileSync(serverTsConfigPath, JSON.stringify(serverTsConfig, undefined, 2))
  9. // Type assertions are no longer needed for createTypeUnsafe in @polkadot/api 5.9.1 (and they break the build)
  10. // Here we're relpacing createTypeUnsafe<Assertions>(...params) to createTypeUnsafe(...params) in all generated types:
  11. const generatedTypesPaths = path.resolve(__dirname, '../generated/types')
  12. fs.readdirSync(generatedTypesPaths).map((fileName) => {
  13. if (path.extname(fileName) === '.ts') {
  14. const filePath = path.join(generatedTypesPaths, fileName)
  15. const fileContent = fs.readFileSync(filePath).toString()
  16. fs.writeFileSync(filePath, fileContent.replace(/createTypeUnsafe<[^(]+[(]/g, 'createTypeUnsafe('))
  17. }
  18. })