-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtypes-post-processor.mjs
More file actions
36 lines (30 loc) · 930 Bytes
/
types-post-processor.mjs
File metadata and controls
36 lines (30 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { readFileSync, writeFileSync } from 'fs';
// These are types autogenerated by the graphql-codegen that we need to prefix
// so they don't collide with the types from the different services
const helperTypes = [
'Maybe',
'InputMaybe',
'Exact',
'Incremental',
'MakeOptional',
'MakeMaybe',
'MakeEmpty',
'Scalars',
];
const [, , filePath] = process.argv;
if (!filePath) {
console.log('File type is missing');
process.exit(1);
}
const fileContent = readFileSync(filePath, 'utf-8');
let modifiedContent = fileContent;
// Avoid exporting the helper types so they don't collide among the different services types
helperTypes.forEach((type) => {
modifiedContent = modifiedContent.replaceAll(
`export type ${type}`,
`type ${type}`
);
});
// Avoid using "any" type in the helper types
modifiedContent = modifiedContent.replaceAll(': any', ': unknown');
writeFileSync(filePath, modifiedContent);