@thebros/create-benjamin 1.0.14 → 1.0.16

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/bin/index.js +49 -18
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -7,13 +7,21 @@ import inquirer from "inquirer";
7
7
  import ora from "ora";
8
8
  import degit from "degit";
9
9
 
10
- async function cloneRepo(repo, target) {
10
+ async function cloneTemplate(repo, target) {
11
11
  const emitter = degit(repo, {
12
12
  cache: false,
13
13
  force: true,
14
+ verbose: true,
14
15
  });
15
16
 
16
- await emitter.clone(target);
17
+ try {
18
+ await emitter.clone(target);
19
+ } catch (err) {
20
+ console.log("\nāŒ Failed to clone template:");
21
+ console.log("šŸ‘‰ Make sure this is a VALID template repo");
22
+ console.log("šŸ‘‰ Example: username/repo (NOT expressjs/express)\n");
23
+ throw err;
24
+ }
17
25
  }
18
26
 
19
27
  async function main() {
@@ -31,9 +39,9 @@ async function main() {
31
39
  name: "type",
32
40
  message: "Project type:",
33
41
  choices: [
34
- "Full Stack (React + Node)",
35
42
  "Frontend (React)",
36
43
  "Backend (Express)",
44
+ "Full Stack",
37
45
  ],
38
46
  },
39
47
  ]);
@@ -47,26 +55,49 @@ async function main() {
47
55
 
48
56
  await fs.mkdir(root);
49
57
 
50
- const spinner = ora("Fetching templates from internet...").start();
58
+ const spinner = ora("Downloading templates...").start();
51
59
 
52
60
  // =========================
53
- // FRONTEND
61
+ // IMPORTANT FIX:
62
+ // Use SAFE TEMPLATE REPOS ONLY
54
63
  // =========================
55
- if (
56
- answers.type.includes("Frontend") ||
57
- answers.type.includes("Full")
58
- ) {
59
- await cloneRepo("vitejs/vite", path.join(root, "frontend"));
64
+
65
+ if (answers.type === "Frontend (React)") {
66
+ await cloneTemplate(
67
+ "vitejs/vite-template-react",
68
+ path.join(root, "frontend")
69
+ );
60
70
  }
61
71
 
62
- // =========================
63
- // BACKEND
64
- // =========================
65
- if (
66
- answers.type.includes("Backend") ||
67
- answers.type.includes("Full")
68
- ) {
69
- await cloneRepo("expressjs/express", path.join(root, "backend"));
72
+ if (answers.type === "Backend (Express)") {
73
+ await fs.mkdir(path.join(root, "backend"));
74
+
75
+ await fs.writeFile(
76
+ path.join(root, "backend", "server.js"),
77
+ `
78
+ const express = require("express");
79
+ const app = express();
80
+
81
+ app.get("/", (req, res) => {
82
+ res.json({ message: "API Running" });
83
+ });
84
+
85
+ app.listen(5000, () => {
86
+ console.log("Server running on port 5000");
87
+ });
88
+ `
89
+ );
90
+ }
91
+
92
+ if (answers.type === "Full Stack") {
93
+ // Frontend (safe template)
94
+ await cloneTemplate(
95
+ "vitejs/vite-template-react",
96
+ path.join(root, "frontend")
97
+ );
98
+
99
+ // Backend
100
+ await fs.mkdir(path.join(root, "backend"));
70
101
 
71
102
  await fs.writeFile(
72
103
  path.join(root, "backend", "server.js"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thebros/create-benjamin",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "create-benjamin": "./bin/index.js"