netcore-blueprint 0.0.31 → 0.0.32

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 +31 -28
  2. package/package.json +1 -1
@@ -5,13 +5,12 @@ const path = require('path');
5
5
  const { execSync } = require('child_process');
6
6
 
7
7
  // =====================================================
8
- // Param = Source Module Name
8
+ // Param = Source Module Name (also base for new module)
9
9
  // Example: copy-module __MODULE__
10
- // Will create: Modules\__MODULE__Module\*
10
+ // Will create: __MODULE__Module
11
11
  // =====================================================
12
12
 
13
13
  const sourceModuleName = process.argv[2];
14
- const force = process.argv.includes('--force');
15
14
 
16
15
  if (!sourceModuleName) {
17
16
  console.error("❌ Usage: copy-module <SourceModuleName>");
@@ -23,8 +22,7 @@ if (!sourceModuleName) {
23
22
  const modulesPath = process.cwd();
24
23
 
25
24
  const templateRoot = path.join(modulesPath, sourceModuleName);
26
- const targetModuleName = `${sourceModuleName}Module`;
27
- const targetModuleRoot = path.join(modulesPath, targetModuleName);
25
+ const targetModuleRoot = path.join(modulesPath, `${sourceModuleName}Module`);
28
26
 
29
27
  const solutionFile = findSolutionFileUpwards(modulesPath);
30
28
 
@@ -34,18 +32,12 @@ if (!fs.existsSync(templateRoot)) {
34
32
  }
35
33
 
36
34
  if (fs.existsSync(targetModuleRoot)) {
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 });
35
+ console.error(`❌ Target module already exists: ${targetModuleRoot}`);
36
+ process.exit(1);
45
37
  }
46
38
 
47
39
  if (!solutionFile) {
48
- console.error("❌ Could not find .sln or .slnx file.");
40
+ console.error("❌ Could not find .sln file in parent directories.");
49
41
  process.exit(1);
50
42
  }
51
43
 
@@ -55,19 +47,19 @@ console.log(` To: ${targetModuleRoot}`);
55
47
  console.log(`🧩 Solution: ${solutionFile}`);
56
48
 
57
49
  // =====================================================
58
- // 1. Create module root folder
50
+ // 1. Create module root
59
51
  // =====================================================
60
52
 
61
53
  fs.mkdirSync(targetModuleRoot, { recursive: true });
62
54
 
63
55
  // =====================================================
64
- // 2. Create projects (ALL classlib)
56
+ // 2. Create projects
65
57
  // =====================================================
66
58
 
67
59
  const projects = [
68
- { name: `${targetModuleName}.API`, type: 'classlib' },
69
- { name: `${targetModuleName}.Core`, type: 'classlib' },
70
- { name: `${targetModuleName}.Infrastructure`, type: 'classlib' },
60
+ { name: `${sourceModuleName}Module.API`, type: 'webapi' },
61
+ { name: `${sourceModuleName}Module.Core`, type: 'classlib' },
62
+ { name: `${sourceModuleName}Module.Infrastructure`, type: 'classlib' },
71
63
  ];
72
64
 
73
65
  projects.forEach(p => {
@@ -81,7 +73,7 @@ projects.forEach(p => {
81
73
  const projectPath = path.join(targetModuleRoot, p.name);
82
74
 
83
75
  // =====================================================
84
- // 3. Copy template files (NO csproj)
76
+ // 3. Copy template files (no csproj)
85
77
  // =====================================================
86
78
 
87
79
  const templateSubFolder = getTemplateSubFolder(p.name, templateRoot);
@@ -96,16 +88,23 @@ projects.forEach(p => {
96
88
  });
97
89
 
98
90
  // =====================================================
99
- // 4. Add Solution Folder + add projects under it
91
+ // 4. Add projects to solution
100
92
  // =====================================================
101
93
 
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
- );
94
+ projects.forEach(p => {
95
+ const csproj = path.join(
96
+ targetModuleRoot,
97
+ p.name,
98
+ `${p.name}.csproj`
99
+ );
100
+
101
+ console.log(`➕ Adding to solution: ${csproj}`);
102
+ execSync(`dotnet sln "${solutionFile}" add "${csproj}"`, {
103
+ stdio: 'inherit'
104
+ });
105
+ });
107
106
 
108
- console.log(`🎉 Module "${targetModuleName}" created successfully!`);
107
+ console.log(`🎉 Module "${sourceModuleName}Module" created successfully!`);
109
108
 
110
109
  // =====================================================
111
110
  // Helpers
@@ -135,7 +134,7 @@ function copyRecursive(src, dest) {
135
134
  const srcPath = path.join(src, entry.name);
136
135
  const destPath = path.join(dest, entry.name);
137
136
 
138
- // Do NOT overwrite .csproj
137
+ // Do NOT overwrite .csproj generated by dotnet new
139
138
  if (entry.isFile() && entry.name.endsWith('.csproj')) {
140
139
  continue;
141
140
  }
@@ -152,10 +151,12 @@ function findSolutionFileUpwards(startDir) {
152
151
  let current = startDir;
153
152
 
154
153
  while (true) {
154
+ // 1. Check current folder
155
155
  const files = fs.readdirSync(current);
156
156
  let sln = files.find(f => f.endsWith('.sln') || f.endsWith('.slnx'));
157
157
  if (sln) return path.join(current, sln);
158
158
 
159
+ // 2. Check BlueprintTemplate sibling
159
160
  const blueprintTemplate = path.join(current, 'BlueprintTemplate');
160
161
  if (fs.existsSync(blueprintTemplate)) {
161
162
  const btFiles = fs.readdirSync(blueprintTemplate);
@@ -163,8 +164,10 @@ function findSolutionFileUpwards(startDir) {
163
164
  if (sln) return path.join(blueprintTemplate, sln);
164
165
  }
165
166
 
167
+ // 3. Go up
166
168
  const parent = path.dirname(current);
167
169
  if (parent === current) return null;
168
170
  current = parent;
169
171
  }
170
172
  }
173
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netcore-blueprint",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "description": "A custom project blueprint",
5
5
  "main": "create.js",
6
6
  "bin": {