@coze-arch/cli 0.1.2 → 0.1.3-alpha.574830

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.
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
  if [ -z "${BASH_VERSION:-}" ]; then exec /usr/bin/env bash "$0" "$@"; fi
3
3
  set -euo pipefail
4
- ROOT_DIR="$(pwd)"
4
+ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
5
  PREVIEW_DIR="/source/preview"
6
6
  SOURCE_DIR="/source"
7
7
 
@@ -34,8 +34,8 @@ echo "==================== 安装项目依赖 ===================="
34
34
  if [ ! -f "package.json" ]; then
35
35
  echo "项目目录下无 package.json,不是合法的 Node.js 项目"
36
36
  fi
37
- # 步骤 2.1/2.2:安装项目依赖
38
- pnpm install --registry=https://registry.npmmirror.com || echo "Expo 项目依赖安装失败(pnpm 执行出错)"
37
+ # 步骤 2.1/2.2:通过受管入口安装项目依赖
38
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --registry=https://registry.npmmirror.com
39
39
 
40
40
  echo "检查根目录 post_install.py"
41
41
  if [ -f "$PREVIEW_DIR/post_install.py" ]; then
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env bash
2
+ # Install dependencies on local disk and expose them to the source tree by symlink.
3
+ set -euo pipefail
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
6
+ if [ "$(basename "$(dirname "$SCRIPT_DIR")")" = ".cozeproj" ]; then
7
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd -P)"
8
+ else
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
10
+ fi
11
+
12
+ command -v pnpm >/dev/null 2>&1 || {
13
+ echo "[node_modules] pnpm is required" >&2
14
+ exit 1
15
+ }
16
+
17
+ DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
18
+ if [ -d "$DRIVE_ROOT" ]; then
19
+ DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
20
+ else
21
+ DRIVE_ROOT="${DRIVE_ROOT%/}"
22
+ fi
23
+ case "$PROJECT_ROOT" in
24
+ "$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
25
+ *)
26
+ (cd "$PROJECT_ROOT" && pnpm install "$@")
27
+ exit 0
28
+ ;;
29
+ esac
30
+
31
+ COZE_ROOT="${COZE_DIR_PATH:-${HOME}/Coze/tmp}"
32
+ PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
33
+ mkdir -p "$COZE_ROOT/nm"
34
+ COZE_ROOT="$(cd "$COZE_ROOT" && pwd -P)"
35
+ WORK_DIR="$COZE_ROOT/nm/$PROJECT_ID"
36
+ mkdir -p "$WORK_DIR"
37
+ case "$WORK_DIR" in
38
+ "$DRIVE_ROOT"|"$DRIVE_ROOT"/*)
39
+ echo "[node_modules] local dependency directory must not be on Coze Drive: $WORK_DIR" >&2
40
+ exit 1
41
+ ;;
42
+ esac
43
+
44
+ # Mirror the project with symlinks. node_modules stays real in WORK_DIR;
45
+ # workspace directories stay real too, so pnpm never writes them to Drive.
46
+ mirror_root() {
47
+ local entry name
48
+ while IFS= read -r -d '' entry; do
49
+ name="$(basename "$entry")"
50
+ case "$name" in
51
+ node_modules|pnpm-lock.yaml) continue ;;
52
+ client|server)
53
+ [ -f "$PROJECT_ROOT/$name/package.json" ] && continue
54
+ ;;
55
+ esac
56
+ rm -rf "$entry"
57
+ done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
58
+
59
+ while IFS= read -r -d '' entry; do
60
+ name="$(basename "$entry")"
61
+ case "$name" in
62
+ node_modules|pnpm-lock.yaml) continue ;;
63
+ client|server)
64
+ [ -f "$entry/package.json" ] && continue
65
+ ;;
66
+ esac
67
+ ln -s "$entry" "$WORK_DIR/$name"
68
+ done < <(find "$PROJECT_ROOT" -mindepth 1 -maxdepth 1 -print0)
69
+ }
70
+
71
+ mirror_workspace() {
72
+ local workspace="$1" source_dir="$PROJECT_ROOT/$1" work_dir="$WORK_DIR/$1"
73
+ local entry name
74
+ if [ -L "$work_dir" ] || { [ -e "$work_dir" ] && [ ! -d "$work_dir" ]; }; then
75
+ rm -rf "$work_dir"
76
+ fi
77
+ mkdir -p "$work_dir"
78
+
79
+ while IFS= read -r -d '' entry; do
80
+ [ "$(basename "$entry")" = "node_modules" ] || rm -rf "$entry"
81
+ done < <(find "$work_dir" -mindepth 1 -maxdepth 1 -print0)
82
+
83
+ while IFS= read -r -d '' entry; do
84
+ name="$(basename "$entry")"
85
+ [ "$name" = "node_modules" ] || ln -s "$entry" "$work_dir/$name"
86
+ done < <(find "$source_dir" -mindepth 1 -maxdepth 1 -print0)
87
+ }
88
+
89
+ mirror_root
90
+ for workspace in client server; do
91
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
92
+ mirror_workspace "$workspace"
93
+ fi
94
+ done
95
+
96
+ # pnpm refuses to update a symlinked lockfile, so install against a local copy.
97
+ rm -rf "$WORK_DIR/pnpm-lock.yaml"
98
+ if [ -f "$PROJECT_ROOT/pnpm-lock.yaml" ]; then
99
+ cp "$PROJECT_ROOT/pnpm-lock.yaml" "$WORK_DIR/pnpm-lock.yaml"
100
+ fi
101
+
102
+ echo "[node_modules] Installing dependencies in $WORK_DIR"
103
+ if ! (cd "$WORK_DIR" && pnpm install "$@"); then
104
+ rm -f "$WORK_DIR/pnpm-lock.yaml"
105
+ exit 1
106
+ fi
107
+
108
+ if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
109
+ temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
110
+ cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
111
+ chmod 0644 "$temporary_lockfile"
112
+ mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
113
+ fi
114
+
115
+ link_node_modules() {
116
+ local source_dir="$1" target_dir="$2"
117
+ local current=""
118
+ mkdir -p "$target_dir"
119
+ if [ -L "$source_dir/node_modules" ]; then
120
+ current="$(readlink "$source_dir/node_modules")"
121
+ case "$current" in
122
+ "$COZE_ROOT"/nm/*/node_modules|"$COZE_ROOT"/nm/*/*/node_modules) ;;
123
+ *)
124
+ echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
125
+ exit 1
126
+ ;;
127
+ esac
128
+ rm "$source_dir/node_modules"
129
+ elif [ -e "$source_dir/node_modules" ]; then
130
+ rm -rf "$source_dir/node_modules"
131
+ fi
132
+ ln -s "$target_dir" "$source_dir/node_modules"
133
+ }
134
+
135
+ link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
136
+ for workspace in client server; do
137
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
138
+ link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
139
+ fi
140
+ done
141
+
142
+ echo "[node_modules] Dependencies ready"
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
  if [ -z "${BASH_VERSION:-}" ]; then exec /usr/bin/env bash "$0" "$@"; fi
3
3
  set -euo pipefail
4
- ROOT_DIR="$(pwd)"
4
+ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
5
 
6
6
  # ==================== 工具函数 ====================
7
7
  info() {
@@ -32,8 +32,8 @@ info "==================== 安装 Node 依赖 ===================="
32
32
  info "开始安装 Node 依赖"
33
33
  if [ -f "$ROOT_DIR/package.json" ]; then
34
34
  info "进入目录:$ROOT_DIR"
35
- info "正在执行:pnpm install"
36
- (cd "$ROOT_DIR" && pnpm install --registry=https://registry.npmmirror.com) || error "Node 依赖安装失败"
35
+ info "正在执行受管依赖准备入口"
36
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --registry=https://registry.npmmirror.com || error "Node 依赖安装失败"
37
37
  else
38
38
  warn "未找到 $ROOT_DIR/package.json 文件,请检查路径是否正确"
39
39
  fi