@coze-arch/cli 0.1.4-alpha.b94eab → 0.1.4-alpha.e6e18e

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.
@@ -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 project dependency installation failed."
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 startup detected a network error; retrying in offline mode."
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 "Services started. Server PID: $($server.Id), Expo PID: $($expo.Id)"
74
+ Write-Host "EXPO_PUBLIC_BACKEND_BASE_URL=$webUrl"
@@ -0,0 +1,7 @@
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
+ & pnpm validate
7
+ exit $LASTEXITCODE
@@ -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,3 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ Write-Host "Taro development build does not require a separate step."
@@ -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"
@@ -0,0 +1,7 @@
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
+ & pnpm build:pack
7
+ exit $LASTEXITCODE
@@ -0,0 +1,7 @@
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
+ & pnpm validate
7
+ exit $LASTEXITCODE
@@ -1,12 +1,9 @@
1
1
  $ErrorActionPreference = "Stop"
2
2
 
3
3
  $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ & "$PSScriptRoot/ensure-deps.ps1"
4
5
  Set-Location $workspace
5
6
 
6
- Write-Host "Installing dependencies..."
7
- & pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
8
- if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
9
-
10
7
  Write-Host "Building frontend with Vite..."
11
8
  & pnpm vite build
12
9
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
@@ -51,13 +51,29 @@ try {
51
51
  }
52
52
 
53
53
  $process.Id | Set-Content $pidFile
54
- Start-Sleep -Seconds 1
55
- if ($process.HasExited) {
56
- Get-Content $errorLogFile -Tail 20 -ErrorAction SilentlyContinue
57
- Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
58
- exit 1
54
+
55
+ $startupTimeoutSeconds = 30
56
+ $startupDeadline = (Get-Date).AddSeconds($startupTimeoutSeconds)
57
+ while ((Get-Date) -lt $startupDeadline) {
58
+ if ($process.HasExited) {
59
+ Write-Error "Dev server exited before listening on port $port."
60
+ Get-Content $errorLogFile -Tail 20 -ErrorAction SilentlyContinue
61
+ Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
62
+ exit 1
63
+ }
64
+
65
+ if (Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue) {
66
+ Write-Host "Dev server is listening on port $port (PID: $($process.Id))."
67
+ Write-Host "Log file: $logFile"
68
+ exit 0
69
+ }
70
+
71
+ Start-Sleep -Milliseconds 200
59
72
  }
60
73
 
61
- Write-Host "Dev server started (PID: $($process.Id))."
62
- Write-Host "Log file: $logFile"
74
+ Write-Error "Dev server did not listen on port $port within $startupTimeoutSeconds seconds."
75
+ Stop-ProcessTree $process.Id
76
+ Get-Content $errorLogFile -Tail 20 -ErrorAction SilentlyContinue
77
+ Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
78
+ exit 1
63
79
  <% } %>
@@ -0,0 +1,33 @@
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
+ $lockfile = Join-Path $workspace "pnpm-lock.yaml"
7
+ $modulesDirectory = Join-Path $workspace "node_modules"
8
+ $modulesManifest = Join-Path $modulesDirectory ".modules.yaml"
9
+ $lockHashFile = Join-Path $modulesDirectory ".coze-lockfile-sha256"
10
+
11
+ if (-not (Test-Path $lockfile)) {
12
+ throw "pnpm-lock.yaml is required to install dependencies."
13
+ }
14
+
15
+ $lockHash = (Get-FileHash -LiteralPath $lockfile -Algorithm SHA256).Hash
16
+ $cachedLockHash = if (Test-Path $lockHashFile) {
17
+ (Get-Content -LiteralPath $lockHashFile -Raw).Trim()
18
+ } else {
19
+ ""
20
+ }
21
+
22
+ if ((Test-Path $modulesManifest) -and $cachedLockHash -eq $lockHash) {
23
+ Write-Host "Dependencies already match pnpm-lock.yaml; skipping install."
24
+ return
25
+ }
26
+
27
+ Write-Host "Installing dependencies..."
28
+ & pnpm install --frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
29
+ if ($LASTEXITCODE -ne 0) {
30
+ throw "pnpm install failed with exit code $LASTEXITCODE."
31
+ }
32
+
33
+ Set-Content -LiteralPath $lockHashFile -Value $lockHash -NoNewline
@@ -1,14 +1,9 @@
1
1
  $ErrorActionPreference = "Stop"
2
2
 
3
3
  $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ & "$PSScriptRoot/ensure-deps.ps1"
4
5
  Set-Location $workspace
5
6
 
6
- Write-Host "Installing dependencies..."
7
- & pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
8
- if ($LASTEXITCODE -ne 0) {
9
- exit $LASTEXITCODE
10
- }
11
-
12
7
  if (Get-Command coze-dev -ErrorAction SilentlyContinue) {
13
8
  & coze-dev check-bins --help *> $null
14
9
  if ($LASTEXITCODE -eq 0) {
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.4-alpha.b94eab";
2117
+ var version = "0.1.4-alpha.e6e18e";
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.1.4-alpha.b94eab",
3
+ "version": "0.1.4-alpha.e6e18e",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",