nextjs-starter-kit 0.1.7 → 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.
- package/bin/cli.js +38 -42
- package/package.json +2 -1
package/bin/cli.js
CHANGED
|
@@ -5,50 +5,58 @@ import path from "path";
|
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
6
|
import ora from "ora";
|
|
7
7
|
import chalk from "chalk";
|
|
8
|
-
import
|
|
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
15
|
execSync(command, { stdio: "inherit", ...options });
|
|
19
|
-
} catch
|
|
16
|
+
} catch {
|
|
20
17
|
console.error(chalk.red(`❌ Failed to run: ${command}`));
|
|
21
18
|
process.exit(1);
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
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",
|
|
30
29
|
});
|
|
31
|
-
return new Promise((resolve) =>
|
|
32
|
-
rl.question(query, (ans) => {
|
|
33
|
-
rl.close();
|
|
34
|
-
resolve(ans.trim());
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
const projectPath = path.resolve(process.cwd(), projectName);
|
|
32
|
+
|
|
41
33
|
if (existsSync(projectPath)) {
|
|
42
34
|
console.error(chalk.red(`❌ Folder "${projectName}" already exists.`));
|
|
43
35
|
process.exit(1);
|
|
44
36
|
}
|
|
45
37
|
|
|
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
|
|
46
53
|
const spinner = ora(
|
|
47
54
|
`Creating Next.js app in ${chalk.cyan(projectName)}...`
|
|
48
55
|
).start();
|
|
49
56
|
|
|
50
|
-
// Create dir + copy template
|
|
51
57
|
mkdirSync(projectPath);
|
|
58
|
+
|
|
59
|
+
// Copy template files (keeps empty folders too)
|
|
52
60
|
const templateDir = path.join(__dirname, "../template");
|
|
53
61
|
cpSync(templateDir, projectPath, { recursive: true });
|
|
54
62
|
|
|
@@ -58,38 +66,26 @@ async function main() {
|
|
|
58
66
|
|
|
59
67
|
spinner.stop();
|
|
60
68
|
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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}...`));
|
|
69
|
+
// Step 4: Install dependencies
|
|
70
|
+
console.log(
|
|
71
|
+
chalk.cyan(`📦 Installing dependencies with ${packageManager}...`)
|
|
72
|
+
);
|
|
77
73
|
|
|
78
|
-
|
|
79
|
-
if (pm === "npm") {
|
|
74
|
+
if (packageManager === "npm") {
|
|
80
75
|
runCommand("npm install", { cwd: projectPath });
|
|
81
|
-
} else if (
|
|
76
|
+
} else if (packageManager === "pnpm") {
|
|
82
77
|
runCommand("pnpm install", { cwd: projectPath });
|
|
83
|
-
} else if (
|
|
78
|
+
} else if (packageManager === "yarn") {
|
|
84
79
|
runCommand("yarn install", { cwd: projectPath });
|
|
85
|
-
} else if (
|
|
80
|
+
} else if (packageManager === "bun") {
|
|
86
81
|
runCommand("bun install", { cwd: projectPath });
|
|
87
82
|
}
|
|
88
83
|
|
|
84
|
+
// Step 5: Success
|
|
89
85
|
console.log(chalk.green("\n✅ Success!"));
|
|
90
86
|
console.log(`\nNext steps:\n`);
|
|
91
87
|
console.log(` ${chalk.cyan("cd")} ${projectName}`);
|
|
92
|
-
console.log(` ${chalk.cyan(`${
|
|
88
|
+
console.log(` ${chalk.cyan(`${packageManager} dev`)}\n`);
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-starter-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"bin": {
|
|
5
5
|
"create-nextjs-starter": "bin/cli.js"
|
|
6
6
|
},
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"chalk": "^5.6.0",
|
|
14
14
|
"ora": "^8.2.0",
|
|
15
|
+
"prompts": "^2.4.2",
|
|
15
16
|
"readline": "^1.3.0"
|
|
16
17
|
}
|
|
17
18
|
}
|