@presencenet/create-pnet-stack 0.2.2 → 0.3.0

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.
@@ -14,6 +14,7 @@ import { createInterface } from "node:readline/promises";
14
14
  import { fileURLToPath } from "node:url";
15
15
 
16
16
  const templates = ["web", "mobile", "electron", "tauri"];
17
+ const packageManagers = ["npm", "pnpm", "yarn", "bun"];
17
18
  const templateNames = {
18
19
  web: "TanStack Start",
19
20
  mobile: "React Native (Expo)",
@@ -21,34 +22,96 @@ const templateNames = {
21
22
  tauri: "Tauri",
22
23
  };
23
24
  const cliDir = dirname(dirname(fileURLToPath(import.meta.url)));
25
+ const color = stdout.isTTY && !process.env.NO_COLOR;
26
+ const paint = (code, value) =>
27
+ color ? `\u001b[${code}m${value}\u001b[0m` : value;
28
+ const cyan = (value) => paint("36", value);
29
+ const dim = (value) => paint("2", value);
30
+ const green = (value) => paint("32", value);
24
31
 
25
32
  async function main() {
26
33
  const args = process.argv.slice(2);
27
34
  if (args.includes("--help") || args.includes("-h")) {
28
35
  stdout.write(
29
- "Usage: npx @presencenet/create-pnet-stack [project-name] [--template web|mobile|electron|tauri]\n",
36
+ "Usage: npx @presencenet/create-pnet-stack [project-name] [--template web|mobile|electron|tauri] [--package-manager npm|pnpm|yarn|bun]\n",
30
37
  );
31
38
  return;
32
39
  }
33
- let projectName = args.find((arg) => !arg.startsWith("--"));
34
- let template = args
35
- .find((arg) => arg.startsWith("--template="))
36
- ?.split("=")[1];
37
- if (!template && args.includes("--template"))
38
- template = args[args.indexOf("--template") + 1];
40
+ let projectName;
41
+ let template;
42
+ let packageManager;
43
+ for (let i = 0; i < args.length; i++) {
44
+ const arg = args[i];
45
+ if (arg === "--template") {
46
+ if (!args[i + 1] || args[i + 1].startsWith("--"))
47
+ throw new Error("--template requires a value.");
48
+ template = args[++i];
49
+ } else if (arg.startsWith("--template=")) template = arg.slice(11);
50
+ else if (arg === "--package-manager") {
51
+ if (!args[i + 1] || args[i + 1].startsWith("--"))
52
+ throw new Error("--package-manager requires a value.");
53
+ packageManager = args[++i];
54
+ } else if (arg.startsWith("--package-manager=")) {
55
+ packageManager = arg.slice(18);
56
+ if (!packageManager)
57
+ throw new Error("--package-manager requires a value.");
58
+ } else if (!arg.startsWith("--") && !projectName) projectName = arg;
59
+ }
60
+ if (packageManager && !packageManagers.includes(packageManager))
61
+ throw new Error("Choose npm, pnpm, yarn, or bun.");
39
62
 
40
- const rl = createInterface({ input: stdin, output: stdout });
41
- if (!projectName) projectName = (await rl.question("Project name: ")).trim();
42
- while (!templates.includes(template)) {
63
+ if (!projectName || !templates.includes(template)) {
43
64
  stdout.write(
44
- `\nChoose a starter: ${templates.map((item, i) => `${i + 1}) ${templateNames[item]}`).join(" ")}\n`,
65
+ `\n${cyan("◆")} ${paint("1", "create-pnet-stack")} ${dim("·")} Create a new project\n\n`,
45
66
  );
46
- const answer = (await rl.question("Starter [1]: ")).trim() || "1";
47
- template = templates[Number(answer) - 1] ?? answer;
48
- if (!templates.includes(template))
49
- stdout.write("Choose web, mobile, electron, or tauri.\n");
67
+ const rl = createInterface({ input: stdin, output: stdout });
68
+ if (!projectName)
69
+ projectName = (
70
+ await rl.question(`${dim("Project name")} ${dim("›")} `)
71
+ ).trim();
72
+ if (!templates.includes(template)) {
73
+ stdout.write(`\n${dim("Choose a starter")}\n`);
74
+ templates.forEach((item, i) => {
75
+ stdout.write(
76
+ ` ${dim(`${i + 1}`)} ${templateNames[item]}${i === 0 ? dim(" recommended") : ""}\n`,
77
+ );
78
+ });
79
+ while (!templates.includes(template)) {
80
+ const answer =
81
+ (
82
+ await rl.question(`\n${dim("Starter")} ${dim("[1]")} ${dim("›")} `)
83
+ ).trim() || "1";
84
+ template = templates[Number(answer) - 1] ?? answer;
85
+ if (!templates.includes(template))
86
+ stdout.write(
87
+ `${paint("31", "×")} Choose 1–4, or enter web, mobile, electron, or tauri.\n`,
88
+ );
89
+ }
90
+ }
91
+ if (!packageManagers.includes(packageManager)) {
92
+ stdout.write(`\n${dim("Choose a package manager")}\n`);
93
+ packageManagers.forEach((item, i) => {
94
+ stdout.write(
95
+ ` ${dim(`${i + 1}`)} ${item}${item === "bun" ? dim(" recommended") : ""}\n`,
96
+ );
97
+ });
98
+ while (!packageManagers.includes(packageManager)) {
99
+ const answer =
100
+ (
101
+ await rl.question(
102
+ `\n${dim("Package manager")} ${dim("[4]")} ${dim("›")} `,
103
+ )
104
+ ).trim() || "4";
105
+ packageManager = packageManagers[Number(answer) - 1] ?? answer;
106
+ if (!packageManagers.includes(packageManager))
107
+ stdout.write(`${paint("31", "×")} Choose npm, pnpm, yarn, or bun.\n`);
108
+ }
109
+ }
110
+ rl.close();
50
111
  }
51
- rl.close();
112
+ if (!packageManager) packageManager = "bun";
113
+ if (!packageManagers.includes(packageManager))
114
+ throw new Error("Choose npm, pnpm, yarn, or bun.");
52
115
 
53
116
  if (!projectName || !/^[a-z0-9][a-z0-9-]*$/.test(projectName))
54
117
  throw new Error(
@@ -73,12 +136,17 @@ async function main() {
73
136
  await replaceTokens(target, {
74
137
  "{{projectName}}": projectName,
75
138
  "{{projectNameRust}}": rustName,
139
+ "bun run": `${packageManager} run`,
76
140
  '"root": false': '"root": true',
77
141
  });
78
142
  execFileSync("git", ["init"], { cwd: target, stdio: "ignore" });
79
- stdout.write(`\nCreated ${projectName} (${templateNames[template]}).\n`);
80
- stdout.write("Initialized Git repository.\n");
81
- stdout.write(`\n cd ${projectName}\n bun install\n bun run dev\n`);
143
+ stdout.write(
144
+ `\n${green("✓")} Created ${paint("1", projectName)} ${dim(`(${templateNames[template]})`)}\n`,
145
+ );
146
+ stdout.write(`${green("✓")} Initialized Git repository\n`);
147
+ stdout.write(
148
+ `\n${dim("Next steps")}\n ${cyan(`cd ${projectName}`)}\n ${cyan(packageManager === "npm" ? "npm install" : `${packageManager} install`)}\n ${cyan(`${packageManager} run dev`)}\n`,
149
+ );
82
150
  if (template === "tauri")
83
151
  stdout.write(
84
152
  "\nTauri also requires the platform prerequisites: https://tauri.app/start/prerequisites/\n",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@presencenet/create-pnet-stack",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Create a Bun and Turborepo app with pnet-stack",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "{{projectName}}",
3
3
  "private": true,
4
- "packageManager": "bun@1.3.14",
5
4
  "workspaces": [
6
5
  "apps/*",
7
6
  "packages/*"
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "{{projectName}}",
3
3
  "private": true,
4
- "packageManager": "bun@1.3.14",
5
4
  "workspaces": [
6
5
  "apps/*",
7
6
  "packages/*"
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "{{projectName}}",
3
3
  "private": true,
4
- "packageManager": "bun@1.3.14",
5
4
  "workspaces": [
6
5
  "apps/*",
7
6
  "packages/*"
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "{{projectName}}",
3
3
  "private": true,
4
- "packageManager": "bun@1.3.14",
5
4
  "workspaces": [
6
5
  "apps/*",
7
6
  "packages/*"