@gadmin2n/cli 0.0.195 → 0.0.197

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;
88
89
  return __awaiter(this, void 0, void 0, function* () {
89
90
  // 检查 prisma schema 配置是否存在
90
91
  const hasPrismaConfig = shell.test('-e', 'config/schema.prisma') ||
@@ -114,8 +115,7 @@ class PrismaAction extends abstract_action_1.AbstractAction {
114
115
  this.buildMergedSchema();
115
116
  // Staging 目录:generator 全量写入到 .gadmin/generated/*,CLI 再增量分发。
116
117
  // 不放在 src/ 下,避免任何 watcher 感知到中间态的进出。
117
- // 用绝对路径以便 (a) 在 shell.cd('server/') 之后仍指向正确位置;
118
- // (b) 通过 env 传给 generator 子进程时无歧义。
118
+ // 用绝对路径以便通过 env 传给 generator 子进程时无歧义。
119
119
  const cwd = process.cwd();
120
120
  const WEB_STAGING = (0, path_1.resolve)(cwd, '.gadmin/generated/web');
121
121
  const SERVER_STAGING = (0, path_1.resolve)(cwd, '.gadmin/generated/server');
@@ -129,14 +129,22 @@ class PrismaAction extends abstract_action_1.AbstractAction {
129
129
  fs.mkdirSync(SERVER_STAGING, { recursive: true });
130
130
  // 执行代码生成(走 npm run 脚本)。通过 env 传 staging 路径,
131
131
  // generator 会优先使用 env 覆盖 .prisma schema 里的 output 配置。
132
+ // 用 spawnSync + stdio:'inherit' 而非 shelljs exec:后者经 exec-child.js
133
+ // 中转时 stdin 是 pipe,会导致 prisma migrate dev 判定为非交互式。
132
134
  const generateScript = devMode ? 'npm run generate:dev' : 'npm run generate';
133
- const { code } = shell.cd('server/').exec(generateScript, {
135
+ const result = (0, child_process_1.spawnSync)(generateScript, {
136
+ cwd: 'server',
137
+ shell: true,
138
+ stdio: 'inherit',
134
139
  env: Object.assign(Object.assign({}, process.env), { GADMIN_WEB_STAGING: WEB_STAGING, GADMIN_SERVER_STAGING: SERVER_STAGING, GADMIN_WEB_ROUTES_DIR: WEB_ROUTES_DIR }),
135
140
  });
136
- if (code !== 0) {
137
- process.exit(code);
141
+ if (result.error) {
142
+ console.error(chalk.red(`Failed to run ${generateScript}: ${result.error.message}`));
143
+ process.exit(1);
144
+ }
145
+ if (result.status !== 0) {
146
+ process.exit((_c = result.status) !== null && _c !== void 0 ? _c : 1);
138
147
  }
139
- shell.cd('../');
140
148
  // 分发策略:先集中写 server/,再集中写 web/。
141
149
  // 目的是把 nest --watch 的 2 波重启合成 1 波,把 Vite 的 4 波 HMR 合成 1 波。
142
150
  //
@@ -338,14 +346,18 @@ class PrismaAction extends abstract_action_1.AbstractAction {
338
346
  if (!((_a = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _a === void 0 ? void 0 : _a.postgadminGenerate))
339
347
  return;
340
348
  console.log(chalk.gray('Running postgadminGenerate hook ...'));
341
- const { code } = shell
342
- .cd('server/')
343
- .exec('npm run --silent postgadminGenerate', {
349
+ const result = (0, child_process_1.spawnSync)('npm run --silent postgadminGenerate', {
350
+ cwd: 'server',
351
+ shell: true,
352
+ stdio: 'inherit',
344
353
  env: Object.assign({}, process.env),
345
354
  });
346
- shell.cd('../');
347
- if (code !== 0) {
348
- console.log(chalk.yellow(`postgadminGenerate exited with code ${code}; ignoring (non-fatal).`));
355
+ if (result.error) {
356
+ console.log(chalk.yellow(`postgadminGenerate failed to spawn: ${result.error.message}; ignoring (non-fatal).`));
357
+ return;
358
+ }
359
+ if (result.status !== 0) {
360
+ console.log(chalk.yellow(`postgadminGenerate exited with code ${result.status}; ignoring (non-fatal).`));
349
361
  }
350
362
  }
351
363
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gadmin2n/cli",
3
- "version": "0.0.195",
3
+ "version": "0.0.197",
4
4
  "description": "Gadmin - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -48,7 +48,7 @@
48
48
  "@angular-devkit/core": "13.3.2",
49
49
  "@angular-devkit/schematics": "13.3.2",
50
50
  "@angular-devkit/schematics-cli": "13.3.2",
51
- "@gadmin2n/schematics": "^0.0.159",
51
+ "@gadmin2n/schematics": "^0.0.160",
52
52
  "abc": "^0.6.1",
53
53
  "chalk": "3.0.0",
54
54
  "chokidar": "3.5.3",