优化android 热更新
This commit is contained in:
1 parent
75d8f87f49
commit
999723508a
4 files changed
+74
-18
No files matched your search
@@ -8,15 +8,30 @@ import { ZipArchive } from 'archiver'
|
||||
const scriptDirectory = path.dirname(fileURLToPath(import.meta.url))
|
||||
const webDirectory = path.resolve(scriptDirectory, '..')
|
||||
const distDirectory = path.join(webDirectory, 'dist')
|
||||
const packageJson = JSON.parse(
|
||||
await readFile(path.join(webDirectory, 'package.json'), 'utf8'),
|
||||
)
|
||||
const versionIndex = process.argv.indexOf('--version')
|
||||
const version =
|
||||
versionIndex >= 0 ? process.argv[versionIndex + 1] : packageJson.version
|
||||
const requestedVersion =
|
||||
versionIndex >= 0 ? process.argv[versionIndex + 1] : undefined
|
||||
const versionProps = await readFile(path.join(webDirectory, '..', 'versions.props'), 'utf8')
|
||||
const version = /<JiaowuFrontendVersion>([^<]+)<\/JiaowuFrontendVersion>/.exec(
|
||||
versionProps,
|
||||
)?.[1]?.trim()
|
||||
|
||||
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$/.test(version ?? '')) {
|
||||
throw new Error('请使用 --version 1.0.1 指定语义版本。')
|
||||
if (!version) {
|
||||
throw new Error('versions.props 中缺少 JiaowuFrontendVersion。')
|
||||
}
|
||||
|
||||
if (versionIndex >= 0 && !requestedVersion) {
|
||||
throw new Error('请在 --version 后提供版本号。')
|
||||
}
|
||||
|
||||
if (requestedVersion && requestedVersion !== version) {
|
||||
throw new Error(
|
||||
`更新包版本必须与 JiaowuFrontendVersion 一致(当前为 ${version})。`,
|
||||
)
|
||||
}
|
||||
|
||||
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$/.test(version)) {
|
||||
throw new Error('JiaowuFrontendVersion 必须使用语义版本,例如 1.0.1。')
|
||||
}
|
||||
|
||||
await stat(path.join(distDirectory, 'index.html')).catch(() => {
|
||||
|
||||
Reference in new issue
Block a user