This commit is contained in:
1518079148
2023-08-21 11:35:19 +08:00
parent 37125ab0c1
commit 64938d5c51
29 changed files with 291 additions and 137 deletions

35
单文件拆分/index.ts Normal file
View File

@@ -0,0 +1,35 @@
import { resolve, join } from 'path'
import FileUtil from './src/utils/FileUtil'
const siconUrl = resolve('E:/repo/code/wty-web-cloud-las-0/src/components/sicon')
const staticIconUrl = resolve('E:/repo/code/wty-web-cloud-las-0/public/static_res/sicon')
const init = async () => {
await FileUtil.deleteFileOrDirectory(staticIconUrl)
await FileUtil.readDirectory(siconUrl, async (filepath: string) => {
if (filepath.endsWith('.ts')) {
const filename =
filepath
.substring(filepath.lastIndexOf('\\') + 1)
.split('.')
.shift() || ''
try {
let fstr = await FileUtil.readFile(filepath)
fstr = fstr.split(`export const ${filename}Name`)[0]
fstr = fstr.split('=')[1]
const ctx = JSON.parse(fstr.replaceAll("'", '"'))
Object.keys(ctx).forEach((key) => {
let _res = JSON.stringify(ctx[key])
if(typeof ctx[key] === 'string'){
_res = _res.substring(1,_res.length-1)
}
FileUtil.writeFile(join(staticIconUrl, `./${filename}/${key}.json`), _res)
})
} catch {
console.log('处理失败', filename)
}
}
})
}
init()