@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.
@@ -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"
@@ -6,7 +6,4 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
- if command -v coze-dev > /dev/null 2>&1 && coze-dev check-bins --help > /dev/null 2>&1; then
11
- coze-dev check-bins --fix
12
- fi
9
+ bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
@@ -1,8 +1,4 @@
1
1
 
2
- import { spawn } from 'child_process';
3
- import { resolve, join, basename } from 'path';
4
- import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
5
- import { homedir } from 'os';
6
2
 
7
3
 
8
4
 
@@ -64,61 +60,6 @@ const config = {
64
60
  onAfterRender: async (_context, _outputPath) => {
65
61
  // 输出由 init 命令统一处理
66
62
  },
67
-
68
- onComplete: async (_context, outputPath) => {
69
- // Skip pnpm update in test environment to avoid monorepo workspace issues
70
- if (process.env.NODE_ENV === 'test') {
71
- console.log('⊘ Skipping dependency update in test environment');
72
- return;
73
- }
74
-
75
- const cmd = 'pnpm';
76
- const args = ['update', 'coze-coding-dev-sdk@^0.7.25'];
77
- console.log(
78
- `\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
79
- );
80
-
81
- try {
82
- const projectRoot = resolve(outputPath);
83
-
84
- // Determine log directory
85
- const cozeHome = process.env.COZE_HOME || join(homedir(), '.coze');
86
- const logDir = process.env.COZE_LOG_DIR || join(cozeHome, 'logs');
87
- mkdirSync(logDir, { recursive: true });
88
-
89
- // Use project name in log file to avoid conflicts
90
- const projectName = basename(projectRoot);
91
- const logFile = join(logDir, `${projectName}-init.log`);
92
-
93
- // Write log header
94
- const timestamp = new Date().toISOString();
95
- appendFileSync(
96
- logFile,
97
- `\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
98
- );
99
-
100
- // Open log file for appending
101
- const logFd = openSync(logFile, 'a');
102
-
103
- // Spawn in detached mode
104
- const child = spawn(cmd, args, {
105
- cwd: projectRoot,
106
- detached: true,
107
- stdio: ['ignore', logFd, logFd],
108
- });
109
-
110
- child.unref();
111
- closeSync(logFd);
112
-
113
- console.log(
114
- '✓ coze-coding-dev-sdk update triggered (running in background)',
115
- );
116
- console.log(` Log file: ${logFile}`);
117
- } catch (error) {
118
- console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
119
- console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
120
- }
121
- },
122
63
  };
123
64
 
124
65
  export default config;
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.2";
2117
+ var version = "0.1.3-alpha.574830";
2118
2118
  var description = "coze coding devtools cli";
2119
2119
  var license = "MIT";
2120
2120
  var author = "fanwenjie.fe@bytedance.com";
@@ -9882,18 +9882,38 @@ 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
+
9885
9904
  /**
9886
- * 运行 pnpm install
9905
+ * 优先通过模板提供的 wrapper 准备依赖。
9887
9906
  */
9888
- const runPnpmInstall = (projectPath) => {
9889
- logger.info('\nInstalling dependencies with pnpm...');
9907
+ const prepareDependencies = (projectPath) => {
9908
+ logger.info('\nPreparing dependencies with the project wrapper...');
9890
9909
 
9891
- const result = shelljs.exec('pnpm install', {
9910
+ const command = getDependencyPreparationCommand(projectPath);
9911
+ const result = shelljs.exec(command, {
9892
9912
  cwd: projectPath,
9893
9913
  silent: true,
9894
9914
  });
9895
9915
 
9896
- // verbose 模式下输出 pnpm install 的详细日志
9916
+ // verbose 模式下输出依赖准备命令的详细日志
9897
9917
  if (result.stdout) {
9898
9918
  logger.verbose(result.stdout);
9899
9919
  }
@@ -9902,11 +9922,11 @@ const runPnpmInstall = (projectPath) => {
9902
9922
  }
9903
9923
 
9904
9924
  if (result.code === 0) {
9905
- logger.success('Dependencies installed successfully!');
9925
+ logger.success('Dependencies prepared successfully!');
9906
9926
  } else {
9907
9927
  // 仅在失败时输出详细信息以便排查
9908
9928
  const errorMessage = [
9909
- `pnpm install failed with exit code ${result.code}`,
9929
+ `${command} failed with exit code ${result.code}`,
9910
9930
  result.stderr ? `\nStderr:\n${result.stderr}` : '',
9911
9931
  result.stdout ? `\nStdout:\n${result.stdout}` : '',
9912
9932
  ]
@@ -10131,7 +10151,7 @@ const installDependenciesStep = ctx => {
10131
10151
  try {
10132
10152
  if (!skipInstall) {
10133
10153
  if (ctx.hasPackageJson) {
10134
- runPnpmInstall(ctx.absoluteOutputPath);
10154
+ prepareDependencies(ctx.absoluteOutputPath);
10135
10155
  ctx.timer.logPhase('Dependencies installation');
10136
10156
  } else {
10137
10157
  logger.info(
@@ -10140,7 +10160,7 @@ const installDependenciesStep = ctx => {
10140
10160
  }
10141
10161
  }
10142
10162
  } catch (error) {
10143
- // 捕获 pnpm install 失败的情况
10163
+ // 捕获依赖准备失败的情况
10144
10164
  installSuccess = false;
10145
10165
  installErrorCode = 1;
10146
10166
  installErrorType = 'execution_failed';
@@ -10227,7 +10247,9 @@ const startDevServerStep = ctx => {
10227
10247
  logger.info('\nNext steps:');
10228
10248
  logger.info(` cd ${ctx.outputPath}`);
10229
10249
  if (skipInstall && ctx.hasPackageJson) {
10230
- logger.info(' pnpm install');
10250
+ logger.info(
10251
+ ` ${getDependencyPreparationCommand(ctx.absoluteOutputPath)}`,
10252
+ );
10231
10253
  }
10232
10254
  if (skipGit) {
10233
10255
  logger.info(' git init');
@@ -10339,7 +10361,7 @@ const registerCommand$1 = program => {
10339
10361
  .argument('[directory]', 'Output directory for the project')
10340
10362
  .requiredOption('-t, --template <name>', 'Template name')
10341
10363
  .option('-o, --output <path>', 'Output directory', process.cwd())
10342
- .option('--skip-install', 'Skip automatic pnpm install', false)
10364
+ .option('--skip-install', 'Skip automatic dependency preparation', false)
10343
10365
  .option('--skip-git', 'Skip automatic git initialization', false)
10344
10366
  .option(
10345
10367
  '--skip-commit',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3-alpha.574830",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",