nextjs-starter-kit 0.1.5 → 0.1.7

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/cli.js +78 -15
  2. package/package.json +6 -2
package/bin/cli.js CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { execSync } from "child_process";
3
- import { existsSync, mkdirSync, writeFileSync, copyFileSync } from "fs";
3
+ import { existsSync, mkdirSync, cpSync } from "fs";
4
4
  import path from "path";
5
5
  import { fileURLToPath } from "url";
6
+ import ora from "ora";
7
+ import chalk from "chalk";
8
+ import readline from "readline";
6
9
 
7
10
  const __filename = fileURLToPath(import.meta.url);
8
11
  const __dirname = path.dirname(__filename);
@@ -10,23 +13,83 @@ const __dirname = path.dirname(__filename);
10
13
  const projectName = process.argv[2] || "my-app";
11
14
  const projectPath = path.resolve(process.cwd(), projectName);
12
15
 
13
- if (existsSync(projectPath)) {
14
- console.error(`❌ Folder "${projectName}" already exists.`);
15
- process.exit(1);
16
+ function runCommand(command, options = {}) {
17
+ try {
18
+ execSync(command, { stdio: "inherit", ...options });
19
+ } catch (err) {
20
+ console.error(chalk.red(`❌ Failed to run: ${command}`));
21
+ process.exit(1);
22
+ }
16
23
  }
17
24
 
18
- console.log(`🚀 Creating Next.js app in "${projectName}"...`);
19
- mkdirSync(projectPath);
25
+ // Ask user a question (sync-like prompt)
26
+ function askQuestion(query) {
27
+ const rl = readline.createInterface({
28
+ input: process.stdin,
29
+ output: process.stdout,
30
+ });
31
+ return new Promise((resolve) =>
32
+ rl.question(query, (ans) => {
33
+ rl.close();
34
+ resolve(ans.trim());
35
+ })
36
+ );
37
+ }
38
+
39
+ async function main() {
40
+ // Check if project folder already exists
41
+ if (existsSync(projectPath)) {
42
+ console.error(chalk.red(`❌ Folder "${projectName}" already exists.`));
43
+ process.exit(1);
44
+ }
45
+
46
+ const spinner = ora(
47
+ `Creating Next.js app in ${chalk.cyan(projectName)}...`
48
+ ).start();
49
+
50
+ // Create dir + copy template
51
+ mkdirSync(projectPath);
52
+ const templateDir = path.join(__dirname, "../template");
53
+ cpSync(templateDir, projectPath, { recursive: true });
54
+
55
+ // Init git
56
+ spinner.text = "Initializing Git repository...";
57
+ runCommand("git init", { cwd: projectPath });
20
58
 
21
- // Copy template files
22
- const templateDir = path.join(__dirname, "../template");
23
- execSync(`cp -r ${templateDir}/* ${projectPath}`);
59
+ spinner.stop();
24
60
 
25
- // Init git
26
- execSync("git init", { cwd: projectPath, stdio: "inherit" });
61
+ // Ask for package manager
62
+ const pm = (
63
+ await askQuestion(
64
+ chalk.yellow(
65
+ "👉 Which package manager do you want to use? (npm / pnpm / yarn / bun): "
66
+ )
67
+ )
68
+ ).toLowerCase();
27
69
 
28
- // Install deps
29
- console.log("📦 Installing dependencies...");
30
- execSync("npm install", { cwd: projectPath, stdio: "inherit" });
70
+ const validPMs = ["npm", "pnpm", "yarn", "bun"];
71
+ if (!validPMs.includes(pm)) {
72
+ console.error(chalk.red(`❌ Invalid choice: ${pm}`));
73
+ process.exit(1);
74
+ }
75
+
76
+ console.log(chalk.cyan(`📦 Installing dependencies with ${pm}...`));
77
+
78
+ // Run correct install
79
+ if (pm === "npm") {
80
+ runCommand("npm install", { cwd: projectPath });
81
+ } else if (pm === "pnpm") {
82
+ runCommand("pnpm install", { cwd: projectPath });
83
+ } else if (pm === "yarn") {
84
+ runCommand("yarn install", { cwd: projectPath });
85
+ } else if (pm === "bun") {
86
+ runCommand("bun install", { cwd: projectPath });
87
+ }
88
+
89
+ console.log(chalk.green("\n✅ Success!"));
90
+ console.log(`\nNext steps:\n`);
91
+ console.log(` ${chalk.cyan("cd")} ${projectName}`);
92
+ console.log(` ${chalk.cyan(`${pm} dev`)}\n`);
93
+ }
31
94
 
32
- console.log(`✅ Done! cd ${projectName} && npm run dev`);
95
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextjs-starter-kit",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "bin": {
5
5
  "create-nextjs-starter": "bin/cli.js"
6
6
  },
@@ -9,5 +9,9 @@
9
9
  "bin",
10
10
  "template"
11
11
  ],
12
- "dependencies": {}
12
+ "dependencies": {
13
+ "chalk": "^5.6.0",
14
+ "ora": "^8.2.0",
15
+ "readline": "^1.3.0"
16
+ }
13
17
  }