netcore-blueprint 0.0.94 → 0.0.95

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.
@@ -3,19 +3,26 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const { execSync } = require('child_process');
6
- const { createModule, addProjectReferencesToCsproj } = require('../lib/replacer');
6
+ const { addProjectReferencesToCsproj, copyRecursive } = require('../lib/replacer');
7
7
 
8
8
  // =======================
9
9
  // FIXED TEMPLATE
10
10
  // =======================
11
11
 
12
12
  const sourceModuleName = "AiAssistantModule";
13
+ const assistantName = "__ASSISTANT_NAME__";
13
14
 
14
15
  // =======================
15
16
  // FIND SOLUTION ROOT
16
17
  // =======================
18
+ const solutionDir = process.cwd(); // đang ở root chứa .sln
17
19
 
18
- const { solutionFile, solutionDir } = findSolutionRoot(process.cwd());
20
+ const solutionFile = fs.readdirSync(solutionDir)
21
+ .find(f => f.endsWith('.sln') || f.endsWith('.slnx'));
22
+ if (!solutionFile) {
23
+ console.error("❌ Could not find .sln file in parent directories.");
24
+ process.exit(1);
25
+ }
19
26
 
20
27
  // =======================
21
28
  // PATHS
@@ -60,93 +67,117 @@ console.log(`📁 Target: ${targetModuleRoot}`);
60
67
  console.log(`🧩 Solution: ${solutionFile}`);
61
68
 
62
69
  // =======================
63
- // 1. COPY MODULE
70
+ // 1. Create root
64
71
  // =======================
65
72
 
66
- createModule(templateRoot, targetModuleRoot);
73
+ fs.mkdirSync(targetModuleRoot, { recursive: true });
67
74
 
68
75
  // =======================
69
- // 2. ADD PROJECTS TO SLN
76
+ // 2. ENGINE PROJECTS
70
77
  // =======================
71
78
 
