@@ -8,40 +8,35 @@ import { showManual } from './manual'
8
8
import { getFiles } from './files'
9
9
10
10
// Helper function to generate namespace from file path (cross-platform)
11
- const generateNamespaceFromPath = ( filePath : string , projectName ? : string ) : string => {
11
+ const generateNamespaceFromPath = ( filePath : string , projectName : string ) : string => {
12
12
const dir = path . dirname ( filePath )
13
13
14
- // If project name is provided, construct namespace by finding the project name in the path
15
- // and using everything after it
16
- if ( projectName ) {
17
- // First, normalize the path to dots
18
- const normalizedDir = path . normalize ( dir )
19
- . replace ( / ^ \. [ \\ / ] / , '' ) // Remove leading ./ or .\
20
- . replace ( / [ \\ / ] + / g, '.' ) // Convert all path separators to dots
21
-
22
- // Find the project name in the normalized path
23
- const projectIndex = normalizedDir . indexOf ( projectName )
24
- if ( projectIndex !== - 1 ) {
25
- const pathAfterProject = normalizedDir . substring ( projectIndex + projectName . length )
26
- // Clean up any leading dots
27
- const cleanPathAfterProject = pathAfterProject . replace ( / ^ \. + / , '' )
28
- return `${ projectName } ${ cleanPathAfterProject ? '.' + cleanPathAfterProject : '' } `
29
- }
30
-
31
- // If project name not found in path, just prepend it
32
- return `${ projectName } .${ normalizedDir } `
14
+ // First, normalize the path to dots
15
+ const normalizedDir = path . normalize ( dir )
16
+ . replace ( / ^ \. [ \\ / ] / , '' ) // Remove leading ./ or .\
17
+ . replace ( / [ \\ / ] + / g, '.' ) // Convert all path separators to dots
18
+
19
+ // Find the project name in the normalized path
20
+ const projectIndex = normalizedDir . indexOf ( projectName )
21
+ if ( projectIndex !== - 1 ) {
22
+ const pathAfterProject = normalizedDir . substring ( projectIndex + projectName . length )
23
+ // Clean up any leading dots
24
+ const cleanPathAfterProject = pathAfterProject . replace ( / ^ \. + / , '' )
25
+ return `${ projectName } ${ cleanPathAfterProject ? '.' + cleanPathAfterProject : '' } `
33
26
}
34
-
35
- // Normalize path separators and remove leading ./ or .\
36
- const normalizedDir = path . normalize ( dir )
37
- . replace ( / ^ \. [ \\ / ] / , '' ) // Remove leading ./ or .\
38
- . replace ( / [ \\ / ] + / g, '.' ) // Convert all path separators to dots
39
-
40
- return normalizedDir
27
+
28
+ // If project name not found in path, just prepend it
29
+ return `${ projectName } .${ normalizedDir } `
41
30
}
42
31
43
32
// Helper function to create dynamic config content based on GraphQL files (cross-platform)
44
- const createDynamicConfig = ( schemaUrl : string , graphqlFiles : string [ ] , graphqlDir : string , projectName ? : string , headers ?: string [ ] ) : string => {
33
+ const createDynamicConfig = (
34
+ schemaUrl : string ,
35
+ graphqlFiles : string [ ] ,
36
+ graphqlDir : string ,
37
+ projectName : string ,
38
+ headers ?: string [ ]
39
+ ) : string => {
45
40
let config = `# generated by agoda-graphql-csharp-generator
46
41
overwrite: true
47
42
schema: "${ schemaUrl } "
@@ -152,21 +147,18 @@ export const run = async (): Promise<void> => {
152
147
const ymlOut = getArgValue ( '--yml-out' )
153
148
const headers = getHeaderArgs ( )
154
149
155
- if ( ! rawGraphqlDirectory || ! schemaUrl ) {
156
- console . error ( 'Usage: script --graphql-dir <dir> --schema-url <url> [ --graphql-project <project-name>] [--yml-out <output-path>]' )
150
+ if ( ! rawGraphqlDirectory || ! schemaUrl || ! graphqlProject ) {
151
+ console . error ( 'Usage: script --graphql-dir <dir> --schema-url <url> --graphql-project <project-name> [--header <name:value >] [--yml-out <output-path>]' )
157
152
process . exit ( 1 )
158
153
}
159
154
160
- // Determine the config file path
161
- const tempConfigPath = ymlOut ? path . resolve ( ymlOut ) : path . join ( currentDir , 'codegen.yml' )
155
+ const outputConfigFilePath = ymlOut ? path . resolve ( ymlOut ) : path . join ( currentDir , 'codegen.yml' )
162
156
163
157
console . log ( 'raw graphql directory: ' , rawGraphqlDirectory )
164
158
console . log ( 'graphql schema url: ' , schemaUrl )
165
- if ( graphqlProject ) {
166
- console . log ( 'graphql project: ' , graphqlProject )
167
- }
159
+ console . log ( 'graphql project: ' , graphqlProject )
168
160
if ( ymlOut ) {
169
- console . log ( 'yml output path: ' , ymlOut )
161
+ console . log ( 'yml output path: ' , outputConfigFilePath )
170
162
}
171
163
if ( headers . length > 0 ) {
172
164
console . log ( 'headers: ' , headers )
@@ -186,9 +178,9 @@ export const run = async (): Promise<void> => {
186
178
console . log ( 'Creating dynamic config content...' )
187
179
const dynamicConfigContent = createDynamicConfig ( schemaUrl , graphqlFiles , rawGraphqlDirectory , graphqlProject , headers )
188
180
189
- const configFileName = path . basename ( tempConfigPath )
190
- console . log ( `Creating ${ configFileName } at:` , tempConfigPath )
191
- await fs . writeFile ( tempConfigPath , dynamicConfigContent , 'utf8' )
181
+ const configFileName = path . basename ( outputConfigFilePath )
182
+ console . log ( `Creating ${ configFileName } at:` , outputConfigFilePath )
183
+ await fs . writeFile ( outputConfigFilePath , dynamicConfigContent , 'utf8' )
192
184
console . log ( `Successfully created ${ configFileName } ` )
193
185
194
186
} catch ( error ) {
0 commit comments