@@ -12,10 +12,8 @@ const DataSourceTemplateCodeGenerator = require('./codegen/template')
12
12
const Watcher = require ( './watcher' )
13
13
const { step, withSpinner } = require ( './command-helpers/spinner' )
14
14
const { applyMigrations } = require ( './migrations' )
15
-
16
- const GENERATED_FILE_NOTE = `
17
- // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
18
- `
15
+ const { GENERATED_FILE_NOTE } = require ( './codegen/typescript' )
16
+ const { displayPath } = require ( './command-helpers/fs' )
19
17
20
18
module . exports = class TypeGenerator {
21
19
constructor ( options ) {
@@ -35,14 +33,6 @@ module.exports = class TypeGenerator {
35
33
} )
36
34
}
37
35
38
- static displayPath ( p ) {
39
- return path . relative ( process . cwd ( ) , p )
40
- }
41
-
42
- static getGeneratedFileNote ( ) {
43
- return GENERATED_FILE_NOTE
44
- }
45
-
46
36
async generateTypes ( ) {
47
37
try {
48
38
if ( ! this . options . skipMigrations && this . options . subgraphManifest ) {
@@ -85,7 +75,7 @@ module.exports = class TypeGenerator {
85
75
? this . options . subgraph
86
76
: Subgraph . load ( this . options . subgraphManifest , subgraphLoadOptions ) . result
87
77
} else {
88
- const manifestPath = TypeGenerator . displayPath ( this . options . subgraphManifest )
78
+ const manifestPath = displayPath ( this . options . subgraphManifest )
89
79
90
80
return await withSpinner (
91
81
`Load subgraph from ${ manifestPath } ` ,
@@ -104,9 +94,9 @@ module.exports = class TypeGenerator {
104
94
let maybeRelativePath = subgraph . getIn ( [ 'schema' , 'file' ] )
105
95
let absolutePath = path . resolve ( this . sourceDir , maybeRelativePath )
106
96
return await withSpinner (
107
- `Load GraphQL schema from ${ TypeGenerator . displayPath ( absolutePath ) } ` ,
108
- `Failed to load GraphQL schema from ${ TypeGenerator . displayPath ( absolutePath ) } ` ,
109
- `Warnings while loading GraphQL schema from ${ TypeGenerator . displayPath ( absolutePath ) } ` ,
97
+ `Load GraphQL schema from ${ displayPath ( absolutePath ) } ` ,
98
+ `Failed to load GraphQL schema from ${ displayPath ( absolutePath ) } ` ,
99
+ `Warnings while loading GraphQL schema from ${ displayPath ( absolutePath ) } ` ,
110
100
async spinner => {
111
101
let maybeRelativePath = subgraph . getIn ( [ 'schema' , 'file' ] )
112
102
let absolutePath = path . resolve ( this . sourceDir , maybeRelativePath )
@@ -125,7 +115,7 @@ module.exports = class TypeGenerator {
125
115
let codeGenerator = schema . codeGenerator ( )
126
116
let code = prettier . format (
127
117
[
128
- TypeGenerator . getGeneratedFileNote ( ) ,
118
+ GENERATED_FILE_NOTE ,
129
119
...codeGenerator . generateModuleImports ( ) ,
130
120
...codeGenerator . generateTypes ( ) ,
131
121
] . join ( '\n' ) ,
@@ -135,7 +125,7 @@ module.exports = class TypeGenerator {
135
125
)
136
126
137
127
let outputFile = path . join ( this . options . outputDir , 'schema.ts' )
138
- step ( spinner , 'Write types to' , TypeGenerator . displayPath ( outputFile ) )
128
+ step ( spinner , 'Write types to' , displayPath ( outputFile ) )
139
129
await fs . mkdirs ( path . dirname ( outputFile ) )
140
130
await fs . writeFile ( outputFile , code )
141
131
} ,
@@ -170,12 +160,12 @@ module.exports = class TypeGenerator {
170
160
} , immutable . List ( ) )
171
161
172
162
if ( ! codeSegments . isEmpty ( ) ) {
173
- let code = prettier . format ( [ TypeGenerator . getGeneratedFileNote ( ) , ...codeSegments ] . join ( '\n' ) , {
163
+ let code = prettier . format ( [ GENERATED_FILE_NOTE , ...codeSegments ] . join ( '\n' ) , {
174
164
parser : 'typescript' ,
175
165
} )
176
166
177
167
let outputFile = path . join ( this . options . outputDir , 'templates.ts' )
178
- step ( spinner , `Write types for templates to` , TypeGenerator . displayPath ( outputFile ) )
168
+ step ( spinner , `Write types for templates to` , displayPath ( outputFile ) )
179
169
await fs . mkdirs ( path . dirname ( outputFile ) )
180
170
await fs . writeFile ( outputFile , code )
181
171
}
@@ -217,7 +207,7 @@ module.exports = class TypeGenerator {
217
207
onReady : ( ) => ( spinner = toolbox . print . spin ( 'Watching subgraph files' ) ) ,
218
208
onTrigger : async changedFile => {
219
209
if ( changedFile !== undefined ) {
220
- spinner . info ( `File change detected: ${ TypeGenerator . displayPath ( changedFile ) } \n` )
210
+ spinner . info ( `File change detected: ${ displayPath ( changedFile ) } \n` )
221
211
}
222
212
await generator . generateTypes ( )
223
213
spinner . start ( )
0 commit comments