init-blueprint 0.0.2

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,12 @@
1
+ image: node:20
2
+
3
+ stages:
4
+ - publish
5
+
6
+ publish:
7
+ stage: publish
8
+ script:
9
+ - npm config set //registry.npmjs.org/:_authToken=${NPM_TOKEN}
10
+ - npm publish --access public
11
+ only:
12
+ - main
@@ -0,0 +1,18 @@
1
+ How to make a blueprint (Ex: python-blueprint)
2
+ 1. Change the name of the blueprint project in package.json file:
3
+ Ex: "name": "python-blueprint",
4
+ 2. Copy the template into BlueprintTemplate. The template include:
5
+ - Basic files
6
+ - Add git
7
+ - Add gitignore file and change it from .gitignore=> gitignore file
8
+ 3. Add git to the blueprint, and change the root branch from master to main
9
+ - git branch -m master main
10
+ 4. Create new repo in git
11
+ - Add environment variables into the git repo: Project > Settings > CI/CD > Variables
12
+ + NPM_TOKEN: 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
13
+ + PACKAGE_NAME: python-blueprint
14
+ - push the blueprint to main branch
15
+ 5. Use the lib from npm:
16
+ - npm install -g python-blueprint
17
+ - npm list -g python-blueprint
18
+ - python-blueprint thmoney
@@ -0,0 +1,75 @@
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 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(/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, "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
+ }
File without changes
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "blueprint",
3
+ "version": "0.0.0",
4
+ "description": "A custom project blueprint",
5
+ "main": "create.js",
6
+ "bin": {
7
+ "blueprint": "./create.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": ["blueprint", "starter-template"],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "files": [
16
+ "BlueprintTemplate/**"
17
+ ]
18
+ }
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ How to make a blueprint (Ex: python-blueprint)
2
+ 1. Change the name of the blueprint project in package.json file:
3
+ Ex: "name": "python-blueprint",
4
+ 2. Copy the template into BlueprintTemplate. The template include:
5
+ - Basic files
6
+ - Add git
7
+ - Add gitignore file and change it from .gitignore=> gitignore file
8
+ 3. Add git to the blueprint, and change the root branch from master to main
9
+ - git branch -m master main
10
+ 4. Create new repo in git
11
+ - Add environment variables into the git repo: Project > Settings > CI/CD > Variables
12
+ + NPM_TOKEN: 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
13
+ + PACKAGE_NAME: python-blueprint
14
+ - push the blueprint to main branch
15
+ 5. Use the lib from npm:
16
+ - npm uninstall -g python-blueprint
17
+ - npm install -g python-blueprint
18
+ - npm list -g python-blueprint
19
+ - python-blueprint thmoney
package/create.js ADDED
@@ -0,0 +1,92 @@
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 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(/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, "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
+ // Update package.json
60
+ const packageJsonPath = path.join(destinationPath, 'package.json');
61
+ if (fs.existsSync(packageJsonPath)) {
62
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
63
+ pkg.name = projectName;
64
+ pkg.bin = {
65
+ [projectName]: './create.js'
66
+ };
67
+ fs.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2), 'utf8');
68
+ console.log("📦 Updated package.json with project name.");
69
+ }
70
+
71
+ // Create an empty BlueprintTemplate folder
72
+ const internalBlueprintPath = path.join(destinationPath, 'BlueprintTemplate');
73
+ fs.mkdirSync(internalBlueprintPath, { recursive: true });
74
+ console.log(`📁 Created empty folder: ${internalBlueprintPath}`);
75
+
76
+ // Initialize Git and commit the first commit
77
+ try {
78
+ process.chdir(destinationPath); // Move into project directory
79
+
80
+ console.log("🚀 Initializing Git repository...");
81
+ execSync('git init', { stdio: 'inherit' });
82
+
83
+ console.log("📂 Adding all files...");
84
+ execSync('git add .', { stdio: 'inherit' });
85
+
86
+ console.log("✅ Creating first commit...");
87
+ execSync('git commit -m "Initial commit from blueprint"', { stdio: 'inherit' });
88
+
89
+ console.log("🎉 Git repository initialized successfully!");
90
+ } catch (error) {
91
+ console.error("❌ Failed to initialize Git:", error);
92
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "init-blueprint",
3
+ "version": "0.0.2",
4
+ "description": "A custom project blueprint",
5
+ "main": "create.js",
6
+ "bin": {
7
+ "init-blueprint": "create.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [
13
+ "blueprint",
14
+ "starter-template"
15
+ ],
16
+ "author": "",
17
+ "license": "ISC",
18
+ "files": [
19
+ "BlueprintTemplate/**"
20
+ ]
21
+ }