@mostajs/orm-cli 0.4.5 → 0.4.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/bin/mostajs.sh +91 -5
  2. package/package.json +1 -1
package/bin/mostajs.sh CHANGED
@@ -98,13 +98,32 @@ ensure_pkg() {
98
98
  warn "Missing package(s): ${missing[*]}"
99
99
  if confirm "Install now with $PKG_MANAGER?"; then
100
100
  cd "$PROJECT_ROOT" || return 1
101
+ local log_file="/tmp/mostajs-install-$$.log"
101
102
  case "$PKG_MANAGER" in
102
- pnpm) pnpm add "${missing[@]}" 2>&1 | tail -5 ;;
103
- yarn) yarn add "${missing[@]}" 2>&1 | tail -5 ;;
104
- bun) bun add "${missing[@]}" 2>&1 | tail -5 ;;
105
- *) npm install --save "${missing[@]}" --legacy-peer-deps 2>&1 | tail -5 ;;
103
+ pnpm) pnpm add "${missing[@]}" >"$log_file" 2>&1 & ;;
104
+ yarn) yarn add "${missing[@]}" >"$log_file" 2>&1 & ;;
105
+ bun) bun add "${missing[@]}" >"$log_file" 2>&1 & ;;
106
+ *) npm install --save "${missing[@]}" --legacy-peer-deps >"$log_file" 2>&1 & ;;
106
107
  esac
107
- local rc=${PIPESTATUS[0]}
108
+ local install_pid=$!
109
+ # Braille spinner — visual feedback while the install runs in background
110
+ local frames='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
111
+ local tick=0
112
+ while kill -0 "$install_pid" 2>/dev/null; do
113
+ local f="${frames:$((tick % 10)):1}"
114
+ local secs=$((tick / 5))
115
+ printf "\r ${YELLOW}%s${RESET} installing ${CYAN}%s${RESET} ${DIM}(%ds)${RESET} " \
116
+ "$f" "${missing[*]}" "$secs"
117
+ tick=$(( tick + 1 ))
118
+ sleep 0.2
119
+ done
120
+ wait "$install_pid"
121
+ local rc=$?
122
+ # Clear the spinner line
123
+ printf "\r%80s\r" ""
124
+ # Show the last lines of the install log (errors or summary)
125
+ tail -5 "$log_file"
126
+ rm -f "$log_file"
108
127
  if [[ $rc -ne 0 ]]; then
109
128
  err "Install failed"
110
129
  return $rc
@@ -438,6 +457,7 @@ menu_main() {
438
457
  echo -e " ${CYAN}8${RESET}) Health checks"
439
458
  echo -e " ${CYAN}9${RESET}) Generate boilerplate (src/db.ts with bridge)"
440
459
  echo -e " ${CYAN}s${RESET}) ${BOLD}Seeding${RESET} (upload / validate / apply seed data)"
460
+ echo -e " ${CYAN}e${RESET}) ${BOLD}Export entities${RESET} → Prisma / JSON Schema / OpenAPI / Native"
441
461
  echo -e " ${GREEN}b${RESET}) ${BOLD}Bootstrap${RESET} — one-shot migration of a Prisma project"
442
462
  echo -e " ${GREEN}i${RESET}) ${BOLD}Install bridge${RESET} — codemod PrismaClient → bridge (dry-run / apply / restore)"
443
463
  echo -e " ${CYAN}0${RESET}) About / Help"
@@ -457,6 +477,7 @@ menu_main() {
457
477
  8) action_healthcheck ;;
458
478
  9) action_generate_boilerplate ;;
459
479
  s|S) menu_seeding ;;
480
+ e|E) action_export_entities ;;
460
481
  b|B) menu_bootstrap ;;
461
482
  i|I) menu_install_bridge ;;
462
483
  0) action_about ;;
@@ -1681,6 +1702,71 @@ menu_seeding() {
1681
1702
  menu_seeding
1682
1703
  }
1683
1704
 
