Parcourir la source

Prep for next

olivermrbl il y a 2 ans
Parent
commit
1876d5af33
6 fichiers modifiés avec 444 ajouts et 675 suppressions
  1. 0 1
      .env.template
  2. 149 406
      data/seed.json
  3. 50 0
      index.js
  4. 18 23
      medusa-config.js
  5. 22 20
      package.json
  6. 205 225
      yarn.lock

+ 0 - 1
.env.template

@@ -1,6 +1,5 @@
 JWT_SECRET=something
 COOKIE_SECRET=something
 
-DATABASE_TYPE=sqlite
 DATABASE_URL="postgres://localhost/medusa-store"
 REDIS_URL=redis://localhost:6379

+ 149 - 406
data/seed.json

@@ -1,6 +1,9 @@
 {
   "store": {
-    "currencies": ["eur", "usd"]
+    "currencies": [
+      "eur",
+      "usd"
+    ]
   },
   "users": [
     {
@@ -14,18 +17,37 @@
       "name": "EU",
       "currency_code": "eur",
       "tax_rate": 0,
-      "payment_providers": ["manual"],
-      "fulfillment_providers": ["manual"],
-      "countries": ["gb", "de", "dk", "se", "fr", "es", "it"]
+      "payment_providers": [
+        "manual"
+      ],
+      "fulfillment_providers": [
+        "manual"
+      ],
+      "countries": [
+        "gb",
+        "de",
+        "dk",
+        "se",
+        "fr",
+        "es",
+        "it"
+      ]
     },
     {
       "id": "test-region-na",
       "name": "NA",
       "currency_code": "usd",
       "tax_rate": 0,
-      "payment_providers": ["manual"],
-      "fulfillment_providers": ["manual"],
-      "countries": ["us", "ca"]
+      "payment_providers": [
+        "manual"
+      ],
+      "fulfillment_providers": [
+        "manual"
+      ],
+      "countries": [
+        "us",
+        "ca"
+      ]
     }
   ],
   "shipping_options": [
@@ -117,6 +139,11 @@
   "products": [
     {
       "title": "Medusa T-Shirt",
+      "categories": [
+        {
+          "id": "pcat_shirts"
+        }
+      ],
       "subtitle": null,
       "description": "Reimagine the feeling of a classic T-shirt. With our cotton T-shirts, everyday essentials no longer have to be ordinary.",
       "handle": "t-shirt",
@@ -131,11 +158,19 @@
       "options": [
         {
           "title": "Size",
-          "values": ["S", "M", "L", "XL"]
+          "values": [
+            "S",
+            "M",
+            "L",
+            "XL"
+          ]
         },
         {
           "title": "Color",
-          "values": ["Black", "White"]
+          "values": [
+            "Black",
+            "White"
+          ]
         }
       ],
       "variants": [
@@ -327,6 +362,11 @@
     },
     {
       "title": "Medusa Sweatshirt",
+      "categories": [
+        {
+          "id": "pcat_shirts"
+        }
+      ],
       "subtitle": null,
       "description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
       "handle": "sweatshirt",
@@ -339,7 +379,12 @@
       "options": [
         {
           "title": "Size",
-          "values": ["S", "M", "L", "XL"]
+          "values": [
+            "S",
+            "M",
+            "L",
+            "XL"
+          ]
         }
       ],
       "variants": [
@@ -427,6 +472,11 @@
     },
     {
       "title": "Medusa Sweatpants",
+      "categories": [
+        {
+          "id": "pcat_pants"
+        }
+      ],
       "subtitle": null,
       "description": "Reimagine the feeling of classic sweatpants. With our cotton sweatpants, everyday essentials no longer have to be ordinary.",
       "handle": "sweatpants",
@@ -439,7 +489,12 @@
       "options": [
         {
           "title": "Size",
-          "values": ["S", "M", "L", "XL"]
+          "values": [
+            "S",
+            "M",
+            "L",
+            "XL"
+          ]
         }
       ],
       "variants": [
@@ -527,6 +582,11 @@
     },
     {
       "title": "Medusa Shorts",
+      "categories": [
+        {
+          "id": "pcat_merch"
+        }
+      ],
       "subtitle": null,
       "description": "Reimagine the feeling of classic shorts. With our cotton shorts, everyday essentials no longer have to be ordinary.",
       "handle": "shorts",
@@ -539,7 +599,12 @@
       "options": [
         {
           "title": "Size",
-          "values": ["S", "M", "L", "XL"]
+          "values": [
+            "S",
+            "M",
+            "L",
+            "XL"
+          ]
         }
       ],
       "variants": [
@@ -627,6 +692,14 @@
     },
     {
       "title": "Medusa Hoodie",
+      "categories": [
+        {
+          "id": "pcat_merch"
+        },
+        {
+          "id": "pcat_hidden_featured"
+        }
+      ],
       "subtitle": null,
       "description": "Reimagine the feeling of a classic hoodie. With our cotton hoodie, everyday essentials no longer have to be ordinary.",
       "handle": "hoodie",
@@ -639,7 +712,12 @@
       "options": [
         {
           "title": "Size",
-          "values": ["S", "M", "L", "XL"]
+          "values": [
+            "S",
+            "M",
+            "L",
+            "XL"
+          ]
         }
       ],
       "variants": [
@@ -727,6 +805,14 @@
     },
     {
       "title": "Medusa Longsleeve",
+      "categories": [
+        {
+          "id": "pcat_shirts"
+        },
+        {
+          "id": "pcat_hidden_featured"
+        }
+      ],
       "subtitle": null,
       "description": "Reimagine the feeling of a classic longsleeve. With our cotton longsleeve, everyday essentials no longer have to be ordinary.",
       "handle": "longsleeve",
@@ -739,7 +825,12 @@
       "options": [
         {
           "title": "Size",
-          "values": ["S", "M", "L", "XL"]
+          "values": [
+            "S",
+            "M",
+            "L",
+            "XL"
+          ]
         }
       ],
       "variants": [
@@ -827,6 +918,14 @@
     },
     {
       "title": "Medusa Coffee Mug",
+      "categories": [
+        {
+          "id": "pcat_merch"
+        },
+        {
+          "id": "pcat_hidden_featured"
+        }
+      ],
       "subtitle": null,
       "description": "Every programmer's best friend.",
       "handle": "coffee-mug",
@@ -838,7 +937,9 @@
       "options": [
         {
           "title": "Size",
-          "values": ["One Size"]
+          "values": [
+            "One Size"
+          ]
         }
       ],
       "variants": [
@@ -865,399 +966,41 @@
       ]
     }
   ],
-  "categories":[
+  "categories": [
     {
-      "name":"Men",
-      "rank":0,
-      "category_children":[
-        {
-          "name":"Clothing",
-          "rank":0,
-          "category_children":[
-            {
-              "name":"T-shirts & Polos",
-              "rank":0,
-              "category_children":[
-                {
-                  "name":"Basic T-shirts",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/clothing/t-shirts-&-polos/basic-t-shirts"
-                },
-                {
-                  "name":"Printed T-shirts",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/clothing/t-shirts-&-polos/printed-t-shirts"
-                },
-                {
-                  "name":"Tank tops",
-                  "rank":2,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/clothing/t-shirts-&-polos/tank-tops"
-                },
-                {
-                  "name":"Polo shirts",
-                  "rank":3,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/clothing/t-shirts-&-polos/polo-shirts"
-                },
-                {
-                  "name":"Long-sleeved tops",
-                  "rank":4,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/clothing/t-shirts-&-polos/long-sleeved-tops"
-                },
-                {
-                  "name":"Sports T-shirts",
-                  "rank":5,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/clothing/t-shirts-&-polos/sports-t-shirts"
-                }
-              ],
-              "handle":"men/clothing/t-shirts-&-polos"
-            },
-            {
-              "name":"Shirts",
-              "rank":1,
-              "category_children":[
-                {
-                  "name":"Casual Shirts",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/clothing/shirts/casual-shirts"
-                },
-                {
-                  "name":"Business Shirts",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/clothing/shirts/business-shirts"
-                }
-              ],
-              "handle":"men/clothing/shirts"
-            }
-          ],
-          "handle":"men/clothing"
-        },
-        {
-          "name":"Shoes",
-          "rank":1,
-          "category_children":[
-            {
-              "name":"Sneakers",
-              "rank":0,
-              "category_children":[
-                {
-                  "name":"Low-Top Sneakers",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/shoes/sneakers/low-top-sneakers"
-                },
-                {
-                  "name":"High-Top Sneakers",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/shoes/sneakers/high-top-sneakers"
-                },
-                {
-                  "name":"Skate shoes",
-                  "rank":2,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/shoes/sneakers/skate-shoes"
-                }
-              ],
-              "handle":"men/shoes/sneakers"
-            },
-            {
-              "name":"Sports shoes",
-              "rank":1,
-              "category_children":[
-                {
-                  "name":"Running shoes",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/shoes/sports-shoes/running-shoes"
-                },
-                {
-                  "name":"Football boots",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/shoes/sports-shoes/football-boots"
-                },
-                {
-                  "name":"Basketball shoes",
-                  "rank":2,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/shoes/sports-shoes/basketball-shoes"
-                },
-                {
-                  "name":"Indoor shoes",
-                  "rank":3,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/shoes/sports-shoes/indoor-shoes"
-                },
-                {
-                  "name":"Boots",
-                  "rank":4,
-                  "category_children":[
-
-                  ],
-                  "handle":"men/shoes/sports-shoes/boots"
-                }
-              ],
-              "handle":"men/shoes/sports-shoes"
-            },
-            {
-              "name":"Business shoes",
-              "rank":2,
-              "category_children":[
-
-              ],
-              "handle":"men/shoes/business-shoes"
-            }
-          ],
-          "handle":"men/shoes"
-        }
-      ],
-      "handle":"men"
+      "id": "pcat_pants",
+      "name": "Pants",
+      "rank": 0,
+      "category_children": [],
+      "handle": "pants"
     },
     {
-      "name":"Women",
-      "rank":1,
-      "category_children":[
-        {
-          "name":"Clothing",
-          "rank":0,
-          "category_children":[
-            {
-              "name":"Shirts",
-              "rank":0,
-              "category_children":[
-                {
-                  "name":"Casual Shirts",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/clothing/shirts/casual-shirts"
-                },
-                {
-                  "name":"Business Shirts",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/clothing/shirts/business-shirts"
-                }
-              ],
-              "handle":"women/clothing/shirts"
-            },
-            {
-              "name":"Sweatshirts & Hoodies",
-              "rank":1,
-              "category_children":[
-                {
-                  "name":"Hoodies",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/clothing/sweatshirts-&-hoodies/hoodies"
-                },
-                {
-                  "name":"Sweatshirts",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/clothing/sweatshirts-&-hoodies/sweatshirts"
-                }
-              ],
-              "handle":"women/clothing/sweatshirts-&-hoodies"
-            },
-            {
-              "name":"Jeans",
-              "rank":2,
-              "category_children":[
-                {
-                  "name":"Skinny fit",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/clothing/jeans/skinny-fit"
-                },
-                {
-                  "name":"Slim fit",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/clothing/jeans/slim-fit"
-                },
-                {
-                  "name":"Straight leg",
-                  "rank":2,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/clothing/jeans/straight-leg"
-                },
-                {
-                  "name":"Tapered fit",
-                  "rank":3,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/clothing/jeans/tapered-fit"
-                }
-              ],
-              "handle":"women/clothing/jeans"
-            }
-          ],
-          "handle":"women/clothing"
-        },
-        {
-          "name":"Shoes",
-          "rank":1,
-          "category_children":[
-            {
-              "name":"Sports shoes",
-              "rank":0,
-              "category_children":[
-                {
-                  "name":"Running shoes",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/sports-shoes/running-shoes"
-                },
-                {
-                  "name":"Training shoes",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/sports-shoes/training-shoes"
-                },
-                {
-                  "name":"Football boots",
-                  "rank":2,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/sports-shoes/football-boots"
-                },
-                {
-                  "name":"Basketball shoes",
-                  "rank":3,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/sports-shoes/basketball-shoes"
-                },
-                {
-                  "name":"Hiking & mountaineering shoes",
-                  "rank":4,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/sports-shoes/hiking-&-mountaineering-shoes"
-                },
-                {
-                  "name":"Boots",
-                  "rank":5,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/sports-shoes/boots"
-                }
-              ],
-              "handle":"women/shoes/sports-shoes"
-            },
-            {
-              "name":"Business shoes",
-              "rank":1,
-              "category_children":[
-
-              ],
-              "handle":"women/shoes/business-shoes"
-            },
-            {
-              "name":"Boots",
-              "rank":2,
-              "category_children":[
-                {
-                  "name":"Lace-up boots",
-                  "rank":0,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/boots/lace-up-boots"
-                },
-                {
-                  "name":"Ankle boots",
-                  "rank":1,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/boots/ankle-boots"
-                },
-                {
-                  "name":"Winter Boots",
-                  "rank":2,
-                  "category_children":[
-
-                  ],
-                  "handle":"women/shoes/boots/winter-boots"
-                }
-              ],
-              "handle":"women/shoes/boots"
-            },
-            {
-              "name":"Slippers",
-              "rank":3,
-              "category_children":[
-
-              ],
-              "handle":"women/shoes/slippers"
-            }
-          ],
-          "handle":"women/shoes"
-        }
-      ],
-      "handle":"women"
+      "id": "pcat_shirts",
+      "name": "Shirts",
+      "rank": 0,
+      "category_children": [],
+      "handle": "shirts"
+    },
+    {
+      "id": "pcat_merch",
+      "name": "Merch",
+      "rank": 0,
+      "category_children": [],
+      "handle": "merch"
+    },
+    {
+      "id": "pcat_hidden_carousel",
+      "name": "Hidden homepage carousel",
+      "rank": 0,
+      "category_children": [],
+      "handle": "hidden-homepage-carousel"
+    },
+    {
+      "id": "pcat_hidden_featured",
+      "name": "Hidden homepage featured",
+      "rank": 0,
+      "category_children": [],
+      "handle": "hidden-homepage-featured-items"
     }
   ]
-}
+}

+ 50 - 0
index.js

@@ -0,0 +1,50 @@
+const express = require("express")
+const { GracefulShutdownServer } = require("medusa-core-utils")
+
+const loaders = require("@medusajs/medusa/dist/loaders/index").default
+
+;(async() => {
+  async function start() {
+    const app = express()
+    const directory = process.cwd()
+
+    try {
+      const { container } = await loaders({
+        directory,
+        expressApp: app
+      })
+      const configModule = container.resolve("configModule")
+      const port = process.env.PORT ?? configModule.projectConfig.port ?? 9000
+
+      const server = GracefulShutdownServer.create(
+        app.listen(port, (err) => {
+          if (err) {
+            return
+          }
+          console.log(`Server is ready on port: ${port}`)
+        })
+      )
+
+      // Handle graceful shutdown
+      const gracefulShutDown = () => {
+        server
+          .shutdown()
+          .then(() => {
+            console.info("Gracefully stopping the server.")
+            process.exit(0)
+          })
+          .catch((e) => {
+            console.error("Error received when shutting down the server.", e)
+            process.exit(1)
+          })
+      }
+      process.on("SIGTERM", gracefulShutDown)
+      process.on("SIGINT", gracefulShutDown)
+    } catch (err) {
+      console.error("Error starting server", err)
+      process.exit(1)
+    }
+  }
+
+  await start()
+})()

+ 18 - 23
medusa-config.js

@@ -28,20 +28,23 @@ const ADMIN_CORS =
 // CORS to avoid issues when consuming Medusa from a client
 const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000";
 
-const DATABASE_TYPE = process.env.DATABASE_TYPE || "sqlite";
-const DATABASE_URL = process.env.DATABASE_URL || "postgres://localhost/medusa-store";
+const DATABASE_URL =
+  process.env.DATABASE_URL || "postgres://localhost/medusa-db";
+  
 const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";
 
 const plugins = [
   `medusa-fulfillment-manual`,
   `medusa-payment-manual`,
-  {
-    resolve: "@medusajs/admin",
-    /** @type {import('@medusajs/admin').PluginOptions} */
-    options: {
-      autoRebuild: true,
-    },
-  },
+  `@medusajs/file-local`,
+  // To enable the admin plugin, uncomment the following lines and run `yarn add @medusajs/admin`
+  // {
+  //   resolve: "@medusajs/admin",
+  //   /** @type {import('@medusajs/admin').PluginOptions} */
+  //   options: {
+  //     autoRebuild: true,
+  //   },
+  // },
 ];
 
 const modules = {
@@ -57,30 +60,22 @@ const modules = {
       redisUrl: REDIS_URL
     }
   },*/
-}
+};
 
 /** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */
 const projectConfig = {
   jwtSecret: process.env.JWT_SECRET,
   cookieSecret: process.env.COOKIE_SECRET,
-  database_database: "./medusa-db.sql",
-  database_type: DATABASE_TYPE,
   store_cors: STORE_CORS,
+  database_url: DATABASE_URL,
   admin_cors: ADMIN_CORS,
-}
-
-if (REDIS_URL) {
-  projectConfig.redis_url = REDIS_URL;
-}
-
-if (DATABASE_URL) {
-  projectConfig.database_url = DATABASE_URL;
-}
-
+  // Uncomment the following lines to enable REDIS
+  // redis_url: REDIS_URL
+};
 
 /** @type {import('@medusajs/medusa').ConfigModule} */
 module.exports = {
   projectConfig,
   plugins,
-	modules,
+  modules,
 };

+ 22 - 20
package.json

@@ -13,32 +13,34 @@
     "medusa"
   ],
   "scripts": {
-    "clean": "./node_modules/.bin/rimraf dist",
-    "build": "yarn run clean && tsc -p tsconfig.json",
-    "watch": "tsc --watch",
-    "test": "jest",
-    "seed": "medusa seed -f ./data/seed.json",
-    "start": "yarn build && medusa start",
-    "build:admin": "medusa-admin build"
+    "clean": "cross-env ./node_modules/.bin/rimraf dist",
+    "build": "cross-env npm run clean && tsc -p tsconfig.json",
+    "watch": "cross-env tsc --watch",
+    "test": "cross-env jest",
+    "seed": "cross-env medusa seed -f ./data/seed.json",
+    "start": "cross-env npm run build && medusa start",
+    "start:custom": "cross-env npm run build && node --preserve-symlinks index.js",
+    "dev": "cross-env npm run build && medusa develop",
+    "build:admin": "cross-env medusa-admin build"
   },
   "dependencies": {
     "@babel/preset-typescript": "^7.21.4",
-    "@medusajs/admin": "1.0.0-rc.7",
-    "@medusajs/cache-inmemory": "1.8.0-rc.3",
-    "@medusajs/cache-redis": "1.8.0-rc.3",
-    "@medusajs/event-bus-local": "1.8.0-rc.2",
-    "@medusajs/event-bus-redis": "1.8.0-rc.3",
-    "@medusajs/medusa": "1.8.0-rc.7",
-    "@medusajs/medusa-cli": "1.3.9-rc.2",
+    "@medusajs/cache-inmemory": "^1.8.7-next-20230529135657",
+    "@medusajs/cache-redis": "^1.8.7-next-20230529135657",
+    "@medusajs/event-bus-local": "^1.9.4-next-20230529135657",
+    "@medusajs/event-bus-redis": "^1.8.7-next-20230529135657",
+    "@medusajs/file-local": "^1.0.1-next-20230529135657",
+    "@medusajs/medusa": "^1.11.1-next-20230529135657",
+    "@medusajs/medusa-cli": "^1.3.15-next-20230529135657",
     "babel-preset-medusa-package": "^1.1.13",
     "body-parser": "^1.19.0",
     "cors": "^2.8.5",
     "express": "^4.17.2",
-    "medusa-fulfillment-manual": "rc",
-    "medusa-interfaces": "rc",
-    "medusa-payment-manual": "rc",
-    "medusa-payment-stripe": "2.0.0-rc.7",
-    "typeorm": "^0.3.11"
+    "medusa-fulfillment-manual": "^1.1.37-next-20230324075823",
+    "medusa-interfaces": "^1.3.7-next-20230324075823",
+    "medusa-payment-manual": "^1.0.23-next-20230324075823",
+    "medusa-payment-stripe": "^5.0.1-next-20230529135657",
+    "typeorm": "^0.3.16"
   },
   "devDependencies": {
     "@babel/cli": "^7.14.3",
@@ -47,7 +49,7 @@
     "@types/jest": "^27.4.0",
     "@types/node": "^17.0.8",
     "babel-preset-medusa-package": "^1.1.13",
-    "cross-env": "^5.2.1",
+    "cross-env": "^7.0.3",
     "eslint": "^6.8.0",
     "jest": "^27.3.1",
     "mongoose": "^5.13.14",

Fichier diff supprimé car celui-ci est trop grand
+ 205 - 225
yarn.lock


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff