@coze-arch/cli 0.0.36-alpha.2c0689 → 0.0.36-alpha.4e6503
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/README.md +104 -66
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +18 -74
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +1 -1
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
- package/lib/__templates__/expo/client/metro.config.js +1 -3
- package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
- package/lib/__templates__/expo/server/package.json +2 -2
- package/lib/__templates__/expo/server/src/index.ts +1 -1
- package/lib/__templates__/expo/template.config.js +2 -11
- package/lib/__templates__/native-static/.coze +0 -2
- package/lib/__templates__/nextjs/.coze +0 -5
- package/lib/__templates__/nextjs/package.json +1 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +5 -5
- package/lib/__templates__/nextjs/scripts/dev.sh +2 -83
- package/lib/__templates__/nextjs/template.config.js +2 -4
- package/lib/__templates__/nuxt-vue/.coze +0 -5
- package/lib/__templates__/nuxt-vue/package.json +1 -1
- package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +1 -82
- package/lib/__templates__/pi-agent/package.json +1 -1
- package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +1 -1
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +68 -150
- package/lib/__templates__/taro/AGENTS.md +7 -11
- package/lib/__templates__/taro/README.md +4 -4
- package/lib/__templates__/taro/config/index.ts +2 -10
- package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/server/package.json +1 -1
- package/lib/__templates__/taro/server/src/main.ts +2 -8
- package/lib/__templates__/templates.json +1 -51
- package/lib/__templates__/vite/package.json +1 -1
- package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
- package/lib/__templates__/vite/scripts/build.ps1 +1 -1
- package/lib/__templates__/vite/scripts/dev.ps1 +65 -9
- package/lib/__templates__/vite/scripts/dev.sh +1 -82
- package/lib/__templates__/vite/scripts/start.ps1 +8 -2
- package/lib/__templates__/vite/template.config.js +2 -4
- package/lib/cli.js +205 -3426
- package/package.json +3 -5
- package/docs/deploy.md +0 -172
- package/lib/__templates__/native-static/scripts/serve.ps1 +0 -7
- package/lib/__templates__/nextjs/scripts/build.ps1 +0 -16
- package/lib/__templates__/nextjs/scripts/dev.ps1 +0 -63
- package/lib/__templates__/nextjs/scripts/prepare.ps1 +0 -18
- package/lib/__templates__/nextjs/scripts/start.ps1 +0 -11
- package/lib/__templates__/nextjs/scripts/validate.ps1 +0 -8
- package/lib/__templates__/nuxt-vue/scripts/build.ps1 +0 -12
- package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +0 -63
- package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +0 -12
- package/lib/__templates__/nuxt-vue/scripts/start.ps1 +0 -11
- package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +0 -8
- package/lib/__templates__/phaser/.coze +0 -18
- package/lib/__templates__/phaser/README.md +0 -45
- package/lib/__templates__/phaser/_gitignore +0 -23
- package/lib/__templates__/phaser/_npmrc +0 -14
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/manifest.json +0 -11
- package/lib/__templates__/phaser/debug-runtime/flow-graph.json +0 -20
- package/lib/__templates__/phaser/index.html +0 -12
- package/lib/__templates__/phaser/package.json +0 -31
- package/lib/__templates__/phaser/pnpm-lock.yaml +0 -661
- package/lib/__templates__/phaser/scripts/build.ps1 +0 -12
- package/lib/__templates__/phaser/scripts/build.sh +0 -8
- package/lib/__templates__/phaser/scripts/dev.ps1 +0 -49
- package/lib/__templates__/phaser/scripts/dev.sh +0 -82
- package/lib/__templates__/phaser/scripts/prepare.ps1 +0 -8
- package/lib/__templates__/phaser/scripts/prepare.sh +0 -7
- package/lib/__templates__/phaser/scripts/spawn-detached.cjs +0 -29
- package/lib/__templates__/phaser/scripts/start.ps1 +0 -49
- package/lib/__templates__/phaser/scripts/start.sh +0 -82
- package/lib/__templates__/phaser/scripts/validate.ps1 +0 -7
- package/lib/__templates__/phaser/scripts/validate.sh +0 -7
- package/lib/__templates__/phaser/src/assets.ts +0 -15
- package/lib/__templates__/phaser/src/global.d.ts +0 -39
- package/lib/__templates__/phaser/src/main.ts +0 -28
- package/lib/__templates__/phaser/src/scene/BootScene.ts +0 -213
- package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +0 -69
- package/lib/__templates__/phaser/src/style.css +0 -28
- package/lib/__templates__/phaser/src/types.ts +0 -32
- package/lib/__templates__/phaser/src/utils/asset-loader.ts +0 -319
- package/lib/__templates__/phaser/src/utils/index.ts +0 -2
- package/lib/__templates__/phaser/src/utils/mark-editable.ts +0 -13
- package/lib/__templates__/phaser/template.config.js +0 -43
- package/lib/__templates__/phaser/tsconfig.json +0 -23
- package/lib/__templates__/phaser/vite.config.ts +0 -96
- package/lib/__templates__/phaser-static/.coze +0 -15
- package/lib/__templates__/phaser-static/README.md +0 -40
- package/lib/__templates__/phaser-static/_gitignore +0 -6
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +0 -11
- package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +0 -20
- package/lib/__templates__/phaser-static/index.html +0 -17
- package/lib/__templates__/phaser-static/scripts/serve.ps1 +0 -7
- package/lib/__templates__/phaser-static/src/assets.js +0 -15
- package/lib/__templates__/phaser-static/src/main.js +0 -26
- package/lib/__templates__/phaser-static/src/phaser.js +0 -7
- package/lib/__templates__/phaser-static/src/scene/BootScene.js +0 -205
- package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +0 -67
- package/lib/__templates__/phaser-static/src/style.css +0 -28
- package/lib/__templates__/phaser-static/src/utils/asset-loader.js +0 -267
- package/lib/__templates__/phaser-static/src/utils/index.js +0 -2
- package/lib/__templates__/phaser-static/src/utils/mark-editable.js +0 -3
- package/lib/__templates__/phaser-static/template.config.js +0 -35
- package/lib/deploy/package-project.js +0 -244
- package/lib/deploy/package-project.py +0 -183
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
$ErrorActionPreference = "Stop"
|
|
2
|
-
|
|
3
|
-
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
4
|
-
Set-Location $workspace
|
|
5
|
-
|
|
6
|
-
Write-Host "Installing dependencies..."
|
|
7
|
-
& pnpm install --prefer-frozen-lockfile --prefer-offline --reporter=append-only
|
|
8
|
-
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
9
|
-
|
|
10
|
-
$env:COZE_PHASER_GAME_ENV = "PROD"
|
|
11
|
-
& pnpm build
|
|
12
|
-
exit $LASTEXITCODE
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
$ErrorActionPreference = "Stop"
|
|
2
|
-
|
|
3
|
-
function Stop-ProcessTree([int] $processId) {
|
|
4
|
-
if ($processId -gt 0 -and (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
|
|
5
|
-
& taskkill.exe /PID $processId /T /F *> $null
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function Stop-ListeningProcess([int] $port) {
|
|
10
|
-
$connections = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue
|
|
11
|
-
$connections | Select-Object -ExpandProperty OwningProcess -Unique | ForEach-Object {
|
|
12
|
-
Stop-ProcessTree $_
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
17
|
-
$defaultPort = <%= port %>
|
|
18
|
-
$port = if ($env:DEPLOY_RUN_PORT) { [int] $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { [int] $env:PORT } else { $defaultPort }
|
|
19
|
-
Set-Location $workspace
|
|
20
|
-
Stop-ListeningProcess $port
|
|
21
|
-
$env:COZE_PHASER_GAME_ENV = "DEV"
|
|
22
|
-
|
|
23
|
-
<% if (process.env.NODE_ENV === 'test') { %>
|
|
24
|
-
& pnpm vite --port $port --host 127.0.0.1 --strictPort
|
|
25
|
-
exit $LASTEXITCODE
|
|
26
|
-
<% } else { %>
|
|
27
|
-
$logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
|
|
28
|
-
$logFile = Join-Path $logDirectory "phaser-dev.log"
|
|
29
|
-
$errorLogFile = Join-Path $logDirectory "phaser-dev-error.log"
|
|
30
|
-
$pidFile = Join-Path $logDirectory "phaser-dev.pid"
|
|
31
|
-
New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
|
|
32
|
-
|
|
33
|
-
if (Test-Path $pidFile) {
|
|
34
|
-
Stop-ProcessTree ([int] (Get-Content $pidFile -Raw))
|
|
35
|
-
Remove-Item $pidFile -Force
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
$process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm vite --port $port --host 127.0.0.1 --strictPort") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
|
|
39
|
-
$process.Id | Set-Content $pidFile
|
|
40
|
-
Start-Sleep -Seconds 1
|
|
41
|
-
if ($process.HasExited) {
|
|
42
|
-
Get-Content $errorLogFile -Tail 20 -ErrorAction SilentlyContinue
|
|
43
|
-
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
|
44
|
-
exit 1
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
Write-Host "Phaser dev server started (PID: $($process.Id))."
|
|
48
|
-
Write-Host "Log file: $logFile"
|
|
49
|
-
<% } %>
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
set -Eeuo pipefail
|
|
3
|
-
|
|
4
|
-
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
5
|
-
PORT="${PORT:-<%= port %>}"
|
|
6
|
-
DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-${PORT}}"
|
|
7
|
-
cd "${COZE_WORKSPACE_PATH}"
|
|
8
|
-
|
|
9
|
-
get_listening_pids() {
|
|
10
|
-
local port="$1"
|
|
11
|
-
|
|
12
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
13
|
-
lsof -tiTCP:"${port}" -sTCP:LISTEN 2>/dev/null || true
|
|
14
|
-
elif command -v ss >/dev/null 2>&1; then
|
|
15
|
-
ss -H -lntp 2>/dev/null \
|
|
16
|
-
| awk -v port="${port}" '$4 ~ ":"port"$"' \
|
|
17
|
-
| grep -o 'pid=[0-9]*' \
|
|
18
|
-
| cut -d= -f2 \
|
|
19
|
-
| sort -u || true
|
|
20
|
-
else
|
|
21
|
-
echo "Warning: neither lsof nor ss found, cannot check port ${port}." >&2
|
|
22
|
-
fi
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
kill_port_if_listening() {
|
|
26
|
-
local port="$1"
|
|
27
|
-
local pids
|
|
28
|
-
|
|
29
|
-
pids="$(get_listening_pids "${port}")"
|
|
30
|
-
if [[ -z "${pids}" ]]; then
|
|
31
|
-
echo "Port ${port} is free."
|
|
32
|
-
return
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
echo "Port ${port} is in use by PIDs: ${pids//$'\n'/ } (SIGKILL)"
|
|
36
|
-
echo "${pids}" | xargs kill -9 2>/dev/null || true
|
|
37
|
-
sleep 1
|
|
38
|
-
|
|
39
|
-
pids="$(get_listening_pids "${port}")"
|
|
40
|
-
if [[ -n "${pids}" ]]; then
|
|
41
|
-
echo "Failed to clear port ${port}; remaining PIDs: ${pids//$'\n'/ }." >&2
|
|
42
|
-
return 1
|
|
43
|
-
fi
|
|
44
|
-
|
|
45
|
-
echo "Port ${port} cleared."
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
echo "Clearing port ${DEPLOY_RUN_PORT} before start."
|
|
49
|
-
kill_port_if_listening "${DEPLOY_RUN_PORT}"
|
|
50
|
-
|
|
51
|
-
<% if (process.env.NODE_ENV === 'test') { %>
|
|
52
|
-
# Keep the process attached in tests so the test runner can collect logs and stop it.
|
|
53
|
-
exec env COZE_PHASER_GAME_ENV=DEV pnpm vite \
|
|
54
|
-
--port "${DEPLOY_RUN_PORT}" \
|
|
55
|
-
--host 127.0.0.1 \
|
|
56
|
-
--strictPort
|
|
57
|
-
<% } else { %>
|
|
58
|
-
LOG_DIR="${COZE_WORKSPACE_PATH}/logs"
|
|
59
|
-
LOG_FILE="${LOG_DIR}/phaser-dev.log"
|
|
60
|
-
PID_FILE="${LOG_DIR}/phaser-dev.pid"
|
|
61
|
-
mkdir -p "${LOG_DIR}"
|
|
62
|
-
|
|
63
|
-
echo "Starting Phaser dev server on port ${DEPLOY_RUN_PORT}..."
|
|
64
|
-
server_pid="$(COZE_PHASER_GAME_ENV=DEV node scripts/spawn-detached.cjs \
|
|
65
|
-
"${LOG_FILE}" pnpm vite \
|
|
66
|
-
--port "${DEPLOY_RUN_PORT}" \
|
|
67
|
-
--host 127.0.0.1 \
|
|
68
|
-
--strictPort)"
|
|
69
|
-
echo "${server_pid}" > "${PID_FILE}"
|
|
70
|
-
|
|
71
|
-
sleep 1
|
|
72
|
-
if ! kill -0 "${server_pid}" 2>/dev/null; then
|
|
73
|
-
echo "Phaser dev server failed to start. See ${LOG_FILE}." >&2
|
|
74
|
-
tail -n 20 "${LOG_FILE}" >&2 || true
|
|
75
|
-
rm -f "${PID_FILE}"
|
|
76
|
-
exit 1
|
|
77
|
-
fi
|
|
78
|
-
|
|
79
|
-
echo "Phaser dev server started (PID: ${server_pid})."
|
|
80
|
-
echo "Log file: ${LOG_FILE}"
|
|
81
|
-
echo "PID file: ${PID_FILE}"
|
|
82
|
-
<% } %>
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
$ErrorActionPreference = "Stop"
|
|
2
|
-
|
|
3
|
-
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
4
|
-
Set-Location $workspace
|
|
5
|
-
|
|
6
|
-
Write-Host "Installing dependencies..."
|
|
7
|
-
& pnpm install --prefer-frozen-lockfile --prefer-offline --reporter=append-only
|
|
8
|
-
exit $LASTEXITCODE
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs');
|
|
2
|
-
const { spawn } = require('node:child_process');
|
|
3
|
-
|
|
4
|
-
const [logFile, command, ...args] = process.argv.slice(2);
|
|
5
|
-
|
|
6
|
-
if (!logFile || !command) {
|
|
7
|
-
process.stderr.write(
|
|
8
|
-
'Usage: node scripts/spawn-detached.cjs <log-file> <command> [...args]\n',
|
|
9
|
-
);
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const logFd = fs.openSync(logFile, 'a');
|
|
14
|
-
const child = spawn(command, args, {
|
|
15
|
-
cwd: process.cwd(),
|
|
16
|
-
detached: process.platform !== 'win32',
|
|
17
|
-
env: process.env,
|
|
18
|
-
stdio: ['ignore', logFd, logFd],
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
fs.closeSync(logFd);
|
|
22
|
-
child.unref();
|
|
23
|
-
|
|
24
|
-
if (!child.pid) {
|
|
25
|
-
process.stderr.write('Failed to start detached process.\n');
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
process.stdout.write(String(child.pid));
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
$ErrorActionPreference = "Stop"
|
|
2
|
-
|
|
3
|
-
function Stop-ProcessTree([int] $processId) {
|
|
4
|
-
if ($processId -gt 0 -and (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
|
|
5
|
-
& taskkill.exe /PID $processId /T /F *> $null
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function Stop-ListeningProcess([int] $port) {
|
|
10
|
-
$connections = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue
|
|
11
|
-
$connections | Select-Object -ExpandProperty OwningProcess -Unique | ForEach-Object {
|
|
12
|
-
Stop-ProcessTree $_
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
17
|
-
$defaultPort = <%= port %>
|
|
18
|
-
$port = if ($env:DEPLOY_RUN_PORT) { [int] $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { [int] $env:PORT } else { $defaultPort }
|
|
19
|
-
Set-Location $workspace
|
|
20
|
-
Stop-ListeningProcess $port
|
|
21
|
-
$env:COZE_PHASER_GAME_ENV = "PROD"
|
|
22
|
-
|
|
23
|
-
<% if (process.env.NODE_ENV === 'test') { %>
|
|
24
|
-
& pnpm vite preview --port $port --host 127.0.0.1 --strictPort
|
|
25
|
-
exit $LASTEXITCODE
|
|
26
|
-
<% } else { %>
|
|
27
|
-
$logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
|
|
28
|
-
$logFile = Join-Path $logDirectory "phaser-start.log"
|
|
29
|
-
$errorLogFile = Join-Path $logDirectory "phaser-start-error.log"
|
|
30
|
-
$pidFile = Join-Path $logDirectory "phaser-start.pid"
|
|
31
|
-
New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
|
|
32
|
-
|
|
33
|
-
if (Test-Path $pidFile) {
|
|
34
|
-
Stop-ProcessTree ([int] (Get-Content $pidFile -Raw))
|
|
35
|
-
Remove-Item $pidFile -Force
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
$process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm vite preview --port $port --host 127.0.0.1 --strictPort") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
|
|
39
|
-
$process.Id | Set-Content $pidFile
|
|
40
|
-
Start-Sleep -Seconds 1
|
|
41
|
-
if ($process.HasExited) {
|
|
42
|
-
Get-Content $errorLogFile -Tail 20 -ErrorAction SilentlyContinue
|
|
43
|
-
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
|
44
|
-
exit 1
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
Write-Host "Phaser production server started (PID: $($process.Id))."
|
|
48
|
-
Write-Host "Log file: $logFile"
|
|
49
|
-
<% } %>
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
set -Eeuo pipefail
|
|
3
|
-
|
|
4
|
-
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
5
|
-
PORT="${PORT:-<%= port %>}"
|
|
6
|
-
DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-${PORT}}"
|
|
7
|
-
cd "${COZE_WORKSPACE_PATH}"
|
|
8
|
-
|
|
9
|
-
get_listening_pids() {
|
|
10
|
-
local port="$1"
|
|
11
|
-
|
|
12
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
13
|
-
lsof -tiTCP:"${port}" -sTCP:LISTEN 2>/dev/null || true
|
|
14
|
-
elif command -v ss >/dev/null 2>&1; then
|
|
15
|
-
ss -H -lntp 2>/dev/null \
|
|
16
|
-
| awk -v port="${port}" '$4 ~ ":"port"$"' \
|
|
17
|
-
| grep -o 'pid=[0-9]*' \
|
|
18
|
-
| cut -d= -f2 \
|
|
19
|
-
| sort -u || true
|
|
20
|
-
else
|
|
21
|
-
echo "Warning: neither lsof nor ss found, cannot check port ${port}." >&2
|
|
22
|
-
fi
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
kill_port_if_listening() {
|
|
26
|
-
local port="$1"
|
|
27
|
-
local pids
|
|
28
|
-
|
|
29
|
-
pids="$(get_listening_pids "${port}")"
|
|
30
|
-
if [[ -z "${pids}" ]]; then
|
|
31
|
-
echo "Port ${port} is free."
|
|
32
|
-
return
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
echo "Port ${port} is in use by PIDs: ${pids//$'\n'/ } (SIGKILL)"
|
|
36
|
-
echo "${pids}" | xargs kill -9 2>/dev/null || true
|
|
37
|
-
sleep 1
|
|
38
|
-
|
|
39
|
-
pids="$(get_listening_pids "${port}")"
|
|
40
|
-
if [[ -n "${pids}" ]]; then
|
|
41
|
-
echo "Failed to clear port ${port}; remaining PIDs: ${pids//$'\n'/ }." >&2
|
|
42
|
-
return 1
|
|
43
|
-
fi
|
|
44
|
-
|
|
45
|
-
echo "Port ${port} cleared."
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
echo "Clearing port ${DEPLOY_RUN_PORT} before start."
|
|
49
|
-
kill_port_if_listening "${DEPLOY_RUN_PORT}"
|
|
50
|
-
|
|
51
|
-
<% if (process.env.NODE_ENV === 'test') { %>
|
|
52
|
-
# Keep the process attached in tests so the test runner can collect logs and stop it.
|
|
53
|
-
exec env COZE_PHASER_GAME_ENV=PROD pnpm vite preview \
|
|
54
|
-
--port "${DEPLOY_RUN_PORT}" \
|
|
55
|
-
--host 127.0.0.1 \
|
|
56
|
-
--strictPort
|
|
57
|
-
<% } else { %>
|
|
58
|
-
LOG_DIR="${COZE_WORKSPACE_PATH}/logs"
|
|
59
|
-
LOG_FILE="${LOG_DIR}/phaser-start.log"
|
|
60
|
-
PID_FILE="${LOG_DIR}/phaser-start.pid"
|
|
61
|
-
mkdir -p "${LOG_DIR}"
|
|
62
|
-
|
|
63
|
-
echo "Starting Phaser production server on port ${DEPLOY_RUN_PORT}..."
|
|
64
|
-
server_pid="$(COZE_PHASER_GAME_ENV=PROD node scripts/spawn-detached.cjs \
|
|
65
|
-
"${LOG_FILE}" pnpm vite preview \
|
|
66
|
-
--port "${DEPLOY_RUN_PORT}" \
|
|
67
|
-
--host 127.0.0.1 \
|
|
68
|
-
--strictPort)"
|
|
69
|
-
echo "${server_pid}" > "${PID_FILE}"
|
|
70
|
-
|
|
71
|
-
sleep 1
|
|
72
|
-
if ! kill -0 "${server_pid}" 2>/dev/null; then
|
|
73
|
-
echo "Phaser production server failed to start. See ${LOG_FILE}." >&2
|
|
74
|
-
tail -n 20 "${LOG_FILE}" >&2 || true
|
|
75
|
-
rm -f "${PID_FILE}"
|
|
76
|
-
exit 1
|
|
77
|
-
fi
|
|
78
|
-
|
|
79
|
-
echo "Phaser production server started (PID: ${server_pid})."
|
|
80
|
-
echo "Log file: ${LOG_FILE}"
|
|
81
|
-
echo "PID file: ${PID_FILE}"
|
|
82
|
-
<% } %>
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const IMAGES: Record<string, string> = {};
|
|
2
|
-
|
|
3
|
-
export const IMAGE_SEQUENCES: Record<string, string> = {
|
|
4
|
-
'coze-game-loading': 'assets/image_sequence/coze-game-loading',
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const VIDEOS: Record<string, string> = {};
|
|
8
|
-
|
|
9
|
-
export const AUDIOS: Record<string, string> = {};
|
|
10
|
-
|
|
11
|
-
// 注册素材到 PhaserBridge,可以在扣子网页游戏开发中定位
|
|
12
|
-
window.PhaserBridge?.markImageAssetMap?.(IMAGES);
|
|
13
|
-
window.PhaserBridge?.markImageSequenceAssetMap?.(IMAGE_SEQUENCES);
|
|
14
|
-
window.PhaserBridge?.markVideoAssetMap?.(VIDEOS);
|
|
15
|
-
window.PhaserBridge?.markAudioAssetMap?.(AUDIOS);
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type Phaser from 'phaser';
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface LaunchSpec {
|
|
5
|
-
protocol_version: 1;
|
|
6
|
-
target: {
|
|
7
|
-
graph_id: string;
|
|
8
|
-
node_id: string;
|
|
9
|
-
};
|
|
10
|
-
input: Record<string, any>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface PhaserBridgeBinding {
|
|
14
|
-
launchGame: (launchSpec: LaunchSpec | undefined) => Phaser.Game;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface PhaserBridgeApi {
|
|
18
|
-
bind: (binding: PhaserBridgeBinding) => Phaser.Game;
|
|
19
|
-
markEditable?: <T extends Phaser.GameObjects.GameObject>(
|
|
20
|
-
stableId: string,
|
|
21
|
-
gameObject: T,
|
|
22
|
-
options?: {
|
|
23
|
-
label?: string;
|
|
24
|
-
},
|
|
25
|
-
) => T;
|
|
26
|
-
markImageAssetMap?: (images: Record<string, string>) => void;
|
|
27
|
-
markImageSequenceAssetMap?: (
|
|
28
|
-
imageSequences: Record<string, string>,
|
|
29
|
-
) => void;
|
|
30
|
-
markVideoAssetMap?: (videos: Record<string, string>) => void;
|
|
31
|
-
markAudioAssetMap?: (audios: Record<string, string>) => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface Window {
|
|
35
|
-
PhaserBridge?: PhaserBridgeApi;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import Phaser from 'phaser';
|
|
2
|
-
|
|
3
|
-
import { BootScene } from './scene/BootScene';
|
|
4
|
-
import { DevLoadingScene } from './scene/DevLoadingScene';
|
|
5
|
-
import './style.css';
|
|
6
|
-
|
|
7
|
-
const createGame = (_launchSpec?: LaunchSpec): Phaser.Game =>
|
|
8
|
-
new Phaser.Game({
|
|
9
|
-
type: Phaser.AUTO,
|
|
10
|
-
pixelArt: true,
|
|
11
|
-
parent: 'game',
|
|
12
|
-
// TODO 根据游戏的要求进行尺寸
|
|
13
|
-
width: 540,
|
|
14
|
-
height: 960,
|
|
15
|
-
backgroundColor: '#ffffff',
|
|
16
|
-
scale: {
|
|
17
|
-
mode: Phaser.Scale.FIT,
|
|
18
|
-
autoCenter: Phaser.Scale.CENTER_BOTH,
|
|
19
|
-
},
|
|
20
|
-
scene: [BootScene, DevLoadingScene],
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// 注册游戏到 PhaserBridge,可以在扣子网页游戏开发中编辑评论
|
|
24
|
-
if (window.PhaserBridge) {
|
|
25
|
-
window.PhaserBridge.bind({ launchGame: createGame });
|
|
26
|
-
} else {
|
|
27
|
-
createGame();
|
|
28
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import Phaser from 'phaser';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
getAssetLabelFromFileKey,
|
|
5
|
-
getImageSequenceRuntimeKeys,
|
|
6
|
-
loadAssets,
|
|
7
|
-
markEditable,
|
|
8
|
-
registerImageSequenceAnimations,
|
|
9
|
-
} from '@/utils';
|
|
10
|
-
|
|
11
|
-
import { AUDIOS, IMAGES, IMAGE_SEQUENCES, VIDEOS } from '../assets';
|
|
12
|
-
|
|
13
|
-
interface LoaderFileLike {
|
|
14
|
-
key: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const LOADING_TEXT_STYLE: Phaser.Types.GameObjects.Text.TextStyle = {
|
|
18
|
-
color: '#71717a',
|
|
19
|
-
fontFamily: '"PingFang SC", "Microsoft YaHei", sans-serif',
|
|
20
|
-
fontSize: '18px',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const DEV_LOADING_ASSET_KEY = 'coze-game-loading';
|
|
24
|
-
const devLoadingSource = IMAGE_SEQUENCES[DEV_LOADING_ASSET_KEY];
|
|
25
|
-
|
|
26
|
-
if (!devLoadingSource) {
|
|
27
|
-
throw new Error(`Image sequence asset not found: ${DEV_LOADING_ASSET_KEY}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const BOOT_IMAGE_SEQUENCES = {
|
|
31
|
-
[DEV_LOADING_ASSET_KEY]: devLoadingSource,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const BOOT_ASSETS = {
|
|
35
|
-
imageSequences: BOOT_IMAGE_SEQUENCES,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const GAME_IMAGE_SEQUENCES = Object.fromEntries(
|
|
39
|
-
Object.entries(IMAGE_SEQUENCES).filter(
|
|
40
|
-
([assetKey]) => assetKey !== DEV_LOADING_ASSET_KEY,
|
|
41
|
-
),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const GAME_ASSETS = {
|
|
45
|
-
images: IMAGES,
|
|
46
|
-
imageSequences: GAME_IMAGE_SEQUENCES,
|
|
47
|
-
videos: VIDEOS,
|
|
48
|
-
audios: AUDIOS,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const DEV_LOADING_RUNTIME_KEYS =
|
|
52
|
-
getImageSequenceRuntimeKeys(DEV_LOADING_ASSET_KEY);
|
|
53
|
-
|
|
54
|
-
export class BootScene extends Phaser.Scene {
|
|
55
|
-
private loadingText?: Phaser.GameObjects.Text;
|
|
56
|
-
private progressBar?: Phaser.GameObjects.Graphics;
|
|
57
|
-
private progressText?: Phaser.GameObjects.Text;
|
|
58
|
-
private loadFailed = false;
|
|
59
|
-
|
|
60
|
-
constructor() {
|
|
61
|
-
super('boot');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
preload(): void {
|
|
65
|
-
loadAssets(this, BOOT_ASSETS);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
create(): void {
|
|
69
|
-
registerImageSequenceAnimations(this, BOOT_IMAGE_SEQUENCES);
|
|
70
|
-
this.createLoadingView();
|
|
71
|
-
|
|
72
|
-
const queuedFileCount = loadAssets(this, GAME_ASSETS);
|
|
73
|
-
if (queuedFileCount === 0) {
|
|
74
|
-
this.finishLoading();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.load.on(Phaser.Loader.Events.FILE_PROGRESS, this.onGameFile, this);
|
|
79
|
-
this.load.on(Phaser.Loader.Events.PROGRESS, this.onProgress, this);
|
|
80
|
-
this.load.once(
|
|
81
|
-
Phaser.Loader.Events.FILE_LOAD_ERROR,
|
|
82
|
-
this.onLoadError,
|
|
83
|
-
this,
|
|
84
|
-
);
|
|
85
|
-
this.load.once(Phaser.Loader.Events.COMPLETE, this.finishLoading, this);
|
|
86
|
-
this.load.start();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private createLoadingView(): void {
|
|
90
|
-
const { centerX, centerY } = this.cameras.main;
|
|
91
|
-
|
|
92
|
-
markEditable(
|
|
93
|
-
'boot.loading-mascot',
|
|
94
|
-
this.add
|
|
95
|
-
.sprite(centerX, centerY - 58, DEV_LOADING_RUNTIME_KEYS.texture)
|
|
96
|
-
.setScale(0.56)
|
|
97
|
-
.play(DEV_LOADING_RUNTIME_KEYS.animation),
|
|
98
|
-
{ label: '加载吉祥物' },
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
this.loadingText = markEditable(
|
|
102
|
-
'boot.loading-text',
|
|
103
|
-
this.add
|
|
104
|
-
.text(
|
|
105
|
-
centerX,
|
|
106
|
-
centerY + 120,
|
|
107
|
-
'正在加载游戏资源…',
|
|
108
|
-
LOADING_TEXT_STYLE,
|
|
109
|
-
)
|
|
110
|
-
.setOrigin(0.5),
|
|
111
|
-
{ label: '加载状态文案' },
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
this.progressBar = markEditable(
|
|
115
|
-
'boot.loading-progress-bar',
|
|
116
|
-
this.add.graphics(),
|
|
117
|
-
{ label: '加载进度条' },
|
|
118
|
-
);
|
|
119
|
-
this.renderProgressBar(0);
|
|
120
|
-
|
|
121
|
-
this.progressText = markEditable(
|
|
122
|
-
'boot.loading-progress',
|
|
123
|
-
this.add
|
|
124
|
-
.text(centerX, centerY + 190, '0%', LOADING_TEXT_STYLE)
|
|
125
|
-
.setOrigin(0.5),
|
|
126
|
-
{ label: '加载进度文本' },
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private readonly onGameFile = (file: LoaderFileLike): void => {
|
|
131
|
-
const assetLabel = getAssetLabelFromFileKey(file.key, GAME_ASSETS);
|
|
132
|
-
this.loadingText?.setText(`正在加载${assetLabel}`);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
private readonly onProgress = (progress: number): void => {
|
|
136
|
-
this.renderProgressBar(progress);
|
|
137
|
-
this.progressText?.setText(`${Math.round(progress * 100)}%`);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
private readonly onLoadError = (file: LoaderFileLike): void => {
|
|
141
|
-
this.loadFailed = true;
|
|
142
|
-
const assetLabel = getAssetLabelFromFileKey(file.key, GAME_ASSETS);
|
|
143
|
-
this.loadingText?.setText(`${assetLabel}加载失败`);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
private renderProgressBar(progress: number): void {
|
|
147
|
-
if (!this.progressBar) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const { centerX, centerY } = this.cameras.main;
|
|
152
|
-
const width = 300;
|
|
153
|
-
const height = 14;
|
|
154
|
-
const x = centerX - width / 2;
|
|
155
|
-
const y = centerY + 154;
|
|
156
|
-
const padding = 3;
|
|
157
|
-
const innerWidth = width - padding * 2;
|
|
158
|
-
const filledWidth = Phaser.Math.Clamp(progress, 0, 1) * innerWidth;
|
|
159
|
-
|
|
160
|
-
this.progressBar.clear();
|
|
161
|
-
this.progressBar.fillStyle(0x102536, 0.12);
|
|
162
|
-
this.progressBar.fillRoundedRect(x, y, width, height, height / 2);
|
|
163
|
-
this.progressBar.lineStyle(2, 0x102536, 0.28);
|
|
164
|
-
this.progressBar.strokeRoundedRect(x, y, width, height, height / 2);
|
|
165
|
-
|
|
166
|
-
if (filledWidth <= 0) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
this.progressBar.fillStyle(0xef648d, 1);
|
|
171
|
-
this.progressBar.fillRoundedRect(
|
|
172
|
-
x + padding,
|
|
173
|
-
y + padding,
|
|
174
|
-
filledWidth,
|
|
175
|
-
height - padding * 2,
|
|
176
|
-
(height - padding * 2) / 2,
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
this.progressBar.fillStyle(0x165ca8, 1);
|
|
180
|
-
this.progressBar.fillCircle(
|
|
181
|
-
Phaser.Math.Clamp(
|
|
182
|
-
x + padding + filledWidth,
|
|
183
|
-
x + padding + 5,
|
|
184
|
-
x + width - padding - 5,
|
|
185
|
-
),
|
|
186
|
-
y + height / 2,
|
|
187
|
-
5,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private readonly finishLoading = (): void => {
|
|
192
|
-
this.removeLoaderListeners();
|
|
193
|
-
|
|
194
|
-
if (this.loadFailed) {
|
|
195
|
-
this.progressText?.setText('请刷新页面重试');
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
registerImageSequenceAnimations(this, GAME_IMAGE_SEQUENCES);
|
|
200
|
-
this.scene.start('dev-loading');
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
private removeLoaderListeners(): void {
|
|
204
|
-
this.load.off(Phaser.Loader.Events.FILE_PROGRESS, this.onGameFile, this);
|
|
205
|
-
this.load.off(Phaser.Loader.Events.PROGRESS, this.onProgress, this);
|
|
206
|
-
this.load.off(
|
|
207
|
-
Phaser.Loader.Events.FILE_LOAD_ERROR,
|
|
208
|
-
this.onLoadError,
|
|
209
|
-
this,
|
|
210
|
-
);
|
|
211
|
-
this.load.off(Phaser.Loader.Events.COMPLETE, this.finishLoading, this);
|
|
212
|
-
}
|
|
213
|
-
}
|