readme.hbs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # {{ name }}
  2. This project was generated with [`@vendure/create`](https://github.com/vendure-ecommerce/vendure/tree/master/packages/create).
  3. Useful links:
  4. - [Vendure docs](https://www.vendure.io/docs)
  5. - [Vendure Discord community](https://www.vendure.io/community)
  6. - [Vendure on GitHub](https://github.com/vendure-ecommerce/vendure)
  7. - [Vendure plugin template](https://github.com/vendure-ecommerce/plugin-template)
  8. ## Directory structure
  9. * `/src` contains the source code of your Vendure server. All your custom code and plugins should reside here.
  10. * `/static` contains static (non-code) files such as assets (e.g. uploaded images) and email templates.
  11. ## Development
  12. ```
  13. {{#if useYarn}}yarn dev{{else}}npm run dev{{/if}}
  14. ```
  15. will start the Vendure server and [worker](https://www.vendure.io/docs/developer-guide/vendure-worker/) processes from
  16. the `src` directory.
  17. ## Build
  18. ```
  19. {{#if useYarn}}yarn build{{else}}npm run build{{/if}}
  20. ```
  21. will compile the TypeScript sources into the `/dist` directory.
  22. ## Production
  23. For production, there are many possibilities which depend on your operational requirements as well as your production
  24. hosting environment.
  25. ### Running directly
  26. You can run the built files directly with the `start` script:
  27. ```
  28. {{#if useYarn}}yarn start{{else}}npm run start{{/if}}
  29. ```
  30. You could also consider using a process manager like [pm2](https://pm2.keymetrics.io/) to run and manage
  31. the server & worker processes.
  32. ### Using Docker
  33. We've included a sample [Dockerfile](./Dockerfile) which you can build with the following command:
  34. ```
  35. docker build -t vendure .
  36. ```
  37. This builds an image and tags it with the name "vendure". We can then run it with:
  38. ```
  39. # Run the server
  40. docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-server vendure npm run start:server
  41. # Run the worker
  42. docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-worker vendure npm run start:worker
  43. ```
  44. Here is a breakdown of the command used above:
  45. - `docker run` - run the image we created with `docker build`
  46. - `-dp 3000:3000` - the `-d` flag means to run in "detached" mode, so it runs in the background and does not take
  47. control of your terminal. `-p 3000:3000` means to expose port 3000 of the container (which is what Vendure listens
  48. on by default) as port 3000 on your host machine.
  49. - `-e "DB_HOST=host.docker.internal"` - the `-e` option allows you to define environment variables. In this case we
  50. are setting the `DB_HOST` to point to a special DNS name that is created by Docker desktop which points to the IP of
  51. the host machine. Note that `host.docker.internal` only exists in a Docker Desktop environment and thus should only be
  52. used in development.
  53. - `--name vendure-server` - we give the container a human-readable name.
  54. - `vendure` - we are referencing the tag we set up during the build.
  55. - `npm run start:server` - this last part is the actual command that should be run inside the container.
  56. ### Docker compose
  57. We've included a sample [docker-compose.yml](./docker-compose.yml) file which demonstrates how the server, worker, and
  58. database may be orchestrated with Docker Compose.
  59. ## Plugins
  60. In Vendure, your custom functionality will live in [plugins](https://www.vendure.io/docs/plugins/).
  61. These should be located in the `./src/plugins` directory.
  62. ## Migrations
  63. [Migrations](https://www.vendure.io/docs/developer-guide/migrations/) allow safe updates to the database schema. Migrations
  64. will be required whenever you make changes to the `customFields` config or define new entities in a plugin.
  65. The following npm scripts can be used to generate migrations:
  66. ```
  67. {{#if useYarn}}yarn{{else}}npm run{{/if}} migration:generate [name]
  68. ```
  69. The generated migration file will be found in the `./src/migrations/` directory, and should be committed to source control.
  70. Next time you start the server, and outstanding migrations found in that directory will be run by the `runMigrations()`
  71. function in the [index.ts file](./src/index.ts).
  72. If, during initial development, you do not wish to manually generate a migration on each change to customFields etc, you
  73. can set `dbConnectionOptions.synchronize` to `true`. This will cause the database schema to get automatically updated
  74. on each start, removing the need for migration files. Note that this is **not** recommended once you have production
  75. data that you cannot lose.
  76. ---
  77. You can also run any pending migrations manually, without starting the server by running:
  78. ```
  79. {{#if useYarn}}yarn{{else}}npm run{{/if}} migration:run
  80. ```
  81. You can revert the most recently-applied migration with:
  82. ```
  83. {{#if useYarn}}yarn{{else}}npm run{{/if}} migration:revert
  84. ```