1705
+ # ------------------------------------------------------------
1706
+ # Export entities → Prisma / JSON Schema / OpenAPI / Native TS
1707
+ # ------------------------------------------------------------
1708
+ action_export_entities() {
1709
+ header
1710
+ echo -e "${BOLD}${MAGENTA}▶ Export entities to another schema format${RESET}"
1711
+ echo
1712
+ local ent_json="$GENERATED_DIR/entities.json"
1713
+ if [[ ! -f "$ent_json" ]]; then
1714
+ err "No entities.json found — run menu 1 (Convert) first."
1715
+ pause; return
1716
+ fi
1717
+ local count
1718
+ count=$(node -e "console.log(JSON.parse(require('fs').readFileSync('$ent_json','utf8')).length)" 2>/dev/null || echo 0)
1719
+ echo -e " Source : ${DIM}${ent_json}${RESET} (${CYAN}${count}${RESET} entities)"
1720
+ echo
1721
+ echo -e " ${CYAN}1${RESET}) Prisma → ${DIM}schema.prisma${RESET}"
1722
+ echo -e " ${CYAN}2${RESET}) JSON Schema → ${DIM}schema.json${RESET} (2020-12)"
1723
+ echo -e " ${CYAN}3${RESET}) OpenAPI 3.1 → ${DIM}openapi.json${RESET}"
1724
+ echo -e " ${CYAN}4${RESET}) Native (TS) → ${DIM}src/schemas.ts${RESET}"
1725
+ echo
1726
+ echo -e " ${CYAN}b${RESET}) Back"
1727
+ echo
1728
+ local choice
1729
+ choice=$(ask "Format" "1")
1730
+ local format="" default_out=""
1731
+ case "$choice" in
1732
+ 1) format="prisma"; default_out="$PROJECT_ROOT/prisma/schema.prisma" ;;
1733
+ 2) format="jsonschema"; default_out="$PROJECT_ROOT/schema.json" ;;
1734
+ 3) format="openapi"; default_out="$PROJECT_ROOT/openapi.json" ;;
1735
+ 4) format="native"; default_out="$PROJECT_ROOT/src/schemas.ts" ;;
1736
+ b|B) return ;;
1737
+ *) warn "Unknown"; pause; return ;;
1738
+ esac
1739
+ local out
1740
+ out=$(ask "Output file" "$default_out")
1741
+ mkdir -p "$(dirname "$out")"
1742
+
1743
+ # Spawn Node to run the adapter's fromEntitySchema
1744
+ node --input-type=module -e "
1745
+ import('@mostajs/orm-adapter').then(async ({ PrismaAdapter, JsonSchemaAdapter, OpenApiAdapter, NativeAdapter }) => {
1746
+ const entities = JSON.parse(await (await import('fs/promises')).readFile('$ent_json', 'utf8'));
1747
+ let out;
1748
+ switch ('$format') {
1749
+ case 'prisma': out = await new PrismaAdapter().fromEntitySchema(entities); break;
1750
+ case 'jsonschema': out = JSON.stringify(await new JsonSchemaAdapter().fromEntitySchema(entities), null, 2); break;
1751
+ case 'openapi': out = JSON.stringify(await new OpenApiAdapter().fromEntitySchema(entities), null, 2); break;
1752
+ case 'native':
1753
+ out = '// Auto-generated by mostajs export → Native (EntitySchema TS)\n'
1754
+ + '// Author: @mostajs/orm-cli\n\n'
1755
+ + \"import type { EntitySchema } from '@mostajs/orm';\n\n\"
1756
+ + 'export const schemas: EntitySchema[] = '
1757
+ + JSON.stringify(entities, null, 2) + ';\n\n'
1758
+ + '// Named exports for convenience\n'
1759
+ + entities.map(e => 'export const ' + e.name + 'Schema: EntitySchema = schemas.find(s => s.name === \"' + e.name + '\")!;').join('\n')
1760
+ + '\n';
1761
+ break;
1762
+ }
1763
+ await (await import('fs/promises')).writeFile('$out', out);
1764
+ console.log(' ✓ written ' + '$out' + ' (' + (out.length/1024).toFixed(1) + ' KB)');
1765
+ }).catch(e => { console.error(' ✗', e.message); process.exit(1); });
1766
+ " 2>&1
1767
+ pause
1768
+ }
1769
+
1684
1770
  # ------------------------------------------------------------
1685
1771
  # seed : drop tables (interactive picker)
1686
1772
  # ------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/orm-cli",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
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",