import { workspace } from "vscode" ; import * as fs from "fs" ; import * as path from "path" ; import { jsConfig } from "./constants" ; import { getFullAppPath } from "./config" ; const pathExists = require ( "path-exists" ) ; const merge = require ( "merge" ) ; export function appendJSConfig ( data ) { if ( ! workspace || ! workspace . rootPath ) { return false ; } let jscPath = path . join ( getFullAppPath ( ) , "jsconfig.json" ) ; let newJsc , mergedJsc , currentJsc ; if ( pathExists . sync ( jscPath ) ) { let extensionConfig = workspace . getConfiguration ( 'vsc-ember-cli' ) ; if ( ! extensionConfig . updateJSConfig ) { return false ; } try { currentJsc = JSON . parse ( fs . readFileSync ( jscPath , "utf8" ) ) ; mergedJsc = merge ( currentJsc , data ) ; } catch ( e ) { console . log ( e ) ; } } try { newJsc = mergedJsc || jsConfig ; fs . writeFileSync ( jscPath , JSON . stringify ( newJsc ) , "utf8" ) ; } catch ( e ) { return false ; } } export function hasFile ( file ) { if ( ! workspace || ! workspace . rootPath ) { return false ; } return pathExists . sync ( path . join ( getFullAppPath ( ) , file ) ) ; }