nextjs-starter-kit 0.1.6 → 0.1.8

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 +70 -32
  2. package/package.json +7 -2
package/bin/cli.js CHANGED
@@ -1,53 +1,91 @@
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 prompts from "prompts";
7
9
 
8
10
  const __filename = fileURLToPath(import.meta.url);
9
11
  const __dirname = path.dirname(__filename);
10
12
 
11
- const projectName = process.argv[2] || "my-app";
12
- const projectPath = path.resolve(process.cwd(), projectName);
13
-
14
13
  function runCommand(command, options = {}) {
15
14
  try {
16
15
  execSync(command, { stdio: "inherit", ...options });
17
- } catch (err) {
18
- console.error(`❌ Failed to run command: ${command}`);
16
+ } catch {
17
+ console.error(chalk.red(`❌ Failed to run: ${command}`));
19
18
  process.exit(1);
20
19
  }
21
20
  }
22
21
 
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);
29
- }
22
+ async function main() {
23
+ // Step 1: Ask for project name
24
+ const { projectName } = await prompts({
25
+ type: "text",
26
+ name: "projectName",
27
+ message: "What is your project named?",
28
+ initial: "my-app",
29
+ });
30
30
 
31
- if (existsSync(projectPath)) {
32
- console.error(`❌ Folder "${projectName}" already exists.`);
33
- process.exit(1);
34
- }
31
+ const projectPath = path.resolve(process.cwd(), projectName);
35
32
 
36
- console.log(`🚀 Creating Next.js app in "${projectName}"...`);
37
- mkdirSync(projectPath);
33
+ if (existsSync(projectPath)) {
34
+ console.error(chalk.red(`❌ Folder "${projectName}" already exists.`));
35
+ process.exit(1);
36
+ }
38
37
 
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
- }
38
+ // Step 2: Ask for package manager
39
+ const { packageManager } = await prompts({
40
+ type: "select",
41
+ name: "packageManager",
42
+ message: "Which package manager would you like to use?",
43
+ choices: [
44
+ { title: "pnpm (recommended)", value: "pnpm" },
45
+ { title: "npm", value: "npm" },
46
+ { title: "yarn", value: "yarn" },
47
+ { title: "bun", value: "bun" },
48
+ ],
49
+ initial: 0,
50
+ });
51
+
52
+ // Step 3: Start spinner
53
+ const spinner = ora(
54
+ `Creating Next.js app in ${chalk.cyan(projectName)}...`
55
+ ).start();
45
56
 
46
- runCommand("git init", { cwd: projectPath });
57
+ mkdirSync(projectPath);
47
58
 
48
- console.log("📦 Installing dependencies...");
49
- runCommand("pnpm install --shamefully-hoist", { cwd: projectPath });
59
+ // Copy template files (keeps empty folders too)
60
+ const templateDir = path.join(__dirname, "../template");
61
+ cpSync(templateDir, projectPath, { recursive: true });
62
+
63
+ // Init git
64
+ spinner.text = "Initializing Git repository...";
65
+ runCommand("git init", { cwd: projectPath });
66
+
67
+ spinner.stop();
68
+
69
+ // Step 4: Install dependencies
70
+ console.log(
71
+ chalk.cyan(`📦 Installing dependencies with ${packageManager}...`)
72
+ );
73
+
74
+ if (packageManager === "npm") {
75
+ runCommand("npm install", { cwd: projectPath });
76
+ } else if (packageManager === "pnpm") {
77
+ runCommand("pnpm install", { cwd: projectPath });
78
+ } else if (packageManager === "yarn") {
79
+ runCommand("yarn install", { cwd: projectPath });
80
+ } else if (packageManager === "bun") {
81
+ runCommand("bun install", { cwd: projectPath });
82
+ }
83
+
84
+ // Step 5: Success
85
+ console.log(chalk.green("\n✅ Success!"));
86
+ console.log(`\nNext steps:\n`);
87
+ console.log(` ${chalk.cyan("cd")} ${projectName}`);
88
+ console.log(` ${chalk.cyan(`${packageManager} dev`)}\n`);
89
+ }
50
90
 
51
- console.log(`\n✅ All done!`);
52
- console.log(`👉 cd ${projectName}`);
53
- console.log(`👉 pnpm dev (or npm run dev)\n`);
91
+ 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.8",
4
4
  "bin": {
5
5
  "create-nextjs-starter": "bin/cli.js"
6
6
  },
@@ -9,5 +9,10 @@
9
9
  "bin",
10
10
  "template"
11
11
  ],
12
- "dependencies": {}
12
+ "dependencies": {
13
+ "chalk": "^5.6.0",
14
+ "ora": "^8.2.0",
15
+ "prompts": "^2.4.2",
16
+ "readline": "^1.3.0"
17
+ }
13
18
  }