@etus/bhono-app 0.1.4 → 0.1.5

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
@@ -13,7 +13,7 @@ function buildProgram() {
13
13
  return new Command()
14
14
  .name('bhono-app')
15
15
  .description('Create a new project from the Etus boilerplate')
16
- .version('0.1.4')
16
+ .version('0.1.5')
17
17
  .argument('<project-name>', 'Name of the project')
18
18
  .option('-d, --domain <domain>', 'Production domain')
19
19
  .option('-m, --modules <modules>', 'Comma-separated modules to include')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etus/bhono-app",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  # BHono - Development Environment Setup
4
- # This script bootstraps dependencies, configures Cloudflare bindings,
4
+ # Bootstraps dependencies, configures Cloudflare bindings,
5
5
  # seeds the local D1 (sqlite) database, and starts the dev server.
6
6
 
7
7
  set -euo pipefail
@@ -19,6 +19,7 @@ cd "$ROOT_DIR"
19
19
  UPDATE_PACKAGES=0
20
20
  SKIP_DEV=0
21
21
  SKIP_PROVISION=0
22
+ SKIP_SEED=0
22
23
 
23
24
  while [[ $# -gt 0 ]]; do
24
25
  case "$1" in
@@ -31,6 +32,9 @@ while [[ $# -gt 0 ]]; do
31
32
  --no-provision)
32
33
  SKIP_PROVISION=1
33
34
  ;;
35
+ --skip-seed)
36
+ SKIP_SEED=1
37
+ ;;
34
38
  *)
35
39
  echo -e "${YELLOW}Ignoring unknown argument: $1${NC}"
36
40
  ;;
@@ -148,8 +152,11 @@ fs.writeFileSync(path, JSON.stringify(data, null, 2));
148
152
  NODE
149
153
 
150
154
  WRANGLER="pnpm exec wrangler"
155
+ WRANGLER_CONFIG="$WRANGLER --config config/wrangler.json"
156
+ WRANGLER_AVAILABLE=1
151
157
  if ! $WRANGLER --version >/dev/null 2>&1; then
152
- log_warn "Wrangler not available. Ensure dependencies are installed."
158
+ WRANGLER_AVAILABLE=0
159
+ log_warn "Wrangler not available. Cloudflare steps will be skipped."
153
160
  fi
154
161
 
155
162
  # Resolve names from wrangler.json
@@ -158,6 +165,8 @@ if [[ -z "$DB_NAME" ]]; then
158
165
  DB_NAME="${PROJECT_NAME}-db"
159
166
  fi
160
167
 
168
+ DB_BINDING=$(node -e "const c=require('./config/wrangler.json'); console.log((c.d1_databases&&c.d1_databases[0]&&c.d1_databases[0].binding)||'DB');")
169
+
161
170
  R2_BUCKET=$(node -e "const c=require('./config/wrangler.json'); console.log((c.r2_buckets&&c.r2_buckets[0]&&c.r2_buckets[0].bucket_name)||'');")
162
171
  if [[ -z "$R2_BUCKET" ]]; then
163
172
  R2_BUCKET="${PROJECT_NAME}-storage"
@@ -171,7 +180,7 @@ KV_ID=$(node -e "const c=require('./config/wrangler.json'); console.log((c.kv_na
171
180
  if [[ "$D1_ID" == "TO_BE_PROVISIONED" ]]; then D1_ID=""; fi
172
181
  if [[ "$KV_ID" == "TO_BE_PROVISIONED" ]]; then KV_ID=""; fi
173
182
 
174
- if [[ "$SKIP_PROVISION" -eq 0 ]]; then
183
+ if [[ "$SKIP_PROVISION" -eq 0 && "$WRANGLER_AVAILABLE" -eq 1 ]]; then
175
184
  if $WRANGLER whoami >/dev/null 2>&1; then
176
185
  log_info "Provisioning Cloudflare resources (D1, KV, R2)..."
177
186
 
@@ -241,13 +250,19 @@ pnpm cf-typegen >/dev/null 2>&1 || log_warn "Skipping cf-typegen (wrangler not c
241
250
 
242
251
  # Ensure local D1 exists and update drizzle config
243
252
  log_info "Preparing local D1 database..."
244
- $WRANGLER d1 execute "$DB_NAME" --local --command "SELECT 1;" >/dev/null 2>&1 || true
253
+ if [[ "$WRANGLER_AVAILABLE" -eq 1 ]]; then
254
+ $WRANGLER_CONFIG d1 execute "$DB_NAME" --local --command "SELECT 1;" >/dev/null 2>&1 || log_warn "Local D1 init failed (continuing)."
255
+ fi
245
256
 
246
257
  D1_ID_FROM_CONFIG=$(node -e "const c=require('./config/wrangler.json'); console.log((c.d1_databases&&c.d1_databases[0]&&c.d1_databases[0].database_id)||'');")
247
258
  if [[ -n "$D1_ID_FROM_CONFIG" ]]; then
248
- LOCAL_DB_PATH=".wrangler/state/v3/d1/miniflare-D1DatabaseObject/${D1_ID_FROM_CONFIG}.sqlite"
259
+ LOCAL_D1_DIR=".wrangler/state/v3/d1/miniflare-D1DatabaseObject"
260
+ LOCAL_DB_PATH="${LOCAL_D1_DIR}/${D1_ID_FROM_CONFIG}.sqlite"
249
261
  DRIZZLE_DB_URL="../${LOCAL_DB_PATH}"
250
262
 
263
+ mkdir -p "$LOCAL_D1_DIR"
264
+ touch "$LOCAL_DB_PATH"
265
+
251
266
  if [[ -f config/drizzle.config.ts ]]; then
252
267
  DRIZZLE_DB_URL="$DRIZZLE_DB_URL" node - <<'NODE'
253
268
  const fs = require('fs');
@@ -264,22 +279,59 @@ if (pattern.test(content)) {
264
279
  fs.writeFileSync(path, content);
265
280
  NODE
266
281
  log_ok "Updated config/drizzle.config.ts with local DB path."
282
+ else
283
+ log_warn "config/drizzle.config.ts not found. Skipping DB config update."
267
284
  fi
268
285
  else
269
286
  log_warn "D1 id not found in wrangler.json. Skipping drizzle config update."
270
287
  fi
271
288
 
272
289
  # Push schema (no migrations) and seed
290
+ DB_PUSH_OK=0
291
+ SEED_OK=0
292
+
273
293
  log_info "Pushing schema to local D1..."
274
- pnpm db:push >/dev/null 2>&1 || log_warn "Schema push skipped (check drizzle config and local D1)."
294
+ if pnpm db:push >/tmp/bhono-db-push.log 2>&1; then
295
+ DB_PUSH_OK=1
296
+ else
297
+ log_warn "Schema push failed."
298
+ tail -n 20 /tmp/bhono-db-push.log || true
299
+ fi
275
300
 
276
- log_info "Generating seed data..."
277
- pnpm db:seed >/dev/null
301
+ if [[ "$SKIP_SEED" -eq 0 ]]; then
302
+ log_info "Generating seed data..."
303
+ if pnpm db:seed >/tmp/bhono-seed-generate.log 2>&1; then
304
+ if [[ -f seed.sql ]]; then
305
+ if [[ "$WRANGLER_AVAILABLE" -eq 1 ]]; then
306
+ log_info "Seeding local D1..."
307
+ if $WRANGLER_CONFIG d1 execute "$DB_NAME" --local --file=seed.sql >/tmp/bhono-seed-apply.log 2>&1; then
308
+ SEED_OK=1
309
+ else
310
+ log_warn "Seed apply failed."
311
+ tail -n 20 /tmp/bhono-seed-apply.log || true
312
+ fi
313
+ else
314
+ log_warn "Wrangler not available. Skipping seed apply."
315
+ fi
316
+ else
317
+ log_warn "seed.sql not found. Seed generation did not create the file."
318
+ fi
319
+ else
320
+ log_warn "Seed generation failed."
321
+ tail -n 20 /tmp/bhono-seed-generate.log || true
322
+ fi
323
+ else
324
+ log_warn "Skipping seed step (--skip-seed)."
325
+ fi
326
+
327
+ rm -f /tmp/bhono-db-push.log /tmp/bhono-seed-generate.log /tmp/bhono-seed-apply.log >/dev/null 2>&1 || true
278
328
 
279
- log_info "Seeding local D1..."
280
- $WRANGLER d1 execute "$DB_NAME" --local --file=seed.sql >/dev/null 2>&1 || log_warn "Seed failed (check local D1)."
329
+ if [[ "$DB_PUSH_OK" -eq 1 && "$SEED_OK" -eq 1 ]]; then
330
+ log_ok "Local D1 ready with seed data."
331
+ else
332
+ log_warn "Local D1 setup incomplete. Review warnings above."
333
+ fi
281
334
 
282
- log_ok "Local D1 ready with seed data."
283
335
  log_info "Seed data is defined in src/server/db/seed.ts (customize as needed)."
284
336
 
285
337
  if [[ "$SKIP_DEV" -eq 0 ]]; then