-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathembed-graphql.js
95 lines (91 loc) · 2.77 KB
/
embed-graphql.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const fs = require("fs");
const path = require("path");
//const chokidar = require("chokidar");
const filesToEmbed = [
{
source: path.resolve(__dirname, "./src/graphql/queries/userVaults.graphql"),
target: path.resolve(__dirname, "./src/graphql/queries/userVaults.ts"),
variableName: "userVaults",
},
{
source: path.resolve(
__dirname,
"./src/graphql/queries/userVaultBalances.graphql",
),
target: path.resolve(
__dirname,
"./src/graphql/queries/userVaultBalances.ts",
),
variableName: "userVaultBalances",
},
{
source: path.resolve(__dirname, "./src/graphql/queries/pools.graphql"),
target: path.resolve(__dirname, "./src/graphql/queries/pools.ts"),
variableName: "pools",
},
{
source: path.resolve(__dirname, "./src/graphql/queries/investors.graphql"),
target: path.resolve(__dirname, "./src/graphql/queries/investors.ts"),
variableName: "investors",
},
{
source: path.resolve(__dirname, "./src/graphql/queries/cetusPools.graphql"),
target: path.resolve(__dirname, "./src/graphql/queries/cetusPools.ts"),
variableName: "cetusPools",
},
{
source: path.resolve(
__dirname,
"./src/graphql/queries/autoCompoundEvents.graphql",
),
target: path.resolve(
__dirname,
"./src/graphql/queries/autoCompoundEvents.ts",
),
variableName: "autoCompoundEvents",
},
{
source: path.resolve(__dirname, "./src/graphql/queries/nftHolders.graphql"),
target: path.resolve(__dirname, "./src/graphql/queries/nftHolders.ts"),
variableName: "nftHolders",
},
{
source: path.resolve(
__dirname,
"./src/graphql/queries/receiptData.graphql",
),
target: path.resolve(__dirname, "./src/graphql/queries/receiptData.ts"),
variableName: "receiptData",
},
{
source: path.resolve(
__dirname,
"./src/graphql/queries/lockedTableDataFragment.graphql",
),
target: path.resolve(
__dirname,
"./src/graphql/queries/lockedTableDataFragment.ts",
),
variableName: "lockedTableDataFragment",
},
{
source: path.resolve(
__dirname,
"./src/graphql/queries/lockedTableData.graphql",
),
target: path.resolve(__dirname, "./src/graphql/queries/lockedTableData.ts"),
variableName: "lockedTableData",
},
];
function embedGraphQL() {
filesToEmbed.forEach(({ source, target, variableName }) => {
const content = fs.readFileSync(source, "utf-8");
const tsContent = `export const ${variableName} = \`${content}\`;`;
fs.writeFileSync(target, tsContent);
console.log(`Embedded ${path.basename(source)} into ${target}`);
});
}
// Run initially
embedGraphQL();
// Watch for changes in GraphQL files and re-embed
// chokidar.watch(filesToEmbed.map((f) => f.source)).on("change", embedGraphQL);