|
1 | 1 | import * as fs from 'fs' |
2 | 2 | import * as http from 'https' |
3 | 3 | import * as async from 'async' |
| 4 | +import * as path from 'path' |
4 | 5 | import { ContentTypeCollection } from 'contentstack' |
5 | 6 | import {HttpClient, cliux, configHandler} from '@contentstack/cli-utilities' |
6 | 7 | import {schemaToInterfaces, generateNamespace} from '@gql2ts/from-schema' |
@@ -160,7 +161,7 @@ export async function getGlobalFields(config: StackConnectionConfig, cdaHost: st |
160 | 161 | } |
161 | 162 | } |
162 | 163 |
|
163 | | -export async function generateGraphQLTypeDef(config: StackConnectionConfig, outPath: string, namespace: string) { |
| 164 | +export async function generateGraphQLTypeDef(config: StackConnectionConfig, outputFile: string, namespace: string) { |
164 | 165 | const spinner = cliux.loaderV2('Fetching graphql schema...') |
165 | 166 | try { |
166 | 167 | if (!GRAPHQL_REGION_URL_MAPPING[config.region]) { |
@@ -192,10 +193,15 @@ export async function generateGraphQLTypeDef(config: StackConnectionConfig, outP |
192 | 193 | } else { |
193 | 194 | schema = schemaToInterfaces(result?.data) |
194 | 195 | } |
195 | | - fs.writeFileSync(outPath, schema) |
| 196 | + |
| 197 | + //Create and write type def in file |
| 198 | + const outputPath = path.resolve(process.cwd(), outputFile) |
| 199 | + const dirName = path.dirname(outputPath) |
| 200 | + fs.mkdirSync(dirName, {recursive: true}) |
| 201 | + fs.writeFileSync(outputPath, schema) |
196 | 202 |
|
197 | 203 | return { |
198 | | - outputPath: outPath, |
| 204 | + outputPath: outputPath, |
199 | 205 | } |
200 | 206 | } catch (error: any) { |
201 | 207 | cliux.loaderV2('', spinner) |
|
0 commit comments