const fs = require ( 'fs-extra' ) ; const { join } = require ( 'path' ) ; /**
 * 自动生成覆盖方法
 */ class OverrideGenerator { constructor ( ) { this . generateOverrideColors ( ) ; } defaultColorPalettes : string [ ] = [ 'blue' , 'purple' , 'cyan' , 'green' , 'magenta' , 'pink' , 'red' , 'orange' , 'yellow' , 'volcano' , 'geekblue' , 'lime' , 'gold' , ] ; overrideList : Record < string , string > = { colors : '' , } ; param colorPalettes generateOverrideColors = ( colorPalettes = this . defaultColorPalettes ) => { let overrideStr = '// overrides color palettes \n\n' ; colorPalettes . forEach ( ( color ) => { overrideStr += `@${ color }-base: var(--${ color }-base);\n` ; for ( let i = 1 ; i <= 10 ; i += 1 ) { const str = `@${ color }-${ i }: var(--${ color }-${ i });\n` ; overrideStr += `${ str }` ; } overrideStr += '\n' ; } ) ; this . overrideList . colors = overrideStr ; return overrideStr ; } ; param name generateOverrideToken = ( name ) => { return `@${ name }: var(--${ name });\n` ; } ; param path param fileMaps generateFiles = ( path = __dirname , fileMaps = [ 'colors' ] ) => { let fileContent = `/**
 * AUTO GENERATED OVERRIDE FILES!
 * Please add this file to .gitignore
 */\n` ; fileMaps . forEach ( ( key ) => { if ( key in this . overrideList ) { fileContent += this . overrideList [ key ] ; fileContent += '\n\n' ; } } ) ; this . writeFileHelper ( path , 'override.less' , fileContent ) ; } ; param dir param fileName param content private writeFileHelper = ( dir , fileName , content ) => { fs . ensureDirSync ( dir ) ; fs . writeFileSync ( join ( dir , fileName ) , content , { encoding : 'utf-8' , } ) ; } ; } export default OverrideGenerator ;