小程序仓库路径统一化完成
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -2,7 +2,7 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
unpackage/
|
unpackage/
|
||||||
dist/
|
dist/
|
||||||
|
lib/
|
||||||
# local env files
|
# local env files
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
@@ -24,5 +24,4 @@ yarn-error.log*
|
|||||||
/package-lock.json
|
/package-lock.json
|
||||||
/.hbuilderx/launch.json
|
/.hbuilderx/launch.json
|
||||||
/src/pages.json
|
/src/pages.json
|
||||||
/src/mods/project/
|
|
||||||
/src/pages/apps.json
|
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ const getDirs = (dir, list = [], cb) => {
|
|||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
getDirs(path.join(__dirname, '..', 'src'), [], (dir, path) => {
|
getDirs(path.join(__dirname, '..', 'src'), [], (dir, path) => {
|
||||||
if (dir.name == "apps") {
|
if (["apps"].includes(dir.name)) {
|
||||||
fse.remove(path)
|
fse.remove(path)
|
||||||
console.log("已清除%s", path)
|
console.log("已清除%s", path)
|
||||||
}
|
}
|
||||||
return dir.name != "apps"
|
return !["apps"].includes(dir.name)
|
||||||
})
|
})
|
||||||
|
fse.remove(path.join(__dirname, '..', 'lib'))
|
||||||
|
|||||||
16
bin/lib.js
Normal file
16
bin/lib.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const {findApp, chalkTag, copyFiles} = require("./tools");
|
||||||
|
const start = () => {
|
||||||
|
chalkTag.info("扫描主库目录,并搬运打包应用至lib文件夹下")
|
||||||
|
let apps = []
|
||||||
|
findApp('src/mods', file => apps.push(file))
|
||||||
|
.then(() => Promise.all([...new Set(apps)].map(e => {
|
||||||
|
let name = e.replace(/.+[\\\/]([^\\\/]+)$/, '$1')
|
||||||
|
if (/^App/.test(name)) {
|
||||||
|
return copyFiles(`lib/${name}`, e)
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
.then(() => {
|
||||||
|
chalkTag.done("打包完成")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
start()
|
||||||
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')
|
const axios = require('axios')
|
||||||
/**
|
const {chalkTag, findApp, fsExtra, fs} = require("./tools");
|
||||||
* 将函数封装成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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}) || [])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
let apps = {list: [], desc: "用于产品库主页面获取应用使用"}
|
let apps = {list: [], desc: "用于产品库主页面获取应用使用"}
|
||||||
const getFileInfo = (app, file) => {
|
const getFileInfo = (app, file) => {
|
||||||
let vue = fs.readFileSync(file).toString()
|
let vue = fs.readFileSync(file).toString()
|
||||||
@@ -70,7 +16,11 @@ const getFileInfo = (app, file) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const saveApps = app => {
|
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 = () => {
|
const start = () => {
|
||||||
chalkTag.info('开始生成pages.json...')
|
chalkTag.info('开始生成pages.json...')
|
||||||
|
|||||||
70
bin/tools.js
Normal file
70
bin/tools.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
const fsExtra = require('fs-extra')
|
||||||
|
const path = require('path')
|
||||||
|
const chalk = require('chalk')
|
||||||
|
const fs = require('fs')
|
||||||
|
/**
|
||||||
|
* 将函数封装成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 {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(dir)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}) || [])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const copyFiles = (dir, source = 'src/mods') => {
|
||||||
|
chalkTag.info(`开始扫描${source}...`)
|
||||||
|
return new Promise(resolve => {
|
||||||
|
fsExtra.emptyDir(dir, err => {
|
||||||
|
if (!err) {
|
||||||
|
fsExtra.copy(source, dir).then(() => {
|
||||||
|
chalkTag.done(source + ' 扫描完毕')
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
module.exports = {findApp, chalkTag, fsExtra, copyFiles, fs, path}
|
||||||
@@ -6,12 +6,12 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node bin/pages.js&&cross-env NODE_ENV=development VUE_APP_CW_MODE=dev UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch --minimize",
|
"dev": "node bin/pages.js&&cross-env NODE_ENV=development VUE_APP_CW_MODE=dev UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch --minimize",
|
||||||
"pages": "node bin/pages.js",
|
"pages": "node bin/pages.js",
|
||||||
"lib": "npm unpublish --force&&npm publish",
|
"lib": "node bin/lib.js&&npm unpublish --force&&npm publish&&node bin/clean.js",
|
||||||
"lib:all": "node src/project/build.js&&npm unpublish --workspaces --force&&npm publish --workspaces&&node bin/clean.js",
|
"lib:all": "node src/project/build.js&&npm unpublish --workspaces --force&&npm publish --workspaces&&node bin/clean.js",
|
||||||
"clean": "node bin/clean.js"
|
"clean": "node bin/clean.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/mods"
|
"lib"
|
||||||
],
|
],
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"src/components",
|
"src/components",
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export default {
|
|||||||
},
|
},
|
||||||
getApps() {
|
getApps() {
|
||||||
this.$instance.post("/node/wechatapps/list", null, {
|
this.$instance.post("/node/wechatapps/list", null, {
|
||||||
baseURL: "http://localhost:12525", params: {size: 999}
|
baseURL: "http://192.168.1.87:12525", params: {size: 999}
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res?.data) {
|
if (res?.data) {
|
||||||
this.apps = res.data.records.map(e => ({...e, path: e.libPath}))
|
this.apps = res.data.records.map(e => ({...e, path: e.libPath}))
|
||||||
|
|||||||
@@ -1,77 +1,5 @@
|
|||||||
const fsExtra = require('fs-extra')
|
const {chalkTag, fsExtra, findApp, copyFiles, fs, path} = require("../../bin/tools");
|
||||||
const path = require('path')
|
|
||||||
const chalk = require('chalk')
|
|
||||||
const fs = require('fs')
|
|
||||||
const {exec} = require("child_process");
|
|
||||||
/**
|
|
||||||
* 将函数封装成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 {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(dir)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}) || [])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 迁移apps文件
|
|
||||||
*/
|
|
||||||
const copyFiles = (dir, source = 'src/mods') => {
|
|
||||||
chalkTag.info(`开始扫描${source}...`)
|
|
||||||
return new Promise(resolve => {
|
|
||||||
fsExtra.emptyDir(dir, err => {
|
|
||||||
if (!err) {
|
|
||||||
fsExtra.copy(source, dir).then(() => {
|
|
||||||
chalkTag.done(source + ' 扫描完毕')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* 初始化打包配置文件
|
* 初始化打包配置文件
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user