import * as fse from 'fs-extra' ; import * as upath from 'upath' ; import * as TypeScript from 'typescript' ; import { Shout } from './Shout' ; import chalk = require ( 'chalk' ) ; const fallbackTypeScriptConfig = { compilerOptions : { "target" : "ES2015" , "module" : "ESNext" , "lib" : [ "DOM" , "DOM.Iterable" , "ES2015" , ] , "resolveJsonModule" : true , "jsx" : "react" , "importHelpers" : false , "strict" : true , "noImplicitAny" : false , "noImplicitReturns" : true , "noFallthroughCasesInSwitch" : true , "moduleResolution" : "node" , "allowSyntheticDefaultImports" : true , "experimentalDecorators" : true , "forceConsistentCasingInFileNames" : true , "skipLibCheck" : true } } ; param folder param json export function parseTypescriptConfig ( folder , json ) { const o = JSON . parse ( JSON . stringify ( json ) ) ; const tsconfig = TypeScript . parseJsonConfigFileContent ( o , TypeScript . sys , folder ) ; if ( tsconfig . errors . length ) { const errorMessage = tsconfig . errors . map ( Q => Q . messageText . toString ( ) ) . join ( "\n\n" ) ; throw Error ( errorMessage ) ; } return tsconfig ; } param folder export async function tryReadTypeScriptConfigJson ( folder ) { const tsconfigJsonPath = upath . join ( folder , 'tsconfig.json' ) ; try { const tsconfigRaw = await fse . readFile ( tsconfigJsonPath , 'utf8' ) ; const parse = TypeScript . parseConfigFileTextToJson ( tsconfigJsonPath , tsconfigRaw ) ; parseTypescriptConfig ( folder , parse . config ) ; return parse . config ; } catch ( error ) { Shout . error ( 'when reading' , chalk . cyanBright ( tsconfigJsonPath ) , error ) ; Shout . warning ( 'Using the default fallback TypeScript configuration!' ) ; console . log ( fallbackTypeScriptConfig ) ; return fallbackTypeScriptConfig ; } }