netcore-blueprint 0.0.98 → 0.0.99
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/copy-assistant-item.js +153 -0
- package/bin/create-assistant-item.js +88 -0
- package/package.json +1 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
findSolutionFileFixed,
|
|
5
|
+
copyRecursive
|
|
6
|
+
} = require('../lib/replacer');
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { execSync } = require('child_process');
|
|
11
|
+
|
|
12
|
+
// =====================================================
|
|
13
|
+
// Usage:
|
|
14
|
+
// copy-assistant-item BlogWriter MyApp
|
|
15
|
+
// =====================================================
|
|
16
|
+
|
|
17
|
+
const assistantName = process.argv[2];
|
|
18
|
+
const targetFolder = process.argv[3];
|
|
19
|
+
const force = process.argv.includes('--force');
|
|
20
|
+
|
|
21
|
+
if (!assistantName || !targetFolder) {
|
|
22
|
+
console.error('Usage: copy-assistant-item <AssistantName> <TargetFolder>');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Assume current working directory is Modules/
|
|
27
|
+
const modulesPath = process.cwd();
|
|
28
|
+
|
|
29
|
+
// Template (phải là __ASSISTANT_NAME__)
|
|
30
|
+
const TEMPLATE_NAME = '__ASSISTANT_NAME__';
|
|
31
|
+
|
|
32
|
+
const templateRoot = path.join(modulesPath, TEMPLATE_NAME);
|
|
33
|
+
|
|
34
|
+
const targetAssistantRoot = path.join(
|
|
35
|
+
modulesPath,
|
|
36
|
+
'..',
|
|
37
|
+
targetFolder,
|
|
38
|
+
'Modules',
|
|
39
|
+
'AIAssistantModule',
|
|
40
|
+
'Assistants',
|
|
41
|
+
assistantName
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const solutionFile = findSolutionFileFixed(modulesPath, targetFolder);
|
|
45
|
+
|
|
46
|
+
if (!fs.existsSync(templateRoot)) {
|
|
47
|
+
console.error(`❌ Template not found: ${templateRoot}`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (fs.existsSync(targetAssistantRoot)) {
|
|
52
|
+
if (!force) {
|
|
53
|
+
console.error(`❌ Assistant already exists: ${targetAssistantRoot}`);
|
|
54
|
+
console.error(` Use --force to overwrite.`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log(`🔥 Removing existing assistant: ${targetAssistantRoot}`);
|
|
59
|
+
fs.rmSync(targetAssistantRoot, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!solutionFile) {
|
|
63
|
+
console.error("❌ Could not find .sln file.");
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(`🚀 Cloning assistant template:`);
|
|
68
|
+
console.log(` From: ${templateRoot}`);
|
|
69
|
+
console.log(` To: ${targetAssistantRoot}`);
|
|
70
|
+
console.log(`🧩 Solution: ${solutionFile}`);
|
|
71
|
+
|
|
72
|
+
// =====================================================
|
|
73
|
+
// 1. Create root
|
|
74
|
+
// =====================================================
|
|
75
|
+
|
|
76
|
+
fs.mkdirSync(targetAssistantRoot, { recursive: true });
|
|
77
|
+
|
|
78
|
+
// =====================================================
|
|
79
|
+
// 2. Create project (CHỈ 1 PROJECT)
|
|
80
|
+
// =====================================================
|
|
81
|
+
|
|
82
|
+
const projectName = assistantName;
|
|
83
|
+
|
|
84
|
+
console.log(`📦 Creating project: ${projectName}`);
|
|
85
|
+
|
|
86
|
+
execSync(`dotnet new classlib -n ${projectName}`, {
|
|
87
|
+
cwd: targetAssistantRoot,
|
|
88
|
+
stdio: 'inherit'
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const projectPath = path.join(targetAssistantRoot, projectName);
|
|
92
|
+
|
|
93
|
+
// =====================================================
|
|
94
|
+
// 2.1 Remove default Class1.cs
|
|
95
|
+
// =====================================================
|
|
96
|
+
|
|
97
|
+
const defaultClassFile = path.join(projectPath, 'Class1.cs');
|
|
98
|
+
|
|
99
|
+
if (fs.existsSync(defaultClassFile)) {
|
|
100
|
+
console.log(`🧹 Removing default file: ${defaultClassFile}`);
|
|
101
|
+
fs.unlinkSync(defaultClassFile);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// =====================================================
|
|
105
|
+
// 3. Copy template files (🔥 quan trọng)
|
|
106
|
+
// =====================================================
|
|
107
|
+
|
|
108
|
+
const templateSubFolder = path.join(templateRoot, TEMPLATE_NAME);
|
|
109
|
+
|
|
110
|
+
if (!fs.existsSync(templateSubFolder)) {
|
|
111
|
+
console.warn(`⚠️ Template subfolder not found: ${templateSubFolder}`);
|
|
112
|
+
} else {
|
|
113
|
+
console.log(`📄 Copying template from: ${templateSubFolder}`);
|
|
114
|
+
copyRecursive(templateSubFolder, projectPath);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// =====================================================
|
|
118
|
+
// 4. Rename csproj nếu cần
|
|
119
|
+
// =====================================================
|
|
120
|
+
|
|
121
|
+
const oldCsproj = path.join(projectPath, `${TEMPLATE_NAME}.csproj`);
|
|
122
|
+
const newCsproj = path.join(projectPath, `${projectName}.csproj`);
|
|
123
|
+
|
|
124
|
+
if (fs.existsSync(oldCsproj)) {
|
|
125
|
+
fs.renameSync(oldCsproj, newCsproj);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// =====================================================
|
|
129
|
+
// 5. Add to solution
|
|
130
|
+
// =====================================================
|
|
131
|
+
|
|
132
|
+
const csprojPath = path.join(
|
|
133
|
+
projectPath,
|
|
134
|
+
`${projectName}.csproj`
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
console.log(`➕ Adding to solution: ${csprojPath}`);
|
|
138
|
+
|
|
139
|
+
execSync(`dotnet sln "${solutionFile}" add "${csprojPath}"`, {
|
|
140
|
+
stdio: 'inherit'
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// =====================================================
|
|
144
|
+
// 6. Build
|
|
145
|
+
// =====================================================
|
|
146
|
+
|
|
147
|
+
console.log('🔄 Restoring NuGet packages...');
|
|
148
|
+
execSync(`dotnet restore "${solutionFile}"`, { stdio: 'inherit' });
|
|
149
|
+
|
|
150
|
+
console.log('🏗️ Building solution...');
|
|
151
|
+
execSync(`dotnet build "${solutionFile}"`, { stdio: 'inherit' });
|
|
152
|
+
|
|
153
|
+
console.log(`🎉 Assistant "${assistantName}" created successfully!`);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { buildReplaceMap, copyAndRenameFiles } = require('../lib/replacer');
|
|
6
|
+
|
|
7
|
+
// =======================
|
|
8
|
+
// Args
|
|
9
|
+
// =======================
|
|
10
|
+
// Usage:
|
|
11
|
+
// create-assistant BlogWriter
|
|
12
|
+
// =======================
|
|
13
|
+
|
|
14
|
+
const newAssistantName = process.argv[2];
|
|
15
|
+
|
|
16
|
+
if (!newAssistantName) {
|
|
17
|
+
console.error("❌ Usage: create-assistant <AssistantName>");
|
|
18
|
+
console.error(" Example: create-assistant BlogWriter");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// =======================
|
|
23
|
+
// Template source
|
|
24
|
+
// =======================
|
|
25
|
+
|
|
26
|
+
const sourceAssistantName = "__ASSISTANT_NAME__";
|
|
27
|
+
|
|
28
|
+
const assistantsTemplateRoot = path.join(__dirname, "..", "Assistants");
|
|
29
|
+
const sourceAssistantPath = path.join(
|
|
30
|
+
assistantsTemplateRoot,
|
|
31
|
+
`${sourceAssistantName}`
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// =======================
|
|
35
|
+
// Destination
|
|
36
|
+
// =======================
|
|
37
|
+
|
|
38
|
+
const destinationRoot = process.cwd(); // đang đứng tại root project
|
|
39
|
+
const destinationAssistantPath = path.join(
|
|
40
|
+
destinationRoot,
|
|
41
|
+
"Assistants",
|
|
42
|
+
`${newAssistantName}`
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// =======================
|
|
46
|
+
// Guards
|
|
47
|
+
// =======================
|
|
48
|
+
|
|
49
|
+
if (!fs.existsSync(sourceAssistantPath)) {
|
|
50
|
+
console.error(`❌ Source assistant not found: ${sourceAssistantPath}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (fs.existsSync(destinationAssistantPath)) {
|
|
55
|
+
console.error(`❌ Assistant already exists: ${destinationAssistantPath}`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// =======================
|
|
60
|
+
// Replace Map
|
|
61
|
+
// =======================
|
|
62
|
+
|
|
63
|
+
const replaceMap = buildReplaceMap({
|
|
64
|
+
sourceModuleName: sourceAssistantName,
|
|
65
|
+
newModuleName: newAssistantName
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Nếu bạn muốn rõ nghĩa hơn thì có thể đổi replacer thành:
|
|
69
|
+
// buildReplaceMap({
|
|
70
|
+
// sourceName: sourceAssistantName,
|
|
71
|
+
// newName: newAssistantName
|
|
72
|
+
// });
|
|
73
|
+
|
|
74
|
+
// =======================
|
|
75
|
+
// Run
|
|
76
|
+
// =======================
|
|
77
|
+
|
|
78
|
+
console.log(`📦 Creating assistant: ${newAssistantName}`);
|
|
79
|
+
console.log(`📁 From template: ${sourceAssistantPath}`);
|
|
80
|
+
console.log(`📁 To: ${destinationAssistantPath}`);
|
|
81
|
+
|
|
82
|
+
copyAndRenameFiles(
|
|
83
|
+
sourceAssistantPath,
|
|
84
|
+
destinationAssistantPath,
|
|
85
|
+
replaceMap
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
console.log(`🎉 Assistant "${newAssistantName}" created successfully!`);
|