小程序仓库路径统一化完成
This commit is contained in:
62
bin/pages.js
62
bin/pages.js
@@ -1,59 +1,5 @@
|
||||
const fsExtra = require('fs-extra')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const axios = require('axios')
|
||||
/**
|
||||
* 将函数封装成promise
|
||||
*/
|
||||
const promisify = fn => {
|
||||
return function () {
|
||||
let args = arguments;
|
||||
return new Promise(function (resolve, reject) {
|
||||
[].push.call(args, function (err, result) {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
fn.apply(null, args);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const readdir = promisify(fs.readdir)
|
||||
const stat = promisify(fs.stat)
|
||||
/**
|
||||
* 封装打印工具
|
||||
*/
|
||||
const chalk = require('chalk')
|
||||
const {log} = console
|
||||
const chalkTag = {
|
||||
info: msg => log([chalk.bgBlue.black(' INFO '), msg].join(' ')),
|
||||
done: msg => log([chalk.bgGreen.black(' DONE '), msg].join(' ')),
|
||||
warn: msg => log([chalk.bgYellow.black(' WARN '), msg].join(' ')),
|
||||
error: msg => log([chalk.bgRed.black(' ERROR '), msg].join(' ')),
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历应用的方法
|
||||
*/
|
||||
const findApp = (dir, cb) => {
|
||||
fsExtra.ensureDirSync(dir)
|
||||
return readdir(dir).then(apps => {
|
||||
return Promise.all(apps.map(e => {
|
||||
let cPath = path.join(dir, e)
|
||||
return stat(cPath).then(state => {
|
||||
if (state.isDirectory()) {
|
||||
return findApp(cPath, cb)
|
||||
} else if (state.isFile()) {
|
||||
cb && cb(cPath)
|
||||
}
|
||||
})
|
||||
}) || [])
|
||||
})
|
||||
}
|
||||
const {chalkTag, findApp, fsExtra, fs} = require("./tools");
|
||||
let apps = {list: [], desc: "用于产品库主页面获取应用使用"}
|
||||
const getFileInfo = (app, file) => {
|
||||
let vue = fs.readFileSync(file).toString()
|
||||
@@ -70,7 +16,11 @@ const getFileInfo = (app, file) => {
|
||||
}
|
||||
}
|
||||
const saveApps = app => {
|
||||
axios.post("http://localhost:12525/node/wechatapps/addOrUpdate", app).catch(() => 0)
|
||||
if (app.list.length > 0) {
|
||||
axios.post("http://192.168.1.87:12525/node/wechatapps/addOrUpdate", app).then(res => {
|
||||
if (res?.code == 0) chalkTag.done("产品库目录已同步至后台数据库...")
|
||||
}).catch(() => 0)
|
||||
}
|
||||
}
|
||||
const start = () => {
|
||||
chalkTag.info('开始生成pages.json...')
|
||||
|
||||
Reference in New Issue
Block a user