Skip to content

Commit 4517f09

Browse files
committed
fix: directory issues
1 parent 36d73e0 commit 4517f09

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/lib/stack/client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs'
22
import * as http from 'https'
33
import * as async from 'async'
4+
import * as path from 'path'
45
import { ContentTypeCollection } from 'contentstack'
56
import {HttpClient, cliux, configHandler} from '@contentstack/cli-utilities'
67
import {schemaToInterfaces, generateNamespace} from '@gql2ts/from-schema'
@@ -160,7 +161,7 @@ export async function getGlobalFields(config: StackConnectionConfig, cdaHost: st
160161
}
161162
}
162163

163-
export async function generateGraphQLTypeDef(config: StackConnectionConfig, outPath: string, namespace: string) {
164+
export async function generateGraphQLTypeDef(config: StackConnectionConfig, outputFile: string, namespace: string) {
164165
const spinner = cliux.loaderV2('Fetching graphql schema...')
165166
try {
166167
if (!GRAPHQL_REGION_URL_MAPPING[config.region]) {
@@ -192,10 +193,15 @@ export async function generateGraphQLTypeDef(config: StackConnectionConfig, outP
192193
} else {
193194
schema = schemaToInterfaces(result?.data)
194195
}
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)
196202

197203
return {
198-
outputPath: outPath,
204+
outputPath: outputPath,
199205
}
200206
} catch (error: any) {
201207
cliux.loaderV2('', spinner)

0 commit comments

Comments
 (0)