@coze-arch/cli 0.1.8-alpha.a5ed27 → 0.1.8-alpha.e237ba

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.
Files changed (36) hide show
  1. package/README.md +18 -0
  2. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +178 -10
  3. package/lib/__templates__/nextjs/.coze +1 -1
  4. package/lib/__templates__/nextjs/README.md +18 -0
  5. package/lib/__templates__/nextjs/scripts/build.sh +1 -1
  6. package/lib/__templates__/nextjs/scripts/dev.sh +16 -34
  7. package/lib/__templates__/nextjs/scripts/local-workspace.cjs +302 -0
  8. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +178 -10
  9. package/lib/__templates__/nextjs/scripts/prepare.sh +10 -2
  10. package/lib/__templates__/nextjs/scripts/validate.sh +11 -1
  11. package/lib/__templates__/nextjs/template.config.js +20 -6
  12. package/lib/__templates__/nextjs/tsconfig.json +0 -1
  13. package/lib/__templates__/nuxt-vue/.coze +1 -1
  14. package/lib/__templates__/nuxt-vue/README.md +20 -2
  15. package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
  16. package/lib/__templates__/nuxt-vue/scripts/dev.sh +10 -4
  17. package/lib/__templates__/nuxt-vue/scripts/local-workspace.cjs +302 -0
  18. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +178 -10
  19. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +10 -2
  20. package/lib/__templates__/nuxt-vue/scripts/validate.sh +11 -1
  21. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +4 -1
  22. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +3 -54
  23. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +1 -40
  24. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +178 -10
  25. package/lib/__templates__/vite/.coze +1 -1
  26. package/lib/__templates__/vite/README.md +20 -0
  27. package/lib/__templates__/vite/scripts/build.sh +1 -1
  28. package/lib/__templates__/vite/scripts/dev.sh +10 -4
  29. package/lib/__templates__/vite/scripts/local-workspace.cjs +302 -0
  30. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +178 -10
  31. package/lib/__templates__/vite/scripts/prepare.sh +10 -2
  32. package/lib/__templates__/vite/scripts/validate.sh +7 -1
  33. package/lib/__templates__/vite/template.config.js +20 -6
  34. package/lib/cli.js +365 -184
  35. package/package.json +2 -1
  36. package/lib/__templates__/taro/.cozeproj/scripts/build-on-local-disk.sh +0 -194
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.1.8-alpha.a5ed27",
3
+ "version": "0.1.8-alpha.e237ba",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",
@@ -34,6 +34,7 @@
34
34
  "test:all": "bash scripts/test-coverage.sh",
35
35
  "test:cov": "vitest --run --passWithNoTests --coverage",
36
36
  "test:e2e": "NODE_ENV=test bash scripts/e2e.sh",
37
+ "test:integration:web": "node --test __tests__/integration/local-workspace.test.cjs",
37
38
  "test:perf": "vitest bench --run --config vitest.perf.config.ts",
38
39
  "test:perf:compare": "bash scripts/compare-perf.sh",
39
40
  "test:perf:save": "bash scripts/run-perf-with-output.sh"
