提交
This commit is contained in:
1 parent
843e13bce3
commit
7b1d4c8729
629 files changed
+74059
-7929
No files matched your search
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 生产发版 / 编译前提醒:检查 config/api.js 是否仍指向本机调试地址。
|
||||
* - 默认:仅打印醒目提醒(不中断)。
|
||||
* - 严格:`node scripts/remind-production-api-url.mjs --strict` 若仍检测到活动行中的本机地址则 exit 1(供 CI)。
|
||||
*/
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const apiPath = path.join(root, 'config', 'api.js')
|
||||
|
||||
const banner = () => {
|
||||
const lines = [
|
||||
'',
|
||||
'================================================================',
|
||||
' shanxia miniprogram 发版提醒',
|
||||
' 部署到生产环境前,必须核对并修改 config/api.js:',
|
||||
' - 常量 DEV_BASE_URL',
|
||||
' - 微信小程序条件编译块 (#ifdef MP-WEIXIN) 内的 devBaseUrl',
|
||||
' 二者须与生产网关 / API 根路径一致(勿保留 127.0.0.1 / localhost)。',
|
||||
' 详见项目 README「生产部署与 API 基址」一节。',
|
||||
'================================================================',
|
||||
''
|
||||
]
|
||||
console.warn('\x1b[33m%s\x1b[0m', lines.join('\n'))
|
||||
}
|
||||
|
||||
const looksLikeLocalApi = (line) => {
|
||||
const t = line.trim()
|
||||
if (!t || t.startsWith('//') || t.startsWith('*')) return false
|
||||
if (!/(DEV_BASE_URL|devBaseUrl)/.test(t)) return false
|
||||
return /127\.0\.0\.1|localhost/.test(t)
|
||||
}
|
||||
|
||||
const strictCheck = () => {
|
||||
const raw = fs.readFileSync(apiPath, 'utf8')
|
||||
const hit = raw.split(/\r?\n/).some(looksLikeLocalApi)
|
||||
if (hit) {
|
||||
console.error(
|
||||
'\x1b[31m[release-check]\x1b[0m config/api.js 中仍存在指向本机的 DEV_BASE_URL 或 devBaseUrl,请先改为生产地址后再发版(或去掉 --strict)。'
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
console.warn('\x1b[32m[release-check]\x1b[0m 未发现活动行中的本机 API 地址(已通过 --strict)。')
|
||||
}
|
||||
|
||||
banner()
|
||||
const strict = process.argv.includes('--strict')
|
||||
if (strict) strictCheck()
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 将「当前选用的静态基址」写入 pages.json、index.html。
|
||||
* - 目标基址:`STATIC_ASSETS_BASE_URL` 环境变量,否则取 `static-assets-defaults.js` 中 **STATIC_ASSETS_BASE_URL_TEST**。
|
||||
* - 若文件中仍是更旧的 CDN 前缀,可一次性指定 `PREV_STATIC_ASSETS_BASE_URL`(要整段替换掉的前缀,须以 / 结尾),例如:
|
||||
* `PREV_STATIC_ASSETS_BASE_URL=https://old-host/sqxp-static/ npm run sync-static-public-urls`
|
||||
* 不设则仅把「与目标相同」视为已就绪,不做无意义的替换。
|
||||
*
|
||||
* 生产发版:先设 `STATIC_ASSETS_BASE_URL` 为生产根地址再执行。
|
||||
* 用法:在 sqxp-wx 根目录执行 `npm run sync-static-public-urls`
|
||||
*/
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const defaultsPath = path.join(root, 'config/static-assets-defaults.js')
|
||||
const raw = fs.readFileSync(defaultsPath, 'utf8')
|
||||
const pick = (name) => {
|
||||
const m = raw.match(new RegExp(`export const ${name}\\s*=\\s*['"]([^'"]+)['"]`))
|
||||
return m?.[1]?.trim() || ''
|
||||
}
|
||||
const testBase = pick('STATIC_ASSETS_BASE_URL_TEST') || pick('STATIC_ASSETS_BASE_URL_DEFAULT')
|
||||
const fromFile = testBase || process.env.VITE_STATIC_ASSETS_BASE_URL || 'https://REPLACE_TEST_STATIC_HOST/shanxia-static/'
|
||||
const normalized = (() => {
|
||||
const b = (process.env.STATIC_ASSETS_BASE_URL || fromFile).trim()
|
||||
return b.endsWith('/') ? b : `${b}/`
|
||||
})()
|
||||
|
||||
const prevRaw = process.env.PREV_STATIC_ASSETS_BASE_URL?.trim()
|
||||
const prev = prevRaw
|
||||
? prevRaw.endsWith('/') ? prevRaw : `${prevRaw}/`
|
||||
: normalized
|
||||
|
||||
for (const rel of ['pages.json', 'index.html']) {
|
||||
const p = path.join(root, rel)
|
||||
if (!fs.existsSync(p)) continue
|
||||
let s = fs.readFileSync(p, 'utf8')
|
||||
if (prev !== normalized) {
|
||||
s = s.split(prev).join(normalized)
|
||||
}
|
||||
fs.writeFileSync(p, s)
|
||||
}
|
||||
|
||||
if (prev === normalized) {
|
||||
console.log('Static base:', normalized, '(未设置 PREV_STATIC_ASSETS_BASE_URL,未执行旧前缀替换)')
|
||||
} else {
|
||||
console.log('Static base set to:', normalized, '(replaced prefix:', prev + ')')
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
# 将 miniprogram/static/ 同步到公网服务器静态目录
|
||||
# 用法:./scripts/sync-static-to-server.sh [user@host]
|
||||
#
|
||||
# 默认:root@121.43.228.102 → /iflytek/shanxia2.0/app/assets/
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
REMOTE="${1:-root@121.43.228.102}"
|
||||
REMOTE_DIR="/iflytek/shanxia2.0/app/assets"
|
||||
|
||||
echo "同步 ${ROOT_DIR}/static/ → ${REMOTE}:${REMOTE_DIR}/"
|
||||
rsync -avz --delete "${ROOT_DIR}/static/" "${REMOTE}:${REMOTE_DIR}/"
|
||||
|
||||
echo ""
|
||||
echo "完成。请自检:"
|
||||
echo " curl -I http://121.43.228.102:9911/shanxia-static/images/logo.gif"
|
||||
echo " curl -I http://121.43.228.102:9911/shanxia-static/health"
|
||||
Reference in new issue
Block a user