const fs = require('fs');
const path = require('path');
global.nv_theme_list = ()=>{
/*返回:
存在 theme.json 才处理进去
[
{
"folder": "xxxxx",
"error": Boolean, //不存在 function.js
"name": "客户端渲染主题示例",
"url": "",
"description": "nvPress自带默认主题",
"version": "0.0.1",
"author": "PANDA Studio",
"author_url": "",
},
...
]
*/
const themeDir = path.join(process.cwd(),'./nv-themes')
const all_themes = [];
try{
fs.readdirSync(themeDir).forEach(folderName=>{
const filePath = path.join(themeDir,folderName);
if ( fs.statSync(filePath).isDirectory() ) {
const themeInfo = path.join(filePath,'./theme.json');
const themeEntrance = path.join(filePath,'./function.js');
try{
if ( fs.statSync(themeInfo).isFile() ) {
try {
var themeJson = require(themeInfo);
} catch(e) {
themeJson = {error:true};
// console.log("主题theme.json格式错误:"+folderName)
}
all_themes.push({
folder: folderName,
error: !fs.statSync(themeEntrance).isFile(),
...themeJson,
})
}
} catch(e) {
all_themes.push({
folder: folderName,
error: true,
})
}
}
})
} catch(e) {
console.log("读取主题信息异常:"+e)
}
return all_themes;
}
global.get_theme_path = sub_path=> path.join(
process.cwd(),
'./nv-themes',
global.nv_current_theme_folder || "",
sub_path || ""
)