netcore-blueprint 0.0.8 → 0.0.9
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.
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const projectName = process.argv[2];
|
|
8
|
+
if (!projectName) {
|
|
9
|
+
console.error("❌ Please specify the project name.");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const templatePath = path.join(__dirname, "BlueprintTemplate");
|
|
14
|
+
const destinationPath = path.join(process.cwd(), projectName);
|
|
15
|
+
|
|
16
|
+
if (fs.existsSync(destinationPath)) {
|
|
17
|
+
console.error(`❌ Project directory "${projectName}" already exists.`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
copyDirectory(templatePath, destinationPath);
|
|
22
|
+
|
|
23
|
+
console.log(`🎉 Project "${projectName}" created successfully!`);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
process.chdir(destinationPath);
|
|
27
|
+
execSync('git init', { stdio: 'inherit' });
|
|
28
|
+
execSync('git add .', { stdio: 'inherit' });
|
|
29
|
+
execSync('git commit -m "Initial commit from blueprint"', { stdio: 'inherit' });
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error("⚠️ Git init failed:", err.message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function copyDirectory(src, dest) {
|
|
35
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
36
|
+
|
|
37
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
38
|
+
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
const srcPath = path.join(src, entry.name);
|
|
41
|
+
const destPath = path.join(dest, entry.name);
|
|
42
|
+
|
|
43
|
+
if (entry.isDirectory()) {
|
|
44
|
+
copyDirectory(srcPath, destPath);
|
|
45
|
+
} else {
|
|
46
|
+
fs.copyFileSync(srcPath, destPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const newModuleName = process.argv[2];
|
|
7
|
+
if (!newModuleName) {
|
|
8
|
+
console.error("❌ Please specify the module name. Example: create-module UserModule");
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const sourceModuleName = "ItemModule";
|
|
13
|
+
|
|
14
|
+
const sourcePath = path.join(process.cwd(), "Modules", sourceModuleName);
|
|
15
|
+
const destinationPath = path.join(process.cwd(), "Modules", newModuleName);
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(sourcePath)) {
|
|
18
|
+
console.error(`❌ Source module not found: ${sourcePath}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (fs.existsSync(destinationPath)) {
|
|
23
|
+
console.error(`❌ Destination module already exists: ${destinationPath}`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
copyAndRenameFiles(sourcePath, destinationPath, sourceModuleName, newModuleName);
|
|
28
|
+
|
|
29
|
+
console.log(`🎉 Module "${newModuleName}" created successfully!`);
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// ===== CORE LOGIC (reuse from old script) =====
|
|
33
|
+
|
|
34
|
+
function copyAndRenameFiles(src, dest, oldName, newName) {
|
|
35
|
+
if (fs.lstatSync(src).isDirectory()) {
|
|
36
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
37
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
38
|
+
|
|
39
|
+
for (let entry of entries) {
|
|
40
|
+
const srcPath = path.join(src, entry.name);
|
|
41
|
+
const destName = entry.name.replace(new RegExp(oldName, 'g'), newName);
|
|
42
|
+
const destPath = path.join(dest, destName);
|
|
43
|
+
|
|
44
|
+
copyAndRenameFiles(srcPath, destPath, oldName, newName);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
let content = fs.readFileSync(src, 'utf8');
|
|
48
|
+
|
|
49
|
+
// Replace namespace + class + references
|
|
50
|
+
content = content.replace(new RegExp(oldName, 'g'), newName);
|
|
51
|
+
|
|
52
|
+
fs.writeFileSync(dest, content, 'utf8');
|
|
53
|
+
}
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netcore-blueprint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A custom project blueprint",
|
|
5
5
|
"main": "create.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"
|
|
7
|
+
"create-app": "./bin/create-app.js",
|
|
8
|
+
"create-module": "./bin/create-module.js"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/create.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { execSync } = require('child_process'); // ✅ Fix: Import execSync
|
|
6
|
-
|
|
7
|
-
// Get the project name from command-line arguments
|
|
8
|
-
const projectName = process.argv[2];
|
|
9
|
-
if (!projectName) {
|
|
10
|
-
console.error("❌ Please specify the project name.");
|
|
11
|
-
process.exit(1);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const templatePath = path.join(__dirname, "BlueprintTemplate"); // Copy from BlueprintTemplate
|
|
15
|
-
const destinationPath = path.join(process.cwd(), projectName);
|
|
16
|
-
|
|
17
|
-
// Function to copy and rename files
|
|
18
|
-
function copyAndRenameFiles(src, dest, oldName, newName) {
|
|
19
|
-
if (fs.lstatSync(src).isDirectory()) {
|
|
20
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
21
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
22
|
-
|
|
23
|
-
for (let entry of entries) {
|
|
24
|
-
let srcPath = path.join(src, entry.name);
|
|
25
|
-
let destPath = path.join(dest, entry.name.replace(new RegExp(oldName, 'g'), newName));
|
|
26
|
-
copyAndRenameFiles(srcPath, destPath, oldName, newName);
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
let content = fs.readFileSync(src, 'utf8');
|
|
30
|
-
content = content.replace(new RegExp(oldName, 'g'), newName); // Replace occurrences of netcore-blueprint
|
|
31
|
-
fs.writeFileSync(dest, content, 'utf8');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Ensure the destination folder doesn't already exist
|
|
36
|
-
if (fs.existsSync(destinationPath)) {
|
|
37
|
-
console.error(`❌ Project directory "${projectName}" already exists.`);
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fs.mkdirSync(destinationPath, { recursive: true });
|
|
42
|
-
|
|
43
|
-
// Copy and rename all files
|
|
44
|
-
fs.readdirSync(templatePath).forEach(item => {
|
|
45
|
-
const srcPath = path.join(templatePath, item);
|
|
46
|
-
let destPath = path.join(destinationPath, item.replace(/netcore-blueprint/g, projectName));
|
|
47
|
-
|
|
48
|
-
if (item === "gitignore") {
|
|
49
|
-
destPath = path.join(destinationPath, ".gitignore"); // Rename gitignore
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
console.log(`✅ Copying and renaming ${item}...`);
|
|
53
|
-
copyAndRenameFiles(srcPath, destPath, "netcore-blueprint", projectName);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
console.log(`🎉 Project "${projectName}" created successfully at ${destinationPath}`);
|
|
57
|
-
console.log(`📌 Open "${projectName}.sln" in Visual Studio to get started!`);
|
|
58
|
-
|
|
59
|
-
// Initialize Git and commit the first commit
|
|
60
|
-
try {
|
|
61
|
-
process.chdir(destinationPath); // Move into project directory
|
|
62
|
-
|
|
63
|
-
console.log("🚀 Initializing Git repository...");
|
|
64
|
-
execSync('git init', { stdio: 'inherit' });
|
|
65
|
-
|
|
66
|
-
console.log("📂 Adding all files...");
|
|
67
|
-
execSync('git add .', { stdio: 'inherit' });
|
|
68
|
-
|
|
69
|
-
console.log("✅ Creating first commit...");
|
|
70
|
-
execSync('git commit -m "Initial commit from blueprint"', { stdio: 'inherit' });
|
|
71
|
-
|
|
72
|
-
console.log("🎉 Git repository initialized successfully!");
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error("❌ Failed to initialize Git:", error);
|
|
75
|
-
}
|