nextjs-starter-kit 0.1.7 → 0.1.9

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 +64 -63
  2. package/package.json +30 -3
package/bin/cli.js CHANGED
@@ -5,91 +5,92 @@ import path from "path";
5
5
  import { fileURLToPath } from "url";
6
6
  import ora from "ora";
7
7
  import chalk from "chalk";
8
- import readline from "readline";
8
+ import prompts from "prompts";
9
9
 
10
10
  const __filename = fileURLToPath(import.meta.url);
11
11
  const __dirname = path.dirname(__filename);
12
12
 
13
- const projectName = process.argv[2] || "my-app";
14
- const projectPath = path.resolve(process.cwd(), projectName);
15
-
16
13
  function runCommand(command, options = {}) {
17
14
  try {
18
- execSync(command, { stdio: "inherit", ...options });
19
- } catch (err) {
20
- console.error(chalk.red(`❌ Failed to run: ${command}`));
21
- process.exit(1);
15
+ return execSync(command, {
16
+ stdio: "pipe",
17
+ encoding: "utf-8",
18
+ ...options,
19
+ }).trim();
20
+ } catch {
21
+ return null;
22
22
  }
23
23
  }
24
24
 
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
25
  async function main() {
40
- // Check if project folder already exists
41
- if (existsSync(projectPath)) {
26
+ let projectName = process.argv[2];
27
+ if (!projectName) {
28
+ const response = await prompts({
29
+ type: "text",
30
+ name: "projectName",
31
+ message: "What is your project named?",
32
+ initial: "my-app",
33
+ });
34
+ projectName = response.projectName;
35
+ }
36
+
37
+ const projectPath = path.resolve(process.cwd(), projectName);
38
+ if (projectName !== "." && existsSync(projectPath)) {
42
39
  console.error(chalk.red(`❌ Folder "${projectName}" already exists.`));
43
40
  process.exit(1);
44
41
  }
45
42
 
46
- const spinner = ora(
47
- `Creating Next.js app in ${chalk.cyan(projectName)}...`
48
- ).start();
43
+ const { packageManager } = await prompts({
44
+ type: "select",
45
+ name: "packageManager",
46
+ message: "Which package manager would you like to use?",
47
+ choices: [
48
+ { title: "pnpm (recommended)", value: "pnpm" },
49
+ { title: "npm", value: "npm" },
50
+ { title: "yarn", value: "yarn" },
51
+ { title: "bun", value: "bun" },
52
+ ],
53
+ initial: 0,
54
+ });
55
+
56
+ console.log(`\nCreating a new Next.js app in ${chalk.cyan(projectPath)}.\n`);
57
+ console.log(`Using ${chalk.cyan(packageManager)}.\n`);
58
+ console.log(`Initializing project with template: app-tw\n`);
49
59
 
50
- // Create dir + copy template
51
- mkdirSync(projectPath);
60
+ if (projectName !== ".") mkdirSync(projectPath);
52
61
  const templateDir = path.join(__dirname, "../template");
53
62
  cpSync(templateDir, projectPath, { recursive: true });
54
63
 
55
- // Init git
56
- spinner.text = "Initializing Git repository...";
64
+ const spinner = ora("Initializing git repository...").start();
57
65
  runCommand("git init", { cwd: projectPath });
58
-
59
66
  spinner.stop();
67
+ console.log(chalk.green("Initialized a git repository.\n"));
60
68
 
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 });
69
+ console.log(chalk.cyan(`Installing dependencies...\n`));
70
+ try {
71
+ if (packageManager === "npm")
72
+ runCommand("npm install", { cwd: projectPath });
73
+ else if (packageManager === "pnpm")
74
+ runCommand("pnpm install", { cwd: projectPath });
75
+ else if (packageManager === "yarn")
76
+ runCommand("yarn install", { cwd: projectPath });
77
+ else if (packageManager === "bun")
78
+ runCommand("bun install", { cwd: projectPath });
79
+ } catch {
80
+ console.log(
81
+ chalk.yellow("\n⚠ Warning: Some build scripts were ignored.\n")
82
+ );
87
83
  }
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`);
84
+ console.log(
85
+ chalk.green(
86
+ `Done in ${chalk.cyan("~10s")} using ${chalk.cyan(packageManager)}.`
87
+ )
88
+ );
89
+ console.log(
90
+ chalk.green(
91
+ `\n✅ Success! Created ${projectName} at ${chalk.cyan(projectPath)}`
92
+ )
93
+ );
93
94
  }
94
95
 
95
96
  main();
package/package.json CHANGED
@@ -1,17 +1,44 @@
1
1
  {
2
2
  "name": "nextjs-starter-kit",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "bin": {
5
- "create-nextjs-starter": "bin/cli.js"
5
+ "create-nextjs-starter": "@/bin/cli.js"
6
6
  },
7
+ "keywords": [
8
+ "react",
9
+ "next",
10
+ "next.js"
11
+ ],
12
+ "description": "Create Next.js-powered React apps with one command",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/harshit-ostwal/nextjs-starter-kit.git"
16
+ },
17
+ "homepage": "https://github.com/harshit-ostwal/nextjs-starter-kit.git",
18
+ "author": "Harshit Ostwal <codewithharshitjain@gmail.com>",
7
19
  "type": "module",
20
+ "bugs": {
21
+ "url": "https://github.com/harshit-ostwal/nextjs-starter-kit.git"
22
+ },
23
+ "license": "MIT",
8
24
  "files": [
9
25
  "bin",
10
26
  "template"
11
27
  ],
12
28
  "dependencies": {
13
29
  "chalk": "^5.6.0",
30
+ "commander": "^14.0.0",
14
31
  "ora": "^8.2.0",
32
+ "prompts": "^2.4.2",
15
33
  "readline": "^1.3.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=18.17.0"
37
+ },
38
+ "nextBundleAnalysis": {
39
+ "budget": 358400,
40
+ "budgetPercentIncreaseRed": 20,
41
+ "minimumChangeThreshold": 0,
42
+ "showDetails": true
16
43
  }
17
- }
44
+ }