netcore-blueprint 1.0.14 → 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 +40 -44
  2. package/package.json +1 -1
package/create.js CHANGED
@@ -3,61 +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
- ];
22
-
23
- function copyFilesRecursively(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
- copyFilesRecursively(srcPath, destPath);
31
- }
32
- } else {
33
- fs.copyFileSync(src, dest);
34
- }
35
- }
14
+ const templatePath = path.join(__dirname, `${oldProjectName}Template`);
15
+ const destinationPath = path.join(process.cwd(), newProjectName);
36
16
 
37
- // Ensure destination doesn't already exist
17
+ // Ensure the destination directory does not already exist
38
18
  if (fs.existsSync(destinationPath)) {
39
- console.error(`❌ Project directory "${projectName}" already exists.`);
19
+ console.error(`❌ Project directory "${newProjectName}" already exists.`);
40
20
  process.exit(1);
41
21
  }
42
22
 
43
- fs.mkdirSync(destinationPath, { recursive: true });
44
-
45
- // Copy template files without renaming
46
- templateItems.forEach(item => {
47
- const srcPath = path.join(__dirname, item);
48
- let destPath = path.join(destinationPath, item);
23
+ // Function to recursively copy and rename files/folders
24
+ function copyAndRename(src, dest) {
25
+ const stat = fs.lstatSync(src);
49
26
 
50
- if (item === "gitignore") {
51
- destPath = path.join(destinationPath, ".gitignore"); // Rename to .gitignore
52
- }
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 });
53
31
 
54
- if (fs.existsSync(srcPath)) {
55
- console.log(`✅ Copying ${item}...`);
56
- copyFilesRecursively(srcPath, destPath);
32
+ fs.readdirSync(src).forEach(entry => {
33
+ copyAndRename(path.join(src, entry), path.join(newDir, entry));
34
+ });
57
35
  } else {
58
- console.error(`❌ Critical error: "${srcPath}" does not exist.`);
59
- process.exit(1);
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);
42
+
43
+ // Rename file if needed
44
+ const newFileName = path.basename(dest).replace(oldProjectName, newProjectName);
45
+ const newDest = path.join(path.dirname(dest), newFileName);
46
+
47
+ fs.writeFileSync(newDest, content);
60
48
  }
49
+ }
50
+
51
+ // Start copying the template
52
+ fs.mkdirSync(destinationPath, { recursive: true });
53
+
54
+ fs.readdirSync(templatePath).forEach(item => {
55
+ copyAndRename(path.join(templatePath, item), path.join(destinationPath, item));
61
56
  });
62
57
 
63
- 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.14",
3
+ "version": "1.0.15",
4
4
  "description": "A custom .NET Core project blueprint",
5
5
  "main": "create.js",
6
6
  "bin": {