@gadmin2n/cli 0.0.196 → 0.0.198

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.
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.PrismaAction = void 0;
13
13
  const chalk = require("chalk");
14
+ const child_process_1 = require("child_process");
14
15
  const fs = require("fs");
15
16
  const path_1 = require("path");
16
17
  const sync_fs_1 = require("../lib/utils/sync-fs");
@@ -84,7 +85,7 @@ class PrismaAction extends abstract_action_1.AbstractAction {
84
85
  return (0, sync_fs_1.writeFileIfChanged)('server/prisma/schema.prisma', generatorHead + merged);
85
86
  }
86
87
  handle(inputs, options) {
87
- var _a, _b;
88
+ var _a, _b, _c, _d;
88
89
  return __awaiter(this, void 0, void 0, function* () {
89
90
  // 检查 prisma schema 配置是否存在
90
91
  const hasPrismaConfig = shell.test('-e', 'config/schema.prisma') ||
@@ -96,6 +97,12 @@ class PrismaAction extends abstract_action_1.AbstractAction {
96
97
  }
97
98
  const devMode = !!((_a = options.find((option) => option.name === 'dev')) === null || _a === void 0 ? void 0 : _a.value);
98
99
  const verbose = !!((_b = options.find((option) => option.name === 'verbose')) === null || _b === void 0 ? void 0 : _b.value);
100
+ // 非交互判定:stdin 非 TTY(CI/CD、管道、多数 AI agent 环境)时自动进入,
101
+ // 无需显式 --yes;--yes 用于强制(stdin 是 TTY 但无人值守的场景无法自动判断)。
102
+ // prisma migrate dev 的确认提示无自动确认参数可传,注入 CI=true 让 prisma 的
103
+ // canPrompt() 判定为非交互,遇确认直接报错退出(fail fast),而不是挂起等输入。
104
+ const yes = !!((_c = options.find((option) => option.name === 'yes')) === null || _c === void 0 ? void 0 : _c.value) ||
105
+ !process.stdin.isTTY;
99
106
  // 分发过程按类别记账,收尾统一打摘要 / --verbose 打完整清单
100
107
  const stats = {
101
108
  serverGeneratedIndex: [],
@@ -114,8 +121,7 @@ class PrismaAction extends abstract_action_1.AbstractAction {
114
121
  this.buildMergedSchema();
115
122
  // Staging 目录:generator 全量写入到 .gadmin/generated/*,CLI 再增量分发。
116
123
  // 不放在 src/ 下,避免任何 watcher 感知到中间态的进出。
117
- // 用绝对路径以便 (a) 在 shell.cd('server/') 之后仍指向正确位置;
118
- // (b) 通过 env 传给 generator 子进程时无歧义。
124
+ // 用绝对路径以便通过 env 传给 generator 子进程时无歧义。
119
125
  const cwd = process.cwd();
120
126
  const WEB_STAGING = (0, path_1.resolve)(cwd, '.gadmin/generated/web');
121
127
  const SERVER_STAGING = (0, path_1.resolve)(cwd, '.gadmin/generated/server');
@@ -129,14 +135,26 @@ class PrismaAction extends abstract_action_1.AbstractAction {
129
135
  fs.mkdirSync(SERVER_STAGING, { recursive: true });
130
136
  // 执行代码生成(走 npm run 脚本)。通过 env 传 staging 路径,
131
137
  // generator 会优先使用 env 覆盖 .prisma schema 里的 output 配置。
138
+ // 用 spawnSync + stdio:'inherit' 而非 shelljs exec:后者经 exec-child.js
139
+ // 中转时 stdin 是 pipe,会导致 prisma migrate dev 判定为非交互式。
132
140
  const generateScript = devMode ? 'npm run generate:dev' : 'npm run generate';
133
- const { code } = shell.cd('server/').exec(generateScript, {
134
- env: Object.assign(Object.assign({}, process.env), { GADMIN_WEB_STAGING: WEB_STAGING, GADMIN_SERVER_STAGING: SERVER_STAGING, GADMIN_WEB_ROUTES_DIR: WEB_ROUTES_DIR }),
141
+ const result = (0, child_process_1.spawnSync)(generateScript, {
142
+ cwd: 'server',
143
+ shell: true,
144
+ stdio: 'inherit',
145
+ env: Object.assign(Object.assign(Object.assign({}, process.env), (yes ? { CI: 'true' } : {})), { GADMIN_WEB_STAGING: WEB_STAGING, GADMIN_SERVER_STAGING: SERVER_STAGING, GADMIN_WEB_ROUTES_DIR: WEB_ROUTES_DIR }),
135
146
  });
136
- if (code !== 0) {
137
- process.exit(code);
147
+ if (result.error) {
148
+ console.error(chalk.red(`Failed to run ${generateScript}: ${result.error.message}`));
149
+ process.exit(1);
150
+ }
151
+ if (result.status !== 0) {
152
+ if (yes) {
153
+ console.log(chalk.yellow('Non-interactive mode: prisma migrate dev requires manual confirmation (e.g. data-loss warnings). ' +
154
+ 'Run `gadmin2 g prisma:dev` in an interactive terminal once to confirm the migration.'));
155
+ }
156
+ process.exit((_d = result.status) !== null && _d !== void 0 ? _d : 1);
138
157
  }
139
- shell.cd('../');
140
158
  // 分发策略:先集中写 server/,再集中写 web/。
141
159
  // 目的是把 nest --watch 的 2 波重启合成 1 波,把 Vite 的 4 波 HMR 合成 1 波。
142
160
  //
@@ -280,7 +298,7 @@ class PrismaAction extends abstract_action_1.AbstractAction {
280
298
  this.printReport(stats, verbose);
281
299
  // 分发全部完成后,若 server/package.json 定义了 postgadminGenerate,
282
300
  // 触发它。项目侧可用来做 dev server 通知、缓存清理等自定义收尾。
283
- this.runProjectPostHook();
301
+ this.runProjectPostHook(yes);
284
302
  process.exit(0);
285
303
  });
286
304
  }
@@ -325,7 +343,7 @@ class PrismaAction extends abstract_action_1.AbstractAction {
325
343
  printGroup('web generated (unchanged)', stats.generatedUnchanged, chalk.gray);
326
344
  printGroup('web orphans removed', stats.orphansRemoved, chalk.red);
327
345
  }
328
- runProjectPostHook() {
346
+ runProjectPostHook(yes) {
329
347
  var _a;
330
348
  const pkgPath = 'server/package.json';
331
349
  let pkg;
@@ -338,14 +356,18 @@ class PrismaAction extends abstract_action_1.AbstractAction {
338
356
  if (!((_a = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _a === void 0 ? void 0 : _a.postgadminGenerate))
339
357
  return;
340
358
  console.log(chalk.gray('Running postgadminGenerate hook ...'));
341
- const { code } = shell
342
- .cd('server/')
343
- .exec('npm run --silent postgadminGenerate', {
344
- env: Object.assign({}, process.env),
359
+ const result = (0, child_process_1.spawnSync)('npm run --silent postgadminGenerate', {
360
+ cwd: 'server',
361
+ shell: true,
362
+ stdio: 'inherit',
363
+ env: Object.assign(Object.assign({}, process.env), (yes ? { CI: 'true' } : {})),
345
364
  });
346
- shell.cd('../');
347
- if (code !== 0) {
348
- console.log(chalk.yellow(`postgadminGenerate exited with code ${code}; ignoring (non-fatal).`));
365
+ if (result.error) {
366
+ console.log(chalk.yellow(`postgadminGenerate failed to spawn: ${result.error.message}; ignoring (non-fatal).`));
367
+ return;
368
+ }
369
+ if (result.status !== 0) {
370
+ console.log(chalk.yellow(`postgadminGenerate exited with code ${result.status}; ignoring (non-fatal).`));
349
371
  }
350
372
  }
351
373
  }
@@ -33,6 +33,8 @@ class GenerateCommand extends abstract_command_1.AbstractCommand {
33
33
  })
34
34
  .option('-c, --collection [collectionName]', 'Schematics collection to use.')
35
35
  .option('-v, --verbose', 'Print each affected src/ file (prisma).')
36
+ .option('-y, --yes', 'Force non-interactive mode: fail fast instead of hanging on prisma migrate dev confirmation prompts. ' +
37
+ 'Auto-enabled when stdin is not a TTY (CI/CD, pipes, AI agents); use this flag for unattended TTY sessions.')
36
38
  .action((schematic, name, path, command) => __awaiter(this, void 0, void 0, function* () {
37
39
  const options = [];
38
40
  options.push({ name: 'dry-run', value: !!command.dryRun });
@@ -66,6 +68,7 @@ class GenerateCommand extends abstract_command_1.AbstractCommand {
66
68
  },
67
69
  });
68
70
  options.push({ name: 'verbose', value: !!command.verbose });
71
+ options.push({ name: 'yes', value: !!command.yes });
69
72
  const inputs = [];
70
73
  inputs.push({ name: 'schematic', value: schematic });
71
74
  inputs.push({ name: 'name', value: name });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gadmin2n/cli",
3
- "version": "0.0.196",
3
+ "version": "0.0.198",
4
4
  "description": "Gadmin - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"