@gadmin2n/cli 0.0.159 → 0.0.160

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.
@@ -51,36 +51,37 @@ function replaceFileContent(filePath, match, src, dest) {
51
51
  }
52
52
  class PrismaAction extends abstract_action_1.AbstractAction {
53
53
  buildMergedSchema() {
54
- shell
55
- .cat('server/prisma/.generator.prisma')
56
- .to('server/prisma/schema.prisma');
54
+ // 读 generator 头
55
+ const generatorHead = fs.readFileSync('server/prisma/.generator.prisma', 'utf8');
56
+ // 读用户 schema
57
57
  let schemaStr = '';
58
58
  if (shell.test('-d', 'config/prisma')) {
59
- schemaStr = shell.cat('config/prisma/*.prisma');
59
+ schemaStr = shell.cat('config/prisma/*.prisma').toString();
60
60
  }
61
61
  else {
62
- schemaStr = shell.cat('config/schema.prisma');
62
+ schemaStr = shell.cat('config/schema.prisma').toString();
63
63
  }
64
64
  const schemaRegex = /([\s\S]*?model\s\w*\s*\{)([^\}]*)(\})/gim; // https://regex101.com/
65
- let m, result = '';
65
+ let m, merged = '';
66
66
  while ((m = schemaRegex.exec(schemaStr)) !== null) {
67
67
  // This is necessary to avoid infinite loops with zero-width matches
68
68
  if (m.index === schemaRegex.lastIndex) {
69
69
  schemaRegex.lastIndex++;
70
70
  }
71
71
  let ignore = !!m[1].match(/\/\/\/\s*@IgnoreAutoField/);
72
- result += m[1];
72
+ merged += m[1];
73
73
  if (!ignore) {
74
- result += '\n id BigInt @id @default(autoincrement())';
74
+ merged += '\n id BigInt @id @default(autoincrement())';
75
75
  }
76
- result += m[2];
76
+ merged += m[2];
77
77
  if (!ignore) {
78
- result +=
78
+ merged +=
79
79
  ' creator String @db.VarChar(128) @map("creator")\n createdAt DateTime @default(now()) @map("created_at")\n updatedAt DateTime @updatedAt @default(now()) @map("updated_at")\n';
80
80
  }
81
- result += m[3];
81
+ merged += m[3];
82
82
  }
83
- new shell.ShellString(result).toEnd('server/prisma/schema.prisma');
83
+ // 一次原子写 + diff:内容未变则完全不 touch 文件,避免任何 watcher 感知抖动。
84
+ return (0, sync_fs_1.writeFileIfChanged)('server/prisma/schema.prisma', generatorHead + merged);
84
85
  }
85
86
  handle(inputs, options) {
86
87
  var _a, _b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gadmin2n/cli",
3
- "version": "0.0.159",
3
+ "version": "0.0.160",
4
4
  "description": "Gadmin - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"