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.
- package/bin/cli.js +69 -27
- 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
|
|
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
|
|
20
|
+
console.error(chalk.red(`❌ Failed to run: ${command}`));
|
|
19
21
|
process.exit(1);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
46
|
+
const spinner = ora(
|
|
47
|
+
`Creating Next.js app in ${chalk.cyan(projectName)}...`
|
|
48
|
+
).start();
|
|
38
49
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
55
|
+
// Init git
|
|
56
|
+
spinner.text = "Initializing Git repository...";
|
|
57
|
+
runCommand("git init", { cwd: projectPath });
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
}
|