@pradip1995/create-storefront-app 0.4.2 → 0.4.3

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.
@@ -52,5 +52,8 @@
52
52
  "medusa-export",
53
53
  "medusa-payment-provider",
54
54
  "@tsc_tech/medusa-plugin-smtp"
55
+ ],
56
+ "moduleOnlyPlugins": [
57
+ "@tsc_tech/medusa-plugin-smtp"
55
58
  ]
56
59
  }
@@ -104,7 +104,7 @@ export function scaffoldBackend(backendRoot, args) {
104
104
  "backend:build": "backend-build",
105
105
  "db:migrate":
106
106
  "npm run backend:build && cd .generated-backend && npm install && npx medusa db:migrate",
107
- dev: "npm run backend:build && cd .generated-backend && npm install && npm run dev",
107
+ dev: "npm run backend:build && cd .generated-backend && npm install && npx medusa db:migrate && npm run dev",
108
108
  build:
109
109
  "npm run backend:build && cd .generated-backend && npm install && npm run build",
110
110
  start:
package/lib/versions.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** Published package semver ranges — bump when releasing framework/components. */
2
2
  export const COMMERCE_CORE_VERSION = "^4.0.2"
3
3
  export const FRAMEWORK_VERSION = "^0.2.1"
4
- export const FRAMEWORK_COMPILER_VERSION = "^0.3.2"
4
+ export const FRAMEWORK_COMPILER_VERSION = "^0.3.3"
5
5
  export const COMPONENTS_VERSION = ">=0.2.0 <0.4.0"
6
6
 
7
7
  export const FRAMEWORK_PACKAGES = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/create-storefront-app",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Scaffold a segment-based Medusa storefront using @pradip1995/framework packages",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,7 +13,7 @@ Medusa source is **generated** into `.generated-backend/` — same pattern as `s
13
13
  ## Commands
14
14
 
15
15
  ```bash
16
- npm run dev # backend-build → medusa develop
16
+ npm run dev # backend-build → migrate → medusa develop
17
17
  npm run db:migrate # first time (run twice on fresh DB if needed)
18
18
  npm run build # backend-build → medusa build
19
19
  npm run seed # seed demo data
@@ -4,6 +4,39 @@ set -euo pipefail
4
4
  DUMP_PATH="${DUMP_PATH:-/dump/dump.sql}"
5
5
  MIN_TABLES="${MIN_TABLES_FOR_DUMP:-1}"
6
6
 
7
+ table_count() {
8
+ psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -tAc \
9
+ "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';" \
10
+ 2>/dev/null || echo "0"
11
+ }
12
+
13
+ restore_dump_if_empty() {
14
+ if [ -z "${POSTGRES_USER:-}" ] || [ -z "${POSTGRES_DB:-}" ]; then
15
+ return 0
16
+ fi
17
+
18
+ if ! pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" >/dev/null 2>&1; then
19
+ return 0
20
+ fi
21
+
22
+ local count
23
+ count="$(table_count)"
24
+
25
+ if [ "${count:-0}" -ge "$MIN_TABLES" ]; then
26
+ return 0
27
+ fi
28
+
29
+ if [ ! -f "$DUMP_PATH" ] || [ ! -s "$DUMP_PATH" ]; then
30
+ echo "Database empty (${count:-0} tables) and no dump at ${DUMP_PATH} — run npm run migrate:backend"
31
+ return 0
32
+ fi
33
+
34
+ echo "Database empty (${count:-0} tables). Restoring from ${DUMP_PATH} ..."
35
+ psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -v ON_ERROR_STOP=1 -f "$DUMP_PATH"
36
+ count="$(table_count)"
37
+ echo "Database restore complete (${count} tables)."
38
+ }
39
+
7
40
  dump_database() {
8
41
  if [ -z "${POSTGRES_USER:-}" ] || [ -z "${POSTGRES_DB:-}" ]; then
9
42
  return 0
@@ -13,19 +46,15 @@ dump_database() {
13
46
  return 0
14
47
  fi
15
48
 
16
- local table_count
17
- table_count=$(
18
- psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -tAc \
19
- "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';" \
20
- 2>/dev/null || echo "0"
21
- )
49
+ local count
50
+ count="$(table_count)"
22
51
 
23
- if [ "${table_count:-0}" -lt "$MIN_TABLES" ]; then
24
- echo "Skipping dump: public schema has ${table_count:-0} table(s)."
52
+ if [ "${count:-0}" -lt "$MIN_TABLES" ]; then
53
+ echo "Skipping dump: public schema has ${count:-0} table(s)."
25
54
  return 0
26
55
  fi
27
56
 
28
- echo "Saving database dump (${table_count} tables) to ${DUMP_PATH} ..."
57
+ echo "Saving database dump (${count} tables) to ${DUMP_PATH} ..."
29
58
  pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fp > "${DUMP_PATH}.tmp"
30
59
  mv "${DUMP_PATH}.tmp" "${DUMP_PATH}"
31
60
  echo "Database dump saved."
@@ -46,4 +75,11 @@ trap shutdown_postgres SIGTERM SIGINT
46
75
 
47
76
  /usr/local/bin/docker-entrypoint.sh "$@" &
48
77
  child_pid=$!
78
+
79
+ until pg_isready -U "${POSTGRES_USER:-postgres}" -d "${POSTGRES_DB:-postgres}" >/dev/null 2>&1; do
80
+ sleep 1
81
+ done
82
+
83
+ restore_dump_if_empty
84
+
49
85
  wait "$child_pid"