浏览代码

update READMEs

Shahed Nasser 5 月之前
父节点
当前提交
3cfe525858
共有 9 个文件被更改,包括 97 次插入48 次删除
  1. 4 12
      README.md
  2. 2 0
      src/admin/README.md
  3. 2 0
      src/api/README.md
  4. 2 0
      src/jobs/README.md
  5. 10 4
      src/links/README.md
  6. 71 32
      src/modules/README.md
  7. 2 0
      src/scripts/README.md
  8. 2 0
      src/subscribers/README.md
  9. 2 0
      src/workflows/README.md

+ 4 - 12
README.md

@@ -34,27 +34,19 @@
 
 ## Compatibility
 
-This starter is compatible with versions >= 1.8.0 of `@medusajs/medusa`. 
+This starter is compatible with versions >= 2 of `@medusajs/medusa`. 
 
 ## Getting Started
 
-Visit the [Quickstart Guide](https://docs.medusajs.com/learn) to set up a server.
+Visit the [Quickstart Guide](https://docs.medusajs.com/learn/installation) to set up a server.
 
-Visit the [Docs](https://docs.medusajs.com/learn#get-started) to learn more about our system requirements.
+Visit the [Docs](https://docs.medusajs.com/learn/installation#get-started) to learn more about our system requirements.
 
 ## What is Medusa
 
 Medusa is a set of commerce modules and tools that allow you to build rich, reliable, and performant commerce applications without reinventing core commerce logic. The modules can be customized and used to build advanced ecommerce stores, marketplaces, or any product that needs foundational commerce primitives. All modules are open-source and freely available on npm.
 
-Learn more about [Medusa’s architecture](https://docs.medusajs.com/learn/advanced-development/architecture/overview) and [commerce modules](https://docs.medusajs.com/learn/basics/commerce-modules) in the Docs.
-
-## Roadmap, Upgrades & Plugins
-
-You can view the planned, started and completed features in the [Roadmap discussion](https://github.com/medusajs/medusa/discussions/categories/roadmap).
-
-Follow the [Upgrade Guides](https://docs.medusajs.com/upgrade-guides/) to keep your Medusa project up-to-date.
-
-Check out all [available Medusa plugins](https://medusajs.com/plugins/).
+Learn more about [Medusa’s architecture](https://docs.medusajs.com/learn/introduction/architecture) and [commerce modules](https://docs.medusajs.com/learn/fundamentals/modules/commerce-modules) in the Docs.
 
 ## Community & Contributions
 

+ 2 - 0
src/admin/README.md

@@ -2,6 +2,8 @@
 
 You can extend the Medusa Admin to add widgets and new pages. Your customizations interact with API routes to provide merchants with custom functionalities.
 
+> Learn more about Admin Extensions in [this documentation](https://docs.medusajs.com/learn/fundamentals/admin).
+
 ## Example: Create a Widget
 
 A widget is a React component that can be injected into an existing page in the admin dashboard.

+ 2 - 0
src/api/README.md

@@ -4,6 +4,8 @@ An API Route is a REST API endpoint.
 
 An API Route is created in a TypeScript or JavaScript file under the `/src/api` directory of your Medusa application. The file’s name must be `route.ts` or `route.js`.
 
+> Learn more about API Routes in [this documentation](https://docs.medusajs.com/learn/fundamentals/api-routes)
+
 For example, to create a `GET` API Route at `/store/hello-world`, create the file `src/api/store/hello-world/route.ts` with the following content:
 
 ```ts

+ 2 - 0
src/jobs/README.md

@@ -2,6 +2,8 @@
 
 A scheduled job is a function executed at a specified interval of time in the background of your Medusa application.
 
+> Learn more about scheduled jobs in [this documentation](https://docs.medusajs.com/learn/fundamentals/scheduled-jobs).
+
 A scheduled job is created in a TypeScript or JavaScript file under the `src/jobs` directory.
 
 For example, create the file `src/jobs/hello-world.ts` with the following content:

+ 10 - 4
src/links/README.md

@@ -2,19 +2,25 @@
 
 A module link forms an association between two data models of different modules, while maintaining module isolation.
 
+> Learn more about links in [this documentation](https://docs.medusajs.com/learn/fundamentals/module-links)
+
 For example:
 
 ```ts
-import HelloModule from "../modules/hello"
+import BlogModule from "../modules/blog"
 import ProductModule from "@medusajs/medusa/product"
 import { defineLink } from "@medusajs/framework/utils"
 
 export default defineLink(
   ProductModule.linkable.product,
-  HelloModule.linkable.myCustom
+  BlogModule.linkable.post
 )
 ```
 
-This defines a link between the Product Module's `product` data model and the Hello Module (custom module)'s `myCustom` data model.
+This defines a link between the Product Module's `product` data model and the Blog Module (custom module)'s `post` data model.
+
+Then, in the Medusa application, run the following command to sync the links to the database:
 
-Learn more about links in [this documentation](https://docs.medusajs.com/learn/fundamentals/module-links)
+```bash
+npx medusa db:migrate
+```

+ 71 - 32
src/modules/README.md

@@ -1,78 +1,117 @@
 # Custom Module
 
-A module is a package of reusable functionalities. It can be integrated into your Medusa application without affecting the overall system.
+A module is a package of reusable functionalities. It can be integrated into your Medusa application without affecting the overall system. You can create a module as part of a plugin.
+
+> Learn more about modules in [this documentation](https://docs.medusajs.com/learn/fundamentals/modules).
 
 To create a module:
 
-## 1. Create a Service
+## 1. Create a Data Model
+
+A data model represents a table in the database. You create a data model in a TypeScript or JavaScript file under the `models` directory of a module.
+
+For example, create the file `src/modules/blog/models/post.ts` with the following content:
+
+```ts
+import { model } from "@medusajs/framework/utils"
+
+const Post = model.define("post", {
+  id: model.id().primaryKey(),
+  title: model.text(),
+})
+
+export default Post
+```
+
+## 2. Create a Service
 
 A module must define a service. A service is a TypeScript or JavaScript class holding methods related to a business logic or commerce functionality.
 
-For example, create the file `src/modules/hello/service.ts` with the following content:
+For example, create the file `src/modules/blog/service.ts` with the following content:
 
-```ts title="src/modules/hello/service.ts"
-export default class HelloModuleService {
-  getMessage() {
-    return "Hello, world!"
-  }
+```ts
+import { MedusaService } from "@medusajs/framework/utils"
+import Post from "./models/post"
+
+class BlogModuleService extends MedusaService({
+  Post,
+}){
 }
+
+export default BlogModuleService
 ```
 
-## 2. Export Module Definition
+## 3. Export Module Definition
 
 A module must have an `index.ts` file in its root directory that exports its definition. The definition specifies the main service of the module.
 
-For example, create the file `src/modules/hello/index.ts` with the following content:
+For example, create the file `src/modules/blog/index.ts` with the following content:
 
-```ts title="src/modules/hello.index.ts" highlights={[["4", "", "The main service of the module."]]}
-import HelloModuleService from "./service"
+```ts
+import BlogModuleService from "./service"
 import { Module } from "@medusajs/framework/utils"
 
-export const HELLO_MODULE = "hello"
+export const BLOG_MODULE = "blog"
 
-export default Module(HELLO_MODULE, {
-  service: HelloModuleService,
+export default Module(BLOG_MODULE, {
+  service: BlogModuleService,
 })
 ```
 
-## 3. Add Module to Configurations
-
-The last step is to add the module in Medusa’s configurations.
+## 4. Add Module to Medusa's Configurations
 
-In `medusa-config.js`, add the module to the `modules` object:
-
-```js title="medusa-config.js"
-import { HELLO_MODULE } from "./src/modules/hello"
+To start using the module, add it to `medusa-config.ts`:
 
+```ts
 module.exports = defineConfig({
-  // ...
+  projectConfig: {
+    // ...
+  },
   modules: [
     {
-      resolve: "./modules/hello",
-    }
-  ]
+      resolve: "./src/modules/blog",
+    },
+  ],
 })
 ```
 
+## 5. Generate and Run Migrations
+
+To generate migrations for your module, run the following command:
+
+```bash
+npx medusa db:generate blog
+```
+
+Then, to run migrations, run the following command:
+
+```bash
+npx medusa db:migrate
+```
+
 ## Use Module
 
-You can resolve the main service of the module in other resources, such as an API route:
+You can use the module in customizations within the Medusa application, such as workflows and API routes.
+
+For example, to use the module in an API route:
 
 ```ts
 import { MedusaRequest, MedusaResponse } from "@medusajs/framework"
-import HelloModuleService from "../../../modules/hello/service"
-import { HELLO_MODULE } from "../../../modules/hello"
+import BlogModuleService from "../../../modules/blog/service"
+import { BLOG_MODULE } from "../../../modules/blog"
 
 export async function GET(
   req: MedusaRequest,
   res: MedusaResponse
 ): Promise<void> {
-  const helloModuleService: HelloModuleService = req.scope.resolve(
-    HELLO_MODULE
+  const blogModuleService: BlogModuleService = req.scope.resolve(
+    BLOG_MODULE
   )
 
+  const posts = await blogModuleService.listPosts()
+
   res.json({
-    message: helloModuleService.getMessage(),
+    posts
   })
 }
 ```

+ 2 - 0
src/scripts/README.md

@@ -2,6 +2,8 @@
 
 A custom CLI script is a function to execute through Medusa's CLI tool. This is useful when creating custom Medusa tooling to run as a CLI tool.
 
+> Learn more about custom CLI scripts in [this documentation](https://docs.medusajs.com/learn/fundamentals/custom-cli-scripts).
+
 ## How to Create a Custom CLI Script?
 
 To create a custom CLI script, create a TypeScript or JavaScript file under the `src/scripts` directory. The file must default export a function.

+ 2 - 0
src/subscribers/README.md

@@ -2,6 +2,8 @@
 
 Subscribers handle events emitted in the Medusa application.
 
+> Learn more about Subscribers in [this documentation](https://docs.medusajs.com/learn/fundamentals/events-and-subscribers).
+
 The subscriber is created in a TypeScript or JavaScript file under the `src/subscribers` directory.
 
 For example, create the file `src/subscribers/product-created.ts` with the following content:

+ 2 - 0
src/workflows/README.md

@@ -4,6 +4,8 @@ A workflow is a series of queries and actions that complete a task.
 
 The workflow is created in a TypeScript or JavaScript file under the `src/workflows` directory.
 
+> Learn more about workflows in [this documentation](https://docs.medusajs.com/learn/fundamentals/workflows).
+
 For example:
 
 ```ts