瀏覽代碼

fixes to seed script

Shahed Nasser 1 年之前
父節點
當前提交
de9530f9f9
共有 2 個文件被更改,包括 34 次插入16 次删除
  1. 3 7
      src/scripts/README.md
  2. 31 9
      src/scripts/seed.ts

+ 3 - 7
src/scripts/README.md

@@ -33,15 +33,12 @@ The function receives as a parameter an object having a `container` property, wh
 
 ## How to Run Custom CLI Script?
 
-To run the custom CLI script, `build` your code then run the `exec` command:
+To run the custom CLI script, run the `exec` command:
 
 ```bash
-npm run build
-npx medusa exec ./dist/scripts/my-script.js
+npx medusa exec ./src/scripts/my-script.ts
 ```
 
-Notice that you pass the path to the file in the `dist` directory.
-
 ---
 
 ## Custom CLI Script Arguments
@@ -63,6 +60,5 @@ export default async function myScript ({
 Then, pass the arguments in the `exec` command after the file path:
 
 ```bash
-npm run build
-npx medusa exec ./dist/scripts/my-script.js arg1 arg2
+npx medusa exec ./src/scripts/my-script.ts arg1 arg2
 ```

+ 31 - 9
src/scripts/seed.ts

@@ -24,6 +24,7 @@ import {
   linkSalesChannelsToApiKeyWorkflow,
   createProductCategoryWorkflow,
   createProductsWorkflow,
+  createTaxRegionsWorkflow
 } from "@medusajs/core-flows"
 
 export default async function seedDemoData({
@@ -41,6 +42,16 @@ export default async function seedDemoData({
   const salesChannelModuleService: ISalesChannelModuleService = container.resolve(
     ModuleRegistrationName.SALES_CHANNEL
   )
+
+  const countries = [
+    "gb",
+    "de",
+    "dk",
+    "se",
+    "fr",
+    "es",
+    "it"
+  ]
   
   try {
     logger.info("Seeding region data...")
@@ -50,15 +61,7 @@ export default async function seedDemoData({
           regions: [{
             name: "Europe",
             currency_code: "eur",
-            countries: [
-              "gb",
-              "de",
-              "dk",
-              "se",
-              "fr",
-              "es",
-              "it"
-            ],
+            countries,
             payment_providers: ["pp_system_default"]
           }]
         }
@@ -66,6 +69,15 @@ export default async function seedDemoData({
     const region = regionResult[0]
     logger.info("Finished seeding regions.")
 
+    logger.info("Seeding tax regions...")
+    await createTaxRegionsWorkflow(container)
+      .run({
+        input: countries.map((country_code) => ({
+          country_code
+        }))
+      })
+    logger.info("Finished seeding tax regions.")
+
     logger.info("Seeding fulfillment data...")
     const { 
       result: shippingProfileResult
@@ -145,6 +157,11 @@ export default async function seedDemoData({
                 attribute: "enabled_in_store",
                 value: "true",
                 operator: "eq"
+              },
+              {
+                attribute: "is_return",
+                value: "false",
+                operator: "eq"
               }
             ]
           },
@@ -170,6 +187,11 @@ export default async function seedDemoData({
                 attribute: "enabled_in_store",
                 value: "true",
                 operator: "eq"
+              },
+              {
+                attribute: "is_return",
+                value: "false",
+                operator: "eq"
               }
             ]
           }