@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.
- package/actions/prisma.action.js +13 -12
- package/package.json +1 -1
package/actions/prisma.action.js
CHANGED
|
@@ -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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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,
|
|
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
|
-
|
|
72
|
+
merged += m[1];
|
|
73
73
|
if (!ignore) {
|
|
74
|
-
|
|
74
|
+
merged += '\n id BigInt @id @default(autoincrement())';
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
merged += m[2];
|
|
77
77
|
if (!ignore) {
|
|
78
|
-
|
|
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
|
-
|
|
81
|
+
merged += m[3];
|
|
82
82
|
}
|
|
83
|
-
|
|
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;
|