Skip to content

Commit dd52dc7

Browse files
Merge pull request #15 from PrabothCharith/development
Feature: Package Manager Selection
2 parents 736d09d + f09c733 commit dd52dc7

11 files changed

Lines changed: 216 additions & 8 deletions

File tree

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ You will be guided to select your preferred tools:
6565
For power users, skip the prompts by passing flags directly:
6666

6767
```bash
68-
# Create a full-stack app
69-
npx nxt-gen-cli my-app --orm prisma --ui shadcn --auth next-auth --react-query --pnpm
68+
# Create a full-stack app with pnpm
69+
npx nxt-gen-cli my-app --pm pnpm --orm prisma --ui shadcn --auth next-auth --react-query
7070

71-
# Create a minimal API service
72-
npx nxt-gen-cli api-service --orm drizzle --docker --ci
71+
# Create a minimal API service with yarn
72+
npx nxt-gen-cli api-service --pm yarn --orm drizzle --docker --ci
73+
74+
# Create a project with bun
75+
npx nxt-gen-cli my-bun-app --pm bun --ui shadcn --react-query
7376
```
7477

7578
## Features
@@ -119,6 +122,7 @@ Arguments:
119122
name Project name (prompted if not provided)
120123
121124
Options:
125+
--pm <type> Package Manager: npm, pnpm, yarn, bun
122126
--orm <type> ORM: prisma, drizzle, none
123127
--auth <type> Auth Provider: next-auth, clerk, none
124128
--ui <type> UI Library: shadcn, heroui, both, none

bin/nxt-gen-cli

100644100755
File mode changed.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nxt-gen-cli",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"description": "The ultimate Next.js scaffold CLI generator. Customize your stack with Prisma, React Query, Shadcn, HeroUI, and more in seconds.",
55
"main": "dist/index.js",
66
"type": "module",

src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import updateNotifier from "update-notifier";
88
import { createRequire } from "module";
99
import { initialPrompt } from "./prompts.js";
1010
import { validateProjectName } from "./lib/validation.js";
11+
import { PACKAGE_MANAGERS, PackageManager } from "./lib/pm.js";
1112

1213
const require = createRequire(import.meta.url);
1314
const pkg = require("../package.json");
@@ -97,6 +98,7 @@ export async function main() {
9798
.description("Create Next.js Project with Custom Features")
9899
.version(pkg.version)
99100
.argument("[name]", "Project name")
101+
.option("--pm <type>", "Package Manager (npm, pnpm, yarn, bun)")
100102
.option("--orm <type>", "ORM (prisma, drizzle, none)")
101103
.option("--react-query [boolean]", "Install React Query")
102104
.option("--axios [boolean]", "Install Axios")
@@ -142,6 +144,33 @@ export async function main() {
142144
process.exit(1);
143145
}
144146

147+
// Normalize and validate pm option
148+
if (options.pm !== undefined && options.pm !== null) {
149+
const rawPm = options.pm;
150+
const normalizedPm =
151+
typeof rawPm === "string" ? rawPm.trim() : rawPm;
152+
153+
if (normalizedPm === "") {
154+
console.log(
155+
chalk.red(
156+
`Package manager value cannot be empty. Must be one of: ${PACKAGE_MANAGERS.join(", ")}`
157+
)
158+
);
159+
process.exit(1);
160+
}
161+
162+
if (!PACKAGE_MANAGERS.includes(normalizedPm as PackageManager)) {
163+
console.log(
164+
chalk.red(
165+
`Invalid package manager: ${normalizedPm}. Must be one of: ${PACKAGE_MANAGERS.join(", ")}`
166+
)
167+
);
168+
process.exit(1);
169+
}
170+
options.packageManager = normalizedPm as PackageManager;
171+
delete options.pm;
172+
}
173+
145174
const config = await initialPrompt(options);
146175
console.log(chalk.blue("Selected Configuration:"), config);
147176

src/lib/pm.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
22

3+
export const PACKAGE_MANAGERS: readonly PackageManager[] = ["npm", "pnpm", "yarn", "bun"];
4+
35
export function detectPackageManager(): PackageManager {
46
const userAgent = process.env.npm_config_user_agent;
57
if (!userAgent) return "npm";

src/prompts.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import prompts from "prompts";
2+
import { PackageManager, PACKAGE_MANAGERS } from "./lib/pm.js";
23

34
export interface ProjectConfig {
5+
packageManager?: PackageManager;
46
orm: "prisma" | "drizzle" | "none";
57
reactQuery: boolean;
68
axios: boolean;
@@ -59,6 +61,13 @@ export async function initialPrompt(
5961

6062
const response = await prompts(
6163
[
64+
{
65+
type: options.packageManager !== undefined ? null : "select",
66+
name: "packageManager",
67+
message: "Which package manager would you like to use?",
68+
choices: PACKAGE_MANAGERS.map(pm => ({ title: pm, value: pm })),
69+
initial: 0,
70+
},
6271
{
6372
type: options.orm !== undefined ? null : "select",
6473
name: "orm",

src/scaffold.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export const scaffoldProject = async (
6868
config: ProjectConfig
6969
) => {
7070
const projectPath = path.resolve(process.cwd(), projectName);
71-
const pm = detectPackageManager();
71+
// Use the package manager from config, or auto-detect as fallback
72+
const pm = config.packageManager || detectPackageManager();
7273
const deps = new DependencyCollector();
7374

7475
// Check if directory already exists

test/fixtures/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Test Fixtures
2+
3+
This directory contains test fixture files used by the test suite.
4+
5+
## package-managers.json
6+
7+
Contains the list of supported package managers for testing purposes. This file should be kept in sync with the `PACKAGE_MANAGERS` constant in `src/lib/pm.ts`.
8+
9+
**Note**: This file is used as a fallback when the compiled `dist/lib/pm.js` is not available. The test suite includes an automatic validation check (Test 5) that will fail if this file becomes out of sync with the source code, ensuring you'll be notified if an update is needed.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
"npm",
3+
"pnpm",
4+
"yarn",
5+
"bun"
6+
]

0 commit comments

Comments
 (0)