@beechcms/cli 0.4.0-preview.6 → 0.4.0-preview.7

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.
Files changed (2) hide show
  1. package/dist/index.js +22 -12
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ function executeD1File(sql, options) {
26
26
  try {
27
27
  writeFileSync(tmpFile, sql, "utf-8");
28
28
  const args = ["d1", "execute", options.db, "--file", tmpFile, ...buildArgs(options)];
29
- const result = spawnSync("npx", ["wrangler", ...args], { stdio: "inherit", cwd: process.cwd() });
29
+ const result = spawnSync("npx", ["wrangler", ...args], { stdio: "inherit", cwd: process.cwd(), shell: true });
30
30
  if (result.status !== 0) {
31
31
  process.exit(result.status ?? 1);
32
32
  }
@@ -39,7 +39,7 @@ function executeD1File(sql, options) {
39
39
  }
40
40
  function queryD1(sql, options) {
41
41
  const args = ["d1", "execute", options.db, "--command", sql, "--json", ...buildArgs(options)];
42
- const result = spawnSync("npx", ["wrangler", ...args], { encoding: "utf-8", cwd: process.cwd() });
42
+ const result = spawnSync("npx", ["wrangler", ...args], { encoding: "utf-8", cwd: process.cwd(), shell: true });
43
43
  if (result.status !== 0) {
44
44
  throw new Error(`wrangler d1 execute failed:
45
45
  ${result.stderr}`);
@@ -53,20 +53,30 @@ ${result.stdout}`);
53
53
  }
54
54
  }
55
55
  function findWranglerConfig() {
56
- const candidates = [
57
- resolve(process.cwd(), "wrangler.jsonc"),
58
- resolve(process.cwd(), "wrangler.json"),
59
- resolve(process.cwd(), "apps", "api", "wrangler.jsonc"),
60
- resolve(process.cwd(), "apps", "api", "wrangler.json")
61
- ];
62
- return candidates.find(existsSync) ?? null;
56
+ let dir = process.cwd();
57
+ while (true) {
58
+ for (const name of ["wrangler.jsonc", "wrangler.json"]) {
59
+ const p = resolve(dir, name);
60
+ if (existsSync(p)) return p;
61
+ }
62
+ for (const name of ["wrangler.jsonc", "wrangler.json"]) {
63
+ const p = resolve(dir, "apps", "api", name);
64
+ if (existsSync(p)) return p;
65
+ }
66
+ const parent = resolve(dir, "..");
67
+ if (parent === dir) break;
68
+ dir = parent;
69
+ }
70
+ return null;
63
71
  }
64
72
  function resolveDbName(configPath) {
65
73
  if (!configPath) return "beech-db";
66
74
  try {
67
- const content = readFileSync(configPath, "utf-8");
68
- const match = content.match(/"database_name"\s*:\s*"([^"]+)"/);
69
- return match?.[1] ?? "beech-db";
75
+ const raw = readFileSync(configPath, "utf-8");
76
+ const stripped = raw.replace(/\/\/[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
77
+ const parsed = JSON.parse(stripped);
78
+ const bindings = parsed?.d1_databases ?? [];
79
+ return bindings[0]?.database_name ?? "beech-db";
70
80
  } catch {
71
81
  return "beech-db";
72
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beechcms/cli",
3
- "version": "0.4.0-preview.6",
3
+ "version": "0.4.0-preview.7",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -11,7 +11,7 @@
11
11
  "dev": "esbuild src/index.ts --bundle --packages=external --platform=node --format=esm --outfile=dist/index.js --watch"
12
12
  },
13
13
  "dependencies": {
14
- "@beechcms/core": "^0.4.0-preview.6",
14
+ "@beechcms/core": "^0.4.0-preview.7",
15
15
  "picocolors": "^1.1.1"
16
16
  },
17
17
  "devDependencies": {