"
+ ],
+ "abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ]
+ },
+ "ios" : {},
+ "sdkConfigs" : {
+ "oauth" : {
+ "univerify" : {},
+ "apple" : {},
+ "weixin" : {
+ "appid" : "wxffdd8fa6ec4ef2a0",
+ "appsecret" : "",
+ "UniversalLinks" : ""
+ }
+ },
+ "ad" : {},
+ "share" : {
+ "weixin" : {
+ "appid" : "wxffdd8fa6ec4ef2a0",
+ "UniversalLinks" : ""
+ }
+ },
+ "geolocation" : {},
+ "push" : {
+ "unipush" : {}
+ },
+ "payment" : {}
+ }
+ },
+ "nvueLaunchMode" : ""
+ },
+ "quickapp" : {},
+ "mp-weixin" : {
+ "appid" : "",
+ "setting" : {
+ "urlCheck" : false,
+ "es6" : false
+ },
+ "usingComponents" : true,
+ "betterScopedSlots" : true
+ },
+ "mp-alipay" : {
+ "usingComponents" : true
+ },
+ "mp-baidu" : {
+ "usingComponents" : true
+ },
+ "mp-toutiao" : {
+ "usingComponents" : true
+ },
+ "uniStatistics" : {
+ "enable" : false
+ },
+ "h5" : {
+ "template" : ""
+ }
+}
diff --git a/uni_modules_tools/copy/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json b/uni_modules_tools/copy/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..02ce9bbf5736bc5d4f76b9cc71d64416435daf1f
--- /dev/null
+++ b/uni_modules_tools/copy/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json
@@ -0,0 +1,52 @@
+{
+ "passwordSecret": "passwordSecret-demo",
+ "tokenSecret": "tokenSecret-demo",
+ "tokenExpiresIn": 7200,
+ "tokenExpiresThreshold": 600,
+ "passwordErrorLimit": 6,
+ "bindTokenToDevice": true,
+ "passwordErrorRetryTime": 3600,
+ "autoSetInviteCode": false,
+ "forceInviteCode": false,
+ "app-plus": {
+ "tokenExpiresIn": 2592000,
+ "oauth": {
+ "weixin": {
+ "appid": "wxffdd8fa6ec4ef2a0",
+ "appsecret": "6c9119430d7be0a147bcbbb73ef33acf"
+ },
+ "apple": {
+ "bundleId": "io.dcloud.hellouniapp"
+ }
+ }
+ },
+ "mp-weixin": {
+ "oauth": {
+ "weixin": {
+ "appid": "wx81dbb061d2258234",
+ "appsecret": "73be6e8b8b31b7b0783fe448cc1fe820"
+ }
+ }
+ },
+ "mp-alipay": {
+ "oauth": {
+ "alipay": {
+ "appid": "alipay appid",
+ "privateKey": "alipay privateKey"
+ }
+ }
+ },
+ "service": {
+ "sms": {
+ "name": "DCloud",
+ "codeExpiresIn": 300,
+ "smsKey": "71a19f38c954f7d768d68a050486bf15",
+ "smsSecret": "d6c424b702d73baa3b6e1a1452469213"
+ },
+ "univerify": {
+ "appid": "__UNI__03B096E",
+ "apiKey": "3fc28519d90d74173bcecf2daf4ffcc4",
+ "apiSecret": "dd793e5bc4b372ce932f35bbb4c5d61b"
+ }
+ }
+}
\ No newline at end of file
diff --git a/uni_modules_tools/main.js b/uni_modules_tools/main.js
new file mode 100644
index 0000000000000000000000000000000000000000..4e2b476d6af259c84f37b54264dc561bfbfcb652
--- /dev/null
+++ b/uni_modules_tools/main.js
@@ -0,0 +1,91 @@
+//脚本文件目录 __dirname
+//运行脚本的目录,即:项目的目录 process.cwd()
+
+//配置文件
+const fs = require('fs'),
+ Hjson = require('hjson'),
+ config = Hjson.rt.parse(fs.readFileSync(__dirname+'/config.js', 'utf-8'))
+
+
+if(process.argv[2] == 'change'){
+ change(config)
+}else{
+ recovery(config)
+}
+
+function change(config){
+ for (let fileName in config) {
+ let path = process.cwd() + fileName
+ let copyPath = __dirname + '/copy' + fileName
+ let fileText = fs.readFileSync(path, 'utf-8')
+ //保持原文件名先备份一份到脚本目录下
+ 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);
+ }
+ })
+ })
+ }
+}
+
+
+
+
+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{
+ mergeJSON(minor[key], main[key]);
+ }
+ }
+}
\ No newline at end of file
diff --git a/uni_modules_tools/package-lock.json b/uni_modules_tools/package-lock.json
new file mode 100644
index 0000000000000000000000000000000000000000..7a3b4c4bd5ab89a20746339325d4926efbd28c1e
--- /dev/null
+++ b/uni_modules_tools/package-lock.json
@@ -0,0 +1,30 @@
+{
+ "name": "uni_modules_tools",
+ "version": "1.0.0",
+ "lockfileVersion": 2,
+ "requires": true,
+ "packages": {
+ "": {
+ "version": "1.0.0",
+ "license": "ISC",
+ "dependencies": {
+ "hjson": "^3.2.2"
+ }
+ },
+ "node_modules/hjson": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/hjson/-/hjson-3.2.2.tgz",
+ "integrity": "sha512-MkUeB0cTIlppeSsndgESkfFD21T2nXPRaBStLtf3cAYA2bVEFdXlodZB0TukwZiobPD1Ksax5DK4RTZeaXCI3Q==",
+ "bin": {
+ "hjson": "bin/hjson"
+ }
+ }
+ },
+ "dependencies": {
+ "hjson": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/hjson/-/hjson-3.2.2.tgz",
+ "integrity": "sha512-MkUeB0cTIlppeSsndgESkfFD21T2nXPRaBStLtf3cAYA2bVEFdXlodZB0TukwZiobPD1Ksax5DK4RTZeaXCI3Q=="
+ }
+ }
+}
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