Skip to content

Commit d163f75

Browse files
committed
fix: publish app update JSON endpoints
1 parent e096744 commit d163f75

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"scripts": {
1010
"dev": "vite",
1111
"build": "vite build",
12+
"check": "node scripts/check-app-update-json.mjs && npm run build",
1213
"preview": "vite preview"
1314
},
1415
"dependencies": {

public/api/app-update/play

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"appId": "com.strawcoding.strawmoneybook",
3+
"latestVersion": "1.3.59",
4+
"version": "1.3.59",
5+
"playUrl": "https://play.google.com/store/apps/details?id=com.strawcoding.strawmoneybook",
6+
"source": "official_site_static",
7+
"message": ""
8+
}

public/app-update.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"latestVersion": "1.3.59",
3+
"playUrl": "https://play.google.com/store/apps/details?id=com.strawcoding.strawmoneybook",
4+
"message": ""
5+
}

scripts/check-app-update-json.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { existsSync, readFileSync } from 'node:fs'
2+
import { resolve } from 'node:path'
3+
4+
const root = process.cwd()
5+
const manifestPath = resolve(root, 'public/app-update.json')
6+
const playApiPath = resolve(root, 'public/api/app-update/play')
7+
8+
function readJson(path) {
9+
return JSON.parse(readFileSync(path, 'utf8'))
10+
}
11+
12+
if (!existsSync(manifestPath)) {
13+
throw new Error('missing public/app-update.json')
14+
}
15+
if (!existsSync(playApiPath)) {
16+
throw new Error('missing public/api/app-update/play')
17+
}
18+
19+
const manifest = readJson(manifestPath)
20+
const playApi = readJson(playApiPath)
21+
const latestVersion = String(manifest.latestVersion ?? '').trim()
22+
23+
if (!latestVersion) {
24+
throw new Error('public/app-update.json missing latestVersion')
25+
}
26+
if (String(playApi.latestVersion ?? '').trim() !== latestVersion) {
27+
throw new Error('Play API latestVersion must match manifest latestVersion')
28+
}
29+
if (String(playApi.version ?? '').trim() !== latestVersion) {
30+
throw new Error('Play API version must match manifest latestVersion')
31+
}
32+
33+
console.log(`[check-app-update-json] latestVersion=${latestVersion}`)

0 commit comments

Comments
 (0)