netcore-blueprint 0.0.26 → 0.0.28
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/README.md +1 -1
- package/bin/copy-module.js +9 -2
- package/bin/create-module.js +24 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,4 +5,4 @@ How to make a blueprint
|
|
|
5
5
|
- npm list -g netcore-blueprint
|
|
6
6
|
- create-app <AppName>
|
|
7
7
|
- create-module <ModuleName> <EntityName>
|
|
8
|
-
- copy-module <CopiedModuleName> (Run the the folder Modules)
|
|
8
|
+
- copy-module <CopiedModuleName> (Run the the folder Modules) (copy-module <CopiedModuleName> --force)
|
package/bin/copy-module.js
CHANGED
|
@@ -11,6 +11,7 @@ const { execSync } = require('child_process');
|
|
|
11
11
|
// =====================================================
|
|
12
12
|
|
|
13
13
|
const sourceModuleName = process.argv[2];
|
|
14
|
+
const force = process.argv.includes('--force');
|
|
14
15
|
|
|
15
16
|
if (!sourceModuleName) {
|
|
16
17
|
console.error("❌ Usage: copy-module <SourceModuleName>");
|
|
@@ -33,8 +34,14 @@ if (!fs.existsSync(templateRoot)) {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
if (fs.existsSync(targetModuleRoot)) {
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
if (!force) {
|
|
38
|
+
console.error(`❌ Target module already exists: ${targetModuleRoot}`);
|
|
39
|
+
console.error(` Use --force to overwrite.`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log(`🔥 --force detected. Removing existing module: ${targetModuleRoot}`);
|
|
44
|
+
fs.rmSync(targetModuleRoot, { recursive: true, force: true });
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
if (!solutionFile) {
|
package/bin/create-module.js
CHANGED
|
@@ -8,33 +8,35 @@ const { buildReplaceMap, applyReplacements } = require('../lib/replacer');
|
|
|
8
8
|
// Args
|
|
9
9
|
// =======================
|
|
10
10
|
// Usage:
|
|
11
|
+
// create-module <NewModuleName> <NewEntityName>
|
|
12
|
+
// Example:
|
|
11
13
|
// create-module AiAssistant Prompt
|
|
12
|
-
//
|
|
14
|
+
// =======================
|
|
13
15
|
|
|
14
16
|
const newModuleName = process.argv[2];
|
|
15
17
|
const newEntityName = process.argv[3];
|
|
16
18
|
|
|
17
19
|
if (!newModuleName || !newEntityName) {
|
|
18
|
-
console.error("❌ Usage: create-module <
|
|
20
|
+
console.error("❌ Usage: create-module <NewModuleName> <NewEntityName>");
|
|
19
21
|
console.error(" Example: create-module AiAssistant Prompt");
|
|
20
22
|
process.exit(1);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// =======================
|
|
24
|
-
// Template
|
|
26
|
+
// Template Source (Module mẫu)
|
|
25
27
|
// =======================
|
|
26
28
|
|
|
27
|
-
const sourceModuleName = "ItemModule";
|
|
28
|
-
const sourceEntityName = "Item";
|
|
29
|
+
const sourceModuleName = "ItemModule"; // module mẫu
|
|
30
|
+
const sourceEntityName = "Item"; // entity mẫu
|
|
29
31
|
|
|
30
32
|
const modulesTemplateRoot = path.join(__dirname, "..", "Modules");
|
|
31
33
|
const sourceModulePath = path.join(modulesTemplateRoot, sourceModuleName);
|
|
32
34
|
|
|
33
35
|
// =======================
|
|
34
|
-
// Destination
|
|
36
|
+
// Destination (nơi user đang đứng)
|
|
35
37
|
// =======================
|
|
36
38
|
|
|
37
|
-
const destinationRoot = process.cwd();
|
|
39
|
+
const destinationRoot = process.cwd(); // thường là thư mục Modules
|
|
38
40
|
const destinationModulePath = path.join(destinationRoot, newModuleName);
|
|
39
41
|
|
|
40
42
|
// =======================
|
|
@@ -42,7 +44,7 @@ const destinationModulePath = path.join(destinationRoot, newModuleName);
|
|
|
42
44
|
// =======================
|
|
43
45
|
|
|
44
46
|
if (!fs.existsSync(sourceModulePath)) {
|
|
45
|
-
console.error(`❌ Source module not found: ${sourceModulePath}`);
|
|
47
|
+
console.error(`❌ Source module template not found: ${sourceModulePath}`);
|
|
46
48
|
process.exit(1);
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -62,10 +64,15 @@ const replaceMap = buildReplaceMap({
|
|
|
62
64
|
newEntityName
|
|
63
65
|
});
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// =======================
|
|
68
|
+
// Logs
|
|
69
|
+
// =======================
|
|
70
|
+
|
|
71
|
+
console.log(`🚀 Creating module from template`);
|
|
72
|
+
console.log(`📦 New Module: ${newModuleName}`);
|
|
73
|
+
console.log(`🧩 New Entity: ${newEntityName}`);
|
|
74
|
+
console.log(`📁 Template: ${sourceModulePath}`);
|
|
75
|
+
console.log(`📁 Target: ${destinationModulePath}`);
|
|
69
76
|
|
|
70
77
|
// =======================
|
|
71
78
|
// Run
|
|
@@ -73,7 +80,7 @@ console.log(`📁 To: ${destinationModulePath}`);
|
|
|
73
80
|
|
|
74
81
|
copyAndRenameFiles(sourceModulePath, destinationModulePath);
|
|
75
82
|
|
|
76
|
-
console.log(`🎉 Module "${newModuleName}" with Entity "${newEntityName}"
|
|
83
|
+
console.log(`🎉 Module "${newModuleName}" created with Entity "${newEntityName}" successfully!`);
|
|
77
84
|
|
|
78
85
|
// =======================
|
|
79
86
|
// Core Logic
|
|
@@ -90,12 +97,14 @@ function copyAndRenameFiles(src, dest) {
|
|
|
90
97
|
for (const entry of entries) {
|
|
91
98
|
const srcPath = path.join(src, entry.name);
|
|
92
99
|
|
|
93
|
-
|
|
94
|
-
const
|
|
100
|
+
// Rename folder/file name
|
|
101
|
+
const renamedName = applyReplacements(entry.name, replaceMap);
|
|
102
|
+
const destPath = path.join(dest, renamedName);
|
|
95
103
|
|
|
96
104
|
copyAndRenameFiles(srcPath, destPath);
|
|
97
105
|
}
|
|
98
106
|
} else {
|
|
107
|
+
// Copy + replace file content
|
|
99
108
|
let content = fs.readFileSync(src, 'utf8');
|
|
100
109
|
content = applyReplacements(content, replaceMap);
|
|
101
110
|
fs.writeFileSync(dest, content, 'utf8');
|