import { SchematicContext , SchematicsException , Tree } from '@angular-devkit/schematics' ; import { IConfigFile } from '@ngx-i18nsupport/ngx-i18nsupport' ; /**
 * Read and edit functionality on xliffmerge.json
 * It allows changes on xliffmerge.json file.
 * At the end we call commit() to write angular.json.
 */ export class XliffmergeConfigJsonSnapshot { private readonly xliffmergeConfigJson : IConfigFile ; private readonly configPath : string ; param filename param host param context throws constructor ( filename , private host , private context ? ) { this . configPath = filename ; this . xliffmergeConfigJson = this . readXliffmergeConfigJson ( ) ; } public getXliffmergeConfigJson ( ) { return this . xliffmergeConfigJson ; } /**
     * Commit all changes done on workspace.
     * (writes angular.json)
     */ public commit ( ) { const newConfigJsonContent = JSON . stringify ( this . xliffmergeConfigJson , null , 2 ) ; this . host . overwrite ( this . configPath , newConfigJsonContent ) ; } public addLanguagesToXliffmergeConfiguration ( languagesToAdd ) { if ( ! this . xliffmergeConfigJson . xliffmergeOptions ) { this . xliffmergeConfigJson . xliffmergeOptions = { } ; } const newLanguagesArray = [ ] ; const languages = this . xliffmergeConfigJson . xliffmergeOptions . languages ; if ( languages ) { newLanguagesArray . push ( ... languages ) ; } newLanguagesArray . push ( ... languagesToAdd ) ; this . xliffmergeConfigJson . xliffmergeOptions . languages = newLanguagesArray ; if ( this . context ) { this . context . logger . info ( `changed ${ this . configPath }, added languages` ) ; } } return private readXliffmergeConfigJson ( ) { const content = this . host . read ( this . configPath ) ; if ( ! content ) { const msg = `Did not find any configuration information (${ this . configPath })` ; if ( this . context ) { this . context . logger . fatal ( msg ) ; } throw new SchematicsException ( msg ) ; } const contentString = content . toString ( 'UTF-8' ) ; return JSON . parse ( contentString ) as IConfigFile ; } }