@mostajs/orm-cli 0.4.0 → 0.4.1
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/bin/mostajs.sh +56 -10
- package/package.json +1 -1
package/bin/mostajs.sh
CHANGED
|
@@ -2460,22 +2460,42 @@ run_subcommand() {
|
|
|
2460
2460
|
;;
|
|
2461
2461
|
bootstrap|b)
|
|
2462
2462
|
# mostajs bootstrap : the full zero-touch migration for a Prisma project.
|
|
2463
|
-
# 1.
|
|
2464
|
-
# 2. npm install @mostajs/orm @mostajs/orm-bridge server-only
|
|
2463
|
+
# 1. Rewrite every `new PrismaClient(...)` site (install-bridge --apply)
|
|
2464
|
+
# 2. npm install @mostajs/orm @mostajs/orm-bridge @mostajs/orm-adapter server-only
|
|
2465
2465
|
# 3. Convert prisma/schema.prisma → entities.json
|
|
2466
2466
|
# 4. Write .mostajs/config.env + init SQLite DDL
|
|
2467
|
-
#
|
|
2467
|
+
#
|
|
2468
|
+
# Hard stop-on-error : no step proceeds if the previous one failed.
|
|
2468
2469
|
local cli_dir
|
|
2469
2470
|
cli_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
2470
2471
|
detect_project
|
|
2471
2472
|
[[ ${#DETECTED_TYPES[@]} -eq 0 ]] && { err "No schema found. Bootstrap needs a prisma/schema.prisma (or OpenAPI/JSONSchema)."; exit 1; }
|
|
2472
2473
|
|
|
2474
|
+
local BS_OK_CODEMOD=0 BS_OK_DEPS=0 BS_OK_CONVERT=0 BS_OK_DDL=0
|
|
2475
|
+
|
|
2476
|
+
# ─── Step 1 ───
|
|
2473
2477
|
echo -e "\n\e[1m▶ Step 1/4 : rewrite PrismaClient sites\e[0m"
|
|
2474
|
-
node "$cli_dir/bin/install-bridge.mjs" --apply
|
|
2478
|
+
if node "$cli_dir/bin/install-bridge.mjs" --apply; then
|
|
2479
|
+
BS_OK_CODEMOD=1
|
|
2480
|
+
else
|
|
2481
|
+
err "Step 1 failed — codemod returned non-zero. Aborting."; exit 1
|
|
2482
|
+
fi
|
|
2475
2483
|
|
|
2476
|
-
|
|
2477
|
-
|
|
2484
|
+
# ─── Step 2 ───
|
|
2485
|
+
echo -e "\n\e[1m▶ Step 2/4 : install runtime deps (this can take 1-2 min)\e[0m"
|
|
2486
|
+
info " installing : @mostajs/orm @mostajs/orm-bridge @mostajs/orm-adapter server-only"
|
|
2487
|
+
if ( cd "$PROJECT_ROOT" && $PKG_MANAGER install \
|
|
2488
|
+
@mostajs/orm @mostajs/orm-bridge @mostajs/orm-adapter server-only \
|
|
2489
|
+
--legacy-peer-deps ); then
|
|
2490
|
+
BS_OK_DEPS=1
|
|
2491
|
+
ok " deps installed"
|
|
2492
|
+
else
|
|
2493
|
+
err "Step 2 failed — \`$PKG_MANAGER install\` returned non-zero."
|
|
2494
|
+
err "Fix your package manager / registry access and re-run \`mostajs bootstrap\`."
|
|
2495
|
+
exit 1
|
|
2496
|
+
fi
|
|
2478
2497
|
|
|
2498
|
+
# ─── Step 3 ───
|
|
2479
2499
|
echo -e "\n\e[1m▶ Step 3/4 : convert schema + init DDL\e[0m"
|
|
2480
2500
|
local type="${DETECTED_TYPES[0]}" input
|
|
2481
2501
|
case "$type" in
|
|
@@ -2483,7 +2503,16 @@ run_subcommand() {
|
|
|
2483
2503
|
openapi) input="$OPENAPI_FILE" ;;
|
|
2484
2504
|
jsonschema) input="${JSON_SCHEMAS[0]}" ;;
|
|
2485
2505
|
esac
|
|
2486
|
-
|
|
2506
|
+
|
|
2507
|
+
if run_adapter_convert "$type" "$input" "$GENERATED_DIR/entities.ts" && \
|
|
2508
|
+
[[ -s "$GENERATED_DIR/entities.json" || -s "$GENERATED_DIR/entities.ts" ]]; then
|
|
2509
|
+
BS_OK_CONVERT=1
|
|
2510
|
+
ok " schema converted → $GENERATED_DIR/entities.json"
|
|
2511
|
+
else
|
|
2512
|
+
err "Step 3.1 failed — schema conversion did not produce entities.json."
|
|
2513
|
+
err "Re-run manually : $CLI_NAME convert (or menu 1)"
|
|
2514
|
+
exit 1
|
|
2515
|
+
fi
|
|
2487
2516
|
|
|
2488
2517
|
mkdir -p "$CONFIG_DIR"
|
|
2489
2518
|
if [[ ! -f "$CONFIG_DIR/config.env" ]]; then
|
|
@@ -2493,25 +2522,42 @@ SGBD_URI=./data.sqlite
|
|
|
2493
2522
|
DB_SCHEMA_STRATEGY=update
|
|
2494
2523
|
CFG
|
|
2495
2524
|
ok " wrote $CONFIG_DIR/config.env (defaults: sqlite ./data.sqlite)"
|
|
2525
|
+
# Reload config so action_init_dialects picks up the new values
|
|
2526
|
+
load_env
|
|
2496
2527
|
fi
|
|
2497
|
-
action_init_dialects || warn "DDL init returned non-zero — inspect and retry with menu 3"
|
|
2498
2528
|
|
|
2529
|
+
if action_init_dialects; then
|
|
2530
|
+
BS_OK_DDL=1
|
|
2531
|
+
ok " DDL applied"
|
|
2532
|
+
else
|
|
2533
|
+
err "Step 3.2 failed — DDL init returned non-zero."
|
|
2534
|
+
err "Re-run manually : $CLI_NAME (menu 3)"
|
|
2535
|
+
exit 1
|
|
2536
|
+
fi
|
|
2537
|
+
|
|
2538
|
+
# ─── Step 4 ───
|
|
2499
2539
|
echo -e "\n\e[1m▶ Step 4/4 : done\e[0m"
|
|
2500
|
-
|
|
2540
|
+
if (( BS_OK_CODEMOD && BS_OK_DEPS && BS_OK_CONVERT && BS_OK_DDL )); then
|
|
2541
|
+
cat <<DONE
|
|
2501
2542
|
|
|
2502
2543
|
✓ Bridge installed in-place. Original files backed up as *.prisma.bak
|
|
2503
2544
|
✓ Schema converted : $GENERATED_DIR/entities.json
|
|
2504
|
-
✓
|
|
2545
|
+
✓ DDL applied (DB_DIALECT=\$(grep ^DB_DIALECT $CONFIG_DIR/config.env | cut -d= -f2))
|
|
2505
2546
|
|
|
2506
2547
|
Next :
|
|
2507
2548
|
- Add seeds to $CONFIG_DIR/seeds/*.json (one file per entity)
|
|
2508
2549
|
- $CLI_NAME # menu S → h (hash) → 4 (apply)
|
|
2509
2550
|
- npm run dev
|
|
2551
|
+
- Open http://localhost:3000/login
|
|
2510
2552
|
|
|
2511
2553
|
To undo the codemod :
|
|
2512
2554
|
$CLI_NAME install-bridge --restore --apply
|
|
2513
2555
|
|
|
2514
2556
|
DONE
|
|
2557
|
+
else
|
|
2558
|
+
err "Bootstrap finished with partial success — see messages above."
|
|
2559
|
+
exit 1
|
|
2560
|
+
fi
|
|
2515
2561
|
;;
|
|
2516
2562
|
version|-v|--version)
|
|
2517
2563
|
echo "$CLI_NAME $VERSION"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostajs/orm-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Universal CLI to integrate @mostajs/orm into any project — one-shot `mostajs bootstrap` migrates a Prisma project (codemod + deps + schema convert + DDL) to 13 databases with zero code change.",
|
|
5
5
|
"author": "Dr Hamid MADANI <drmdh@msn.com>",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|