@betterstart/cli 0.1.17 → 0.1.19

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
@@ -4672,7 +4672,12 @@ export const ${toCamelCase5(junctionName)} = pgTable(
4672
4672
  }
4673
4673
  function mergeImports(content, requiredImports, needsSql) {
4674
4674
  const pgCoreMatch = content.match(/import\s+\{([^}]+)\}\s+from\s+['"]drizzle-orm\/pg-core['"]/);
4675
- const hasSqlImport = content.includes("import { sql } from 'drizzle-orm'");
4675
+ const drizzleOrmMatch = content.match(/import\s*\{([^}]*)\}\s*from\s*['"]drizzle-orm['"]/);
4676
+ const existingDrizzleOrmImports = /* @__PURE__ */ new Set();
4677
+ if (drizzleOrmMatch) {
4678
+ drizzleOrmMatch[1].split(",").map((i) => i.trim()).filter(Boolean).forEach((i) => existingDrizzleOrmImports.add(i));
4679
+ }
4680
+ const hasSqlImport = existingDrizzleOrmImports.has("sql");
4676
4681
  const existing = /* @__PURE__ */ new Set();
4677
4682
  if (pgCoreMatch) {
4678
4683
  pgCoreMatch[1].split(",").map((i) => i.trim()).filter(Boolean).forEach((i) => {
@@ -4687,9 +4692,9 @@ function mergeImports(content, requiredImports, needsSql) {
4687
4692
  let updated = content;
4688
4693
  if (pgCoreMatch) {
4689
4694
  updated = updated.replace(/import\s+\{[^}]+\}\s+from\s+['"]drizzle-orm\/pg-core['"]/, newImport);
4690
- } else if (hasSqlImport) {
4695
+ } else if (drizzleOrmMatch) {
4691
4696
  updated = updated.replace(
4692
- /import\s+\{[^}]+\}\s+from\s+['"]drizzle-orm['"]/,
4697
+ /import\s*\{[^}]*\}\s*from\s*['"]drizzle-orm['"]/,
4693
4698
  (match) => `${match}
4694
4699
  ${newImport}`
4695
4700
  );
@@ -4698,8 +4703,17 @@ ${newImport}`
4698
4703
  ${updated}`;
4699
4704
  }
4700
4705
  if (needsSql && !hasSqlImport) {
4701
- updated = `import { sql } from 'drizzle-orm'
4706
+ if (drizzleOrmMatch) {
4707
+ existingDrizzleOrmImports.add("sql");
4708
+ const sortedOrm = Array.from(existingDrizzleOrmImports).sort();
4709
+ updated = updated.replace(
4710
+ /import\s*\{[^}]*\}\s*from\s*['"]drizzle-orm['"]/,
4711
+ `import { ${sortedOrm.join(", ")} } from 'drizzle-orm'`
4712
+ );
4713
+ } else {
4714
+ updated = `import { sql } from 'drizzle-orm'
4702
4715
  ${updated}`;
4716
+ }
4703
4717
  }
4704
4718
  return updated;
4705
4719
  }
@@ -7707,8 +7721,9 @@ function runPostGenerate(cwd, schemaName, options = {}) {
7707
7721
  console.log(ok ? " Database schema synced" : " Database push failed (run db:push manually)");
7708
7722
  } else {
7709
7723
  console.log("\n Running drizzle-kit push...");
7724
+ const drizzleBin = path21.join(cwd, "node_modules", ".bin", "drizzle-kit");
7710
7725
  try {
7711
- execFileSync2("npx", ["drizzle-kit", "push"], { cwd, stdio: "pipe" });
7726
+ execFileSync2(drizzleBin, ["push", "--force"], { cwd, stdio: "pipe" });
7712
7727
  result.dbPush = "success";
7713
7728
  console.log(" Database schema synced");
7714
7729
  } catch {
@@ -7725,8 +7740,9 @@ function runPostGenerate(cwd, schemaName, options = {}) {
7725
7740
  result.lintFix = ok ? "success" : "failed";
7726
7741
  console.log(ok ? " Code formatted" : " Lint fix had issues (run lint:fix manually)");
7727
7742
  } else {
7743
+ const biomeBin = path21.join(cwd, "node_modules", ".bin", "biome");
7728
7744
  try {
7729
- execFileSync2("npx", ["biome", "check", "--write", "."], { cwd, stdio: "pipe" });
7745
+ execFileSync2(biomeBin, ["check", "--write", "."], { cwd, stdio: "pipe" });
7730
7746
  result.lintFix = "success";
7731
7747
  console.log(" Code formatted with Biome");
7732
7748
  } catch {
@@ -11432,10 +11448,25 @@ export default db
11432
11448
 
11433
11449
  // src/init/templates/db/drizzle-config.ts
11434
11450
  function drizzleConfigTemplate() {
11435
- return `import { loadEnvConfig } from '@next/env'
11451
+ return `import { readFileSync } from 'node:fs'
11452
+ import { resolve } from 'node:path'
11436
11453
  import { defineConfig } from 'drizzle-kit'
11437
11454
 
11438
- loadEnvConfig(process.cwd())
11455
+ // Load .env.local (avoids @next/env dependency for drizzle-kit)
11456
+ for (const envFile of ['.env.local', '.env']) {
11457
+ try {
11458
+ const content = readFileSync(resolve(process.cwd(), envFile), 'utf-8')
11459
+ for (const line of content.split('\\n')) {
11460
+ const trimmed = line.trim()
11461
+ if (!trimmed || trimmed.startsWith('#')) continue
11462
+ const eqIdx = trimmed.indexOf('=')
11463
+ if (eqIdx === -1) continue
11464
+ const key = trimmed.slice(0, eqIdx).trim()
11465
+ const val = trimmed.slice(eqIdx + 1).trim().replace(/^['"]|['"]$/g, '')
11466
+ if (!process.env[key]) process.env[key] = val
11467
+ }
11468
+ } catch {}
11469
+ }
11439
11470
 
11440
11471
  export default defineConfig({
11441
11472
  out: './cms/db/migrations',