From 2515d1ff0772a6ec4c966680430cd55fa12dcf10 Mon Sep 17 00:00:00 2001 From: aixianling Date: Tue, 1 Mar 2022 18:01:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=88=86=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 7 +- project/build.js | 124 +++++++++++++++++++++++++ project/shandong10086/.gitignore | 24 +++++ project/shandong10086/apps.import.json | 15 +++ project/shandong10086/package.json | 9 ++ 5 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 project/build.js create mode 100644 project/shandong10086/.gitignore create mode 100644 project/shandong10086/apps.import.json create mode 100644 project/shandong10086/package.json diff --git a/package.json b/package.json index 83b3492..4b59597 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,9 @@ "author": "Kubbo", "scripts": { "dev:mp-weixin": "node bin/serve.js&&cross-env NODE_ENV=development VUE_APP_CW_MODE=dev UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch --minimize", - "lib": "npm unpublish --force&&npm publish&&npm unpublish --workspaces --force&&npm publish --workspaces", - "pages": "node bin/serve.js" + "lib": "npm unpublish --force&&npm publish", + "pages": "node bin/serve.js", + "lib:all": "node project/build.js&&npm unpublish --workspaces --force&&npm publish --workspaces" }, "files": [ "src/mods", @@ -15,7 +16,7 @@ ], "workspaces": [ "src/components", - "src/project/*" + "project/*" ], "dependencies": { "@dcloudio/uni-app-plus": "^2.0.1-33320211224001", diff --git a/project/build.js b/project/build.js new file mode 100644 index 0000000..70de82c --- /dev/null +++ b/project/build.js @@ -0,0 +1,124 @@ +const fsExtra = require('fs-extra') +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() + }) + } + }) + }) +} +/** + * 初始化打包配置文件 + */ +const init = () => { + chalkTag.info('开始运行项目打包工具...') + return new Promise(resolve => fs.readdir('./project', (err, files) => { + resolve(files.filter(e => e.indexOf('.') < 0)) + })) +} +/** + * 拷贝对应文件 + */ +const generateMain = project => { + const getApps = new Promise(resolve => { + const appLib = path.join(__dirname, project.toString(), 'apps.import.json') + fsExtra.readJson(appLib, (err, data) => { + chalkTag.info(project + '加载业务应用配置...') + let apps = [] + if (data) { + fsExtra.emptyDirSync(`project/${project}/apps`) + findApp('src/mods', file => { + apps.push(file) + }).then(() => { + Promise.all(Object.keys(data).map(e => { + let app = [...new Set(apps)].find(s => s.indexOf(e) > -1) + if (app) { + return copyFiles(`project/${project}/apps/${e}`, app) + } + })).then(() => { + chalkTag.done(project + '业务应用加载完成') + resolve() + }) + }) + } else { + chalkTag.done(project + '业务应用无打包') + resolve() + } + }) + }) + return Promise.all([getApps]) +} +const start = () => { + //询问打包哪个项目 + init().then(choices => { + return Promise.all(choices.map(prj => generateMain(prj))).then(() => { + chalkTag.info('开始发布...') + }) + }) +} +start(); diff --git a/project/shandong10086/.gitignore b/project/shandong10086/.gitignore new file mode 100644 index 0000000..a95154a --- /dev/null +++ b/project/shandong10086/.gitignore @@ -0,0 +1,24 @@ +.DS_Store +node_modules/ +unpackage/ +dist/ + +# local env files +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Editor directories and files +.project +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw* +apps/ diff --git a/project/shandong10086/apps.import.json b/project/shandong10086/apps.import.json new file mode 100644 index 0000000..66c1d31 --- /dev/null +++ b/project/shandong10086/apps.import.json @@ -0,0 +1,15 @@ +{ + "AppAddressBook": "便民通讯录", + "AppContent": "内容发布", + "AppPhotoReport": "随手拍", + "AppServiceOnlineNew": "网上办事", + "AppReturnHomeRegister": "返乡登记", + "AppHealthReport": "健康上报", + "AppProgressNew": "办事指南", + "AppIntegralApply": "积分申请", + "AppCreditPoints": "信用积分", + "AppSupermarket": "积分超市", + "AppVillageInfo": "一村一群", + "AppVillageActivity": "居民活动", + "AppVideoSurve": "视频监控" +} diff --git a/project/shandong10086/package.json b/project/shandong10086/package.json new file mode 100644 index 0000000..85379bc --- /dev/null +++ b/project/shandong10086/package.json @@ -0,0 +1,9 @@ +{ + "name": "@dvcp-wechat-apps/shandong10086", + "version": "1.0.0", + "files": [ + "apps" + ], + "dependencies": { + } +}