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.
- package/bin/create-assistant.js +88 -57
- package/package.json +1 -1
package/bin/create-assistant.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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.
|
|
70
|
+
// 1. Create root
|
|
64
71
|
// =======================
|
|
65
72
|
|
|
66
|
-
|
|
73
|
+
fs.mkdirSync(targetModuleRoot, { recursive: true });
|
|
67
74
|
|
|
68
75
|
// =======================
|
|
69
|
-
// 2.
|
|
76
|
+
// 2. ENGINE PROJECTS
|
|
70
77
|
// =======================
|
|
71
78
|
|
|
72
|
-
const
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
104
|
+
// copy template
|
|
105
|
+
const templatePath = path.join(templateRoot, "Engine", name);
|
|
91
106
|
|
|
92
|
-
|
|
93
|
-
|
|
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.
|
|
114
|
+
// 3. ASSISTANT PROJECT
|
|
99
115
|
// =======================
|
|
100
116
|
|
|
101
|
-
|
|
102
|
-
|
|
117
|
+
const assistantRoot = path.join(targetModuleRoot, "Assistants");
|
|
118
|
+
fs.mkdirSync(assistantRoot, { recursive: true });
|
|
103
119
|
|
|
104
|
-
console.log(
|
|
105
|
-
execSync(`dotnet build "${solutionFile}"`, { stdio: 'inherit' });
|
|
120
|
+
console.log(`📦 Creating Assistant project: ${assistantName}`);
|
|
106
121
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
execSync(`dotnet new classlib -n ${assistantName}`, {
|
|
123
|
+
cwd: assistantRoot,
|
|
124
|
+
stdio: 'inherit'
|
|
125
|
+
});
|
|
110
126
|
|
|
111
|
-
|
|
127
|
+
const assistantProjectPath = path.join(assistantRoot, assistantName);
|
|
112
128
|
|
|
113
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
148
|
+
// 4. ADD TO SOLUTION
|
|
119
149
|
// =======================
|
|
120
150
|
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
163
|
+
// =======================
|
|
164
|
+
// 5. BUILD
|
|
165
|
+
// =======================
|
|
127
166
|
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
136
|
-
|
|
170
|
+
console.log('🏗️ Building...');
|
|
171
|
+
execSync(`dotnet build "${solutionFile}"`, { stdio: 'inherit' });
|
|
137
172
|
|
|
138
|
-
|
|
139
|
-
|
|
173
|
+
// =======================
|
|
174
|
+
// 6. ADD REFERENCES
|
|
175
|
+
// =======================
|
|
140
176
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
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`);
|