nextjs-starter-kit 0.1.6 → 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 +69 -27
  2. package/package.json +6 -2
package/bin/cli.js CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { execSync } from "child_process";
3
- import { existsSync, mkdirSync } from "fs";
3
+ import { existsSync, mkdirSync, cpSync } from "fs";
4
4
  import path from "path";
5
5
  import { fileURLToPath } from "url";
6
- import os from "os";
6
+ import ora from "ora";
7
+ import chalk from "chalk";
8
+ import readline from "readline";
7
9
 
8
10
  const __filename = fileURLToPath(import.meta.url);
9
11
  const __dirname = path.dirname(__filename);
@@ -15,39 +17,79 @@ function runCommand(command, options = {}) {
15
17
  try {
16
18
  execSync(command, { stdio: "inherit", ...options });
17
19
  } catch (err) {
18
- console.error(`❌ Failed to run command: ${command}`);
20
+ console.error(chalk.red(`❌ Failed to run: ${command}`));
19
21
  process.exit(1);
20
22
  }
21
23
  }
22
24
 
23
- try {
24
- execSync("pnpm -v", { stdio: "ignore" });
25
- } catch {
26
- console.error("❌ pnpm is not installed. Please install it first:");
27
- console.error(" npm install -g pnpm");
28
- process.exit(1);
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
+ );
29
37
  }
30
38
 
31
- if (existsSync(projectPath)) {
32
- console.error(`❌ Folder "${projectName}" already exists.`);
33
- process.exit(1);
34
- }
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
+ }
35
45
 
36
- console.log(`🚀 Creating Next.js app in "${projectName}"...`);
37
- mkdirSync(projectPath);
46
+ const spinner = ora(
47
+ `Creating Next.js app in ${chalk.cyan(projectName)}...`
48
+ ).start();
38
49
 
39
- const templateDir = path.join(__dirname, "../template");
40
- if (os.platform() === "win32") {
41
- runCommand(`xcopy "${templateDir}" "${projectPath}" /E /I /Q`);
42
- } else {
43
- runCommand(`cp -r ${templateDir}/. ${projectPath}`);
44
- }
50
+ // Create dir + copy template
51
+ mkdirSync(projectPath);
52
+ const templateDir = path.join(__dirname, "../template");
53
+ cpSync(templateDir, projectPath, { recursive: true });
45
54
 
46
- runCommand("git init", { cwd: projectPath });
55
+ // Init git
56
+ spinner.text = "Initializing Git repository...";
57
+ runCommand("git init", { cwd: projectPath });
47
58
 
48
- console.log("📦 Installing dependencies...");
49
- runCommand("pnpm install --shamefully-hoist", { cwd: projectPath });
59
+ spinner.stop();
60
+
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();
69
+
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
+ }
50
94
 
51
- console.log(`\n✅ All done!`);
52
- console.log(`👉 cd ${projectName}`);
53
- console.log(`👉 pnpm dev (or npm run dev)\n`);
95
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextjs-starter-kit",
3
- "version": "0.1.6",
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
  }