@@ -39,6 +39,8 @@ export function createGraphQLCommand(): Command {
39
39
} ) ;
40
40
}
41
41
42
+ export const graphQLCmd = createGraphQLCommand ( ) ;
43
+
42
44
export async function generateGraphQL ( options : GraphQLOptions ) : Promise < void > {
43
45
const protocols : Indexer . Protocol [ ] = [ "airdrops" , "flow" , "lockup" ] ;
44
46
const vendors = [ "graph" , "envio" ] ;
@@ -55,18 +57,21 @@ export async function generateGraphQL(options: GraphQLOptions): Promise<void> {
55
57
targetProtocols = _ . filter ( protocols , ( p ) => p === options . protocol ) ;
56
58
}
57
59
58
- const basePaths : string [ ] = [ ] ;
60
+ const docsPaths : string [ ] = [ ] ;
59
61
for ( const p of targetProtocols ) {
60
62
if ( options . vendor === "all" || options . vendor === "graph" ) {
61
- basePaths . push ( await generateGraph ( p ) ) ;
63
+ const docsPath = await generateGraph ( p ) ;
64
+ docsPaths . push ( docsPath ) ;
65
+ await runPrettier ( docsPath ) ;
62
66
}
63
67
if ( options . vendor === "all" || options . vendor === "envio" ) {
64
- basePaths . push ( await generateEnvio ( p ) ) ;
68
+ const docsPath = await generateEnvio ( p ) ;
69
+ docsPaths . push ( docsPath ) ;
70
+ await runPrettier ( docsPath ) ;
65
71
}
66
72
}
67
73
68
- cleanupDocs ( basePaths ) ;
69
- await runPrettier ( basePaths ) ;
74
+ cleanupDocs ( docsPaths ) ;
70
75
}
71
76
72
77
/* -------------------------------------------------------------------------- */
@@ -86,50 +91,50 @@ const ENUMS_CATEGORY: Category = { ...COLLAPSED, className: "hidden", label: "En
86
91
const INPUTS_CATEGORY : Category = { ...COLLAPSED , className : "hidden" , label : "Inputs" , position : 5 } ;
87
92
const SCALARS_CATEGORY : Category = { ...COLLAPSED , className : "hidden" , label : "Scalars" , position : 6 } ;
88
93
89
- function cleanupDocs ( basePaths : string [ ] ) : void {
90
- for ( const basePath of basePaths ) {
91
- fs . rmSync ( join ( basePath , "directives" ) , { force : true , recursive : true } ) ;
92
- fs . rmSync ( join ( basePath , "subscriptions" ) , { force : true , recursive : true } ) ;
94
+ function cleanupDocs ( docsPaths : string [ ] ) : void {
95
+ for ( const docsPath of docsPaths ) {
96
+ fs . rmSync ( join ( docsPath , "directives" ) , { force : true , recursive : true } ) ;
97
+ fs . rmSync ( join ( docsPath , "subscriptions" ) , { force : true , recursive : true } ) ;
93
98
94
99
// Delete all _category_.yml files
95
- fs . unlinkSync ( join ( basePath , "queries" , "_category_.yml" ) ) ;
96
- fs . unlinkSync ( join ( basePath , "enums" , "_category_.yml" ) ) ;
97
- fs . unlinkSync ( join ( basePath , "inputs" , "_category_.yml" ) ) ;
98
- fs . unlinkSync ( join ( basePath , "objects" , "_category_.yml" ) ) ;
99
- fs . unlinkSync ( join ( basePath , "scalars" , "_category_.yml" ) ) ;
100
+ fs . unlinkSync ( join ( docsPath , "queries" , "_category_.yml" ) ) ;
101
+ fs . unlinkSync ( join ( docsPath , "enums" , "_category_.yml" ) ) ;
102
+ fs . unlinkSync ( join ( docsPath , "inputs" , "_category_.yml" ) ) ;
103
+ fs . unlinkSync ( join ( docsPath , "objects" , "_category_.yml" ) ) ;
104
+ fs . unlinkSync ( join ( docsPath , "scalars" , "_category_.yml" ) ) ;
100
105
101
106
// Rewrite _category_.yml files
102
- fs . writeFileSync ( join ( basePath , "queries" , "_category_.yml" ) , yaml . dump ( QUERIES_CATEGORY ) ) ;
103
- fs . writeFileSync ( join ( basePath , "objects" , "_category_.yml" ) , yaml . dump ( OBJECTS_CATEGORY ) ) ;
104
- fs . writeFileSync ( join ( basePath , "enums" , "_category_.yml" ) , yaml . dump ( ENUMS_CATEGORY ) ) ;
105
- fs . writeFileSync ( join ( basePath , "inputs" , "_category_.yml" ) , yaml . dump ( INPUTS_CATEGORY ) ) ;
106
- fs . writeFileSync ( join ( basePath , "scalars" , "_category_.yml" ) , yaml . dump ( SCALARS_CATEGORY ) ) ;
107
+ fs . writeFileSync ( join ( docsPath , "queries" , "_category_.yml" ) , yaml . dump ( QUERIES_CATEGORY ) ) ;
108
+ fs . writeFileSync ( join ( docsPath , "objects" , "_category_.yml" ) , yaml . dump ( OBJECTS_CATEGORY ) ) ;
109
+ fs . writeFileSync ( join ( docsPath , "enums" , "_category_.yml" ) , yaml . dump ( ENUMS_CATEGORY ) ) ;
110
+ fs . writeFileSync ( join ( docsPath , "inputs" , "_category_.yml" ) , yaml . dump ( INPUTS_CATEGORY ) ) ;
111
+ fs . writeFileSync ( join ( docsPath , "scalars" , "_category_.yml" ) , yaml . dump ( SCALARS_CATEGORY ) ) ;
107
112
108
113
// Write vendor category file at base path
109
- if ( basePath . includes ( "envio" ) ) {
110
- fs . writeFileSync ( join ( basePath , "_category_.yml" ) , yaml . dump ( ENVIO_CATEGORY ) ) ;
111
- } else if ( basePath . includes ( "the-graph" ) ) {
112
- fs . writeFileSync ( join ( basePath , "_category_.yml" ) , yaml . dump ( THE_GRAPH_CATEGORY ) ) ;
114
+ if ( docsPath . includes ( "envio" ) ) {
115
+ fs . writeFileSync ( join ( docsPath , "_category_.yml" ) , yaml . dump ( ENVIO_CATEGORY ) ) ;
116
+ } else if ( docsPath . includes ( "the-graph" ) ) {
117
+ fs . writeFileSync ( join ( docsPath , "_category_.yml" ) , yaml . dump ( THE_GRAPH_CATEGORY ) ) ;
113
118
}
114
119
}
115
120
}
116
121
117
122
async function generateEnvio ( protocol : Indexer . Protocol ) : Promise < string > {
118
- const basePath = `./docs/api/${ protocol } /graphql/envio` ;
123
+ const docsPath = `./docs/api/${ protocol } /graphql/envio` ;
119
124
const schemaURL = getSablierIndexerEnvio ( { chainId : CHAIN_ID_SEPOLIA , protocol } ) . endpoint . url ;
120
125
121
- await runGenerator ( basePath , schemaURL ) ;
126
+ await runGenerator ( docsPath , schemaURL ) ;
122
127
console . log ( `✔️ Generated GraphQL docs for Envio vendor and ${ _ . capitalize ( protocol ) } protocol\n` ) ;
123
- return basePath ;
128
+ return docsPath ;
124
129
}
125
130
126
131
async function generateGraph ( protocol : Indexer . Protocol ) : Promise < string > {
127
- const basePath = `./docs/api/${ protocol } /graphql/the-graph` ;
132
+ const docsPath = `./docs/api/${ protocol } /graphql/the-graph` ;
128
133
const schemaURL = `https://api.studio.thegraph.com/query/112500/sablier-${ protocol } -experimental/version/latest` ;
129
134
130
- await runGenerator ( basePath , schemaURL ) ;
135
+ await runGenerator ( docsPath , schemaURL ) ;
131
136
console . log ( `✔️ Generated GraphQL docs for The Graph vendor and ${ _ . capitalize ( protocol ) } protocol\n` ) ;
132
- return basePath ;
137
+ return docsPath ;
133
138
}
134
139
135
140
/**
@@ -140,7 +145,6 @@ async function runGenerator(base: string, schema: string): Promise<void> {
140
145
await $ ( "bun" , [ "docusaurus" , "graphql-to-doc" , "--base" , base , "--schema" , schema ] , { stdio : "inherit" } ) ;
141
146
}
142
147
143
- async function runPrettier ( targetPaths : string [ ] ) : Promise < void > {
144
- const patterns = targetPaths . map ( ( path ) => `${ path } /**/*.{md,mdx,yml,yaml}` ) ;
145
- await $ ( "bun" , [ "prettier" , "--write" , ...patterns ] ) ;
148
+ async function runPrettier ( targetPath : string ) : Promise < void > {
149
+ await $ ( "bun" , [ "prettier" , "--write" , `${ targetPath } /**/*.{md,mdx,yml,yaml}` ] ) ;
146
150
}
0 commit comments