netcore-blueprint 0.0.76 → 0.0.78
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 +99 -0
- package/bin/create-module.js +1 -6
- package/lib/replacer.js +2 -11
- package/package.json +3 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { buildReplaceMap, applyReplacements } = 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(assistantsTemplateRoot, sourceAssistantName);
|
|
30
|
+
|
|
31
|
+
// =======================
|
|
32
|
+
// Destination
|
|
33
|
+
// =======================
|
|
34
|
+
|
|
35
|
+
const destinationRoot = process.cwd();
|
|
36
|
+
const destinationAssistantPath = path.join(destinationRoot, newAssistantName);
|
|
37
|
+
|
|
38
|
+
// =======================
|
|
39
|
+
// Guards
|
|
40
|
+
// =======================
|
|
41
|
+
|
|
42
|
+
if (!fs.existsSync(sourceAssistantPath)) {
|
|
43
|
+
console.error(`❌ Source assistant not found: ${sourceAssistantPath}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (fs.existsSync(destinationAssistantPath)) {
|
|
48
|
+
console.error(`❌ Destination assistant already exists: ${destinationAssistantPath}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// =======================
|
|
53
|
+
// Replace Map
|
|
54
|
+
// =======================
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const replaceMap = buildReplaceMap({
|
|
58
|
+
sourceModuleName: sourceAssistantName,
|
|
59
|
+
newModuleName: newAssistantName
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
console.log(`📦 Creating assistant: ${newAssistantName}`);
|
|
63
|
+
console.log(`📁 From template: ${sourceAssistantPath}`);
|
|
64
|
+
console.log(`📁 To: ${destinationAssistantPath}`);
|
|
65
|
+
|
|
66
|
+
// =======================
|
|
67
|
+
// Run
|
|
68
|
+
// =======================
|
|
69
|
+
|
|
70
|
+
copyAndRenameFiles(sourceAssistantPath, destinationAssistantPath);
|
|
71
|
+
|
|
72
|
+
console.log(`🎉 Assistant "${newAssistantName}" created successfully!`);
|
|
73
|
+
|
|
74
|
+
// =======================
|
|
75
|
+
// Core Logic
|
|
76
|
+
// =======================
|
|
77
|
+
|
|
78
|
+
function copyAndRenameFiles(src, dest) {
|
|
79
|
+
const stat = fs.lstatSync(src);
|
|
80
|
+
|
|
81
|
+
if (stat.isDirectory()) {
|
|
82
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
83
|
+
|
|
84
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
85
|
+
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
const srcPath = path.join(src, entry.name);
|
|
88
|
+
|
|
89
|
+
const renamed = applyReplacements(entry.name, replaceMap);
|
|
90
|
+
const destPath = path.join(dest, renamed);
|
|
91
|
+
|
|
92
|
+
copyAndRenameFiles(srcPath, destPath);
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
let content = fs.readFileSync(src, 'utf8');
|
|
96
|
+
content = applyReplacements(content, replaceMap);
|
|
97
|
+
fs.writeFileSync(dest, content, 'utf8');
|
|
98
|
+
}
|
|
99
|
+
}
|
package/bin/create-module.js
CHANGED
|
@@ -24,7 +24,6 @@ if (!newModuleName) {
|
|
|
24
24
|
// =======================
|
|
25
25
|
|
|
26
26
|
const sourceModuleName = "__MODULE__";
|
|
27
|
-
const sourceEntityName = "__MODULE__";
|
|
28
27
|
|
|
29
28
|
const modulesTemplateRoot = path.join(__dirname, "..", "Modules");
|
|
30
29
|
const sourceModulePath = path.join(modulesTemplateRoot, `${sourceModuleName}Module`);
|
|
@@ -53,17 +52,13 @@ if (fs.existsSync(destinationModulePath)) {
|
|
|
53
52
|
// =======================
|
|
54
53
|
// Replace Map
|
|
55
54
|
// =======================
|
|
56
|
-
// 👉 newModuleName dùng cho cả Module + Entity
|
|
57
55
|
|
|
58
56
|
const replaceMap = buildReplaceMap({
|
|
59
57
|
sourceModuleName,
|
|
60
|
-
newModuleName
|
|
61
|
-
sourceEntityName,
|
|
62
|
-
newEntityName: newModuleName // 🔥 ENTITY = MODULE
|
|
58
|
+
newModuleName
|
|
63
59
|
});
|
|
64
60
|
|
|
65
61
|
console.log(`📦 Creating module: ${newModuleName}`);
|
|
66
|
-
console.log(`🧩 Entity name (auto): ${newModuleName}`);
|
|
67
62
|
console.log(`📁 From template: ${sourceModulePath}`);
|
|
68
63
|
console.log(`📁 To: ${destinationModulePath}`);
|
|
69
64
|
|
package/lib/replacer.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
function buildReplaceMap({
|
|
2
2
|
sourceModuleName, // "ItemModule" or "__MODULE__"
|
|
3
|
-
newModuleName
|
|
4
|
-
sourceEntityName, // "Item"
|
|
5
|
-
newEntityName // e.g. Product (same as module)
|
|
3
|
+
newModuleName // e.g. Product
|
|
6
4
|
}) {
|
|
7
5
|
return [
|
|
8
6
|
// =====================
|
|
9
7
|
// Module placeholders
|
|
10
8
|
// =====================
|
|
11
|
-
{ from:
|
|
12
|
-
{ from: "__module__", to: newModuleName.toLowerCase() },
|
|
13
|
-
{ from: sourceModuleName, to: newModuleName },
|
|
14
|
-
|
|
15
|
-
// =====================
|
|
16
|
-
// Lowercase entity fallback
|
|
17
|
-
// =====================
|
|
18
|
-
{ from: sourceEntityName.toLowerCase(), to: newEntityName.toLowerCase() },
|
|
9
|
+
{ from: sourceModuleName, to: newModuleName }
|
|
19
10
|
];
|
|
20
11
|
}
|
|
21
12
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netcore-blueprint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.78",
|
|
4
4
|
"description": "A custom project blueprint",
|
|
5
5
|
"main": "create.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"create-app": "./bin/create-app.js",
|
|
8
8
|
"create-module": "./bin/create-module.js",
|
|
9
|
-
"copy-module": "./bin/copy-module.js"
|
|
9
|
+
"copy-module": "./bin/copy-module.js",
|
|
10
|
+
"create-assistant": "./bin/create-assistant.js"
|
|
10
11
|
},
|
|
11
12
|
"scripts": {
|
|
12
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|