netcore-blueprint 0.0.48 → 0.0.49

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.
Files changed (2) hide show
  1. package/bin/copy-module.js +37 -29
  2. package/package.json +1 -1
@@ -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 __MODULE__
10
- // Will create: __MODULE__Module
9
+ // Example: copy-module Order
10
+ // Will create: OrderModule
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 __MODULE__");
18
+ console.error(" Example: copy-module Order");
19
19
  process.exit(1);
20
20
  }
21
21
 
@@ -23,10 +23,20 @@ if (!sourceModuleName) {
23
23
  const modulesPath = process.cwd();
24
24
 
25
25
  const templateRoot = path.join(modulesPath, sourceModuleName);
26
- const targetModuleRoot = path.join(modulesPath, '..', 'BlueprintTemplate', 'Modules', `${sourceModuleName}Module`);
26
+ const targetModuleRoot = path.join(
27
+ modulesPath,
28
+ '..',
29
+ 'BlueprintTemplate',
30
+ 'Modules',
31
+ `${sourceModuleName}Module`
32
+ );
27
33
 
28
34
  const solutionFile = findSolutionFileFixed(modulesPath);
29
35
 
36
+ // =====================================================
37
+ // Safety checks
38
+ // =====================================================
39
+
30
40
  if (!fs.existsSync(templateRoot)) {
31
41
  console.error(`❌ Source module folder not found: ${templateRoot}`);
32
42
  process.exit(1);
@@ -60,28 +70,20 @@ console.log(`🧩 Solution: ${solutionFile}`);
60
70
  fs.mkdirSync(targetModuleRoot, { recursive: true });
61
71
 
62
72
  // =====================================================
63
- // 2. Create projects
73
+ // 2. Copy projects from template (NO dotnet new)
64
74
  // =====================================================
65
75
 
66
76
  const projects = [
67
- { name: `${sourceModuleName}Module.API`, type: 'classlib' },
68
- { name: `${sourceModuleName}Module.Core`, type: 'classlib' },
69
- { name: `${sourceModuleName}Module.Infrastructure`, type: 'classlib' },
77
+ { name: `${sourceModuleName}Module.API` },
78
+ { name: `${sourceModuleName}Module.Core` },
79
+ { name: `${sourceModuleName}Module.Infrastructure` },
70
80
  ];
71
81
 
72
82
  projects.forEach(p => {
73
- console.log(`📦 Creating project: ${p.name}`);
74
-
75
- execSync(`dotnet new ${p.type} -n ${p.name}`, {
76
- cwd: targetModuleRoot,
77
- stdio: 'inherit'
78
- });
83
+ console.log(`📦 Copying project from template: ${p.name}`);
79
84
 
80
85
  const projectPath = path.join(targetModuleRoot, p.name);
81
-
82
- // =====================================================
83
- // 3. Copy template files (no csproj)
84
- // =====================================================
86
+ fs.mkdirSync(projectPath, { recursive: true });
85
87
 
86
88
  const templateSubFolder = getTemplateSubFolder(p.name, templateRoot);
87
89
 
@@ -95,7 +97,7 @@ projects.forEach(p => {
95
97
  });
96
98
 
97
99
  // =====================================================
98
- // 4. Add projects to solution
100
+ // 3. Add projects to solution
99
101
  // =====================================================
100
102
 
101
103
  projects.forEach(p => {
@@ -105,12 +107,27 @@ projects.forEach(p => {
105
107
  `${p.name}.csproj`
106
108
  );
107
109
 
110
+ if (!fs.existsSync(csproj)) {
111
+ console.warn(`⚠️ csproj not found, skipping: ${csproj}`);
112
+ return;
113
+ }
114
+
108
115
  console.log(`➕ Adding to solution: ${csproj}`);
109
116
  execSync(`dotnet sln "${solutionFile}" add "${csproj}"`, {
110
117
  stdio: 'inherit'
111
118
  });
112
119
  });
113
120
 
121
+ // =====================================================
122
+ // 4. Restore & Build
123
+ // =====================================================
124
+
125
+ console.log('🔄 Restoring NuGet packages...');
126
+ execSync(`dotnet restore "${solutionFile}"`, { stdio: 'inherit' });
127
+
128
+ console.log('🏗️ Building solution...');
129
+ execSync(`dotnet build "${solutionFile}"`, { stdio: 'inherit' });
130
+
114
131
  console.log(`🎉 Module "${sourceModuleName}Module" created successfully!`);
115
132
 
116
133
  // =====================================================
@@ -136,19 +153,11 @@ function copyRecursive(src, dest) {
136
153
  }
137
154
 
138
155
  const entries = fs.readdirSync(src, { withFileTypes: true });
139
- console.log(`📄 TruongDX8 src: ${src}`);
140
- console.log(`📄 TruongDX8 dest: ${dest}`);
141
156
 
142
157
  for (const entry of entries) {
143
- console.log(`📄 TruongDX8 Item: ${entry.name}`);
144
158
  const srcPath = path.join(src, entry.name);
145
159
  const destPath = path.join(dest, entry.name);
146
160
 
147
- // Do NOT overwrite .csproj generated by dotnet new
148
- if (entry.isFile() && entry.name.endsWith('.csproj')) {
149
- continue;
150
- }
151
-
152
161
  if (entry.isDirectory()) {
153
162
  copyRecursive(srcPath, destPath);
154
163
  } else {
@@ -158,8 +167,7 @@ function copyRecursive(src, dest) {
158
167
  }
159
168
 
160
169
  function findSolutionFileFixed(startDir) {
161
- // startDir = .../Modules/SomeModule
162
- const root = path.dirname(startDir);
170
+ const root = path.dirname(startDir);
163
171
  const blueprintTemplate = path.join(root, 'BlueprintTemplate');
164
172
 
165
173
  if (!fs.existsSync(blueprintTemplate)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netcore-blueprint",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "description": "A custom project blueprint",
5
5
  "main": "create.js",
6
6
  "bin": {