72
- const projects = [
79
+ const engineRoot = path.join(targetModuleRoot, "Engine");
80
+ fs.mkdirSync(engineRoot, { recursive: true });
81
+
82
+ const engineProjects = [
73
83
  `${sourceModuleName}.API`,
74
84
  `${sourceModuleName}.Core`,
75
85
  `${sourceModuleName}.Infrastructure`
76
86
  ];
77
87
 
78
- projects.forEach(projectName => {
79
- const csproj = path.join(
80
- targetModuleRoot,
81
- projectName,
82
- `${projectName}.csproj`
83
- );
88
+ engineProjects.forEach(name => {
89
+ console.log(`📦 Creating Engine project: ${name}`);
90
+
91
+ execSync(`dotnet new classlib -n ${name}`, {
92
+ cwd: engineRoot,
93
+ stdio: 'inherit'
94
+ });
84
95
 
85
- if (!fs.existsSync(csproj)) {
86
- console.warn(`⚠️ Missing project: ${csproj}`);
87
- return;
96
+ const projectPath = path.join(engineRoot, name);
97
+
98
+ // remove default file
99
+ const defaultFile = path.join(projectPath, 'Class1.cs');
100
+ if (fs.existsSync(defaultFile)) {
101
+ fs.unlinkSync(defaultFile);
88
102
  }
89
103
 
90
- console.log(`➕ Adding to solution: ${csproj}`);
104
+ // copy template
105
+ const templatePath = path.join(templateRoot, "Engine", name);
91
106
 
92
- execSync(`dotnet sln "${solutionFile}" add "${csproj}"`, {
93
- stdio: 'inherit'
94
- });
107
+ if (fs.existsSync(templatePath)) {
108
+ console.log(`📄 Copying template: ${templatePath}`);
109
+ copyRecursive(templatePath, projectPath);
110
+ }
95
111
  });
96
112
 
97
113
  // =======================
98
- // 3. RESTORE + BUILD
114
+ // 3. ASSISTANT PROJECT
99
115
  // =======================
100
116
 
101
- console.log('🔄 Restoring...');
102
- execSync(`dotnet restore "${solutionFile}"`, { stdio: 'inherit' });
117
+ const assistantRoot = path.join(targetModuleRoot, "Assistants");
118
+ fs.mkdirSync(assistantRoot, { recursive: true });
103
119
 
104
- console.log('🏗️ Building...');
105
- execSync(`dotnet build "${solutionFile}"`, { stdio: 'inherit' });
120
+ console.log(`📦 Creating Assistant project: ${assistantName}`);
106
121
 
107
- // =======================
108
- // 4. ADD HOST API REF
109
- // =======================
122
+ execSync(`dotnet new classlib -n ${assistantName}`, {
123
+ cwd: assistantRoot,
124
+ stdio: 'inherit'
125
+ });
110
126
 
111
- console.log('🔗 Adding references to HostAPI...');
127
+ const assistantProjectPath = path.join(assistantRoot, assistantName);
112
128
 
113
- addModuleReferencesToHostApi(sourceModuleName, hostApiProjectPath);
129
+ // remove default file
130
+ const defaultFile = path.join(assistantProjectPath, 'Class1.cs');
131
+ if (fs.existsSync(defaultFile)) {
132
+ fs.unlinkSync(defaultFile);
133
+ }
114
134
 
115
- console.log(`🎉 Assistant module created successfully!`);
135
+ // copy template
136
+ const assistantTemplate = path.join(
137
+ templateRoot,
138
+ "Assistants",
139
+ "__ASSISTANT_NAME__"
140
+ );
141
+
142
+ if (fs.existsSync(assistantTemplate)) {
143
+ console.log(`📄 Copying assistant template`);
144
+ copyRecursive(assistantTemplate, assistantProjectPath);
145
+ }
116
146
 
117
147
  // =======================
118
- // HELPERS
148
+ // 4. ADD TO SOLUTION
119
149
  // =======================
120
150
 
121
- function findSolutionRoot(startDir) {
122
- let current = startDir;
151
+ const allProjects = [
152
+ ...engineProjects.map(p => path.join(engineRoot, p, `${p}.csproj`)),
153
+ path.join(assistantProjectPath, `${assistantName}.csproj`)
154
+ ];
155
+
156
+ allProjects.forEach(csproj => {
157
+ console.log(`➕ Adding to solution: ${csproj}`);
158
+ execSync(`dotnet sln "${solutionFile}" add "${csproj}"`, {
159
+ stdio: 'inherit'
160
+ });
161
+ });
123
162
 
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'));
163
+ // =======================
164
+ // 5. BUILD
165
+ // =======================
127
166
 
128
- if (sln) {
129
- return {
130
- solutionFile: path.join(current, sln),
131
- solutionDir: current
132
- };
133
- }
167
+ console.log('🔄 Restoring...');
168
+ execSync(`dotnet restore "${solutionFile}"`, { stdio: 'inherit' });
134
169
 
135
- current = path.dirname(current);
136
- }
170
+ console.log('🏗️ Building...');
171
+ execSync(`dotnet build "${solutionFile}"`, { stdio: 'inherit' });
137
172
 
138
- throw new Error('❌ No solution file found');
139
- }
173
+ // =======================
174
+ // 6. ADD REFERENCES
175
+ // =======================
140
176
 
141
- function addModuleReferencesToHostApi(moduleName, hostApiCsprojPath) {
142
- const refs = buildStaticProjectRefs(moduleName);
143
- addProjectReferencesToCsproj(hostApiCsprojPath, refs);
144
- }
177
+ addProjectReferencesToCsproj(hostApiProjectPath, [
178
+ `..\\..\\Modules\\${sourceModuleName}\\Engine\\${sourceModuleName}.API\\${sourceModuleName}.API.csproj`,
179
+ `..\\..\\Modules\\${sourceModuleName}\\Engine\\${sourceModuleName}.Core\\${sourceModuleName}.Core.csproj`,
180
+ `..\\..\\Modules\\${sourceModuleName}\\Engine\\${sourceModuleName}.Infrastructure\\${sourceModuleName}.Infrastructure.csproj`
181
+ ]);
145
182
 
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
- }
183
+ console.log(`🎉 DONE`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netcore-blueprint",
3
- "version": "0.0.94",
3
+ "version": "0.0.95",
4
4
  "description": "A custom project blueprint",
5
5
  "main": "create.js",
6
6
  "bin": {