@betterstart/cli 0.1.32 → 0.1.34

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
@@ -7583,23 +7583,28 @@ var LOCKFILE_MAP = {
7583
7583
  "bun.lock": "bun"
7584
7584
  };
7585
7585
  function detectPackageManager(cwd) {
7586
- for (const [lockfile, pm] of Object.entries(LOCKFILE_MAP)) {
7587
- if (fs20.existsSync(path20.join(cwd, lockfile))) {
7588
- return pm;
7586
+ let dir = path20.resolve(cwd);
7587
+ const root = path20.parse(dir).root;
7588
+ while (dir !== root) {
7589
+ for (const [lockfile, pm] of Object.entries(LOCKFILE_MAP)) {
7590
+ if (fs20.existsSync(path20.join(dir, lockfile))) {
7591
+ return pm;
7592
+ }
7589
7593
  }
7590
- }
7591
- const pkgPath = path20.join(cwd, "package.json");
7592
- if (fs20.existsSync(pkgPath)) {
7593
- try {
7594
- const pkg = JSON.parse(fs20.readFileSync(pkgPath, "utf-8"));
7595
- if (typeof pkg.packageManager === "string") {
7596
- const name = pkg.packageManager.split("@")[0];
7597
- if (name === "pnpm" || name === "npm" || name === "yarn" || name === "bun") {
7598
- return name;
7594
+ const pkgPath = path20.join(dir, "package.json");
7595
+ if (fs20.existsSync(pkgPath)) {
7596
+ try {
7597
+ const pkg = JSON.parse(fs20.readFileSync(pkgPath, "utf-8"));
7598
+ if (typeof pkg.packageManager === "string") {
7599
+ const name = pkg.packageManager.split("@")[0];
7600
+ if (name === "pnpm" || name === "npm" || name === "yarn" || name === "bun") {
7601
+ return name;
7602
+ }
7599
7603
  }
7604
+ } catch {
7600
7605
  }
7601
- } catch {
7602
7606
  }
7607
+ dir = path20.dirname(dir);
7603
7608
  }
7604
7609
  return "npm";
7605
7610
  }
@@ -11706,6 +11711,8 @@ async function installDependenciesAsync({
11706
11711
 
11707
11712
  // src/init/scaffolders/env.ts
11708
11713
  import crypto from "crypto";
11714
+ import { existsSync, readFileSync } from "fs";
11715
+ import { join } from "path";
11709
11716
 
11710
11717
  // src/utils/env.ts
11711
11718
  import fs27 from "fs";
@@ -11762,7 +11769,22 @@ ${lines.join("\n")}` : header + lines.join("\n");
11762
11769
  }
11763
11770
 
11764
11771
  // src/init/scaffolders/env.ts
11765
- function getCoreEnvSections(databaseUrl) {
11772
+ function detectDevPort(cwd) {
11773
+ const pkgPath = join(cwd, "package.json");
11774
+ if (!existsSync(pkgPath)) return 3e3;
11775
+ try {
11776
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
11777
+ const devScript = pkg.scripts?.dev ?? "";
11778
+ const match = devScript.match(/--port\s+(\d+)|-p\s+(\d+)/);
11779
+ if (match) {
11780
+ const port = Number.parseInt(match[1] ?? match[2], 10);
11781
+ if (port > 0 && port <= 65535) return port;
11782
+ }
11783
+ } catch {
11784
+ }
11785
+ return 3e3;
11786
+ }
11787
+ function getCoreEnvSections(databaseUrl, devPort) {
11766
11788
  const authSecret = crypto.randomBytes(32).toString("base64");
11767
11789
  return [
11768
11790
  {
@@ -11773,7 +11795,7 @@ function getCoreEnvSections(databaseUrl) {
11773
11795
  header: "Authentication",
11774
11796
  vars: [
11775
11797
  { key: "BETTERSTART_AUTH_SECRET", value: authSecret },
11776
- { key: "BETTERSTART_AUTH_URL", value: "http://localhost:3000" },
11798
+ { key: "BETTERSTART_AUTH_URL", value: `http://localhost:${devPort}` },
11777
11799
  { key: "BETTERSTART_AUTH_BASE_PATH", value: "/api/cms/auth" }
11778
11800
  ]
11779
11801
  },
@@ -11799,7 +11821,8 @@ function getEmailEnvSection() {
11799
11821
  };
11800
11822
  }
11801
11823
  function scaffoldEnv(cwd, options) {
11802
- const sections = getCoreEnvSections(options.databaseUrl);
11824
+ const devPort = detectDevPort(cwd);
11825
+ const sections = getCoreEnvSections(options.databaseUrl, devPort);
11803
11826
  if (options.includeEmail) {
11804
11827
  sections.push(getEmailEnvSection());
11805
11828
  }
@@ -14028,7 +14051,7 @@ Run manually: ${pc2.cyan("npx betterstart seed")}`,
14028
14051
  "",
14029
14052
  `Admin: ${pc2.cyan(seedEmail)}`,
14030
14053
  `Password: ${pc2.cyan(seedPassword)}`,
14031
- `CMS: ${pc2.cyan("http://localhost:3000/cms/login")}`
14054
+ `CMS: ${pc2.cyan(`http://localhost:${detectDevPort(cwd)}/cms/login`)}`
14032
14055
  );
14033
14056
  }
14034
14057
  const nextSteps = [];