@coze-arch/cli 0.1.3-alpha.cb26ca → 0.1.4-alpha.007b56
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/lib/__templates__/expo/.coze +3 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_build.ps1 +10 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.ps1 +74 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +1 -1
- package/lib/__templates__/expo/.cozeproj/scripts/validate.ps1 +7 -0
- package/lib/__templates__/taro/.coze +4 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.ps1 +3 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.ps1 +62 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.ps1 +7 -0
- package/lib/__templates__/taro/.cozeproj/scripts/validate.ps1 +7 -0
- package/lib/cli.js +2 -1
- package/package.json +1 -1
|
@@ -5,8 +5,11 @@ project_type = "app"
|
|
|
5
5
|
|
|
6
6
|
[dev]
|
|
7
7
|
build = ["bash", ".cozeproj/scripts/dev_build.sh"]
|
|
8
|
+
build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/dev_build.ps1"]
|
|
8
9
|
run = ["bash", ".cozeproj/scripts/dev_run.sh"]
|
|
10
|
+
run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/dev_run.ps1"]
|
|
9
11
|
validate = ["bash", ".cozeproj/scripts/validate.sh"]
|
|
12
|
+
validate_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/validate.ps1"]
|
|
10
13
|
|
|
11
14
|
[deploy]
|
|
12
15
|
build = ["bash", ".cozeproj/scripts/prod_build.sh"]
|
|
@@ -0,0 +1,10 @@
|
|
|
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 Expo project dependencies..."
|
|
7
|
+
& pnpm install --registry=https://registry.npmmirror.com
|
|
8
|
+
if ($LASTEXITCODE -ne 0) {
|
|
9
|
+
Write-Warning "Expo 项目依赖安装失败"
|
|
10
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue |
|
|
11
|
+
Select-Object -ExpandProperty OwningProcess -Unique |
|
|
12
|
+
ForEach-Object { Stop-ProcessTree $_ }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function Start-LoggedProcess([string] $workingDirectory, [string] $logFile, [string[]] $arguments, [hashtable] $environment) {
|
|
16
|
+
$previousEnvironment = @{}
|
|
17
|
+
foreach ($key in $environment.Keys) {
|
|
18
|
+
$previousEnvironment[$key] = [Environment]::GetEnvironmentVariable($key, 'Process')
|
|
19
|
+
[Environment]::SetEnvironmentVariable($key, $environment[$key], 'Process')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
return Start-Process -FilePath "pnpm.cmd" -ArgumentList $arguments -WorkingDirectory $workingDirectory -RedirectStandardOutput $logFile -RedirectStandardError "$logFile.error" -PassThru
|
|
24
|
+
} finally {
|
|
25
|
+
foreach ($key in $environment.Keys) {
|
|
26
|
+
[Environment]::SetEnvironmentVariable($key, $previousEnvironment[$key], 'Process')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
32
|
+
$serverPort = if ($env:SERVER_PORT) { [int] $env:SERVER_PORT } else { <%= serverPort %> }
|
|
33
|
+
$expoPort = if ($env:DEPLOY_RUN_PORT) { [int] $env:DEPLOY_RUN_PORT } elseif ($env:EXPO_PORT) { [int] $env:EXPO_PORT } else { <%= port %> }
|
|
34
|
+
$logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
|
|
35
|
+
$serverLog = Join-Path $logDirectory "server.log"
|
|
36
|
+
$clientLog = Join-Path $logDirectory "client.log"
|
|
37
|
+
New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
|
|
38
|
+
|
|
39
|
+
Stop-ListeningProcess $serverPort
|
|
40
|
+
Stop-ListeningProcess $expoPort
|
|
41
|
+
|
|
42
|
+
$webUrl = if ($env:COZE_PROJECT_DOMAIN_DEFAULT) {
|
|
43
|
+
$env:COZE_PROJECT_DOMAIN_DEFAULT
|
|
44
|
+
} elseif ($env:COZE_HARDWARE_DID) {
|
|
45
|
+
"https://cozedaemon-$($env:COZE_HARDWARE_DID)-$expoPort.dev.coze.site"
|
|
46
|
+
} else {
|
|
47
|
+
"http://127.0.0.1:$serverPort"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
$sharedEnvironment = @{
|
|
51
|
+
EXPO_PUBLIC_BACKEND_BASE_URL = $webUrl
|
|
52
|
+
EXPO_PACKAGER_PROXY_URL = $webUrl
|
|
53
|
+
EXPO_PUBLIC_COZE_PROJECT_ID = $env:COZE_PROJECT_ID
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Write-Host "Starting server on port $serverPort..."
|
|
57
|
+
$server = Start-LoggedProcess (Join-Path $workspace "server") $serverLog @("exec", "tsx", "watch", "./src/index.ts") (@{ NODE_ENV = "development"; PORT = "$serverPort" })
|
|
58
|
+
|
|
59
|
+
Write-Host "Starting Expo on port $expoPort..."
|
|
60
|
+
$expoEnvironment = @{}
|
|
61
|
+
$sharedEnvironment.GetEnumerator() | ForEach-Object { $expoEnvironment[$_.Key] = $_.Value }
|
|
62
|
+
$expoEnvironment.EXPO_NO_DEPENDENCY_VALIDATION = "1"
|
|
63
|
+
$expo = Start-LoggedProcess (Join-Path $workspace "client") $clientLog @("exec", "expo", "start", "--web", "--clear", "--port", "$expoPort") $expoEnvironment
|
|
64
|
+
|
|
65
|
+
Start-Sleep -Seconds 8
|
|
66
|
+
if ((Test-Path $clientLog) -and (Select-String -Path $clientLog -Pattern "TypeError: fetch failed" -Quiet)) {
|
|
67
|
+
Write-Host "Expo 启动检测到网络错误,启用离线模式重试"
|
|
68
|
+
Stop-ProcessTree $expo.Id
|
|
69
|
+
$expoEnvironment.EXPO_OFFLINE = "1"
|
|
70
|
+
$expo = Start-LoggedProcess (Join-Path $workspace "client") $clientLog @("exec", "expo", "start", "--web", "--clear", "--port", "$expoPort") $expoEnvironment
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Write-Host "服务已启动。Server PID: $($server.Id), Expo PID: $($expo.Id)"
|
|
74
|
+
Write-Host "EXPO_PUBLIC_BACKEND_BASE_URL=$webUrl"
|
|
@@ -18,7 +18,7 @@ EXPO_DIR="expo"
|
|
|
18
18
|
EXPO_PORT="${DEPLOY_RUN_PORT:-${EXPO_PORT:-<%= port %>}}"
|
|
19
19
|
COZE_HARDWARE_DID="${COZE_HARDWARE_DID:-}"
|
|
20
20
|
if [ -n "${EXPO_PORT:-}" ] && [ -n "${COZE_HARDWARE_DID}" ]; then
|
|
21
|
-
WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-https://
|
|
21
|
+
WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-https://preview-${COZE_HARDWARE_DID}-${EXPO_PORT}.dev.coze.site}"
|
|
22
22
|
else
|
|
23
23
|
WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
|
|
24
24
|
fi
|
|
@@ -5,10 +5,14 @@ project_type = "miniprogram"
|
|
|
5
5
|
|
|
6
6
|
[dev]
|
|
7
7
|
build = ["bash", ".cozeproj/scripts/dev_build.sh"]
|
|
8
|
+
build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/dev_build.ps1"]
|
|
8
9
|
run = ["bash", ".cozeproj/scripts/dev_run.sh"]
|
|
10
|
+
run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/dev_run.ps1"]
|
|
9
11
|
deps = ["git"] # -> apt install git
|
|
10
12
|
pack = ["bash", ".cozeproj/scripts/pack.sh"]
|
|
13
|
+
pack_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/pack.ps1"]
|
|
11
14
|
validate = ["bash", ".cozeproj/scripts/validate.sh"]
|
|
15
|
+
validate_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/validate.ps1"]
|
|
12
16
|
|
|
13
17
|
[deploy]
|
|
14
18
|
build = ["bash", ".cozeproj/scripts/deploy_build.sh"]
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue |
|
|
11
|
+
Select-Object -ExpandProperty OwningProcess -Unique |
|
|
12
|
+
ForEach-Object { Stop-ProcessTree $_ }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function Start-DevProcess([string] $workingDirectory, [string] $logFile, [hashtable] $environment) {
|
|
16
|
+
$previousEnvironment = @{}
|
|
17
|
+
foreach ($key in $environment.Keys) {
|
|
18
|
+
$previousEnvironment[$key] = [Environment]::GetEnvironmentVariable($key, 'Process')
|
|
19
|
+
[Environment]::SetEnvironmentVariable($key, $environment[$key], 'Process')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
return Start-Process -FilePath "pnpm.cmd" -ArgumentList @("dev") -WorkingDirectory $workingDirectory -RedirectStandardOutput $logFile -RedirectStandardError "$logFile.error" -PassThru
|
|
24
|
+
} finally {
|
|
25
|
+
foreach ($key in $environment.Keys) {
|
|
26
|
+
[Environment]::SetEnvironmentVariable($key, $previousEnvironment[$key], 'Process')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
32
|
+
$port = if ($env:DEPLOY_RUN_PORT) { [int] $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { [int] $env:PORT } else { <%= port %> }
|
|
33
|
+
$serverPort = if ($env:SERVER_PORT) { [int] $env:SERVER_PORT } else { <%= serverPort %> }
|
|
34
|
+
$logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
|
|
35
|
+
$logFile = Join-Path $logDirectory "dev.log"
|
|
36
|
+
$pidFile = Join-Path $logDirectory "dev.pid"
|
|
37
|
+
New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
|
|
38
|
+
|
|
39
|
+
if (Test-Path $pidFile) {
|
|
40
|
+
Stop-ProcessTree ([int] (Get-Content $pidFile -Raw))
|
|
41
|
+
Remove-Item $pidFile -Force
|
|
42
|
+
}
|
|
43
|
+
Stop-ListeningProcess $port
|
|
44
|
+
Stop-ListeningProcess $serverPort
|
|
45
|
+
|
|
46
|
+
$environment = @{ PORT = "$port"; SERVER_PORT = "$serverPort" }
|
|
47
|
+
if ($env:COZE_PROJECT_DOMAIN_DEFAULT) {
|
|
48
|
+
$environment.PROJECT_DOMAIN = $env:COZE_PROJECT_DOMAIN_DEFAULT
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
$process = Start-DevProcess $workspace $logFile $environment
|
|
52
|
+
$process.Id | Set-Content $pidFile
|
|
53
|
+
Start-Sleep -Seconds 1
|
|
54
|
+
if ($process.HasExited) {
|
|
55
|
+
Get-Content "$logFile.error" -Tail 20 -ErrorAction SilentlyContinue
|
|
56
|
+
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
|
57
|
+
exit 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Write-Host "Taro H5 and NestJS services started. PID: $($process.Id)"
|
|
61
|
+
Write-Host "Web port: $port; server port: $serverPort"
|
|
62
|
+
Write-Host "Log file: $logFile"
|
package/lib/cli.js
CHANGED
|
@@ -2114,7 +2114,7 @@ const EventBuilder = {
|
|
|
2114
2114
|
};
|
|
2115
2115
|
|
|
2116
2116
|
var name = "@coze-arch/cli";
|
|
2117
|
-
var version = "0.1.
|
|
2117
|
+
var version = "0.1.4-alpha.007b56";
|
|
2118
2118
|
var description = "coze coding devtools cli";
|
|
2119
2119
|
var license = "MIT";
|
|
2120
2120
|
var author = "fanwenjie.fe@bytedance.com";
|
|
@@ -9179,6 +9179,7 @@ const shouldRenderFile = (filePath) => {
|
|
|
9179
9179
|
'.prettierrc',
|
|
9180
9180
|
'.babelrc',
|
|
9181
9181
|
'.sh',
|
|
9182
|
+
'.ps1',
|
|
9182
9183
|
]);
|
|
9183
9184
|
|
|
9184
9185
|
const ext = path.extname(filePath).toLowerCase();
|