netcore-blueprint 0.0.93 → 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 +154 -14
- package/package.json +1 -1
package/bin/create-assistant.js
CHANGED
|
@@ -2,42 +2,182 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const {
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
const { addProjectReferencesToCsproj, copyRecursive } = require('../lib/replacer');
|
|
6
7
|
|
|
7
8
|
// =======================
|
|
8
|
-
//
|
|
9
|
+
// FIXED TEMPLATE
|
|
9
10
|
// =======================
|
|
10
11
|
|
|
11
12
|
const sourceModuleName = "AiAssistantModule";
|
|
13
|
+
const assistantName = "__ASSISTANT_NAME__";
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
// =======================
|
|
16
|
+
// FIND SOLUTION ROOT
|
|
17
|
+
// =======================
|
|
18
|
+
const solutionDir = process.cwd(); // đang ở root chứa .sln
|
|
19
|
+
|
|
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
|
+
}
|
|
15
26
|
|
|
16
27
|
// =======================
|
|
17
|
-
//
|
|
28
|
+
// PATHS
|
|
18
29
|
// =======================
|
|
19
30
|
|
|
20
|
-
const
|
|
21
|
-
|
|
31
|
+
const templateRoot = path.join(
|
|
32
|
+
__dirname,
|
|
33
|
+
"..",
|
|
34
|
+
"Modules",
|
|
35
|
+
sourceModuleName
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const targetModuleRoot = path.join(
|
|
39
|
+
solutionDir,
|
|
40
|
+
'Modules',
|
|
41
|
+
sourceModuleName
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const hostApiProjectPath = path.join(
|
|
45
|
+
solutionDir,
|
|
46
|
+
'Host',
|
|
47
|
+
'Host.API',
|
|
48
|
+
'Host.API.csproj'
|
|
49
|
+
);
|
|
22
50
|
|
|
23
51
|
// =======================
|
|
24
|
-
//
|
|
52
|
+
// GUARDS
|
|
25
53
|
// =======================
|
|
26
54
|
|
|
27
|
-
if (!fs.existsSync(
|
|
28
|
-
console.error(`❌
|
|
55
|
+
if (!fs.existsSync(templateRoot)) {
|
|
56
|
+
console.error(`❌ Template not found: ${templateRoot}`);
|
|
29
57
|
process.exit(1);
|
|
30
58
|
}
|
|
31
59
|
|
|
32
|
-
if (fs.existsSync(
|
|
33
|
-
console.error(`❌
|
|
60
|
+
if (fs.existsSync(targetModuleRoot)) {
|
|
61
|
+
console.error(`❌ Module already exists: ${targetModuleRoot}`);
|
|
34
62
|
process.exit(1);
|
|
35
63
|
}
|
|
36
64
|
|
|
37
65
|
console.log(`📦 Creating assistant module`);
|
|
66
|
+
console.log(`📁 Target: ${targetModuleRoot}`);
|
|
67
|
+
console.log(`🧩 Solution: ${solutionFile}`);
|
|
68
|
+
|
|
69
|
+
// =======================
|
|
70
|
+
// 1. Create root
|
|
71
|
+
// =======================
|
|
72
|
+
|
|
73
|
+
fs.mkdirSync(targetModuleRoot, { recursive: true });
|
|
38
74
|
|
|
39
75
|
// =======================
|
|
40
|
-
//
|
|
76
|
+
// 2. ENGINE PROJECTS
|
|
41
77
|
// =======================
|
|
42
78
|
|
|
43
|
-
|
|
79
|
+
const engineRoot = path.join(targetModuleRoot, "Engine");
|
|
80
|
+
fs.mkdirSync(engineRoot, { recursive: true });
|
|
81
|
+
|
|
82
|
+
const engineProjects = [
|
|
83
|
+
`${sourceModuleName}.API`,
|
|
84
|
+
`${sourceModuleName}.Core`,
|
|
85
|
+
`${sourceModuleName}.Infrastructure`
|
|
86
|
+
];
|
|
87
|
+
|
|
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
|
+
});
|
|
95
|
+
|
|
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);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// copy template
|
|
105
|
+
const templatePath = path.join(templateRoot, "Engine", name);
|
|
106
|
+
|
|
107
|
+
if (fs.existsSync(templatePath)) {
|
|
108
|
+
console.log(`📄 Copying template: ${templatePath}`);
|
|
109
|
+
copyRecursive(templatePath, projectPath);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// =======================
|
|
114
|
+
// 3. ASSISTANT PROJECT
|
|
115
|
+
// =======================
|
|
116
|
+
|
|
117
|
+
const assistantRoot = path.join(targetModuleRoot, "Assistants");
|
|
118
|
+
fs.mkdirSync(assistantRoot, { recursive: true });
|
|
119
|
+
|
|
120
|
+
console.log(`📦 Creating Assistant project: ${assistantName}`);
|
|
121
|
+
|
|
122
|
+
execSync(`dotnet new classlib -n ${assistantName}`, {
|
|
123
|
+
cwd: assistantRoot,
|
|
124
|
+
stdio: 'inherit'
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const assistantProjectPath = path.join(assistantRoot, assistantName);
|
|
128
|
+
|
|
129
|
+
// remove default file
|
|
130
|
+
const defaultFile = path.join(assistantProjectPath, 'Class1.cs');
|
|
131
|
+
if (fs.existsSync(defaultFile)) {
|
|
132
|
+
fs.unlinkSync(defaultFile);
|
|
133
|
+
}
|
|
134
|
+
|
|
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
|
+
}
|
|
146
|
+
|
|
147
|
+
// =======================
|
|
148
|
+
// 4. ADD TO SOLUTION
|
|
149
|
+
// =======================
|
|
150
|
+
|
|
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
|
+
});
|
|
162
|
+
|
|
163
|
+
// =======================
|
|
164
|
+
// 5. BUILD
|
|
165
|
+
// =======================
|
|
166
|
+
|
|
167
|
+
console.log('🔄 Restoring...');
|
|
168
|
+
execSync(`dotnet restore "${solutionFile}"`, { stdio: 'inherit' });
|
|
169
|
+
|
|
170
|
+
console.log('🏗️ Building...');
|
|
171
|
+
execSync(`dotnet build "${solutionFile}"`, { stdio: 'inherit' });
|
|
172
|
+
|
|
173
|
+
// =======================
|
|
174
|
+
// 6. ADD REFERENCES
|
|
175
|
+
// =======================
|
|
176
|
+
|
|
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
|
+
]);
|
|
182
|
+
|
|
183
|
+
console.log(`🎉 DONE`);
|