@@ -2,11 +2,12 @@ import * as fs from 'fs'
22import * as http from 'https'
33import * as async from 'async'
44import * as path from 'path'
5- import { ContentTypeCollection } from 'contentstack'
6- import { HttpClient , cliux , configHandler } from '@contentstack/cli-utilities'
7- import { schemaToInterfaces , generateNamespace } from '@gql2ts/from-schema'
5+ import { ContentTypeCollection } from 'contentstack'
6+ import { HttpClient , cliux , configHandler } from '@contentstack/cli-utilities'
7+ import { schemaToInterfaces , generateNamespace } from '@gql2ts/from-schema'
88
9- import { introspectionQuery } from '../../graphQL'
9+ import { introspectionQuery } from '../../graphQL'
10+ import { sanitizePath } from '../helper'
1011
1112type RegionUrlMap = {
1213 [ prop : string ] : string ;
@@ -35,7 +36,7 @@ export type StackConnectionConfig = {
3536 token : string ;
3637 region : any ;
3738 environment : string ;
38- branch ?: string | null ;
39+ branch ?: string | null ;
3940}
4041
4142const limit = 100
@@ -83,7 +84,7 @@ export async function stackConnect(client: any, config: StackConnectionConfig, c
8384
8485 if ( results . count > limit ) {
8586 const additionalQueries = Array . from (
86- { length : Math . ceil ( results . count / limit ) - 1 } ,
87+ { length : Math . ceil ( results . count / limit ) - 1 } ,
8788 ( _ , i ) => {
8889 return async . reflect ( async ( ) => {
8990 return stack . getContentTypes ( {
@@ -183,9 +184,9 @@ export async function generateGraphQLTypeDef(config: StackConnectionConfig, outp
183184 // Generate graphql schema with introspection query
184185 const url = `${ GRAPHQL_REGION_URL_MAPPING [ config . region ] } /${ config . apiKey } `
185186 const result = await new HttpClient ( )
186- . headers ( headers )
187- . queryParams ( query )
188- . post ( url , { query : introspectionQuery } )
187+ . headers ( headers )
188+ . queryParams ( query )
189+ . post ( url , { query : introspectionQuery } )
189190
190191 cliux . loaderV2 ( '' , spinner )
191192
@@ -197,9 +198,9 @@ export async function generateGraphQLTypeDef(config: StackConnectionConfig, outp
197198 }
198199
199200 //Create and write type def in file
200- const outputPath = path . resolve ( process . cwd ( ) , outputFile )
201+ const outputPath = path . resolve ( sanitizePath ( process . cwd ( ) ) , sanitizePath ( outputFile ) )
201202 const dirName = path . dirname ( outputPath )
202- fs . mkdirSync ( dirName , { recursive : true } )
203+ fs . mkdirSync ( dirName , { recursive : true } )
203204 fs . writeFileSync ( outputPath , schema )
204205
205206 return {
0 commit comments