@@ -1,194 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Run one-shot Taro builds from a local shadow workspace when the project lives
3
- # on Coze Drive. This avoids repeated compiler stat/read traffic against the
4
- # network filesystem while keeping final artifacts in the project directory.
5
- set -Eeuo pipefail
6
-
7
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
8
- ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd -P)"
9
- PROJECT_ROOT="$(cd "${COZE_WORKSPACE_PATH:-$ROOT_DIR}" && pwd -P)"
10
-
11
- if [ "$#" -eq 0 ]; then
12
- set -- pnpm build
13
- fi
14
-
15
- is_under_root() {
16
- local path="$1"
17
- local root="$2"
18
- [ -n "$root" ] || return 1
19
- case "$path" in
20
- "$root"|"$root"/*) return 0 ;;
21
- *) return 1 ;;
22
- esac
23
- }
24
-
25
- is_coze_drive_workspace() {
26
- local path="$1"
27
- local root
28
- local candidates=()
29
-
30
- if [ -n "${COZE_DRIVE_ROOT:-}" ]; then
31
- candidates+=("$COZE_DRIVE_ROOT")
32
- fi
33
- candidates+=("/Coze/Drive")
34
-
35
- for root in "${candidates[@]}"; do
36
- if [ -d "$root" ]; then
37
- root="$(cd "$root" && pwd -P)"
38
- else
39
- root="${root%/}"
40
- fi
41
- if is_under_root "$path" "$root"; then
42
- return 0
43
- fi
44
- done
45
-
46
- return 1
47
- }
48
-
49
- prepare_dependencies() {
50
- if [ "${COZE_SKIP_PREPARE_NODE_MODULES:-0}" = "1" ]; then
51
- return
52
- fi
53
- echo "[local-build] Preparing dependencies..."
54
- bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
55
- }
56
-
57
- if ! is_coze_drive_workspace "$PROJECT_ROOT"; then
58
- prepare_dependencies
59
- cd "$PROJECT_ROOT"
60
- "$@"
61
- exit $?
62
- fi
63
-
64
- command -v rsync >/dev/null 2>&1 || {
65
- echo "[local-build] rsync is required for Coze Drive local builds" >&2
66
- exit 1
67
- }
68
-
69
- prepare_dependencies
70
-
71
- BUILD_ROOT="${COZE_LOCAL_BUILD_ROOT:-/tmp/coze-taro-build}"
72
- PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
73
- WORK_DIR="$BUILD_ROOT/$PROJECT_ID"
74
- LOCAL_WORKSPACE="$WORK_DIR/workspace"
75
- LOCK_DIR="$WORK_DIR.lock"
76
-
77
- mkdir -p "$BUILD_ROOT"
78
- if is_coze_drive_workspace "$(cd "$BUILD_ROOT" && pwd -P)"; then
79
- echo "[local-build] COZE_LOCAL_BUILD_ROOT must not be on Coze Drive: $BUILD_ROOT" >&2
80
- exit 1
81
- fi
82
-
83
- while ! mkdir "$LOCK_DIR" 2>/dev/null; do
84
- echo "[local-build] Waiting for another local build for this project..."
85
- sleep 1
86
- done
87
-
88
- cleanup() {
89
- if [ -n "${SOURCE_SYNC_PID:-}" ]; then
90
- kill "$SOURCE_SYNC_PID" 2>/dev/null || true
91
- fi
92
- rm -rf "$LOCAL_WORKSPACE"
93
- rmdir "$WORK_DIR" 2>/dev/null || true
94
- rmdir "$LOCK_DIR" 2>/dev/null || true
95
- }
96
- trap cleanup EXIT
97
-
98
- mkdir -p "$LOCAL_WORKSPACE"
99
-
100
- sync_source_to_local() {
101
- rsync -rlgoD --checksum --delete \
102
- --exclude '/.git/' \
103
- --exclude '/node_modules/' \
104
- --exclude '/server/node_modules/' \
105
- --exclude '/logs/' \
106
- --exclude '/dist/' \
107
- --exclude '/dist-web/' \
108
- --exclude '/dist-tt/' \
109
- --exclude '/server/dist/' \
110
- --exclude '/.next/' \
111
- --exclude '/.nuxt/' \
112
- --exclude '/.output/' \
113
- --exclude '/coverage/' \
114
- "$PROJECT_ROOT/" "$LOCAL_WORKSPACE/"
115
- }
116
-
117
- echo "[local-build] Syncing source to $LOCAL_WORKSPACE"
118
- sync_source_to_local
119
-
120
- link_node_modules() {
121
- local source_node_modules="$1"
122
- local shadow_parent="$2"
123
- local shadow_node_modules="$shadow_parent/node_modules"
124
- local target
125
-
126
- if [ ! -e "$source_node_modules" ] && [ ! -L "$source_node_modules" ]; then
127
- return
128
- fi
129
-
130
- if [ -L "$source_node_modules" ]; then
131
- target="$(readlink "$source_node_modules")"
132
- else
133
- target="$source_node_modules"
134
- fi
135
-
136
- mkdir -p "$shadow_parent"
137
- rm -rf "$shadow_node_modules"
138
- ln -s "$target" "$shadow_node_modules"
139
- }
140
-
141
- link_node_modules "$PROJECT_ROOT/node_modules" "$LOCAL_WORKSPACE"
142
- for workspace in server; do
143
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
144
- link_node_modules "$PROJECT_ROOT/$workspace/node_modules" "$LOCAL_WORKSPACE/$workspace"
145
- fi
146
- done
147
-
148
- SOURCE_SYNC_PID=""
149
- if [ "${COZE_SYNC_SOURCE_TO_LOCAL:-0}" = "1" ]; then
150
- (
151
- while true; do
152
- sleep "${COZE_SYNC_INTERVAL_SECONDS:-1}"
153
- sync_source_to_local
154
- done
155
- ) &
156
- SOURCE_SYNC_PID=$!
157
- fi
158
-
159
- rm -rf \
160
- "$LOCAL_WORKSPACE/dist" \
161
- "$LOCAL_WORKSPACE/dist-web" \
162
- "$LOCAL_WORKSPACE/dist-tt" \
163
- "$LOCAL_WORKSPACE/server/dist"
164
-
165
- echo "[local-build] Building on local disk..."
166
- (
167
- cd "$LOCAL_WORKSPACE"
168
- export COZE_WORKSPACE_PATH="$LOCAL_WORKSPACE"
169
- "$@"
170
- )
171
-
172
- sync_output_back() {
173
- local output_name="$1"
174
- local local_output="$LOCAL_WORKSPACE/$output_name"
175
- local project_output="$PROJECT_ROOT/$output_name"
176
-
177
- if [ ! -e "$local_output" ]; then
178
- return
179
- fi
180
-
181
- if [ -L "$project_output" ] || [ -e "$project_output" ]; then
182
- rm -rf "$project_output"
183
- fi
184
-
185
- mkdir -p "$(dirname "$project_output")"
186
- rsync -a --delete "$local_output/" "$project_output/"
187
- }
188
-
189
- echo "[local-build] Syncing build artifacts back to $PROJECT_ROOT"
190
- sync_output_back dist
191
- sync_output_back dist-web
192
- sync_output_back dist-tt
193
- sync_output_back server/dist
194
- echo "[local-build] Build artifacts are ready in the project directory"