@lark-apaas/coding-templates 0.1.43-alpha.8 → 0.1.43-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/meta.json +2 -8
- package/package.json +1 -1
- package/template-apex/package.json +2 -2
- package/template-apex/tsconfig.app.json +1 -2
- package/template-html/_gitignore +2 -0
- package/template-html/index.html +20 -19
- package/template-html/package.json +2 -17
- package/template-html/routes.json +1 -0
- package/template-html/scripts/build.sh +16 -28
- package/template-vite-react/README.md +32 -55
- package/template-vite-react/{src → client/src}/hooks/use-mobile.ts +3 -4
- package/template-vite-react/{src → client/src}/index.tsx +2 -9
- package/template-vite-react/components.json +1 -1
- package/template-vite-react/package.json +6 -8
- package/template-vite-react/tsconfig.app.json +2 -3
- package/template-vite-react/tsconfig.json +1 -1
- package/template-vite-react/vite.config.ts +2 -1
- package/template-html/.spark_project +0 -17
- package/template-html/scripts/mock-health.cjs +0 -32
- package/template-html/src/main.js +0 -38
- package/template-html/src/styles.css +0 -1
- package/template-html/vite.config.ts +0 -70
- package/template-vite-react/.spark/meta.json +0 -8
- package/template-vite-react/.spark/meta.json.example +0 -8
- package/template-vite-react/.spark_project +0 -18
- package/template-vite-react/scripts/dev.cjs +0 -109
- package/template-vite-react/scripts/measure-boot.sh +0 -219
- package/template-vite-react/scripts/mock-health.cjs +0 -32
- package/template-vite-react/src/assets/logo.svg +0 -4
- /package/template-vite-react/{index.html → client/index.html} +0 -0
- /package/template-vite-react/{public → client/public}/favicon.svg +0 -0
- /package/template-vite-react/{public → client/public}/icons.svg +0 -0
- /package/template-vite-react/{src → client/src}/app.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/layout.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/accordion.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/alert-dialog.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/alert.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/aspect-ratio.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/avatar.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/badge.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/breadcrumb.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/button-group.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/button.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/calendar.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/card.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/carousel.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/chart.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/checkbox.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/collapsible.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/command.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/context-menu.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/dialog.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/drawer.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/dropdown-menu.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/empty.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/field.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/form.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/hover-card.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/image.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/input-group.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/input-otp.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/input.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/item.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/kbd.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/label.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/menubar.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/native-select.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/navigation-menu.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/pagination.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/popover.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/progress.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/radio-group.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/resizable.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/scroll-area.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/select.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/separator.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/sheet.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/sidebar.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/skeleton.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/slider.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/sonner.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/spinner.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/switch.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/table.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/tabs.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/textarea.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/toggle-group.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/toggle.tsx +0 -0
- /package/template-vite-react/{src → client/src}/components/ui/tooltip.tsx +0 -0
- /package/template-vite-react/{src → client/src}/index.css +0 -0
- /package/template-vite-react/{src → client/src}/pages/NotFoundPage/NotFoundPage.tsx +0 -0
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
run = ["npm", "run", "dev"]
|
|
2
|
-
lint = ["npm", "run", "lint"]
|
|
3
|
-
hidden = [".config", ".git", "scripts", "node_modules", "dist", ".spark", ".agent", ".agents", "tmp", ".spark_project", ".playwright-cli"]
|
|
4
|
-
|
|
5
|
-
[deployment]
|
|
6
|
-
build = ["npm", "run", "build"]
|
|
7
|
-
|
|
8
|
-
[files]
|
|
9
|
-
[files.restrict]
|
|
10
|
-
pathPatterns = ["package.json", ".spark_project", ".spark/meta.json", ".gitignore"]
|
|
11
|
-
[files.hidden]
|
|
12
|
-
pathPatterns = [".config", ".git", "scripts", "node_modules", "dist", ".spark", ".agent", ".agents", "tmp", ".spark_project", ".playwright-cli"]
|
|
13
|
-
|
|
14
|
-
[sandbox]
|
|
15
|
-
# 临时兼容老沙箱硬编码探测的 3000 / 8001 端口。
|
|
16
|
-
# 这两个端口由 scripts/mock-health.cjs 占位,Vite dev server 实际监听 CLIENT_DEV_PORT(默认 8080)。
|
|
17
|
-
# 沙箱链路切到新协议后,可改回 [8080],并删掉 mock-health.cjs。
|
|
18
|
-
healthCheck = [8001, 3000]
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* jsPage 模板 dev launcher。
|
|
4
|
-
*
|
|
5
|
-
* 跟全栈 dev.js 对齐:每个子进程的 stdout/stderr 经 readline 逐行拼上
|
|
6
|
-
* 时间戳 + [name] 前缀,同时写到 logs/<name>.std.log(沙箱外壳 dev-logs
|
|
7
|
-
* middleware 监听的标准路径)和当前 stdout。
|
|
8
|
-
*
|
|
9
|
-
* jsPage 只需要 client(vite) + health 两个进程,没有 server。
|
|
10
|
-
* 端口约定(保持跟 .spark_project healthCheck 一致):
|
|
11
|
-
* - vite → 8001(CLIENT_DEV_PORT 可覆盖)
|
|
12
|
-
* - mock-health → 3000(占位,老沙箱探针兼容用)
|
|
13
|
-
*
|
|
14
|
-
* Ctrl+C / SIGTERM 时 kill 整个进程组。
|
|
15
|
-
*/
|
|
16
|
-
'use strict';
|
|
17
|
-
|
|
18
|
-
const fs = require('fs');
|
|
19
|
-
const path = require('path');
|
|
20
|
-
const readline = require('readline');
|
|
21
|
-
const { spawn } = require('child_process');
|
|
22
|
-
|
|
23
|
-
const ROOT = path.resolve(__dirname, '..');
|
|
24
|
-
process.chdir(ROOT);
|
|
25
|
-
|
|
26
|
-
const LOG_DIR = process.env.LOG_DIR || 'logs';
|
|
27
|
-
const CLIENT_DEV_PORT = process.env.CLIENT_DEV_PORT || '8001';
|
|
28
|
-
|
|
29
|
-
fs.mkdirSync(LOG_DIR, { recursive: true });
|
|
30
|
-
|
|
31
|
-
function timestamp() {
|
|
32
|
-
const now = new Date();
|
|
33
|
-
const pad = (n) => String(n).padStart(2, '0');
|
|
34
|
-
return (
|
|
35
|
-
`${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ` +
|
|
36
|
-
`${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const managed = [];
|
|
41
|
-
|
|
42
|
-
function startProcess({ name, command, args, logFileName }) {
|
|
43
|
-
const logFd = logFileName
|
|
44
|
-
? fs.openSync(path.join(LOG_DIR, logFileName), 'a')
|
|
45
|
-
: null;
|
|
46
|
-
|
|
47
|
-
const child = spawn(command, args, {
|
|
48
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
49
|
-
shell: false,
|
|
50
|
-
cwd: ROOT,
|
|
51
|
-
env: process.env,
|
|
52
|
-
detached: true,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const pipeLines = (stream) => {
|
|
56
|
-
const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
|
|
57
|
-
rl.on('line', (line) => {
|
|
58
|
-
const msg = `[${timestamp()}] [${name}] ${line}\n`;
|
|
59
|
-
try { process.stdout.write(msg); } catch {}
|
|
60
|
-
if (logFd != null) {
|
|
61
|
-
try { fs.writeSync(logFd, msg); } catch {}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
pipeLines(child.stdout);
|
|
66
|
-
pipeLines(child.stderr);
|
|
67
|
-
|
|
68
|
-
managed.push({ name, child });
|
|
69
|
-
return child;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
startProcess({
|
|
73
|
-
name: 'client',
|
|
74
|
-
command: 'npx',
|
|
75
|
-
args: ['vite', '--port', CLIENT_DEV_PORT, '--host', '0.0.0.0'],
|
|
76
|
-
logFileName: 'client.std.log',
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
startProcess({
|
|
80
|
-
name: 'health',
|
|
81
|
-
command: 'node',
|
|
82
|
-
args: ['scripts/mock-health.cjs'],
|
|
83
|
-
// health 进程不单独写 log,透传到 stdout 就够
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
let stopping = false;
|
|
87
|
-
function cleanup(signal) {
|
|
88
|
-
if (stopping) return;
|
|
89
|
-
stopping = true;
|
|
90
|
-
for (const { child } of managed) {
|
|
91
|
-
if (!child.pid) continue;
|
|
92
|
-
try { process.kill(-child.pid, signal || 'SIGTERM'); } catch {}
|
|
93
|
-
}
|
|
94
|
-
setTimeout(() => {
|
|
95
|
-
for (const { child } of managed) {
|
|
96
|
-
if (!child.pid) continue;
|
|
97
|
-
try { process.kill(-child.pid, 'SIGKILL'); } catch {}
|
|
98
|
-
}
|
|
99
|
-
process.exit(0);
|
|
100
|
-
}, 2000);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
process.on('SIGINT', () => cleanup('SIGTERM'));
|
|
104
|
-
process.on('SIGTERM', () => cleanup('SIGTERM'));
|
|
105
|
-
|
|
106
|
-
// 任意子进程退出就触发整体 cleanup,避免半残留
|
|
107
|
-
Promise.race(
|
|
108
|
-
managed.map(({ child }) => new Promise((r) => child.on('exit', r)))
|
|
109
|
-
).then(() => cleanup('SIGTERM'));
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# 测沙箱(或本机)模板从 0 到"预览可访问"的耗时拆解。
|
|
3
|
-
# 默认只测 dev 启动那段(不跑 npm install),符合沙箱里依赖已装好的常见场景。
|
|
4
|
-
#
|
|
5
|
-
# 用法:
|
|
6
|
-
# bash scripts/measure-boot.sh # 默认:只测 dev 启动(warm)
|
|
7
|
-
# bash scripts/measure-boot.sh --cold # 冷启动:清光 vite 预打包缓存
|
|
8
|
-
# bash scripts/measure-boot.sh --with-install # 顺带跑一次 npm install 测装包耗时
|
|
9
|
-
# bash scripts/measure-boot.sh --with-install --cold # 模拟首次冷启(清 node_modules + .vite)
|
|
10
|
-
# bash scripts/measure-boot.sh --port 18001 # 临时换端口
|
|
11
|
-
# bash scripts/measure-boot.sh --base /app/whatever # 临时换 CLIENT_BASE_PATH
|
|
12
|
-
#
|
|
13
|
-
# 兼容:--skip-install 等同于不传(默认就是跳过),保留作为 no-op 防止旧脚本/手势失败。
|
|
14
|
-
#
|
|
15
|
-
# 输出:每段耗时 + 总耗时,写到 ./logs/boot-timing.log(同时打到 stdout)
|
|
16
|
-
|
|
17
|
-
set -uo pipefail
|
|
18
|
-
T1=0; T2=0
|
|
19
|
-
DEV_PID=0
|
|
20
|
-
|
|
21
|
-
WITH_INSTALL=0
|
|
22
|
-
COLD=0
|
|
23
|
-
PORT=""
|
|
24
|
-
BASE="/app/probe"
|
|
25
|
-
LOG_DIR="./logs"
|
|
26
|
-
LOG_FILE="$LOG_DIR/boot-timing.log"
|
|
27
|
-
|
|
28
|
-
while [ $# -gt 0 ]; do
|
|
29
|
-
case "$1" in
|
|
30
|
-
--with-install) WITH_INSTALL=1; shift ;;
|
|
31
|
-
--skip-install) shift ;; # no-op,兼容旧手势;默认就是跳过
|
|
32
|
-
--cold) COLD=1; shift ;;
|
|
33
|
-
--port) PORT="$2"; shift 2 ;;
|
|
34
|
-
--base) BASE="$2"; shift 2 ;;
|
|
35
|
-
*) echo "未知参数: $1"; exit 1 ;;
|
|
36
|
-
esac
|
|
37
|
-
done
|
|
38
|
-
|
|
39
|
-
mkdir -p "$LOG_DIR"
|
|
40
|
-
: > "$LOG_FILE"
|
|
41
|
-
|
|
42
|
-
now_ms() {
|
|
43
|
-
# GNU date 支持 %N,macOS 的 BSD date 不支持——优先用 python3 兜底,避免 sandbox 上 BSD 镜像出错。
|
|
44
|
-
if command -v python3 >/dev/null 2>&1; then
|
|
45
|
-
python3 -c 'import time; print(int(time.time()*1000))'
|
|
46
|
-
else
|
|
47
|
-
local raw="$(date +%s%3N)"
|
|
48
|
-
case "$raw" in
|
|
49
|
-
*N) echo $(($(date +%s) * 1000));; # date 不支持 %N,降级到秒级精度
|
|
50
|
-
*) echo "$raw";;
|
|
51
|
-
esac
|
|
52
|
-
fi
|
|
53
|
-
}
|
|
54
|
-
log() {
|
|
55
|
-
local msg="[$(date +%H:%M:%S)] $*"
|
|
56
|
-
echo "$msg" | tee -a "$LOG_FILE"
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
# 自动从 package.json 提取 vite 端口
|
|
60
|
-
if [ -z "$PORT" ]; then
|
|
61
|
-
PORT=$(grep -oE -- '--port[[:space:]]+[0-9]+' package.json 2>/dev/null | head -1 | awk '{print $2}')
|
|
62
|
-
PORT="${PORT:-8001}"
|
|
63
|
-
fi
|
|
64
|
-
|
|
65
|
-
export CLIENT_BASE_PATH="$BASE"
|
|
66
|
-
|
|
67
|
-
log "=============================================="
|
|
68
|
-
log "Boot timing — port=$PORT base=$BASE with-install=$WITH_INSTALL cold=$COLD"
|
|
69
|
-
log "=============================================="
|
|
70
|
-
|
|
71
|
-
# ── 冷启动:清光本地缓存(不计入耗时,T_TOTAL_START 之前完成)────────
|
|
72
|
-
if [ "$COLD" = "1" ]; then
|
|
73
|
-
log "[cold] 清缓存以模拟冷启动..."
|
|
74
|
-
# vite 依赖预打包缓存(永远要清,热启动的最大区别就在这)
|
|
75
|
-
if [ -d node_modules/.vite ]; then
|
|
76
|
-
log " - rm -rf node_modules/.vite"
|
|
77
|
-
rm -rf node_modules/.vite
|
|
78
|
-
fi
|
|
79
|
-
# 本脚本上轮日志
|
|
80
|
-
if [ -d "$LOG_DIR" ]; then
|
|
81
|
-
log " - 清 $LOG_DIR/dev.log(避免 grep 命中旧 ready 行)"
|
|
82
|
-
: > "$LOG_DIR/dev.log" 2>/dev/null || true
|
|
83
|
-
fi
|
|
84
|
-
# 项目级 dist(一般不影响 dev,但顺手)
|
|
85
|
-
[ -d dist ] && rm -rf dist
|
|
86
|
-
# 默认保留 node_modules(典型冷启动对照:装好依赖、只清 .vite)
|
|
87
|
-
# 仅 --with-install 模式才清 node_modules 触发 npm install 重装
|
|
88
|
-
if [ "$WITH_INSTALL" = "1" ]; then
|
|
89
|
-
if [ -d node_modules ]; then
|
|
90
|
-
log " - rm -rf node_modules(--with-install 模式:清依赖以模拟首次冷启)"
|
|
91
|
-
rm -rf node_modules
|
|
92
|
-
fi
|
|
93
|
-
# npm 全局缓存留着(不动 /tmp/.npmcache / ~/.npm),不然太慢且不真实
|
|
94
|
-
else
|
|
95
|
-
log " - 保留 node_modules(默认模式:只清 .vite 缓存)"
|
|
96
|
-
fi
|
|
97
|
-
log "[cold] 缓存清理完成"
|
|
98
|
-
fi
|
|
99
|
-
|
|
100
|
-
T_TOTAL_START=$(now_ms)
|
|
101
|
-
|
|
102
|
-
# ── 阶段 1: npm install ──────────────────────────────────────────────
|
|
103
|
-
if [ "$WITH_INSTALL" = "1" ]; then
|
|
104
|
-
log "[1/4] npm install ..."
|
|
105
|
-
T1=$(now_ms)
|
|
106
|
-
npm install --silent > "$LOG_DIR/install.log" 2>&1
|
|
107
|
-
RC=$?
|
|
108
|
-
T2=$(now_ms)
|
|
109
|
-
if [ $RC -ne 0 ]; then
|
|
110
|
-
log " ❌ npm install 失败(exit=$RC,详见 $LOG_DIR/install.log)"
|
|
111
|
-
exit 1
|
|
112
|
-
fi
|
|
113
|
-
log " ✅ 耗时 $((T2 - T1)) ms"
|
|
114
|
-
else
|
|
115
|
-
log "[1/4] 跳过 npm install(默认;用 --with-install 启用)"
|
|
116
|
-
fi
|
|
117
|
-
|
|
118
|
-
# ── 阶段 2: 启动 dev(进程拉起到出现 \"VITE ready\" 提示)──────────────
|
|
119
|
-
log "[2/4] npm run dev — 等 vite ready 提示 ..."
|
|
120
|
-
|
|
121
|
-
# 杀光占用目标端口的所有进程(不依赖进程名匹配,沙箱里 vite 可能被各种 wrapper 拉起)
|
|
122
|
-
kill_port() {
|
|
123
|
-
local p="$1"
|
|
124
|
-
local pids
|
|
125
|
-
pids=$(lsof -tiTCP:"$p" -sTCP:LISTEN 2>/dev/null | tr '\n' ' ')
|
|
126
|
-
if [ -n "$pids" ]; then
|
|
127
|
-
log " 清理 :$p 上的进程: $pids"
|
|
128
|
-
# shellcheck disable=SC2086
|
|
129
|
-
kill -9 $pids 2>/dev/null || true
|
|
130
|
-
fi
|
|
131
|
-
}
|
|
132
|
-
kill_port "$PORT"
|
|
133
|
-
kill_port 3000
|
|
134
|
-
# 再保险一道:按名字
|
|
135
|
-
pkill -f 'concurrently.*vite' 2>/dev/null || true
|
|
136
|
-
pkill -f 'mock-health' 2>/dev/null || true
|
|
137
|
-
sleep 1
|
|
138
|
-
|
|
139
|
-
# 二次校验:端口必须真的空了
|
|
140
|
-
if lsof -tiTCP:"$PORT" -sTCP:LISTEN >/dev/null 2>&1; then
|
|
141
|
-
log " ❌ 清理后 :$PORT 仍被占用,请手动 kill 后重试"
|
|
142
|
-
log " lsof -i :$PORT"
|
|
143
|
-
exit 1
|
|
144
|
-
fi
|
|
145
|
-
|
|
146
|
-
# 截断 log 文件确保 grep 命中的是本次启动的输出(不是旧 log 残留)
|
|
147
|
-
: > "$LOG_DIR/dev.log"
|
|
148
|
-
|
|
149
|
-
T3=$(now_ms)
|
|
150
|
-
nohup npm run dev > "$LOG_DIR/dev.log" 2>&1 &
|
|
151
|
-
DEV_PID=$!
|
|
152
|
-
|
|
153
|
-
# 等 vite ready 提示(最多 60s)
|
|
154
|
-
T_READY=""
|
|
155
|
-
for i in $(seq 1 600); do
|
|
156
|
-
if grep -q 'VITE.*ready' "$LOG_DIR/dev.log" 2>/dev/null; then
|
|
157
|
-
T_READY=$(now_ms)
|
|
158
|
-
break
|
|
159
|
-
fi
|
|
160
|
-
# 短路:如果 dev 进程已经退出且没出现 ready,提早失败
|
|
161
|
-
if ! kill -0 "$DEV_PID" 2>/dev/null; then
|
|
162
|
-
log " ❌ dev 进程提前退出,看 $LOG_DIR/dev.log"
|
|
163
|
-
tail -20 "$LOG_DIR/dev.log" | sed 's/^/ /' | tee -a "$LOG_FILE"
|
|
164
|
-
exit 1
|
|
165
|
-
fi
|
|
166
|
-
sleep 0.1
|
|
167
|
-
done
|
|
168
|
-
|
|
169
|
-
if [ -z "$T_READY" ]; then
|
|
170
|
-
log " ❌ 60s 内未看到 vite ready 提示,看 $LOG_DIR/dev.log"
|
|
171
|
-
kill ${DEV_PID} 2>/dev/null
|
|
172
|
-
exit 1
|
|
173
|
-
fi
|
|
174
|
-
log " ✅ 耗时 $((T_READY - T3)) ms"
|
|
175
|
-
|
|
176
|
-
# ── 阶段 3: 端口可 TCP 连接 ──────────────────────────────────────────
|
|
177
|
-
log "[3/4] 端口 :$PORT 接受 TCP 连接 ..."
|
|
178
|
-
T4=$(now_ms)
|
|
179
|
-
T_TCP=""
|
|
180
|
-
for i in $(seq 1 100); do
|
|
181
|
-
if (echo > /dev/tcp/127.0.0.1/$PORT) 2>/dev/null; then
|
|
182
|
-
T_TCP=$(now_ms)
|
|
183
|
-
break
|
|
184
|
-
fi
|
|
185
|
-
sleep 0.05
|
|
186
|
-
done
|
|
187
|
-
if [ -z "$T_TCP" ]; then
|
|
188
|
-
log " ❌ 5s 内端口不可连接"
|
|
189
|
-
kill ${DEV_PID} 2>/dev/null
|
|
190
|
-
exit 1
|
|
191
|
-
fi
|
|
192
|
-
log " ✅ 耗时 $((T_TCP - T4)) ms(自 ready 后再 $((T_TCP - T_READY)) ms)"
|
|
193
|
-
|
|
194
|
-
# ── 阶段 4: 首屏 HTML 200 ─────────────────────────────────────────────
|
|
195
|
-
log "[4/4] curl 首屏(含 base normalize rewrite 路径)..."
|
|
196
|
-
T5=$(now_ms)
|
|
197
|
-
URL="http://127.0.0.1:$PORT${BASE}?probe=1"
|
|
198
|
-
HTTP_CODE=$(curl -sS -o "$LOG_DIR/first.html" -w '%{http_code}' --max-time 10 "$URL" 2>&1)
|
|
199
|
-
T6=$(now_ms)
|
|
200
|
-
SIZE=$(wc -c < "$LOG_DIR/first.html" 2>/dev/null | tr -d ' ')
|
|
201
|
-
|
|
202
|
-
log " URL=$URL"
|
|
203
|
-
log " HTTP=$HTTP_CODE size=${SIZE}B 耗时 $((T6 - T5)) ms"
|
|
204
|
-
|
|
205
|
-
if [ "$HTTP_CODE" != "200" ]; then
|
|
206
|
-
log " ⚠️ 非 200,看 $LOG_DIR/first.html"
|
|
207
|
-
fi
|
|
208
|
-
|
|
209
|
-
# ── 汇总 ──────────────────────────────────────────────────────────────
|
|
210
|
-
T_TOTAL_END=$(now_ms)
|
|
211
|
-
log "=============================================="
|
|
212
|
-
log "总耗时 $((T_TOTAL_END - T_TOTAL_START)) ms"
|
|
213
|
-
log "dev 进程 PID=${DEV_PID}(kill 后退出:kill ${DEV_PID})"
|
|
214
|
-
log " install: $([ $WITH_INSTALL = 1 ] && echo "$((T2 - T1)) ms" || echo skipped)"
|
|
215
|
-
log " vite ready: $((T_READY - T3)) ms"
|
|
216
|
-
log " tcp accept after ready: $((T_TCP - T_READY)) ms"
|
|
217
|
-
log " first html curl: $((T6 - T5)) ms"
|
|
218
|
-
log "=============================================="
|
|
219
|
-
log "详细日志:$LOG_FILE / $LOG_DIR/dev.log"
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 沙箱预览态健康检查兜底:在 3000 端口起 HTTP listener。
|
|
4
|
-
*
|
|
5
|
-
* 老沙箱硬编码探测 3000 + 8001 判定"应用启动了"。jsPage 没有真实 Node server,
|
|
6
|
-
* 8001 由 Vite dev server 真正占(预览流量也走 8001),3000 没有任何业务进程,
|
|
7
|
-
* 只能 mock 一个 listener 让健康检查过。
|
|
8
|
-
*
|
|
9
|
-
* 等沙箱链路切到新协议(读 .spark_project [sandbox].healthCheck)后可删除。
|
|
10
|
-
*/
|
|
11
|
-
const http = require('node:http');
|
|
12
|
-
|
|
13
|
-
const PORTS = [3000];
|
|
14
|
-
|
|
15
|
-
for (const port of PORTS) {
|
|
16
|
-
const server = http.createServer((_req, res) => {
|
|
17
|
-
res.writeHead(200, { 'content-type': 'text/plain' });
|
|
18
|
-
res.end('ok');
|
|
19
|
-
});
|
|
20
|
-
server.on('error', (err) => {
|
|
21
|
-
console.error(`[mock-health] :${port} listen error:`, err.message);
|
|
22
|
-
if (err.code === 'EADDRINUSE') {
|
|
23
|
-
// 端口已被占说明业务已起来,mock 退场即可
|
|
24
|
-
console.warn(`[mock-health] :${port} 已被占用,跳过 mock`);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
process.exitCode = 1;
|
|
28
|
-
});
|
|
29
|
-
server.listen(port, '0.0.0.0', () => {
|
|
30
|
-
console.log(`[mock-health] listening on :${port}`);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="none">
|
|
2
|
-
<rect width="64" height="64" rx="12" fill="currentColor" opacity="0.1"/>
|
|
3
|
-
<path d="M20 32 L28 40 L44 24" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
-
</svg>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|