-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from biaov/release/v1.4.1
更新依赖并优化代码
- Loading branch information
Showing
51 changed files
with
949 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# 接口前缀 | ||
VITE_BASE_URL=https://ecosystem.biaov.cn/api | ||
|
||
# HBuilderX 账号 | ||
VITE_USERNAME= | ||
|
||
# HBuilderX 密码 | ||
VITE_PASSWORD= | ||
|
||
# wgt 包下载地址 | ||
VITE_WGT_URL=https://ecosystem.biaov.cn/uploads/upgrade.wgt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# 接口前缀 | ||
VITE_BASE_URL=https://ecosystem.biaov.cn/api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,4 @@ fonts | |
.prettierignore | ||
.prettierrc | ||
LICENSE | ||
package.json | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { existsSync, cpSync } from 'fs' | ||
import { resolve } from 'path' | ||
|
||
const { dirname } = import.meta | ||
const source = resolve(dirname, '../.env') | ||
const output = resolve(dirname, '../.env.development') | ||
|
||
!existsSync(output) && cpSync(source, output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"platform": "android", | ||
"android": { | ||
"packagename": "cn.ecosystem.android", | ||
"androidpacktype": "0", | ||
"certalias": "ecosystem", | ||
"certpassword": "123456", | ||
"channels": "" | ||
}, | ||
"iscustom": false, | ||
"safemode": true, | ||
"isconfusion": true, | ||
"splashads": false, | ||
"rpads": false, | ||
"pushads": false, | ||
"exchange": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { resolve } from 'path' | ||
import { cpSync, rmSync, existsSync, mkdirSync, renameSync } from 'fs' | ||
import { execSync } from 'child_process' | ||
import { loadEnv } from 'vite' | ||
import chalk from 'chalk' | ||
import manifestJson from '../src/manifest.json' assert { type: 'json' } | ||
|
||
/** | ||
* 转换路径 | ||
*/ | ||
const transformPath = path => path.replace(/\\/g, '/') | ||
|
||
/** | ||
* 相对路径 | ||
*/ | ||
const { dirname } = import.meta | ||
|
||
/** | ||
* 项目打包目录 | ||
*/ | ||
const output = resolve(dirname, '../dist/build/app') | ||
|
||
const outputUnpackage = resolve(output, 'unpackage') | ||
const keystore = resolve(outputUnpackage, 'res/ecosystem.keystore') | ||
const rmOption = { force: true, recursive: true } | ||
|
||
/** | ||
* 复制资源 | ||
*/ | ||
const unpackagePath = resolve(dirname, '../unpackage') | ||
|
||
cpSync(unpackagePath, outputUnpackage, rmOption) | ||
|
||
/** | ||
* 配置文件路径 | ||
*/ | ||
const configurePath = resolve(dirname, './configure.json') | ||
|
||
/** | ||
* 环境变量 | ||
*/ | ||
const env = loadEnv('development', resolve(dirname, '../')) | ||
const execOption = { encoding: 'utf-8' } | ||
|
||
const release = () => { | ||
execSync('cli open', execOption) | ||
const userInfo = execSync('cli user info', execOption) | ||
|
||
if (!userInfo) { | ||
if (!(env.VITE_USERNAME && env.VITE_PASSWORD)) return console.log(chalk.red('请先配置 HbuilderX 或 DCloud 的账号和密码')) | ||
const loginInfo = execSync(`cli user login --username ${env.VITE_USERNAME} --password ${env.VITE_PASSWORD}`, execOption) | ||
if (!loginInfo) return console.log(chalk.red('登录失败')) | ||
console.log(chalk.green('登录成功')) | ||
} | ||
|
||
const wgtDir = resolve(outputUnpackage, 'wgt') | ||
// 65001 | ||
existsSync(wgtDir) && rmSync(wgtDir, rmOption) | ||
mkdirSync(wgtDir) | ||
console.log() | ||
console.log(chalk.yellow(`开始生成 wgt 包...`)) | ||
console.log() | ||
execSync(`cli publish --platform APP --type wgt --project ${transformPath(output)} --path ${wgtDir} --name upgrade.wgt --confuse true`) | ||
console.log(chalk.green(`wgt 包生成完成,路径:${resolve(dirname, '../dist/build/app/unpackage/wgt/upgrade.wgt')}`)) | ||
console.log() | ||
/** | ||
* cli: HBuilderX 软件安装目录的 cli.exe | ||
* 由于配置了环境变量,因此此处可以直接可以使用 cli 命令 | ||
*/ | ||
console.log(chalk.yellow(`开始生成 apk...`)) | ||
|
||
const result = execSync(`cli pack --config ${transformPath(configurePath)} --project ${transformPath(output)} --android.certfile ${transformPath(keystore)}`, execOption) | ||
let pkgName = result.match(/(?<=dist\/build\/app\/unpackage\/release\/apk\/)(.+\.apk)/g) | ||
if (!pkgName) return console.log(chalk.red('打包失败')) | ||
pkgName = pkgName[0] | ||
const renameDest = resolve(outputUnpackage, `release/apk/ecosystem.${manifestJson.versionName}.apk`) | ||
renameSync(resolve(outputUnpackage, `release/apk/${pkgName}`), renameDest) | ||
console.log() | ||
console.log(chalk.green(`下载成功,APK 路径:${renameDest}`)) | ||
execSync('cli app quit', execOption) | ||
} | ||
release() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<template> | ||
<view-mask v-model:visible="modalVisible"> | ||
<view-modal title="更新提示" v-bind="modalPreset[modalTips.type]" @cancel="setModalVisible(false)" @ok="handleSubmit"> | ||
<view class="p-tb-60"> | ||
<progress-bar :progress="modalTips.progress" class="m-b-20" v-if="modalTips.type === 'progress'" /> | ||
<view class="color-primary fs-30">{{ modalTips.message }}</view> | ||
</view> | ||
</view-modal> | ||
</view-mask> | ||
</template> | ||
<script lang="ts" setup> | ||
import { useVisible } from '@/composables/useVisible' | ||
import { toast } from '@/utils/function' | ||
import { latestVersionApi } from '@/api/common' | ||
import type { AppUpgrador } from './types' | ||
const props = withDefaults( | ||
defineProps<{ | ||
/** | ||
* 显示状态 | ||
*/ | ||
visible?: boolean | ||
/** | ||
* 自动检查更新 | ||
*/ | ||
autoUpdate?: boolean | ||
}>(), | ||
{ | ||
visible: false, | ||
autoUpdate: false | ||
} | ||
) | ||
const [modalVisible, setModalVisible] = useVisible() | ||
const modalTips = ref<{ | ||
message: string | ||
type: string | ||
progress?: number | ||
}>({ message: '', type: '', progress: 0 }) | ||
const defaultPreset = { cancelText: '', okText: '知道了' } | ||
const noFooterPreset = { cancelText: '', okText: '' } | ||
const modalPreset: Readonly<AppUpgrador.ModalPreset> = Object.freeze({ | ||
upgrade: { cancelText: '不更新', okText: '更新' }, | ||
noUpgrade: defaultPreset, | ||
installFail: defaultPreset, | ||
installing: noFooterPreset, | ||
progress: noFooterPreset, | ||
success: defaultPreset, | ||
downloadFail: defaultPreset | ||
}) | ||
/** | ||
* 检测升级器 | ||
*/ | ||
const checkUpdator = async () => { | ||
const { name } = await latestVersionApi.get<{ name: string }>() | ||
const latestVersion = name.slice(1) | ||
const { appVersion } = uni.getSystemInfoSync() | ||
const version = appVersion.split('.') | ||
const latest = latestVersion.split('.') | ||
if (latest.some((value, i) => value > version[i])) { | ||
modalTips.value = { | ||
message: `发现最新版本 ${name},是否更新?体验更多功能`, | ||
type: 'upgrade' | ||
} | ||
setModalVisible(true) | ||
} else if (!props.autoUpdate) { | ||
modalTips.value = { | ||
message: `当前版本 v${appVersion} 已是最新版本`, | ||
type: 'noUpgrade' | ||
} | ||
setModalVisible(true) | ||
} | ||
} | ||
watch( | ||
() => props.visible, | ||
value => { | ||
if (!value) return | ||
// #ifdef APP-PLUS | ||
checkUpdator() | ||
// #endif | ||
// #ifndef APP-PLUS | ||
toast('只支持 APP 端') | ||
// #endif | ||
}, | ||
{ immediate: true } | ||
) | ||
/** | ||
* 格式化文件大小,Bytes -> M | ||
*/ | ||
const formatterSize = (value: number) => +(value / 1024 / 1024).toFixed(2) | ||
/** | ||
* 确定 | ||
*/ | ||
const handleSubmit = () => { | ||
switch (modalTips.value.type) { | ||
case 'upgrade': | ||
uni | ||
.downloadFile({ | ||
url: import.meta.env.VITE_WGT_URL, | ||
success: res => { | ||
if (res.statusCode === 200) { | ||
modalTips.value = { message: '下载完成,安装中...', type: 'installing' } | ||
plus.runtime.install( | ||
res.tempFilePath, | ||
{ force: false }, | ||
() => { | ||
modalTips.value = { message: '更新完成,须重启应用!', type: 'success' } | ||
}, | ||
() => { | ||
modalTips.value = { message: '安装失败', type: 'installFail' } | ||
} | ||
) | ||
} else { | ||
modalTips.value = { message: '下载失败', type: 'downloadFail' } | ||
} | ||
} | ||
}) | ||
.onProgressUpdate(res => { | ||
modalTips.value = { | ||
message: `安装包下载中,请稍后 (${formatterSize(res.totalBytesWritten)} / ${formatterSize(res.totalBytesExpectedToWrite)}M)`, | ||
progress: res.progress, | ||
type: 'progress' | ||
} | ||
}) | ||
break | ||
case 'success': | ||
plus.runtime.restart() | ||
break | ||
default: | ||
setModalVisible(false) | ||
break | ||
} | ||
} | ||
</script> |
Oops, something went wrong.