@coze-arch/cli 0.1.3-alpha.6f25e6 → 0.1.3-alpha.cb26ca

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 (26) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +3 -3
  2. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +3 -3
  3. package/lib/__templates__/nextjs/package.json +6 -1
  4. package/lib/__templates__/nextjs/pnpm-lock.yaml +59 -54
  5. package/lib/__templates__/nextjs/scripts/build.sh +1 -1
  6. package/lib/__templates__/nextjs/scripts/dev.sh +0 -2
  7. package/lib/__templates__/nextjs/scripts/prepare.sh +4 -1
  8. package/lib/__templates__/nextjs/src/server.ts +1 -1
  9. package/lib/__templates__/nextjs/template.config.js +59 -0
  10. package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
  11. package/lib/__templates__/nuxt-vue/scripts/dev.sh +0 -2
  12. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +4 -1
  13. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +2 -3
  14. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -3
  15. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +1 -3
  16. package/lib/__templates__/vite/scripts/build.sh +1 -1
  17. package/lib/__templates__/vite/scripts/dev.sh +0 -2
  18. package/lib/__templates__/vite/scripts/prepare.sh +4 -1
  19. package/lib/__templates__/vite/template.config.js +59 -0
  20. package/lib/cli.js +12 -34
  21. package/package.json +1 -1
  22. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +0 -142
  23. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +0 -142
  24. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +0 -142
  25. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +0 -142
  26. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +0 -142
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.3-alpha.6f25e6";
2117
+ var version = "0.1.3-alpha.cb26ca";
2118
2118
  var description = "coze coding devtools cli";
2119
2119
  var license = "MIT";
2120
2120
  var author = "fanwenjie.fe@bytedance.com";
@@ -9882,38 +9882,18 @@ const execute = async (
9882
9882
  };
9883
9883
 
9884
9884
  function _nullishCoalesce$2(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
9885
- const getDependencyPreparationCommand = (projectPath) => {
9886
- if (fs.existsSync(path.join(projectPath, 'scripts', 'prepare.sh'))) {
9887
- return 'bash ./scripts/prepare.sh';
9888
- }
9889
- if (
9890
- fs.existsSync(
9891
- path.join(
9892
- projectPath,
9893
- '.cozeproj',
9894
- 'scripts',
9895
- 'prepare-node-modules.sh',
9896
- ),
9897
- )
9898
- ) {
9899
- return 'bash ./.cozeproj/scripts/prepare-node-modules.sh';
9900
- }
9901
- return 'pnpm install';
9902
- };
9903
-
9904
9885
  /**
9905
- * 优先通过模板提供的 wrapper 准备依赖。
9886
+ * 运行 pnpm install
9906
9887
  */
9907
- const prepareDependencies = (projectPath) => {
9908
- logger.info('\nPreparing dependencies with the project wrapper...');
9888
+ const runPnpmInstall = (projectPath) => {
9889
+ logger.info('\nInstalling dependencies with pnpm...');
9909
9890
 
9910
- const command = getDependencyPreparationCommand(projectPath);
9911
- const result = shelljs.exec(command, {
9891
+ const result = shelljs.exec('pnpm install', {
9912
9892
  cwd: projectPath,
9913
9893
  silent: true,
9914
9894
  });
9915
9895
 
9916
- // verbose 模式下输出依赖准备命令的详细日志
9896
+ // verbose 模式下输出 pnpm install 的详细日志
9917
9897
  if (result.stdout) {
9918
9898
  logger.verbose(result.stdout);
9919
9899
  }
@@ -9922,11 +9902,11 @@ const prepareDependencies = (projectPath) => {
9922
9902
  }
9923
9903
 
9924
9904
  if (result.code === 0) {
9925
- logger.success('Dependencies prepared successfully!');
9905
+ logger.success('Dependencies installed successfully!');
9926
9906
  } else {
9927
9907
  // 仅在失败时输出详细信息以便排查
9928
9908
  const errorMessage = [
9929
- `${command} failed with exit code ${result.code}`,
9909
+ `pnpm install failed with exit code ${result.code}`,
9930
9910
  result.stderr ? `\nStderr:\n${result.stderr}` : '',
9931
9911
  result.stdout ? `\nStdout:\n${result.stdout}` : '',
9932
9912
  ]
@@ -10151,7 +10131,7 @@ const installDependenciesStep = ctx => {
10151
10131
  try {
10152
10132
  if (!skipInstall) {
10153
10133
  if (ctx.hasPackageJson) {
10154
- prepareDependencies(ctx.absoluteOutputPath);
10134
+ runPnpmInstall(ctx.absoluteOutputPath);
10155
10135
  ctx.timer.logPhase('Dependencies installation');
10156
10136
  } else {
10157
10137
  logger.info(
@@ -10160,7 +10140,7 @@ const installDependenciesStep = ctx => {
10160
10140
  }
10161
10141
  }
10162
10142
  } catch (error) {
10163
- // 捕获依赖准备失败的情况
10143
+ // 捕获 pnpm install 失败的情况
10164
10144
  installSuccess = false;
10165
10145
  installErrorCode = 1;
10166
10146
  installErrorType = 'execution_failed';
@@ -10247,9 +10227,7 @@ const startDevServerStep = ctx => {
10247
10227
  logger.info('\nNext steps:');
10248
10228
  logger.info(` cd ${ctx.outputPath}`);
10249
10229
  if (skipInstall && ctx.hasPackageJson) {
10250
- logger.info(
10251
- ` ${getDependencyPreparationCommand(ctx.absoluteOutputPath)}`,
10252
- );
10230
+ logger.info(' pnpm install');
10253
10231
  }
10254
10232
  if (skipGit) {
10255
10233
  logger.info(' git init');
@@ -10361,7 +10339,7 @@ const registerCommand$1 = program => {
10361
10339
  .argument('[directory]', 'Output directory for the project')
10362
10340
  .requiredOption('-t, --template <name>', 'Template name')
10363
10341
  .option('-o, --output <path>', 'Output directory', process.cwd())
10364
- .option('--skip-install', 'Skip automatic dependency preparation', false)
10342
+ .option('--skip-install', 'Skip automatic pnpm install', false)
10365
10343
  .option('--skip-git', 'Skip automatic git initialization', false)
10366
10344
  .option(
10367
10345
  '--skip-commit',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.1.3-alpha.6f25e6",
3
+ "version": "0.1.3-alpha.cb26ca",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",
@@ -1,142 +0,0 @@
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,142 +0,0 @@
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,142 +0,0 @@
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,142 +0,0 @@
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"