import * as fs from 'fs' ; import * as yargs from 'yargs' ; import { join } from 'path' ; import { getSupplemental } from '../../../cldr' ; import { getCurrencyInfo } from './currency' ; import { getMatching } from './matching' ; import { getMetazones } from './metazones' ; import { getPlurals } from './plurals' ; import { getPluralRanges } from './pluralranges' ; import { getSubtags } from './subtags' ; import { getSymbols } from './symbols' ; import { getTimeData } from './timedata' ; import { getWeekData } from './weekdata' ; const supplemental = getSupplemental ( ) ; const getAliases = ( ) : any => supplemental . Aliases ; const OUTPUTS = { aliases : getAliases , currencyinfo : getCurrencyInfo , matching : getMatching , metazones : getMetazones , plurals : getPlurals , pluralranges : getPluralRanges , subtags : getSubtags , symbols : getSymbols , timedata : getTimeData , weekdata : getWeekData , } ; const save = ( name , data ) : void => { const root = join ( __dirname , '..' , '..' , '..' , '..' , 'temp' ) ; if ( ! fs . existsSync ( root ) ) { fs . mkdirSync ( root ) ; } const path = join ( root , `${ name }.json` ) ; const json = JSON . stringify ( data , undefined , 2 ) ; console . warn ( `Writing ${ path }` ) ; fs . writeFileSync ( path , json , { encoding : 'utf-8' } ) ; } ; interface PreprocessOptions { which ? : string [ ] ; } const run = ( args ) : void => { let keys = Object . keys ( OUTPUTS ) . sort ( ) ; if ( args . which ) { keys = args . which ; } for ( const key of keys ) { const impl = OUTPUTS [ key ] ; save ( key , impl ( ) ) ; } } ; export const preprocessOptions = ( argv ) => argv . command ( 'data' , 'Preprocess data files' , ( y ) => y . option ( 'w' , { alias : 'which' , type : 'array' , description : 'Which data' } ) . choices ( 'w' , Object . keys ( OUTPUTS ) ) , run ) ;