netcore-blueprint 0.0.18 → 0.0.19
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/BlueprintTemplate/README.md +1 -1
- package/README.md +2 -2
- package/bin/create-module.js +51 -27
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
- Update-Database
|
|
19
19
|
|
|
20
20
|
8. Todos
|
|
21
|
-
-
|
|
21
|
+
- Đổi tên item mẫu (Sửa lại JS và thử chức năng tạo tự động, thay vì làm thủ công)
|
|
22
22
|
- Plug/ Unplug module (config)
|
|
23
23
|
- Plug/ Unplug database provider (config)
|
|
24
24
|
- Thêm chức năng tạo module qua script
|
package/README.md
CHANGED
package/bin/create-module.js
CHANGED
|
@@ -2,23 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const { buildReplaceMap, applyReplacements } = require('./replacer');
|
|
6
|
+
|
|
7
|
+
// =======================
|
|
8
|
+
// Args
|
|
9
|
+
// =======================
|
|
10
|
+
// Usage:
|
|
11
|
+
// create-module AiAssistant Prompt
|
|
12
|
+
//
|
|
5
13
|
|
|
6
14
|
const newModuleName = process.argv[2];
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
const newEntityName = process.argv[3];
|
|
16
|
+
|
|
17
|
+
if (!newModuleName || !newEntityName) {
|
|
18
|
+
console.error("❌ Usage: create-module <ModuleName> <EntityName>");
|
|
19
|
+
console.error(" Example: create-module AiAssistant Prompt");
|
|
9
20
|
process.exit(1);
|
|
10
21
|
}
|
|
11
22
|
|
|
23
|
+
// =======================
|
|
24
|
+
// Template source
|
|
25
|
+
// =======================
|
|
26
|
+
|
|
12
27
|
const sourceModuleName = "ItemModule";
|
|
28
|
+
const sourceEntityName = "Item";
|
|
13
29
|
|
|
14
|
-
// 🔥 NEW: Modules folder (not BlueprintTemplate)
|
|
15
30
|
const modulesTemplateRoot = path.join(__dirname, "..", "Modules");
|
|
16
31
|
const sourceModulePath = path.join(modulesTemplateRoot, sourceModuleName);
|
|
17
32
|
|
|
18
|
-
//
|
|
33
|
+
// =======================
|
|
34
|
+
// Destination
|
|
35
|
+
// =======================
|
|
36
|
+
|
|
19
37
|
const destinationRoot = process.cwd();
|
|
20
38
|
const destinationModulePath = path.join(destinationRoot, newModuleName);
|
|
21
39
|
|
|
40
|
+
// =======================
|
|
41
|
+
// Guards
|
|
42
|
+
// =======================
|
|
43
|
+
|
|
22
44
|
if (!fs.existsSync(sourceModulePath)) {
|
|
23
45
|
console.error(`❌ Source module not found: ${sourceModulePath}`);
|
|
24
46
|
process.exit(1);
|
|
@@ -29,22 +51,35 @@ if (fs.existsSync(destinationModulePath)) {
|
|
|
29
51
|
process.exit(1);
|
|
30
52
|
}
|
|
31
53
|
|
|
54
|
+
// =======================
|
|
55
|
+
// Replace Map
|
|
56
|
+
// =======================
|
|
57
|
+
|
|
58
|
+
const replaceMap = buildReplaceMap({
|
|
59
|
+
sourceModuleName,
|
|
60
|
+
newModuleName,
|
|
61
|
+
sourceEntityName,
|
|
62
|
+
newEntityName
|
|
63
|
+
});
|
|
64
|
+
|
|
32
65
|
console.log(`📦 Creating module: ${newModuleName}`);
|
|
66
|
+
console.log(`🧩 Entity name: ${newEntityName}`);
|
|
33
67
|
console.log(`📁 From template: ${sourceModulePath}`);
|
|
34
68
|
console.log(`📁 To: ${destinationModulePath}`);
|
|
35
69
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
70
|
+
// =======================
|
|
71
|
+
// Run
|
|
72
|
+
// =======================
|
|
73
|
+
|
|
74
|
+
copyAndRenameFiles(sourceModulePath, destinationModulePath);
|
|
42
75
|
|
|
43
|
-
console.log(`🎉 Module "${newModuleName}" created successfully!`);
|
|
76
|
+
console.log(`🎉 Module "${newModuleName}" with Entity "${newEntityName}" created successfully!`);
|
|
44
77
|
|
|
45
|
-
//
|
|
78
|
+
// =======================
|
|
79
|
+
// Core Logic
|
|
80
|
+
// =======================
|
|
46
81
|
|
|
47
|
-
function copyAndRenameFiles(src, dest
|
|
82
|
+
function copyAndRenameFiles(src, dest) {
|
|
48
83
|
const stat = fs.lstatSync(src);
|
|
49
84
|
|
|
50
85
|
if (stat.isDirectory()) {
|
|
@@ -55,25 +90,14 @@ function copyAndRenameFiles(src, dest, oldName, newName) {
|
|
|
55
90
|
for (const entry of entries) {
|
|
56
91
|
const srcPath = path.join(src, entry.name);
|
|
57
92
|
|
|
58
|
-
|
|
59
|
-
const renamed = entry.name.replace(
|
|
60
|
-
new RegExp(oldName, 'g'),
|
|
61
|
-
newName
|
|
62
|
-
);
|
|
63
|
-
|
|
93
|
+
let renamed = applyReplacements(entry.name, replaceMap);
|
|
64
94
|
const destPath = path.join(dest, renamed);
|
|
65
95
|
|
|
66
|
-
copyAndRenameFiles(srcPath, destPath
|
|
96
|
+
copyAndRenameFiles(srcPath, destPath);
|
|
67
97
|
}
|
|
68
98
|
} else {
|
|
69
99
|
let content = fs.readFileSync(src, 'utf8');
|
|
70
|
-
|
|
71
|
-
// 🔁 Replace namespace + content
|
|
72
|
-
content = content.replace(
|
|
73
|
-
new RegExp(oldName, 'g'),
|
|
74
|
-
newName
|
|
75
|
-
);
|
|
76
|
-
|
|
100
|
+
content = applyReplacements(content, replaceMap);
|
|
77
101
|
fs.writeFileSync(dest, content, 'utf8');
|
|
78
102
|
}
|
|
79
103
|
}
|