@bill742/create-nextstarter 1.0.0

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/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # create-nextstarter
2
+
3
+ Scaffold a new [NextStarter](https://github.com/bill742/nextstarter) project with a single command.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ npx create-nextstarter my-project
9
+ cd my-project
10
+ npm run dev
11
+ ```
12
+
13
+ ## What it does
14
+
15
+ 1. Clones the NextStarter template
16
+ 2. Cleans up template-only files (`.git`, `CLAUDE.md`, `CHANGELOG.md`, etc.)
17
+ 3. Copies `.env.example` → `.env`
18
+ 4. Sets the project `name` and `version` in `package.json`
19
+ 5. Optionally runs `npm install`
20
+
21
+ ## Requirements
22
+
23
+ - Node.js 18 or higher
24
+ - Git
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Node version check
4
+ const nodeMajor = parseInt(process.versions.node.split(".")[0], 10);
5
+ if (nodeMajor < 18) {
6
+ console.error("Error: Node.js 18 or higher is required.");
7
+ process.exit(1);
8
+ }
9
+
10
+ const { createNextStarter } = require("../src/index.js");
11
+
12
+ const args = process.argv.slice(2);
13
+ const projectName = args[0];
14
+
15
+ if (!projectName || projectName === "--help" || projectName === "-h") {
16
+ console.log("Usage: create-nextstarter <project-name>");
17
+ console.log("Example: npx create-nextstarter my-project");
18
+ process.exit(projectName ? 0 : 1);
19
+ }
20
+
21
+ createNextStarter(projectName);
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "bin": {
3
+ "create-nextstarter": "bin/create-nextstarter.js"
4
+ },
5
+ "description": "Create a new project from the NextStarter boilerplate",
6
+ "engines": {
7
+ "node": ">=18.0.0"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "src/"
12
+ ],
13
+ "license": "MIT",
14
+ "name": "@bill742/create-nextstarter",
15
+ "version": "1.0.0"
16
+ }
package/src/index.js ADDED
@@ -0,0 +1,131 @@
1
+ const fs = require("node:fs");
2
+ const path = require("node:path");
3
+ const { execSync } = require("node:child_process");
4
+ const readline = require("node:readline");
5
+
6
+ const TEMPLATE_REPO = "https://github.com/bill742/nextstarter.git";
7
+
8
+ const CLEANUP_PATHS = [
9
+ ".git",
10
+ "node_modules",
11
+ ".next",
12
+ ".env",
13
+ ".skills",
14
+ "CLAUDE.md",
15
+ "CHANGELOG.md",
16
+ "playwright-report",
17
+ "test-results",
18
+ "package-lock.json",
19
+ ];
20
+
21
+ /**
22
+ * Removes a file or directory recursively.
23
+ * @param {string} targetPath - Absolute path to remove.
24
+ */
25
+ function removePath(targetPath) {
26
+ if (fs.existsSync(targetPath)) {
27
+ fs.rmSync(targetPath, { recursive: true, force: true });
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Prompts the user with a question and returns their answer.
33
+ * @param {string} question - The question to display.
34
+ * @returns {Promise<string>} The user's input.
35
+ */
36
+ function prompt(question) {
37
+ const rl = readline.createInterface({
38
+ input: process.stdin,
39
+ output: process.stdout,
40
+ });
41
+ return new Promise((resolve) => {
42
+ rl.question(question, (answer) => {
43
+ rl.close();
44
+ resolve(answer);
45
+ });
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Main orchestration function for scaffolding a new NextStarter project.
51
+ * @param {string} projectName - The name of the new project directory.
52
+ */
53
+ async function createNextStarter(projectName) {
54
+ // Validate project name
55
+ if (/\s/.test(projectName)) {
56
+ console.error("Error: Project name must not contain spaces.");
57
+ process.exit(1);
58
+ }
59
+
60
+ const targetDir = path.resolve(process.cwd(), projectName);
61
+
62
+ if (fs.existsSync(targetDir)) {
63
+ console.error(`Error: Directory "${projectName}" already exists.`);
64
+ process.exit(1);
65
+ }
66
+
67
+ console.log(`\nCreating a new NextStarter project in ./${projectName}...\n`);
68
+
69
+ // Step 1: Clone template
70
+ try {
71
+ execSync(`git clone --depth=1 ${TEMPLATE_REPO} ${projectName}`, {
72
+ stdio: "pipe",
73
+ });
74
+ console.log(" \u2713 Cloning template");
75
+ } catch (err) {
76
+ console.error("Error: Failed to clone template repository.");
77
+ console.error(err.stderr?.toString() ?? err.message);
78
+ process.exit(1);
79
+ }
80
+
81
+ // Step 2: Clean up unwanted files
82
+ for (const relPath of CLEANUP_PATHS) {
83
+ removePath(path.join(targetDir, relPath));
84
+ }
85
+ console.log(" \u2713 Cleaning up");
86
+
87
+ // Step 3: Copy .env.example → .env
88
+ const envExample = path.join(targetDir, ".env.example");
89
+ const envTarget = path.join(targetDir, ".env");
90
+ if (fs.existsSync(envExample)) {
91
+ fs.copyFileSync(envExample, envTarget);
92
+ }
93
+ console.log(" \u2713 Setting up .env");
94
+
95
+ // Step 4: Rewrite package.json
96
+ const pkgPath = path.join(targetDir, "package.json");
97
+ if (fs.existsSync(pkgPath)) {
98
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
99
+ pkg.name = projectName;
100
+ pkg.version = "0.1.0";
101
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
102
+ }
103
+ console.log(" \u2713 Updating package.json");
104
+
105
+ // Step 5: Prompt to install dependencies
106
+ const answer = await prompt("\n? Install dependencies now? (Y/n) ");
107
+ const shouldInstall = answer.trim().toLowerCase() !== "n";
108
+
109
+ if (shouldInstall) {
110
+ try {
111
+ execSync("npm install", { cwd: targetDir, stdio: "inherit" });
112
+ console.log("\n \u2713 Dependencies installed");
113
+ } catch (err) {
114
+ console.error("Error: npm install failed.");
115
+ process.exit(1);
116
+ }
117
+ }
118
+
119
+ // Step 6: Print next steps
120
+ console.log("\nDone! Your project is ready.\n");
121
+ console.log(` cd ${projectName}`);
122
+ if (!shouldInstall) {
123
+ console.log(" npm install");
124
+ }
125
+ console.log(" npm run dev\n");
126
+ console.log(
127
+ "Edit .env to set NEXT_PUBLIC_SITE_URL and NEXT_PUBLIC_SITE_NAME before deploying.",
128
+ );
129
+ }
130
+
131
+ module.exports = { createNextStarter };