netcore-blueprint 1.0.13 → 1.0.15

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.
Files changed (2) hide show
  1. package/create.js +38 -48
  2. package/package.json +1 -1
package/create.js CHANGED
@@ -3,67 +3,57 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
 
6
- const projectName = process.argv[2];
7
- if (!projectName) {
8
- console.error("❌ Please specify the project name.");
6
+ const oldProjectName = "Blueprint"; // Your template project name
7
+ const newProjectName = process.argv[2];
8
+
9
+ if (!newProjectName) {
10
+ console.error("❌ Please specify the new project name.");
9
11
  process.exit(1);
10
12
  }
11
13
 
12
- const destinationPath = path.join(process.cwd(), projectName);
13
- const templateItems = [
14
- "Blueprint.API.sln",
15
- "Blueprint.API",
16
- "Blueprint.Core",
17
- "Blueprint.Infra",
18
- "Blueprint.Test",
19
- "README.md",
20
- "gitignore" // Rename later
21
- ];
14
+ const templatePath = path.join(__dirname, `${oldProjectName}Template`);
15
+ const destinationPath = path.join(process.cwd(), newProjectName);
16
+
17
+ // Ensure the destination directory does not already exist
18
+ if (fs.existsSync(destinationPath)) {
19
+ console.error(`❌ Project directory "${newProjectName}" already exists.`);
20
+ process.exit(1);
21
+ }
22
22
 
23
+ // Function to recursively copy and rename files/folders
23
24
  function copyAndRename(src, dest) {
24
- if (fs.lstatSync(src).isDirectory()) {
25
- fs.mkdirSync(dest, { recursive: true });
26
- const entries = fs.readdirSync(src, { withFileTypes: true });
27
- for (let entry of entries) {
28
- const srcPath = path.join(src, entry.name);
29
- const destPath = path.join(dest, entry.name);
30
- copyAndRename(srcPath, destPath);
31
- }
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
+ });
32
35
  } else {
36
+ // Read file content
33
37
  let content = fs.readFileSync(src, 'utf8');
34
38
 
35
- // Rename Solution and Project Names
36
- content = content.replace(/Blueprint\.API/g, projectName.toUpperCase());
37
- content = content.replace(/Blueprint/g, projectName.toUpperCase());
39
+ // Replace all occurrences of "Blueprint" dynamically
40
+ const regex = new RegExp(oldProjectName, "g");
41
+ content = content.replace(regex, newProjectName);
38
42
 
39
- fs.writeFileSync(dest, content);
40
- }
41
- }
43
+ // Rename file if needed
44
+ const newFileName = path.basename(dest).replace(oldProjectName, newProjectName);
45
+ const newDest = path.join(path.dirname(dest), newFileName);
42
46
 
43
- // Ensure destination doesn't already exist
44
- if (fs.existsSync(destinationPath)) {
45
- console.error(`❌ Project directory "${projectName}" already exists.`);
46
- process.exit(1);
47
+ fs.writeFileSync(newDest, content);
48
+ }
47
49
  }
48
50
 
51
+ // Start copying the template
49
52
  fs.mkdirSync(destinationPath, { recursive: true });
50
53
 
51
- // Copy template files
52
- templateItems.forEach(item => {
53
- const srcPath = path.join(__dirname, item);
54
- let destPath = path.join(destinationPath, item);
55
-
56
- if (item === "gitignore") {
57
- destPath = path.join(destinationPath, ".gitignore"); // Rename to .gitignore
58
- }
59
-
60
- if (fs.existsSync(srcPath)) {
61
- console.log(`✅ Copying ${item}...`);
62
- copyAndRename(srcPath, destPath);
63
- } else {
64
- console.error(`❌ Critical error: "${srcPath}" does not exist.`);
65
- process.exit(1);
66
- }
54
+ fs.readdirSync(templatePath).forEach(item => {
55
+ copyAndRename(path.join(templatePath, item), path.join(destinationPath, item));
67
56
  });
68
57
 
69
- console.log(`🎉 Project "${projectName}" created successfully at ${destinationPath}`);
58
+ console.log(`🎉 Project "${newProjectName}" created successfully at ${destinationPath}`);
59
+ console.log(`📌 Open "${newProjectName}.sln" in Visual Studio to get started!`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netcore-blueprint",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "A custom .NET Core project blueprint",
5
5
  "main": "create.js",
6
6
  "bin": {