netcore-blueprint 0.0.92 → 0.0.94

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.
@@ -2,41 +2,151 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const { execSync } = require('child_process');
6
+ const { createModule, addProjectReferencesToCsproj } = require('../lib/replacer');
5
7
 
6
8
  // =======================
7
- // Template source
9
+ // FIXED TEMPLATE
8
10
  // =======================
9
11
 
10
12
  const sourceModuleName = "AiAssistantModule";
11
13
 
12
- const modulesTemplateRoot = path.join(__dirname, "..", "Modules");
13
- const sourceModulePath = path.join(modulesTemplateRoot, `${sourceModuleName}`);
14
+ // =======================
15
+ // FIND SOLUTION ROOT
16
+ // =======================
17
+
18
+ const { solutionFile, solutionDir } = findSolutionRoot(process.cwd());
14
19
 
15
20
  // =======================
16
- // Destination
21
+ // PATHS
17
22
  // =======================
18
23
 
19
- const destinationRoot = process.cwd();
20
- const destinationModulePath = path.join(destinationRoot, `${sourceModuleName}`);
24
+ const templateRoot = path.join(
25
+ __dirname,
26
+ "..",
27
+ "Modules",
28
+ sourceModuleName
29
+ );
30
+
31
+ const targetModuleRoot = path.join(
32
+ solutionDir,
33
+ 'Modules',
34
+ sourceModuleName
35
+ );
36
+
37
+ const hostApiProjectPath = path.join(
38
+ solutionDir,
39
+ 'Host',
40
+ 'Host.API',
41
+ 'Host.API.csproj'
42
+ );
21
43
 
22
44
  // =======================
23
- // Guards
45
+ // GUARDS
24
46
  // =======================
25
47
 
26
- if (!fs.existsSync(sourceModulePath)) {
27
- console.error(`❌ Source module not found: ${sourceModulePath}`);
48
+ if (!fs.existsSync(templateRoot)) {
49
+ console.error(`❌ Template not found: ${templateRoot}`);
28
50
  process.exit(1);
29
51
  }
30
52
 
31
- if (fs.existsSync(destinationModulePath)) {
32
- console.error(`❌ Destination module already exists: ${destinationModulePath}`);
53
+ if (fs.existsSync(targetModuleRoot)) {
54
+ console.error(`❌ Module already exists: ${targetModuleRoot}`);
33
55
  process.exit(1);
34
56
  }
35
57
 
36
58
  console.log(`📦 Creating assistant module`);
59
+ console.log(`📁 Target: ${targetModuleRoot}`);
60
+ console.log(`🧩 Solution: ${solutionFile}`);
61
+
62
+ // =======================
63
+ // 1. COPY MODULE
64
+ // =======================
65
+
66
+ createModule(templateRoot, targetModuleRoot);
67
+
68
+ // =======================
69
+ // 2. ADD PROJECTS TO SLN
70
+ // =======================
71
+
72
+ const projects = [
73
+ `${sourceModuleName}.API`,
74
+ `${sourceModuleName}.Core`,
75
+ `${sourceModuleName}.Infrastructure`
76
+ ];
77
+
78
+ projects.forEach(projectName => {
79
+ const csproj = path.join(
80
+ targetModuleRoot,
81
+ projectName,
82
+ `${projectName}.csproj`
83
+ );
84
+
85
+ if (!fs.existsSync(csproj)) {
86
+ console.warn(`⚠️ Missing project: ${csproj}`);
87
+ return;
88
+ }
89
+
90
+ console.log(`➕ Adding to solution: ${csproj}`);
91
+
92
+ execSync(`dotnet sln "${solutionFile}" add "${csproj}"`, {
93
+ stdio: 'inherit'
94
+ });
95
+ });
96
+
97
+ // =======================
98
+ // 3. RESTORE + BUILD
99
+ // =======================
100
+
101
+ console.log('🔄 Restoring...');
102
+ execSync(`dotnet restore "${solutionFile}"`, { stdio: 'inherit' });
103
+
104
+ console.log('🏗️ Building...');
105
+ execSync(`dotnet build "${solutionFile}"`, { stdio: 'inherit' });
106
+
107
+ // =======================
108
+ // 4. ADD HOST API REF
109
+ // =======================
110
+
111
+ console.log('🔗 Adding references to HostAPI...');
112
+
113
+ addModuleReferencesToHostApi(sourceModuleName, hostApiProjectPath);
114
+
115
+ console.log(`🎉 Assistant module created successfully!`);
37
116
 
38
117
  // =======================
39
- // Run
118
+ // HELPERS
40
119
  // =======================
41
120
 
42
- createModule(sourceModulePath, destinationModulePath);
121
+ function findSolutionRoot(startDir) {
122
+ let current = startDir;
123
+
124
+ while (current !== path.parse(current).root) {
125
+ const files = fs.readdirSync(current);
126
+ const sln = files.find(f => f.endsWith('.sln') || f.endsWith('.slnx'));
127
+
128
+ if (sln) {
129
+ return {
130
+ solutionFile: path.join(current, sln),
131
+ solutionDir: current
132
+ };
133
+ }
134
+
135
+ current = path.dirname(current);
136
+ }
137
+
138
+ throw new Error('❌ No solution file found');
139
+ }
140
+
141
+ function addModuleReferencesToHostApi(moduleName, hostApiCsprojPath) {
142
+ const refs = buildStaticProjectRefs(moduleName);
143
+ addProjectReferencesToCsproj(hostApiCsprojPath, refs);
144
+ }
145
+
146
+ function buildStaticProjectRefs(moduleName) {
147
+ return [
148
+ `..\\..\\Modules\\${moduleName}\\${moduleName}.API\\${moduleName}.API.csproj`,
149
+ `..\\..\\Modules\\${moduleName}\\${moduleName}.Core\\${moduleName}.Core.csproj`,
150
+ `..\\..\\Modules\\${moduleName}\\${moduleName}.Infrastructure\\${moduleName}.Infrastructure.csproj`,
151
+ ];
152
+ }
package/lib/replacer.js CHANGED
@@ -218,5 +218,6 @@ module.exports = {
218
218
  copyAndRenameFiles,
219
219
  findSolutionFileFixed,
220
220
  copyRecursive,
221
- addProjectReferencesToCsproj
221
+ addProjectReferencesToCsproj,
222
+ createModule
222
223
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netcore-blueprint",
3
- "version": "0.0.92",
3
+ "version": "0.0.94",
4
4
  "description": "A custom project blueprint",
5
5
  "main": "create.js",
6
6
  "bin": {