netcore-blueprint 0.0.49 → 0.0.51
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 +76 -31
- package/package.json +1 -1
package/bin/copy-module.js
CHANGED
|
@@ -6,8 +6,8 @@ const { execSync } = require('child_process');
|
|
|
6
6
|
|
|
7
7
|
// =====================================================
|
|
8
8
|
// Param = Source Module Name (also base for new module)
|
|
9
|
-
// Example: copy-module
|
|
10
|
-
// Will create:
|
|
9
|
+
// Example: copy-module __MODULE__
|
|
10
|
+
// Will create: __MODULE__Module
|
|
11
11
|
// =====================================================
|
|
12
12
|
|
|
13
13
|
const sourceModuleName = process.argv[2];
|
|
@@ -15,7 +15,7 @@ const force = process.argv.includes('--force');
|
|
|
15
15
|
|
|
16
16
|
if (!sourceModuleName) {
|
|
17
17
|
console.error("❌ Usage: copy-module <SourceModuleName>");
|
|
18
|
-
console.error(" Example: copy-module
|
|
18
|
+
console.error(" Example: copy-module __MODULE__");
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -23,20 +23,10 @@ if (!sourceModuleName) {
|
|
|
23
23
|
const modulesPath = process.cwd();
|
|
24
24
|
|
|
25
25
|
const templateRoot = path.join(modulesPath, sourceModuleName);
|
|
26
|
-
const targetModuleRoot = path.join(
|
|
27
|
-
modulesPath,
|
|
28
|
-
'..',
|
|
29
|
-
'BlueprintTemplate',
|
|
30
|
-
'Modules',
|
|
31
|
-
`${sourceModuleName}Module`
|
|
32
|
-
);
|
|
26
|
+
const targetModuleRoot = path.join(modulesPath, '..', 'BlueprintTemplate', 'Modules', `${sourceModuleName}Module`);
|
|
33
27
|
|
|
34
28
|
const solutionFile = findSolutionFileFixed(modulesPath);
|
|
35
29
|
|
|
36
|
-
// =====================================================
|
|
37
|
-
// Safety checks
|
|
38
|
-
// =====================================================
|
|
39
|
-
|
|
40
30
|
if (!fs.existsSync(templateRoot)) {
|
|
41
31
|
console.error(`❌ Source module folder not found: ${templateRoot}`);
|
|
42
32
|
process.exit(1);
|
|
@@ -70,20 +60,28 @@ console.log(`🧩 Solution: ${solutionFile}`);
|
|
|
70
60
|
fs.mkdirSync(targetModuleRoot, { recursive: true });
|
|
71
61
|
|
|
72
62
|
// =====================================================
|
|
73
|
-
// 2.
|
|
63
|
+
// 2. Create projects
|
|
74
64
|
// =====================================================
|
|
75
65
|
|
|
76
66
|
const projects = [
|
|
77
|
-
{ name: `${sourceModuleName}Module.API
|
|
78
|
-
{ name: `${sourceModuleName}Module.Core
|
|
79
|
-
{ name: `${sourceModuleName}Module.Infrastructure
|
|
67
|
+
{ name: `${sourceModuleName}Module.API`, type: 'classlib' },
|
|
68
|
+
{ name: `${sourceModuleName}Module.Core`, type: 'classlib' },
|
|
69
|
+
{ name: `${sourceModuleName}Module.Infrastructure`, type: 'classlib' },
|
|
80
70
|
];
|
|
81
71
|
|
|
82
72
|
projects.forEach(p => {
|
|
83
|
-
console.log(`📦
|
|
73
|
+
console.log(`📦 Creating project: ${p.name}`);
|
|
74
|
+
|
|
75
|
+
execSync(`dotnet new ${p.type} -n ${p.name}`, {
|
|
76
|
+
cwd: targetModuleRoot,
|
|
77
|
+
stdio: 'inherit'
|
|
78
|
+
});
|
|
84
79
|
|
|
85
80
|
const projectPath = path.join(targetModuleRoot, p.name);
|
|
86
|
-
|
|
81
|
+
|
|
82
|
+
// =====================================================
|
|
83
|
+
// 3. Copy template files (no csproj)
|
|
84
|
+
// =====================================================
|
|
87
85
|
|
|
88
86
|
const templateSubFolder = getTemplateSubFolder(p.name, templateRoot);
|
|
89
87
|
|
|
@@ -97,7 +95,7 @@ projects.forEach(p => {
|
|
|
97
95
|
});
|
|
98
96
|
|
|
99
97
|
// =====================================================
|
|
100
|
-
//
|
|
98
|
+
// 4. Add projects to solution
|
|
101
99
|
// =====================================================
|
|
102
100
|
|
|
103
101
|
projects.forEach(p => {
|
|
@@ -107,21 +105,12 @@ projects.forEach(p => {
|
|
|
107
105
|
`${p.name}.csproj`
|
|
108
106
|
);
|
|
109
107
|
|
|
110
|
-
if (!fs.existsSync(csproj)) {
|
|
111
|
-
console.warn(`⚠️ csproj not found, skipping: ${csproj}`);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
108
|
console.log(`➕ Adding to solution: ${csproj}`);
|
|
116
109
|
execSync(`dotnet sln "${solutionFile}" add "${csproj}"`, {
|
|
117
110
|
stdio: 'inherit'
|
|
118
111
|
});
|
|
119
112
|
});
|
|
120
113
|
|
|
121
|
-
// =====================================================
|
|
122
|
-
// 4. Restore & Build
|
|
123
|
-
// =====================================================
|
|
124
|
-
|
|
125
114
|
console.log('🔄 Restoring NuGet packages...');
|
|
126
115
|
execSync(`dotnet restore "${solutionFile}"`, { stdio: 'inherit' });
|
|
127
116
|
|
|
@@ -153,11 +142,30 @@ function copyRecursive(src, dest) {
|
|
|
153
142
|
}
|
|
154
143
|
|
|
155
144
|
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
145
|
+
console.log(`📄 TruongDX8 src: ${src}`);
|
|
146
|
+
console.log(`📄 TruongDX8 dest: ${dest}`);
|
|
156
147
|
|
|
157
148
|
for (const entry of entries) {
|
|
149
|
+
console.log(`📄 TruongDX8 Item: ${entry.name}`);
|
|
158
150
|
const srcPath = path.join(src, entry.name);
|
|
159
151
|
const destPath = path.join(dest, entry.name);
|
|
160
152
|
|
|
153
|
+
// Do NOT overwrite .csproj generated by dotnet new
|
|
154
|
+
if (entry.isFile() && entry.name.endsWith('.csproj')) {
|
|
155
|
+
const deps = extractDependenciesFromCsproj(srcPath);
|
|
156
|
+
|
|
157
|
+
const targetCsprojPath = path.join(
|
|
158
|
+
dest,
|
|
159
|
+
path.basename(srcPath)
|
|
160
|
+
).replace(
|
|
161
|
+
path.basename(srcPath),
|
|
162
|
+
path.basename(dest) + '.csproj'
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
injectDependenciesIntoCsproj(targetCsprojPath, deps);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
|
|
161
169
|
if (entry.isDirectory()) {
|
|
162
170
|
copyRecursive(srcPath, destPath);
|
|
163
171
|
} else {
|
|
@@ -167,7 +175,8 @@ function copyRecursive(src, dest) {
|
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
function findSolutionFileFixed(startDir) {
|
|
170
|
-
|
|
178
|
+
// startDir = .../Modules/SomeModule
|
|
179
|
+
const root = path.dirname(startDir);
|
|
171
180
|
const blueprintTemplate = path.join(root, 'BlueprintTemplate');
|
|
172
181
|
|
|
173
182
|
if (!fs.existsSync(blueprintTemplate)) {
|
|
@@ -183,3 +192,39 @@ function findSolutionFileFixed(startDir) {
|
|
|
183
192
|
|
|
184
193
|
return path.join(blueprintTemplate, sln);
|
|
185
194
|
}
|
|
195
|
+
|
|
196
|
+
function extractDependenciesFromCsproj(templateCsprojPath) {
|
|
197
|
+
const xml = fs.readFileSync(templateCsprojPath, 'utf8');
|
|
198
|
+
|
|
199
|
+
const packageRefs = xml.match(/<PackageReference[\s\S]*?\/>/g) || [];
|
|
200
|
+
const projectRefs = xml.match(/<ProjectReference[\s\S]*?\/>/g) || [];
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
packageRefs,
|
|
204
|
+
projectRefs
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function injectDependenciesIntoCsproj(targetCsprojPath, deps) {
|
|
209
|
+
let targetXml = fs.readFileSync(targetCsprojPath, 'utf8');
|
|
210
|
+
|
|
211
|
+
const injection = `
|
|
212
|
+
<ItemGroup>
|
|
213
|
+
${deps.packageRefs.map(x => ' ' + x).join('\n')}
|
|
214
|
+
</ItemGroup>
|
|
215
|
+
|
|
216
|
+
<ItemGroup>
|
|
217
|
+
${deps.projectRefs.map(x => ' ' + x).join('\n')}
|
|
218
|
+
</ItemGroup>
|
|
219
|
+
`;
|
|
220
|
+
|
|
221
|
+
// Inject before </Project>
|
|
222
|
+
targetXml = targetXml.replace(
|
|
223
|
+
/<\/Project>/i,
|
|
224
|
+
`${injection}\n</Project>`
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
fs.writeFileSync(targetCsprojPath, targetXml, 'utf8');
|
|
228
|
+
|
|
229
|
+
console.log(`🧩 Injected dependencies into: ${targetCsprojPath}`);
|
|
230
|
+
}
|