import fs from 'fs' ; import { IBuild , TRootDir , TTheme , TSetting , TBaseProps , TCreateFile , } from './types' ; import { Scss } from '../scss' ; export default class Build implements IBuild { readonly rootDir : TRootDir ; public settings : TSetting = { fileType : 'json' , } ; public scss = new Scss ( ) ; public theme : TTheme = { stage : { } , final : { } , variants : [ ] , } ; constructor param { TBaseProps } props constructor ( { rootDir } ) { this . rootDir = rootDir ; } method get listThemes ( ) : string [ ] { return fs . readdirSync ( this . rootDir . themes ) . filter ( theme => theme . match ( /\.[0-9a-z]+$/i ) ) ; } method param { String } pathFile getFile ( pathFile ) { return JSON . parse ( fs . readFileSync ( pathFile , 'utf8' ) ) ; } method param { TCreateFile } options param { String } options . path param { String } options . file param { String } options . fileName createFile ( { path , file , fileName } ) { if ( ! fs . existsSync ( path ) ) { fs . mkdirSync ( path ) ; } fs . writeFileSync ( `${ path }/${ fileName }` , JSON . stringify ( file ) , { encoding : 'utf8' , } ) ; return 'created' ; } method setColors ( ) { const theme = this . theme . stage ; Object . entries ( this . scss . getColors ( null , theme . variant ) ) . forEach ( ( [ nameColor , color ] ) => { this . theme . stage = JSON . parse ( JSON . stringify ( this . theme . stage ) . replace ( new RegExp ( `\\${ nameColor }` , 'g' ) , color ) ) ; } ) ; return this ; } }