diff --git a/changelog.md b/changelog.md index 6bdccbd2df49b0165680d170f124cce14a543576..de06bfba3ff59cbee25400047aa998a855397f75 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ -## 2.0.0(2022-08-10) -- 重要:应用`uni-id-pages`、`uniIdRouter` +## 2.0.1(2022-09-16) +- 更改默认值 +## 2.0.0(2022-09-16) +- 【重要】 v2版正式发布 应用`uni-id-pages`、`uniIdRouter`;(注意:此版本更新内容较多,升级请注意备份) +- 考虑到部分旧项目不想升级,保留`uni-starter v1`版源码,托管在仓库的[v1分支](https://gitcode.net/dcloud/uni-starter/-/blob/v1/README.md);继续使用v1版,遇到问题可以提交[Issue](https://gitcode.net/dcloud/uni-starter/-/issues/new?issue%5Bassignee_id%5D=&issue%5Bmilestone_id%5D=)有bug仍然会修复,但v1版本不再新增功能。 ## 1.2.7(2022-08-10) - 修复微信小程序绑定手机号失败的问题 ## 1.2.6(2022-06-29) diff --git a/package.json b/package.json index 09cc29fa421763fd15488a314e2a963caac67695..7ffaa5073a60d678a988327e4c4504d2b668f1cc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "id": "uni-starter", "displayName": "uni-starter", - "version": "2.0.0", + "version": "2.0.1", "description": "云端一体应用快速开发基本项目模版", "keywords": [ "login", diff --git a/uni_modules.config.json b/uni_modules.config.json new file mode 100644 index 0000000000000000000000000000000000000000..3d01554c86e45b1cdb2edece03b413a3504d9641 --- /dev/null +++ b/uni_modules.config.json @@ -0,0 +1,6 @@ +{ + "scripts":{ + "preupload": "node uni_modules_tools/main.js change", + "postupload": "node uni_modules_tools/main.js recovery" + } +} \ No newline at end of file diff --git a/uni_modules_tools/change_after.js b/uni_modules_tools/change_after.js new file mode 100644 index 0000000000000000000000000000000000000000..431dc4e0f2c2898ec2bd616dd66ed769f5b9538e --- /dev/null +++ b/uni_modules_tools/change_after.js @@ -0,0 +1,27 @@ +const fs = require('fs'); +module.exports = function(){ + console.log('开始执行脚本change_after'); +/* let changelog = fs.readFileSync(process.cwd() + '/changelog.md', 'utf-8').split("##")[1].split("\n").slice(1).join(' '); + console.log(changelog); + // 这里是修改完相关敏感配置后执行的脚本,你可以在这里自定义逻辑, + + + // 比如执行git提交命令 + var shell = require("shelljs"); + var exec = shell.exec; + + if (exec('git add .').code !== 0) { + shell.echo('Error: Git add failed'); + shell.exit(1); + } + if (exec(`git commit -a -m "${changelog}"`).code !== 0) { + shell.echo('Error: Git commit failed'); + shell.exit(1); + } + if (exec('git push').code !== 0) { + shell.echo('Error: Git commit failed'); + shell.exit(1); + } + shell.exec(`echo git success ${changelog}`); + */ +} \ No newline at end of file diff --git a/uni_modules_tools/config.js b/uni_modules_tools/config.js new file mode 100644 index 0000000000000000000000000000000000000000..25f997222c9074f7417d65ec0c74a14e6e1c41f5 --- /dev/null +++ b/uni_modules_tools/config.js @@ -0,0 +1,84 @@ +// "文件路径" : {"键名":"改成什么"} +{ + "/manifest.json": { + "appid": "", + "name": "", + "versionName": "", + "mp-weixin": { + "appid": "" + }, + "vueVersion": "2", + "app-plus": { + "modules": { + "OAuth": {} + }, + "distribute": { + "sdkConfigs": { + "oauth": { + "univerify": {}, + "weixin": { + "appid": "", + "appsecret": "", + "UniversalLinks": "" + }, + "apple": {} + } + } + } + } + }, + "/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json": { + "tokenExpiresIn": 7200, + "app": { + "oauth": { + "weixin": { + "appid": "填写来源微信开放平台https://open.weixin.qq.com/创建的应用的appid", + "appsecret": "填写来源微信开放平台https://open.weixin.qq.com/创建的应用的appsecret" + }, + "apple": { + "bundleId": "苹果开发者后台获取的bundleId" + } + } + }, + "web": { + "oauth": { + "h5-weixin": { + "appid": "微信浏览器内微信登录,所用的微信公众号appid", + "appsecret": "微信公众号后台获取的appsecret" + }, + "web-weixin": { + "appid": "手机微信扫码登录,所用的微信开放平台(https://open.weixin.qq.com/)-网站应用的appid", + "appsecret": "微信开放平台-网站应用的appsecret" + } + } + }, + "mp-weixin": { + "oauth": { + "weixin": { + "appid": "微信小程序登录所用的appid、appsecret需要在对应的小程序管理控制台获取", + "appsecret": "微信小程序后台获取的appsecret" + } + } + }, + "mp-alipay": { + "oauth": { + "alipay": { + "appid": "支付宝小程序登录用到的appid、privateKey请参考支付宝小程序的文档进行设置或者获取,https://opendocs.alipay.com/open/291/105971#LDsXr", + "privateKey": "支付宝小程序登录用到的appid、privateKey请参考支付宝小程序的文档进行设置或者获取,https://opendocs.alipay.com/open/291/105971#LDsXr" + } + } + }, + "service": { + "sms": { + "name": "应用名称,对应短信模版的name", + "smsKey": "短信密钥key,开通短信服务处可以看到", + "smsSecret": "短信密钥secret,开通短信服务处可以看到" + }, + "univerify": { + "appid": "当前应用的appid,使用云函数URL化,此项必须配置", + "apiKey": "apiKey 和 apiSecret 在开发者中心获取,开发者中心:https://dev.dcloud.net.cn/uniLogin/index?type=0,文档:https://ask.dcloud.net.cn/article/37965", + "apiSecret": "" + } + } + } +} diff --git a/uni_modules_tools/main.js b/uni_modules_tools/main.js new file mode 100644 index 0000000000000000000000000000000000000000..475ce97438334c63c33637122f21522cb216aaf6 --- /dev/null +++ b/uni_modules_tools/main.js @@ -0,0 +1,103 @@ +//脚本文件目录 __dirname +//运行脚本的目录,即:项目的目录 process.cwd() + +//配置文件 +const fs = require('fs'), + Hjson = require('hjson'), + config = Hjson.rt.parse(fs.readFileSync(__dirname+'/config.js', 'utf-8')) +const change_after = require('./change_after') + +if(process.argv[2] == 'change'){ + change(config,()=>{ + console.log('脚本change已经执行成功'); + change_after() + }) +}else{ + recovery(config) +} + +function change(config,callback){ + const total = Object.keys(config).length + let index = 0; + for (let fileName in config) { + let path = process.cwd() + fileName + let copyPath = __dirname + '/copy' + fileName + let fileText = fs.readFileSync(path, 'utf-8') + //保持原文件名先备份一份到/uni_modules_tools/copy目录下,然后再覆盖 + writeFileRecursive(copyPath, fileText, function(err) { //创建目录并写入文件 + if (err) { + return console.log(err); + } + //改写 + let HfileObj = Hjson.rt.parse(fileText) + //递归合并,为了保留注释内容 + mergeJSON(HfileObj,config[fileName]) + + fs.writeFile(path, Hjson.rt.stringify(HfileObj, { + quotes: 'all', + separator: true, + multiline: "off", + bracesSameLine: true + }), function(err) { + if (err) { + return console.log(err); + } + index++ + if(index == total){ + callback() + } + }) + }) + } +} + + + + +function recovery(){ + let paths = Object.keys(config) + console.log(paths); + paths.forEach(path=>{ + console.log(__dirname + '/copy' + path); + let oldFile = fs.readFileSync(__dirname + '/copy' + path) + console.log(process.cwd() + path); + fs.writeFile(process.cwd() + path, oldFile, function(err) { + if (err) { + console.log(err); + return + } + // fs.unlinkSync(__dirname + path+'.lock') + }) + }) +} + + + + + + +//创建目录并写入文件 +function writeFileRecursive(path, buffer, callback) { + let lastPath = path.substring(0, path.lastIndexOf("/")); + fs.mkdir(lastPath, { + recursive: true + }, (err) => { + if (err) return callback(err); + fs.writeFile(path, buffer, function(err) { + if (err) return callback(err); + return callback(null); + }); + }); +} + +//递归合并,为了保留注释内容 +function mergeJSON(minor, main) { + for (var key in main) { + if (typeof(main[key]) != 'object' ) { + minor[key] = main[key]; + }else{ + console.log('[',minor[key], main[key],']'); + mergeJSON(minor[key], main[key]); + } + } +} \ No newline at end of file diff --git a/uni_modules_tools/package.json b/uni_modules_tools/package.json new file mode 100644 index 0000000000000000000000000000000000000000..5fdc53706ecffa46d9d9ae7c3988cb3a578c7fa1 --- /dev/null +++ b/uni_modules_tools/package.json @@ -0,0 +1,14 @@ +{ + "name": "uni_modules_tools", + "version": "1.0.0", + "description": "本插件是一个[uni_modules钩子脚本](https://uniapp.dcloud.io/uni_modules?id=uni_modulesconfigjson),仅限uni_modules插件使用 #### 为什么使用 uni_modules_tools 在实际开发中很多插件需要配置文件才可以正常运行,比如uni-id、uni-pay等; 有些配置内容属于密钥,在发表到插件市场的时候我们通常不希望这些配置被暴露。 传统的方式你需要手动备份密钥内容,上传结束后再将配置填回。这样插件作者发表插件会比较不便。", + "main": "main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "hjson": "^3.2.2" + } +} diff --git a/uni_modules_tools/readme.md b/uni_modules_tools/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..dc309e5a6df36c0bc81b04000281ea47ffdce03f --- /dev/null +++ b/uni_modules_tools/readme.md @@ -0,0 +1,84 @@ +本插件是一个[uni_modules钩子脚本](https://uniapp.dcloud.io/uni_modules?id=uni_modulesconfigjson),仅限uni_modules插件使用 +#### 为什么使用 uni_modules_tools +在实际开发中很多插件需要配置文件才可以正常运行,比如uni-id、uni-pay等; +有些配置内容属于密钥,在发表到插件市场的时候我们通常不希望这些配置被暴露。 +传统的方式你需要手动备份密钥内容,上传结束后再将配置填回。这样插件作者发表插件会比较不便。 + +而现在有了 `uni_modules_tools` 只需配置`/uni_modules_tools/config.js`即实现 +- 在插件上传之前,自动根据配置改写项目中对应配置。 +- 上传结束(成功和失败都触发)后自动恢复项目中的配置。 + +#### 示例目录结构 +
+├─ uni_modules						// 存放uni_module规范的插件。
+│	└─uni-config-center
+│		└─uniCloud
+│			└─cloudfunctions
+│				└─common
+│					└─uni-config-center
+│						└─uni-id
+│							└─config.json
+├─ manifest.json
+├─ uni_modules.config.json		//uni_modules的配置文件
+└─ uni_modules_tools
+	├─ copy						//用于自动修改配置文件时的,临时备份目录
+	├─ config.js				//插件配置文件,下面会有示例说明
+	├─ main.js					//插件核心代码,入口文件;你无需修改此文件中的代码,除非你了解内部逻辑
+	└─ readme.md 				//插件文档
+
+ + +#### 使用方式 +`/uni_modules_tools/config.js`的格式为: +``` +{ + "文件路径" : {"键名":"改后的内容"} +} +``` + +- 文件仅支持json格式,如:`manifest.json`、`uni-config-center`下的`config.json`等 + +使用示例,比如你需要: +- 修改manifest.json文件的appid内容改为:请重新获取appid +- 修改uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json 文件的内容app-plus -> oauth -> weixin 和 apple 下的 `appid` `appsecret` `apple`值为:`请填写你的自己的appid` `请填写你的自己的appsecret` `请填写你的自己的bundleId` + +1. 配置,根目录下的`/uni_modules_tools/config.js`文件,如下: + +``` +{ + "/manifest.json": { + "appid": "请重新获取appid" + }, + "/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json": { + "app-plus": { + "oauth": { + "weixin": { + "appid": "请填写你的自己的appid", + "appsecret": "请填写你的自己的appsecret" + }, + "apple": { + "bundleId": "请填写你的自己的bundleId" + } + } + } + } +} +``` + +2. 根目录下的`/uni_modules.config.json`配置如下: +``` +{ + "scripts":{ + "preupload": "node uni_modules_tools/main.js change", + "postupload": "node uni_modules_tools/main.js recovery" + } +} +``` + +3. 项目依赖hjson-js需要在uni_modules_tools目录,执行npm install完成依赖的安装 + +#### 测试方式 +- 在项目根目录直接执行 `node uni_modules_tools/main.js change` 即可测试修改相关配置的效果 +- 在项目根目录直接执行 `node uni_modules_tools/main.js recovery` 即可测试恢复相关配置的效果 + +> 本插件中使用了[hjson-js](https://www.npmjs.com/package/hjson) 感谢@hjson-js的作者 \ No newline at end of file