netcore-blueprint 0.0.13 → 0.0.16
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-module.js +27 -15
- package/package.json +2 -1
package/bin/create-module.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
const fs = require('fs');
|
|
4
2
|
const path = require('path');
|
|
5
3
|
|
|
@@ -10,26 +8,43 @@ if (!newModuleName) {
|
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
const sourceModuleName = "ItemModule";
|
|
11
|
+
const templatePath = path.join(__dirname, "..", "BlueprintTemplate");
|
|
12
|
+
const destinationRoot = process.cwd(); // project root
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!fs.existsSync(sourcePath)) {
|
|
18
|
-
console.error(`❌ Source module not found: ${sourcePath}`);
|
|
14
|
+
if (!fs.existsSync(templatePath)) {
|
|
15
|
+
console.error(`❌ BlueprintTemplate not found: ${templatePath}`);
|
|
19
16
|
process.exit(1);
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
// Find all ItemModule.* folders
|
|
20
|
+
const sourceFolders = fs.readdirSync(templatePath, { withFileTypes: true })
|
|
21
|
+
.filter(d => d.isDirectory() && d.name.startsWith(sourceModuleName));
|
|
22
|
+
|
|
23
|
+
if (sourceFolders.length === 0) {
|
|
24
|
+
console.error(`❌ No ItemModule templates found in: ${templatePath}`);
|
|
24
25
|
process.exit(1);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
for (const dir of sourceFolders) {
|
|
29
|
+
const srcPath = path.join(templatePath, dir.name);
|
|
30
|
+
const destName = dir.name.replace(
|
|
31
|
+
new RegExp(sourceModuleName, 'g'),
|
|
32
|
+
newModuleName
|
|
33
|
+
);
|
|
34
|
+
const destPath = path.join(destinationRoot, destName);
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
if (fs.existsSync(destPath)) {
|
|
37
|
+
console.error(`❌ Destination already exists: ${destPath}`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
30
40
|
|
|
41
|
+
console.log(`📦 Copying ${dir.name} -> ${destName}`);
|
|
42
|
+
copyAndRenameFiles(srcPath, destPath, sourceModuleName, newModuleName);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(`🎉 Module "${newModuleName}" created successfully!`);
|
|
31
46
|
|
|
32
|
-
// ===== CORE LOGIC
|
|
47
|
+
// ===== CORE LOGIC =====
|
|
33
48
|
|
|
34
49
|
function copyAndRenameFiles(src, dest, oldName, newName) {
|
|
35
50
|
if (fs.lstatSync(src).isDirectory()) {
|
|
@@ -45,10 +60,7 @@ function copyAndRenameFiles(src, dest, oldName, newName) {
|
|
|
45
60
|
}
|
|
46
61
|
} else {
|
|
47
62
|
let content = fs.readFileSync(src, 'utf8');
|
|
48
|
-
|
|
49
|
-
// Replace namespace + class + references
|
|
50
63
|
content = content.replace(new RegExp(oldName, 'g'), newName);
|
|
51
|
-
|
|
52
64
|
fs.writeFileSync(dest, content, 'utf8');
|
|
53
65
|
}
|
|
54
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netcore-blueprint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "A custom project blueprint",
|
|
5
5
|
"main": "create.js",
|
|
6
6
|
"bin": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"files": [
|
|
20
|
+
"bin",
|
|
20
21
|
"BlueprintTemplate/**"
|
|
21
22
|
]
|
|
22
23
|
}
|