naive-ui/scripts/generate-style-imports.js

25 lines
721 B
JavaScript
Raw Normal View History

2020-11-03 13:04:24 +08:00
const fs = require('fs').promises
const path = require('path')
const { camelCase } = require('lodash')
;(async () => {
const srcPath = path.resolve(__dirname, '..', 'src')
const files = await fs.opendir(
srcPath
)
let code = ''
for await (const file of files) {
if (file.isDirectory() && !file.name.startsWith('_')) {
if (await fs.stat(path.resolve(srcPath, file.name, 'styles')).then(() => false).catch(() => {
return true
})) continue
code += `export {
${camelCase(file.name)}Dark,
${camelCase(file.name)}Light
} from '../${file.name}/styles\n`
// await fs.writeFile(path.resolve(srcPath, file.name, 'styles', 'index.js'), code)
}
}
console.log(code)
})()