加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
Orochi-sx 提交于 2023-08-05 15:58 . feat:提交文档代码
const fs = require('fs');
const path = require('path');
fs.readdir("./packages", (err, files) => {
files.forEach((item, index) => {
fs.readdirSync(path.resolve(__dirname, `./packages/${item}/output`)).forEach((item2) => {
if (item2.endsWith(".zip")) {
fs.renameSync(path.resolve(__dirname, `./packages/${item}/output/${item2}`), path.resolve(__dirname, `./packages/${item}/output/插件包.zip`))
}
if (item2.endsWith(".png") || item2.endsWith(".jpg")) {
fs.renameSync(path.resolve(__dirname, `./packages/${item}/output/${item2}`), path.resolve(__dirname, `./packages/${item}/output/preview.png`))
}
})
})
})
fs.readdir("./packages", (err, files) => {
let pic = [], zipFile = []
files.forEach((item) => {
!fs.existsSync(path.resolve(__dirname, `./packages/${item}/output/preview.png`)) && pic.push(item)
!fs.existsSync(path.resolve(__dirname, `./packages/${item}/output/插件包.zip`)) && zipFile.push(item)
})
console.log(`未传入zip包的样例:${JSON.stringify(zipFile, null, 2)}\n未传入预览图的样例:${JSON.stringify(pic, null, 2)}`);
})
const templates = require('./templates.json');
fs.readdir("./packages", (err, files) => {
let fileMap = files.map((item) => {
let itemArr = item.split("-")
let isVue = itemArr[itemArr.length - 2] === "vue" ? true : false
let picPath = fs.existsSync(path.resolve(__dirname, `./packages/${item}/output/preview.png`))
? `https://gitee.com/njsmartdata/sdata-plugins/raw/master/packages/${item}/output/preview.png`
: ""
let zipPath = fs.existsSync(path.resolve(__dirname, `./packages/${item}/output/插件包.zip`))
? encodeURI(`https://gitee.com/njsmartdata/sdata-plugins/raw/master/packages/${item}/output/插件包.zip`)
: "暂无"
let plugin = isVue ? itemArr.slice(0, -2).join("-") : itemArr.slice(0, -1).join("-")
let pluginName = templates[plugin].name
let templateType = isVue ? "Vue 2" : "React"
let sourcePath = `https://gitee.com/njsmartdata/sdata-plugins/tree/master/packages/${item}`
// return [picPath, pluginName, plugin, "", templateType, sourcePath, zipPath]
return {
picPath: picPath ? JSON.stringify([{previewUrl: picPath, url: picPath, name: picPath}]) : "暂无", pluginName, plugin, description: "", templateType, sourcePath, zipPath
}
})
fs.writeFile("./fileMap.json", JSON.stringify(fileMap, null, 2), () => {
})
console.log(fileMap);
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化