sakura/scripts/options-export/dump-options.ts

32 lines
883 B
TypeScript
Raw Permalink Normal View History

2021-07-18 19:52:09 +08:00
import options from './options'
import { writeFileSync } from 'fs'
const exportOptions: { [key: string]: any } = {}
const optionTypesTemplate = (fill: string) => {
return `
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
// Generated by scripts/options-export/dump-options.ts
export interface SakuraOptions {
${fill}
}
`
}
let types = ''
2021-07-18 19:52:09 +08:00
Object.keys(options).forEach((tab) => {
options[tab].options.forEach((option) => {
if (option.depends) delete option.depends // remove function
exportOptions[option.namespace] = option
types += `'${option.namespace}': any, `
2021-07-18 19:52:09 +08:00
})
})
console.dir(exportOptions)
const optionTypes = optionTypesTemplate(types)
2021-07-18 19:52:09 +08:00
writeFileSync('./app/configs/options.json', JSON.stringify(exportOptions, null, 2), { flag: 'w+' })
writeFileSync('./src/admin/optionsType.ts', optionTypes, { flag: 'w+' })