提交 cae0e903 编写于 作者: DCloud_JSON's avatar DCloud_JSON

删除中可选链操作符,解决vue3版本在hbuilderX内置浏览器不兼容的问题

上级 394628f2
{
"name": "统一应用基本项目",
"name": "uuuu",
"appid": "请点击重新获取",
"description": "云端一体应用快速开发模版",
"versionName": "1.0.0",
......@@ -8,28 +8,23 @@
"app-plus": {
"locales": {
"en": {
// 英文
"name": "uni-starter", // 应用名称
"name": "uni-starter",
"android": {
"strings": {
//Android平台自定义字符串
"CustomKey": "CustomValue"
}
},
"ios": {
"privacyDescription": {
//iOS平台隐私访问描述信息
"NSPhotoLibraryUsageDescription": "access to the user’s photo library(read)"
},
"infoPlist": {
//iOS平台自定义InfoPlist.strings
"CustomKey": "CustomValue"
}
}
},
"zh": {
// 中文(简体)
"name": "统一应用基本项目" // 应用名称
"name": "统一应用基本项目"
}
},
"privacy": {
......@@ -224,6 +219,3 @@
"_spaceID": "",
"vueVersion": "2"
}
\ No newline at end of file
//...
// 中文(简体)
// 应用名称
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
// "文件路径" : {"键名":"改成什么"}
{
"/manifest.json": {
"appid": "请点击重新获取" ,//清空appid
"mp-weixin" : {
"appid" : ""
},
"app-plus" : {
"distribute" :{
"sdkConfigs" : {
"oauth" : {
"weixin" : {
"appid" : "",
"appsecret" : "",
"UniversalLinks" : ""
},
"univerify" : {}
},
"share" : {
"weixin" : {
"appid" : "",
"UniversalLinks" : ""
}
},
"geolocation" : {
"baidu" : {
"__platform__" : [ "ios", "android" ],
"appkey_ios" : "请填写地图的key",
"appkey_android" : "请填写地图的key"
}
}
}
}
},
"_spaceID" : "",
"vueVersion" : "2"
},
"/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json": {
"tokenExpiresIn": 7200,
"app-plus": {
"oauth": {
"weixin": {
"appid": "填写来源微信开放平台https://open.weixin.qq.com/创建的应用的appid",
"appsecret": "填写来源微信开放平台https://open.weixin.qq.com/创建的应用的appsecret"
},
"apple": {
"bundleId": "苹果开发者后台获取的bundleId"
}
}
},
"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": ""
}
}
}
}
\ No newline at end of file
//脚本文件目录 __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{
mergeJSON(minor[key], main[key]);
}
}
}
\ No newline at end of file
{
"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"
}
}
本插件是一个[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`即实现
- 在插件上传之前,自动根据配置改写项目中对应配置。
- 上传结束(成功和失败都触发)后自动恢复项目中的配置。
#### 示例目录结构
<pre>
├─ 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 //插件文档
</pre>
#### 使用方式
`/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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册