netcore-blueprint 0.0.28 → 0.0.29
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/bin/copy-module.js +78 -136
- package/bin/create-module.js +15 -24
- package/package.json +1 -1
package/bin/copy-module.js
CHANGED
|
@@ -2,169 +2,111 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
const { buildReplaceMap, applyReplacements } = require('../lib/replacer');
|
|
6
|
+
|
|
7
|
+
// =======================
|
|
8
|
+
// Args
|
|
9
|
+
// =======================
|
|
10
|
+
// Usage:
|
|
11
|
+
// create-module <NewModuleName> <NewEntityName>
|
|
12
|
+
// Example:
|
|
13
|
+
// create-module AiAssistant Prompt
|
|
14
|
+
// =======================
|
|
15
|
+
|
|
16
|
+
const newModuleName = process.argv[2];
|
|
17
|
+
const newEntityName = process.argv[3];
|
|
18
|
+
|
|
19
|
+
if (!newModuleName || !newEntityName) {
|
|
20
|
+
console.error("❌ Usage: create-module <NewModuleName> <NewEntityName>");
|
|
21
|
+
console.error(" Example: create-module AiAssistant Prompt");
|
|
19
22
|
process.exit(1);
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
//
|
|
23
|
-
|
|
25
|
+
// =======================
|
|
26
|
+
// Template Source (Module mẫu)
|
|
27
|
+
// =======================
|
|
24
28
|
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const targetModuleRoot = path.join(modulesPath, targetModuleName);
|
|
29
|
+
const sourceModuleName = "ItemModule"; // module mẫu
|
|
30
|
+
const sourceEntityName = "Item"; // entity mẫu
|
|
28
31
|
|
|
29
|
-
const
|
|
32
|
+
const modulesTemplateRoot = path.join(__dirname, "..", "Modules");
|
|
33
|
+
const sourceModulePath = path.join(modulesTemplateRoot, sourceModuleName);
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
+
// =======================
|
|
36
|
+
// Destination (nơi user đang đứng)
|
|
37
|
+
// =======================
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
console.error(`❌ Target module already exists: ${targetModuleRoot}`);
|
|
39
|
-
console.error(` Use --force to overwrite.`);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
39
|
+
const destinationRoot = process.cwd(); // thường là thư mục Modules
|
|
40
|
+
const destinationModulePath = path.join(destinationRoot, newModuleName);
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
// =======================
|
|
43
|
+
// Guards
|
|
44
|
+
// =======================
|
|
46
45
|
|
|
47
|
-
if (!
|
|
48
|
-
console.error(
|
|
46
|
+
if (!fs.existsSync(sourceModulePath)) {
|
|
47
|
+
console.error(`❌ Source module template not found: ${sourceModulePath}`);
|
|
49
48
|
process.exit(1);
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
console.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// =====================================================
|
|
58
|
-
// 1. Create module root folder
|
|
59
|
-
// =====================================================
|
|
60
|
-
|
|
61
|
-
fs.mkdirSync(targetModuleRoot, { recursive: true });
|
|
62
|
-
|
|
63
|
-
// =====================================================
|
|
64
|
-
// 2. Create projects (ALL classlib)
|
|
65
|
-
// =====================================================
|
|
66
|
-
|
|
67
|
-
const projects = [
|
|
68
|
-
{ name: `${targetModuleName}.API`, type: 'classlib' },
|
|
69
|
-
{ name: `${targetModuleName}.Core`, type: 'classlib' },
|
|
70
|
-
{ name: `${targetModuleName}.Infrastructure`, type: 'classlib' },
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
projects.forEach(p => {
|
|
74
|
-
console.log(`📦 Creating project: ${p.name}`);
|
|
75
|
-
|
|
76
|
-
execSync(`dotnet new ${p.type} -n ${p.name}`, {
|
|
77
|
-
cwd: targetModuleRoot,
|
|
78
|
-
stdio: 'inherit'
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const projectPath = path.join(targetModuleRoot, p.name);
|
|
82
|
-
|
|
83
|
-
// =====================================================
|
|
84
|
-
// 3. Copy template files (NO csproj)
|
|
85
|
-
// =====================================================
|
|
86
|
-
|
|
87
|
-
const templateSubFolder = getTemplateSubFolder(p.name, templateRoot);
|
|
51
|
+
if (fs.existsSync(destinationModulePath)) {
|
|
52
|
+
console.error(`❌ Destination module already exists: ${destinationModulePath}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
88
55
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
56
|
+
// =======================
|
|
57
|
+
// Replace Map
|
|
58
|
+
// =======================
|
|
93
59
|
|
|
94
|
-
|
|
95
|
-
|
|
60
|
+
const replaceMap = buildReplaceMap({
|
|
61
|
+
sourceModuleName,
|
|
62
|
+
newModuleName,
|
|
63
|
+
sourceEntityName,
|
|
64
|
+
newEntityName
|
|
96
65
|
});
|
|
97
66
|
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
console.log(`📁 Creating solution folder: Modules\\${targetModuleName}`);
|
|
103
|
-
execSync(
|
|
104
|
-
`dotnet sln "${solutionFile}" add --solution-folder "Modules\\${targetModuleName}" "${targetModuleRoot}\\*\\*.csproj"`,
|
|
105
|
-
{ stdio: 'inherit' }
|
|
106
|
-
);
|
|
67
|
+
// =======================
|
|
68
|
+
// Logs
|
|
69
|
+
// =======================
|
|
107
70
|
|
|
108
|
-
console.log(
|
|
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}`);
|
|
109
76
|
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
77
|
+
// =======================
|
|
78
|
+
// Run
|
|
79
|
+
// =======================
|
|
113
80
|
|
|
114
|
-
|
|
115
|
-
if (projectName.endsWith('.API')) {
|
|
116
|
-
return path.join(templateRoot, 'API');
|
|
117
|
-
}
|
|
118
|
-
if (projectName.endsWith('.Core')) {
|
|
119
|
-
return path.join(templateRoot, 'Core');
|
|
120
|
-
}
|
|
121
|
-
if (projectName.endsWith('.Infrastructure')) {
|
|
122
|
-
return path.join(templateRoot, 'Infrastructure');
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
81
|
+
copyAndRenameFiles(sourceModulePath, destinationModulePath);
|
|
126
82
|
|
|
127
|
-
|
|
128
|
-
if (!fs.existsSync(dest)) {
|
|
129
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
130
|
-
}
|
|
83
|
+
console.log(`🎉 Module "${newModuleName}" created with Entity "${newEntityName}" successfully!`);
|
|
131
84
|
|
|
132
|
-
|
|
85
|
+
// =======================
|
|
86
|
+
// Core Logic
|
|
87
|
+
// =======================
|
|
133
88
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const destPath = path.join(dest, entry.name);
|
|
89
|
+
function copyAndRenameFiles(src, dest) {
|
|
90
|
+
const stat = fs.lstatSync(src);
|
|
137
91
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
92
|
+
if (stat.isDirectory()) {
|
|
93
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
142
94
|
|
|
143
|
-
|
|
144
|
-
copyRecursive(srcPath, destPath);
|
|
145
|
-
} else {
|
|
146
|
-
fs.copyFileSync(srcPath, destPath);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
95
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
150
96
|
|
|
151
|
-
|
|
152
|
-
|
|
97
|
+
for (const entry of entries) {
|
|
98
|
+
const srcPath = path.join(src, entry.name);
|
|
153
99
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (sln) return path.join(current, sln);
|
|
100
|
+
// Rename folder/file name
|
|
101
|
+
const renamedName = applyReplacements(entry.name, replaceMap);
|
|
102
|
+
const destPath = path.join(dest, renamedName);
|
|
158
103
|
|
|
159
|
-
|
|
160
|
-
if (fs.existsSync(blueprintTemplate)) {
|
|
161
|
-
const btFiles = fs.readdirSync(blueprintTemplate);
|
|
162
|
-
sln = btFiles.find(f => f.endsWith('.sln') || f.endsWith('.slnx'));
|
|
163
|
-
if (sln) return path.join(blueprintTemplate, sln);
|
|
104
|
+
copyAndRenameFiles(srcPath, destPath);
|
|
164
105
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
106
|
+
} else {
|
|
107
|
+
// Copy + replace file content
|
|
108
|
+
let content = fs.readFileSync(src, 'utf8');
|
|
109
|
+
content = applyReplacements(content, replaceMap);
|
|
110
|
+
fs.writeFileSync(dest, content, 'utf8');
|
|
169
111
|
}
|
|
170
112
|
}
|
package/bin/create-module.js
CHANGED
|
@@ -8,35 +8,33 @@ const { buildReplaceMap, applyReplacements } = require('../lib/replacer');
|
|
|
8
8
|
// Args
|
|
9
9
|
// =======================
|
|
10
10
|
// Usage:
|
|
11
|
-
// create-module <NewModuleName> <NewEntityName>
|
|
12
|
-
// Example:
|
|
13
11
|
// create-module AiAssistant Prompt
|
|
14
|
-
//
|
|
12
|
+
//
|
|
15
13
|
|
|
16
14
|
const newModuleName = process.argv[2];
|
|
17
15
|
const newEntityName = process.argv[3];
|
|
18
16
|
|
|
19
17
|
if (!newModuleName || !newEntityName) {
|
|
20
|
-
console.error("❌ Usage: create-module <
|
|
18
|
+
console.error("❌ Usage: create-module <ModuleName> <EntityName>");
|
|
21
19
|
console.error(" Example: create-module AiAssistant Prompt");
|
|
22
20
|
process.exit(1);
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
// =======================
|
|
26
|
-
// Template
|
|
24
|
+
// Template source
|
|
27
25
|
// =======================
|
|
28
26
|
|
|
29
|
-
const sourceModuleName = "ItemModule";
|
|
30
|
-
const sourceEntityName = "Item";
|
|
27
|
+
const sourceModuleName = "ItemModule";
|
|
28
|
+
const sourceEntityName = "Item";
|
|
31
29
|
|
|
32
30
|
const modulesTemplateRoot = path.join(__dirname, "..", "Modules");
|
|
33
31
|
const sourceModulePath = path.join(modulesTemplateRoot, sourceModuleName);
|
|
34
32
|
|
|
35
33
|
// =======================
|
|
36
|
-
// Destination
|
|
34
|
+
// Destination
|
|
37
35
|
// =======================
|
|
38
36
|
|
|
39
|
-
const destinationRoot = process.cwd();
|
|
37
|
+
const destinationRoot = process.cwd();
|
|
40
38
|
const destinationModulePath = path.join(destinationRoot, newModuleName);
|
|
41
39
|
|
|
42
40
|
// =======================
|
|
@@ -44,7 +42,7 @@ const destinationModulePath = path.join(destinationRoot, newModuleName);
|
|
|
44
42
|
// =======================
|
|
45
43
|
|
|
46
44
|
if (!fs.existsSync(sourceModulePath)) {
|
|
47
|
-
console.error(`❌ Source module
|
|
45
|
+
console.error(`❌ Source module not found: ${sourceModulePath}`);
|
|
48
46
|
process.exit(1);
|
|
49
47
|
}
|
|
50
48
|
|
|
@@ -64,15 +62,10 @@ const replaceMap = buildReplaceMap({
|
|
|
64
62
|
newEntityName
|
|
65
63
|
});
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
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}`);
|
|
65
|
+
console.log(`📦 Creating module: ${newModuleName}`);
|
|
66
|
+
console.log(`🧩 Entity name: ${newEntityName}`);
|
|
67
|
+
console.log(`📁 From template: ${sourceModulePath}`);
|
|
68
|
+
console.log(`📁 To: ${destinationModulePath}`);
|
|
76
69
|
|
|
77
70
|
// =======================
|
|
78
71
|
// Run
|
|
@@ -80,7 +73,7 @@ console.log(`📁 Target: ${destinationModulePath}`);
|
|
|
80
73
|
|
|
81
74
|
copyAndRenameFiles(sourceModulePath, destinationModulePath);
|
|
82
75
|
|
|
83
|
-
console.log(`🎉 Module "${newModuleName}"
|
|
76
|
+
console.log(`🎉 Module "${newModuleName}" with Entity "${newEntityName}" created successfully!`);
|
|
84
77
|
|
|
85
78
|
// =======================
|
|
86
79
|
// Core Logic
|
|
@@ -97,14 +90,12 @@ function copyAndRenameFiles(src, dest) {
|
|
|
97
90
|
for (const entry of entries) {
|
|
98
91
|
const srcPath = path.join(src, entry.name);
|
|
99
92
|
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
const destPath = path.join(dest, renamedName);
|
|
93
|
+
let renamed = applyReplacements(entry.name, replaceMap);
|
|
94
|
+
const destPath = path.join(dest, renamed);
|
|
103
95
|
|
|
104
96
|
copyAndRenameFiles(srcPath, destPath);
|
|
105
97
|
}
|
|
106
98
|
} else {
|
|
107
|
-
// Copy + replace file content
|
|
108
99
|
let content = fs.readFileSync(src, 'utf8');
|
|
109
100
|
content = applyReplacements(content, replaceMap);
|
|
110
101
|
fs.writeFileSync(dest, content, 'utf8');
|