import { SchematicsException , Tree } from "@angular-devkit/schematics" ; import * as fs from "fs" ; function throwPathNotFound ( path ) { throw new SchematicsException ( `Could not find ${ path }` ) ; } export function readFileFromFS ( path ) { return fs . readFileSync ( path , { encoding : "utf-8" } ) ; } export function readFile ( host , path ) { const buffer = host . read ( path ) ; if ( buffer ) { return buffer . toString ( "utf-8" ) ; } throwPathNotFound ( path ) ; } export function writeFile ( path , content , host ) { host . overwrite ( path , content ) ; } export function getJSON < T > ( host , path ) { if ( ! host . exists ( path ) ) { throwPathNotFound ( path ) ; } const sourceText = readFile ( host , path ) ; return JSON . parse ( sourceText ) ; } export function getJSONFromFS < T > ( path ) { if ( ! fs . existsSync ( path ) ) { throwPathNotFound ( path ) ; } const sourceText = readFileFromFS ( path ) ; return JSON . parse ( sourceText ) ; } export function setJSON ( host , path , content ) { host . overwrite ( path , JSON . stringify ( content , null , 2 ) ) ; return host ; }