netcore-blueprint 1.0.16 → 1.0.17
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 +32 -40
- package/package.json +1 -1
package/create.js
CHANGED
|
@@ -3,57 +3,49 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!newProjectName) {
|
|
10
|
-
console.error("❌ Please specify the new project name.");
|
|
6
|
+
const projectName = process.argv[2];
|
|
7
|
+
if (!projectName) {
|
|
8
|
+
console.error("❌ Please specify the project name.");
|
|
11
9
|
process.exit(1);
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
const templatePath = path.join(__dirname,
|
|
15
|
-
const destinationPath = path.join(process.cwd(),
|
|
12
|
+
const templatePath = path.join(__dirname, "BlueprintTemplate"); // Copy from BlueprintTemplate
|
|
13
|
+
const destinationPath = path.join(process.cwd(), projectName);
|
|
14
|
+
|
|
15
|
+
function copyFilesRecursively(src, dest) {
|
|
16
|
+
if (fs.lstatSync(src).isDirectory()) {
|
|
17
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
18
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
19
|
+
for (let entry of entries) {
|
|
20
|
+
const srcPath = path.join(src, entry.name);
|
|
21
|
+
const destPath = path.join(dest, entry.name);
|
|
22
|
+
copyFilesRecursively(srcPath, destPath);
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
fs.copyFileSync(src, dest);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
16
28
|
|
|
17
|
-
// Ensure the destination
|
|
29
|
+
// Ensure the destination folder doesn't already exist
|
|
18
30
|
if (fs.existsSync(destinationPath)) {
|
|
19
|
-
console.error(`❌ Project directory "${
|
|
31
|
+
console.error(`❌ Project directory "${projectName}" already exists.`);
|
|
20
32
|
process.exit(1);
|
|
21
33
|
}
|
|
22
34
|
|
|
23
|
-
|
|
24
|
-
function copyAndRename(src, dest) {
|
|
25
|
-
const stat = fs.lstatSync(src);
|
|
26
|
-
|
|
27
|
-
if (stat.isDirectory()) {
|
|
28
|
-
// Rename folder if needed
|
|
29
|
-
const newDir = path.join(path.dirname(dest), path.basename(dest).replace(oldProjectName, newProjectName));
|
|
30
|
-
fs.mkdirSync(newDir, { recursive: true });
|
|
31
|
-
|
|
32
|
-
fs.readdirSync(src).forEach(entry => {
|
|
33
|
-
copyAndRename(path.join(src, entry), path.join(newDir, entry));
|
|
34
|
-
});
|
|
35
|
-
} else {
|
|
36
|
-
// Read file content
|
|
37
|
-
let content = fs.readFileSync(src, 'utf8');
|
|
38
|
-
|
|
39
|
-
// Replace all occurrences of "Blueprint" dynamically
|
|
40
|
-
const regex = new RegExp(oldProjectName, "g");
|
|
41
|
-
content = content.replace(regex, newProjectName);
|
|
35
|
+
fs.mkdirSync(destinationPath, { recursive: true });
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
// Copy everything inside BlueprintTemplate
|
|
38
|
+
fs.readdirSync(templatePath).forEach(item => {
|
|
39
|
+
const srcPath = path.join(templatePath, item);
|
|
40
|
+
let destPath = path.join(destinationPath, item);
|
|
46
41
|
|
|
47
|
-
|
|
42
|
+
if (item === "gitignore") {
|
|
43
|
+
destPath = path.join(destinationPath, ".gitignore"); // Rename to .gitignore
|
|
48
44
|
}
|
|
49
|
-
}
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
fs.readdirSync(templatePath).forEach(item => {
|
|
55
|
-
copyAndRename(path.join(templatePath, item), path.join(destinationPath, item));
|
|
46
|
+
console.log(`✅ Copying ${item}...`);
|
|
47
|
+
copyFilesRecursively(srcPath, destPath);
|
|
56
48
|
});
|
|
57
49
|
|
|
58
|
-
console.log(`🎉 Project "${
|
|
59
|
-
console.log(`📌 Open "${
|
|
50
|
+
console.log(`🎉 Project "${projectName}" created successfully at ${destinationPath}`);
|
|
51
|
+
console.log(`📌 Open "${projectName}.sln" in Visual Studio to get started!`);
|