netcore-blueprint 1.0.19 → 1.0.20
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/create.js +15 -10
- package/package.json +1 -1
package/create.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
+
// Get the project name from command-line arguments
|
|
6
7
|
const projectName = process.argv[2];
|
|
7
8
|
if (!projectName) {
|
|
8
9
|
console.error("❌ Please specify the project name.");
|
|
@@ -12,17 +13,21 @@ if (!projectName) {
|
|
|
12
13
|
const templatePath = path.join(__dirname, "BlueprintTemplate"); // Copy from BlueprintTemplate
|
|
13
14
|
const destinationPath = path.join(process.cwd(), projectName);
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
// Function to copy and rename files
|
|
17
|
+
function copyAndRenameFiles(src, dest, oldName, newName) {
|
|
16
18
|
if (fs.lstatSync(src).isDirectory()) {
|
|
17
19
|
fs.mkdirSync(dest, { recursive: true });
|
|
18
20
|
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
21
|
+
|
|
19
22
|
for (let entry of entries) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
let srcPath = path.join(src, entry.name);
|
|
24
|
+
let destPath = path.join(dest, entry.name.replace(new RegExp(oldName, 'g'), newName));
|
|
25
|
+
copyAndRenameFiles(srcPath, destPath, oldName, newName);
|
|
23
26
|
}
|
|
24
27
|
} else {
|
|
25
|
-
fs.
|
|
28
|
+
let content = fs.readFileSync(src, 'utf8');
|
|
29
|
+
content = content.replace(new RegExp(oldName, 'g'), newName); // Replace occurrences of Blueprint
|
|
30
|
+
fs.writeFileSync(dest, content, 'utf8');
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -34,17 +39,17 @@ if (fs.existsSync(destinationPath)) {
|
|
|
34
39
|
|
|
35
40
|
fs.mkdirSync(destinationPath, { recursive: true });
|
|
36
41
|
|
|
37
|
-
// Copy
|
|
42
|
+
// Copy and rename all files
|
|
38
43
|
fs.readdirSync(templatePath).forEach(item => {
|
|
39
44
|
const srcPath = path.join(templatePath, item);
|
|
40
|
-
let destPath = path.join(destinationPath, item);
|
|
45
|
+
let destPath = path.join(destinationPath, item.replace(/Blueprint/g, projectName));
|
|
41
46
|
|
|
42
47
|
if (item === "gitignore") {
|
|
43
|
-
destPath = path.join(destinationPath, ".gitignore"); // Rename
|
|
48
|
+
destPath = path.join(destinationPath, ".gitignore"); // Rename gitignore
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
console.log(`✅ Copying ${item}...`);
|
|
47
|
-
|
|
51
|
+
console.log(`✅ Copying and renaming ${item}...`);
|
|
52
|
+
copyAndRenameFiles(srcPath, destPath, "Blueprint", projectName);
|
|
48
53
|
});
|
|
49
54
|
|
|
50
55
|
console.log(`🎉 Project "${projectName}" created successfully at ${destinationPath}`);
|