@betterstart/cli 0.1.8 → 0.1.10

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/dist/cli.js CHANGED
@@ -7630,6 +7630,18 @@ function runCommand(pm, script) {
7630
7630
  return `npm run ${script}`;
7631
7631
  }
7632
7632
  }
7633
+ function createNextAppCommand(pm) {
7634
+ switch (pm) {
7635
+ case "pnpm":
7636
+ return { bin: "pnpm", prefix: ["create", "next-app@latest"] };
7637
+ case "yarn":
7638
+ return { bin: "yarn", prefix: ["create", "next-app@latest"] };
7639
+ case "bun":
7640
+ return { bin: "bunx", prefix: ["create-next-app@latest"] };
7641
+ default:
7642
+ return { bin: "npx", prefix: ["create-next-app@latest"] };
7643
+ }
7644
+ }
7633
7645
 
7634
7646
  // src/generators/post-generate.ts
7635
7647
  function loadEnvFile(cwd) {
@@ -7978,6 +7990,7 @@ async function promptProject(defaultName) {
7978
7990
  defaultValue: defaultName ?? "my-app",
7979
7991
  validate: (value) => {
7980
7992
  if (!value.trim()) return "Project name is required";
7993
+ if (value.trim() === ".") return void 0;
7981
7994
  if (!/^[a-z0-9_-]+$/i.test(value.trim())) {
7982
7995
  return "Project name can only contain letters, numbers, hyphens, and underscores";
7983
7996
  }
@@ -13626,27 +13639,29 @@ var initCommand = new Command3("init").description("Scaffold CMS into a new or e
13626
13639
  pm = pmChoice;
13627
13640
  }
13628
13641
  const cnaSpinner = p4.spinner();
13629
- cnaSpinner.start(`Creating Next.js app: ${projectPrompt.projectName}...`);
13642
+ const displayName = projectPrompt.projectName === "." ? path37.basename(cwd) : projectPrompt.projectName;
13643
+ cnaSpinner.start(`Creating Next.js app: ${displayName}...`);
13644
+ const { bin, prefix } = createNextAppCommand(pm);
13645
+ const cnaArgs = [
13646
+ ...prefix,
13647
+ projectPrompt.projectName,
13648
+ "--yes",
13649
+ "--typescript",
13650
+ "--tailwind",
13651
+ "--app",
13652
+ "--no-git",
13653
+ "--no-import-alias",
13654
+ "--turbopack",
13655
+ `--use-${pm}`
13656
+ ];
13657
+ if (srcDir) cnaArgs.push("--src-dir");
13658
+ else cnaArgs.push("--no-src-dir");
13630
13659
  try {
13631
- const cnaArgs = [
13632
- "create-next-app@latest",
13633
- projectPrompt.projectName,
13634
- "--typescript",
13635
- "--tailwind",
13636
- "--app",
13637
- "--no-git",
13638
- "--no-import-alias",
13639
- "--turbopack",
13640
- `--use-${pm}`
13641
- ];
13642
- if (srcDir) cnaArgs.push("--src-dir");
13643
- else cnaArgs.push("--no-src-dir");
13644
- execFileSync4("npx", cnaArgs, {
13660
+ execFileSync4(bin, cnaArgs, {
13645
13661
  cwd,
13646
13662
  stdio: "pipe",
13647
13663
  timeout: 12e4
13648
13664
  });
13649
- cnaSpinner.stop(`Created ${projectPrompt.projectName}`);
13650
13665
  } catch (err) {
13651
13666
  cnaSpinner.stop("Failed to create Next.js app");
13652
13667
  p4.log.error(err instanceof Error ? err.message : "create-next-app failed");
@@ -13658,6 +13673,24 @@ var initCommand = new Command3("init").description("Scaffold CMS into a new or e
13658
13673
  process.exit(1);
13659
13674
  }
13660
13675
  cwd = path37.resolve(cwd, projectPrompt.projectName);
13676
+ const hasPackageJson = fs32.existsSync(path37.join(cwd, "package.json"));
13677
+ const hasNextConfig = ["next.config.ts", "next.config.js", "next.config.mjs"].some(
13678
+ (f) => fs32.existsSync(path37.join(cwd, f))
13679
+ );
13680
+ if (!hasPackageJson || !hasNextConfig) {
13681
+ cnaSpinner.stop("Failed to create Next.js app");
13682
+ p4.log.error(
13683
+ "create-next-app completed but the project was not created. This can happen with nested npx calls."
13684
+ );
13685
+ const manualCmd = `npx create-next-app@latest ${projectPrompt.projectName} --typescript --tailwind --app`;
13686
+ p4.log.info(
13687
+ `Create the project manually:
13688
+ ${pc2.cyan(manualCmd)}
13689
+ Then run ${pc2.cyan("betterstart init")} inside it.`
13690
+ );
13691
+ process.exit(1);
13692
+ }
13693
+ cnaSpinner.stop(`Created ${displayName}`);
13661
13694
  project = detectProject(cwd);
13662
13695
  }
13663
13696
  const features = options.yes ? { includeEmail: true, preset: options.preset } : await promptFeatures(options.preset);