@vendure/create 2.0.0-next.9 → 2.0.1

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.
@@ -0,0 +1,14 @@
1
+ APP_ENV=dev
2
+ COOKIE_SECRET={{ cookieSecret }}
3
+ SUPERADMIN_USERNAME={{{ escapeSingle superadminIdentifier }}}
4
+ SUPERADMIN_PASSWORD={{{ escapeSingle superadminPassword }}}
5
+ {{#if requiresConnection}}
6
+ DB_HOST={{ dbHost }}
7
+ DB_PORT={{ dbPort }}
8
+ DB_NAME={{{ escapeSingle dbName }}}
9
+ DB_USERNAME={{{ escapeSingle dbUserName }}}
10
+ DB_PASSWORD={{{ escapeSingle dbPassword }}}
11
+ {{/if}}
12
+ {{#if dbSchema}}
13
+ DB_SCHEMA={{ dbSchema }}
14
+ {{/if}}
@@ -0,0 +1,9 @@
1
+ FROM node:16
2
+
3
+ WORKDIR /usr/src/app
4
+
5
+ COPY package.json ./
6
+ COPY {{#if useYarn}}yarn.lock{{else}}package-lock.json{{/if}} ./
7
+ RUN {{#if useYarn}}yarn{{else}}npm install{{/if}} --production
8
+ COPY . .
9
+ RUN {{#if useYarn}}yarn{{else}}npm run{{/if}} build
@@ -0,0 +1,39 @@
1
+ version: "3"
2
+ services:
3
+ server:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile
7
+ ports:
8
+ - 3000:3000
9
+ command: [{{#if useYarn}}"yarn"{{else}}"npm", "run"{{/if}}, "start:server"]
10
+ volumes:
11
+ - /usr/src/app
12
+ environment:
13
+ DB_HOST: database
14
+ DB_PORT: 5432
15
+ DB_NAME: vendure
16
+ DB_USERNAME: postgres
17
+ DB_PASSWORD: password
18
+ worker:
19
+ build:
20
+ context: .
21
+ dockerfile: Dockerfile
22
+ command: [{{#if useYarn}}"yarn"{{else}}"npm", "run"{{/if}}, "start:worker"]
23
+ volumes:
24
+ - /usr/src/app
25
+ environment:
26
+ DB_HOST: database
27
+ DB_PORT: 5432
28
+ DB_NAME: vendure
29
+ DB_USERNAME: postgres
30
+ DB_PASSWORD: password
31
+ database:
32
+ image: postgres
33
+ volumes:
34
+ - /var/lib/postgresql/data
35
+ ports:
36
+ - 5432:5432
37
+ environment:
38
+ POSTGRES_PASSWORD: password
39
+ POSTGRES_DB: vendure
@@ -0,0 +1,24 @@
1
+ export {};
2
+
3
+ // Here we declare the members of the process.env object, so that we
4
+ // can use them in our application code in a type-safe manner.
5
+ declare global {
6
+ namespace NodeJS {
7
+ interface ProcessEnv {
8
+ APP_ENV: string;
9
+ COOKIE_SECRET: string;
10
+ SUPERADMIN_USERNAME: string;
11
+ SUPERADMIN_PASSWORD: string;
12
+ {{#if requiresConnection}}
13
+ DB_HOST: string;
14
+ DB_PORT: number;
15
+ DB_NAME: string;
16
+ DB_USERNAME: string;
17
+ DB_PASSWORD: string;
18
+ {{/if}}
19
+ {{#if dbSchema}}
20
+ DB_SCHEMA: string;
21
+ {{/if}}
22
+ }
23
+ }
24
+ }
@@ -1,9 +1,8 @@
1
- {{#if isTs }}import { bootstrapWorker } from '@vendure/core';{{else}}const { bootstrapWorker } = require('@vendure/core');{{/if}}
2
- {{#if isTs }}import { config } from './vendure-config';{{else}}const { config } = require('./vendure-config');{{/if}}
1
+ import { bootstrapWorker } from '@vendure/core';
2
+ import { config } from './vendure-config';
3
3
 
4
4
  bootstrapWorker(config)
5
- .then(worker => worker.startJobQueue())
6
- .catch(err => {
7
- // tslint:disable-next-line:no-console
8
- console.log(err);
9
- });
5
+ .then(worker => worker.startJobQueue())
6
+ .catch(err => {
7
+ console.log(err);
8
+ });
package/assets/index.hbs CHANGED
@@ -1,7 +1,8 @@
1
- {{#if isTs }}import { bootstrap } from '@vendure/core';{{else}}const { bootstrap } = require('@vendure/core');{{/if}}
2
- {{#if isTs }}import { config } from './vendure-config';{{else}}const { config } = require('./vendure-config');{{/if}}
1
+ import { bootstrap, runMigrations } from '@vendure/core';
2
+ import { config } from './vendure-config';
3
3
 
4
- bootstrap(config).catch(err => {
5
- // tslint:disable-next-line:no-console
6
- console.log(err);
7
- });
4
+ runMigrations(config)
5
+ .then(() => bootstrap(config))
6
+ .catch(err => {
7
+ console.log(err);
8
+ });
@@ -1,13 +1,13 @@
1
- {{#if isTs }}import { generateMigration, revertLastMigration, runMigrations } from '@vendure/core';{{else}}const { generateMigration, revertLastMigration, runMigrations } = require('@vendure/core');{{/if}}
2
- {{#if isTs }}import program from 'commander';{{else}}const program = require('commander');{{/if}}
1
+ import { generateMigration, revertLastMigration, runMigrations } from '@vendure/core';
2
+ import program from 'commander';
3
3
 
4
- {{#if isTs }}import { config } from './src/vendure-config';{{else}}const { config } = require('./src/vendure-config');{{/if}}
4
+ import { config } from './src/vendure-config';
5
5
 
6
6
  program
7
7
  .command('generate <name>')
8
8
  .description('Generate a new migration file with the given name')
9
9
  .action(name => {
10
- return generateMigration(config, { name, outputDir: './migrations' });
10
+ return generateMigration(config, { name, outputDir: './src/migrations' });
11
11
  });
12
12
 
13
13
  program
package/assets/readme.hbs CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This project was generated with [`@vendure/create`](https://github.com/vendure-ecommerce/vendure/tree/master/packages/create).
4
4
 
5
+ Useful links:
6
+
7
+ - [Vendure docs](https://www.vendure.io/docs)
8
+ - [Vendure Discord community](https://www.vendure.io/community)
9
+ - [Vendure on GitHub](https://github.com/vendure-ecommerce/vendure)
10
+ - [Vendure plugin template](https://github.com/vendure-ecommerce/plugin-template)
11
+
5
12
  ## Directory structure
6
13
 
7
14
  * `/src` contains the source code of your Vendure server. All your custom code and plugins should reside here.
@@ -10,48 +17,108 @@ This project was generated with [`@vendure/create`](https://github.com/vendure-e
10
17
  ## Development
11
18
 
12
19
  ```
13
- yarn start
14
- # or
15
- npm run start
20
+ {{#if useYarn}}yarn dev{{else}}npm run dev{{/if}}
16
21
  ```
17
22
 
18
23
  will start the Vendure server and [worker](https://www.vendure.io/docs/developer-guide/vendure-worker/) processes from
19
24
  the `src` directory.
20
25
 
21
- {{#if isTs}}## Build
26
+ ## Build
22
27
 
23
28
  ```
24
- yarn build
25
- # or
26
- npm run build
29
+ {{#if useYarn}}yarn build{{else}}npm run build{{/if}}
27
30
  ```
28
31
 
29
- will compile the TypeScript sources into the `/dist` directory.{{/if}}
32
+ will compile the TypeScript sources into the `/dist` directory.
33
+
34
+ ## Production
35
+
36
+ For production, there are many possibilities which depend on your operational requirements as well as your production
37
+ hosting environment.
38
+
39
+ ### Running directly
40
+
41
+ You can run the built files directly with the `start` script:
42
+
43
+ ```
44
+ {{#if useYarn}}yarn start{{else}}npm run start{{/if}}
45
+ ```
46
+
47
+ You could also consider using a process manager like [pm2](https://pm2.keymetrics.io/) to run and manage
48
+ the server & worker processes.
49
+
50
+ ### Using Docker
51
+
52
+ We've included a sample [Dockerfile](./Dockerfile) which you can build with the following command:
53
+
54
+ ```
55
+ docker build -t vendure .
56
+ ```
57
+
58
+ This builds an image and tags it with the name "vendure". We can then run it with:
59
+
60
+ ```
61
+ # Run the server
62
+ docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-server vendure npm run start:server
63
+
64
+ # Run the worker
65
+ docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-worker vendure npm run start:worker
66
+ ```
67
+
68
+ Here is a breakdown of the command used above:
69
+
70
+ - `docker run` - run the image we created with `docker build`
71
+ - `-dp 3000:3000` - the `-d` flag means to run in "detached" mode, so it runs in the background and does not take
72
+ control of your terminal. `-p 3000:3000` means to expose port 3000 of the container (which is what Vendure listens
73
+ on by default) as port 3000 on your host machine.
74
+ - `-e "DB_HOST=host.docker.internal"` - the `-e` option allows you to define environment variables. In this case we
75
+ are setting the `DB_HOST` to point to a special DNS name that is created by Docker desktop which points to the IP of
76
+ the host machine. Note that `host.docker.internal` only exists in a Docker Desktop environment and thus should only be
77
+ used in development.
78
+ - `--name vendure-server` - we give the container a human-readable name.
79
+ - `vendure` - we are referencing the tag we set up during the build.
80
+ - `npm run start:server` - this last part is the actual command that should be run inside the container.
81
+
82
+ ### Docker compose
83
+
84
+ We've included a sample [docker-compose.yml](./docker-compose.yml) file which demonstrates how the server, worker, and
85
+ database may be orchestrated with Docker Compose.
86
+
87
+ ## Plugins
88
+
89
+ In Vendure, your custom functionality will live in [plugins](https://www.vendure.io/docs/plugins/).
90
+ These should be located in the `./src/plugins` directory.
30
91
 
31
92
  ## Migrations
32
93
 
33
- [Migrations](https://www.vendure.io/docs/developer-guide/migrations/) allow safe updates to the database schema.
94
+ [Migrations](https://www.vendure.io/docs/developer-guide/migrations/) allow safe updates to the database schema. Migrations
95
+ will be required whenever you make changes to the `customFields` config or define new entities in a plugin.
34
96
 
35
97
  The following npm scripts can be used to generate migrations:
36
98
 
37
99
  ```
38
- yarn migration:generate [name]
39
- # or
40
- npm run migration:generate [name]
100
+ {{#if useYarn}}yarn{{else}}npm run{{/if}} migration:generate [name]
41
101
  ```
42
102
 
43
- run any pending migrations that have been generated:
103
+ The generated migration file will be found in the `./src/migrations/` directory, and should be committed to source control.
104
+ Next time you start the server, and outstanding migrations found in that directory will be run by the `runMigrations()`
105
+ function in the [index.ts file](./src/index.ts).
106
+
107
+ If, during initial development, you do not wish to manually generate a migration on each change to customFields etc, you
108
+ can set `dbConnectionOptions.synchronize` to `true`. This will cause the database schema to get automatically updated
109
+ on each start, removing the need for migration files. Note that this is **not** recommended once you have production
110
+ data that you cannot lose.
111
+
112
+ ---
113
+
114
+ You can also run any pending migrations manually, without starting the server by running:
44
115
 
45
116
  ```
46
- yarn migration:run
47
- # or
48
- npm run migration:run
117
+ {{#if useYarn}}yarn{{else}}npm run{{/if}} migration:run
49
118
  ```
50
119
 
51
- and revert the most recently-applied migration:
120
+ You can revert the most recently-applied migration with:
52
121
 
53
122
  ```
54
- yarn migration:revert
55
- # or
56
- npm run migration:revert
123
+ {{#if useYarn}}yarn{{else}}npm run{{/if}} migration:revert
57
124
  ```
@@ -5,11 +5,16 @@
5
5
  "esModuleInterop": true,
6
6
  "emitDecoratorMetadata": true,
7
7
  "experimentalDecorators": true,
8
- "target": "es2017",
8
+ "strictPropertyInitialization": false,
9
+ "target": "es2019",
9
10
  "strict": true,
10
11
  "sourceMap": false,
12
+ "skipLibCheck": true,
11
13
  "outDir": "./dist",
12
14
  "baseUrl": "./"
13
15
  },
14
- "exclude": ["node_modules", "migration.ts"]
16
+ "exclude": ["node_modules", "migration.ts"],
17
+ "ts-node": {
18
+ "files": true
19
+ }
15
20
  }
@@ -1,82 +1,82 @@
1
- {{#if isTs }}import{{ else }}const{{/if}} {
1
+ import {
2
2
  dummyPaymentHandler,
3
3
  DefaultJobQueuePlugin,
4
- DefaultSearchPlugin,{{#if isTs}}
5
- VendureConfig,{{/if}}
6
- } {{#if isTs}}from '@vendure/core'; {{ else }}= require('@vendure/core');{{/if}}
7
- {{#if isTs }}
4
+ DefaultSearchPlugin,
5
+ VendureConfig,
6
+ } from '@vendure/core';
8
7
  import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
9
- {{ else }}
10
- const { defaultEmailHandlers, EmailPlugin } = require('@vendure/email-plugin');
11
- {{/if}}
12
- {{#if isTs }}
13
8
  import { AssetServerPlugin } from '@vendure/asset-server-plugin';
14
- {{ else }}
15
- const { AssetServerPlugin } = require('@vendure/asset-server-plugin');
16
- {{/if}}
17
- {{#if isTs }}
18
9
  import { AdminUiPlugin } from '@vendure/admin-ui-plugin';
19
- {{ else }}
20
- const { AdminUiPlugin } = require('@vendure/admin-ui-plugin');
21
- {{/if}}
22
- {{#if isTs }}
10
+ import 'dotenv/config';
23
11
  import path from 'path';
24
- {{ else }}
25
- const path = require('path');
26
- {{/if}}
27
12
 
28
- {{#if isTs}}export {{/if}}const config{{#if isTs}}: VendureConfig{{/if}} = {
13
+ const IS_DEV = process.env.APP_ENV === 'dev';
14
+
15
+ export const config: VendureConfig = {
29
16
  apiOptions: {
30
17
  port: 3000,
31
18
  adminApiPath: 'admin-api',
32
- adminApiPlayground: {
33
- settings: {
34
- 'request.credentials': 'include',
35
- }{{#if isTs}} as any{{/if}},
36
- },// turn this off for production
37
- adminApiDebug: true, // turn this off for production
38
19
  shopApiPath: 'shop-api',
39
- shopApiPlayground: {
40
- settings: {
41
- 'request.credentials': 'include',
42
- }{{#if isTs}} as any{{/if}},
43
- },// turn this off for production
44
- shopApiDebug: true,// turn this off for production
20
+ // The following options are useful in development mode,
21
+ // but are best turned off for production for security
22
+ // reasons.
23
+ ...(IS_DEV ? {
24
+ adminApiPlayground: {
25
+ settings: { 'request.credentials': 'include' } as any,
26
+ },
27
+ adminApiDebug: true,
28
+ shopApiPlayground: {
29
+ settings: { 'request.credentials': 'include' } as any,
30
+ },
31
+ shopApiDebug: true,
32
+ } : {}),
45
33
  },
46
34
  authOptions: {
35
+ tokenMethod: ['bearer', 'cookie'],
47
36
  superadminCredentials: {
48
- identifier: '{{{ escapeSingle superadminIdentifier }}}',
49
- password: '{{{ escapeSingle superadminPassword }}}',
37
+ identifier: process.env.SUPERADMIN_USERNAME,
38
+ password: process.env.SUPERADMIN_PASSWORD,
50
39
  },
51
40
  cookieOptions: {
52
- secret: process.env.COOKIE_SECRET || 'cookie-secret',
41
+ secret: process.env.COOKIE_SECRET,
53
42
  },
54
43
  },
55
44
  dbConnectionOptions: {
56
45
  type: '{{ dbType }}',
57
- synchronize: true, // turn this off for production
46
+ // See the README.md "Migrations" section for an explanation of
47
+ // the `synchronize` and `migrations` options.
48
+ synchronize: false,
49
+ migrations: [path.join(__dirname, './migrations/*.+(js|ts)')],
58
50
  logging: false,
59
- database: {{#if isSQLjs}}new Uint8Array([]){{else if isSQLite}}path.join(__dirname, '../vendure.sqlite'){{else}}'{{{ escapeSingle dbName }}}'{{/if}},
51
+ database: {{#if isSQLjs}}new Uint8Array([]){{else if isSQLite}}path.join(__dirname, '../vendure.sqlite'){{else}}process.env.DB_NAME{{/if}},
52
+ {{#if dbSchema}}
53
+ schema: process.env.DB_SCHEMA,
54
+ {{/if}}
60
55
  {{#if isSQLjs}}
61
56
  location: path.join(__dirname, 'vendure.sqlite'),
62
57
  autoSave: true,
63
58
  {{/if}}
64
59
  {{#if requiresConnection}}
65
- host: '{{ dbHost }}',
66
- port: {{ dbPort }},
67
- username: '{{{ escapeSingle dbUserName }}}',
68
- password: '{{{ escapeSingle dbPassword }}}',
60
+ host: process.env.DB_HOST,
61
+ port: +process.env.DB_PORT,
62
+ username: process.env.DB_USERNAME,
63
+ password: process.env.DB_PASSWORD,
69
64
  {{/if}}
70
- migrations: [path.join(__dirname, '../migrations/*.ts')],
71
65
  },
72
66
  paymentOptions: {
73
67
  paymentMethodHandlers: [dummyPaymentHandler],
74
68
  },
69
+ // When adding or altering custom field definitions, the database will
70
+ // need to be updated. See the "Migrations" section in README.md.
75
71
  customFields: {},
76
72
  plugins: [
77
73
  AssetServerPlugin.init({
78
74
  route: 'assets',
79
75
  assetUploadDir: path.join(__dirname, '../static/assets'),
76
+ // For local dev, the correct value for assetUrlPrefix should
77
+ // be guessed correctly, but for production it will usually need
78
+ // to be set manually to match your production url.
79
+ assetUrlPrefix: IS_DEV ? undefined : 'https://www.my-shop.com/assets',
80
80
  }),
81
81
  DefaultJobQueuePlugin.init({ useDatabaseForBuffer: true }),
82
82
  DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: true }),
@@ -87,7 +87,8 @@ const path = require('path');
87
87
  handlers: defaultEmailHandlers,
88
88
  templatePath: path.join(__dirname, '../static/email/templates'),
89
89
  globalTemplateVars: {
90
- // The following variables will change depending on your storefront implementation
90
+ // The following variables will change depending on your storefront implementation.
91
+ // Here we are assuming a storefront running at http://localhost:8080.
91
92
  fromAddress: '"example" <noreply@example.com>',
92
93
  verifyEmailAddressUrl: 'http://localhost:8080/verify',
93
94
  passwordResetUrl: 'http://localhost:8080/password-reset',
@@ -100,8 +101,3 @@ const path = require('path');
100
101
  }),
101
102
  ],
102
103
  };
103
- {{#if isTs}}
104
- {{else}}
105
-
106
- module.exports = { config };
107
- {{/if}}
@@ -1,7 +1,7 @@
1
- export declare const REQUIRED_NODE_VERSION = ">=10.13.0";
1
+ export declare const REQUIRED_NODE_VERSION = ">=14.0.0";
2
2
  export declare const SERVER_PORT = 3000;
3
3
  /**
4
4
  * The TypeScript version needs to pinned because minor versions often
5
5
  * introduce breaking changes.
6
6
  */
7
- export declare const TYPESCRIPT_VERSION = "4.3.5";
7
+ export declare const TYPESCRIPT_VERSION = "4.9.5";
package/lib/constants.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TYPESCRIPT_VERSION = exports.SERVER_PORT = exports.REQUIRED_NODE_VERSION = void 0;
4
- exports.REQUIRED_NODE_VERSION = '>=10.13.0';
4
+ exports.REQUIRED_NODE_VERSION = '>=14.0.0';
5
5
  exports.SERVER_PORT = 3000;
6
6
  /**
7
7
  * The TypeScript version needs to pinned because minor versions often
8
8
  * introduce breaking changes.
9
9
  */
10
- exports.TYPESCRIPT_VERSION = '4.3.5';
10
+ exports.TYPESCRIPT_VERSION = '4.9.5';
11
11
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,WAAW,CAAC;AACpC,QAAA,WAAW,GAAG,IAAI,CAAC;AAChC;;;GAGG;AACU,QAAA,kBAAkB,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,UAAU,CAAC;AACnC,QAAA,WAAW,GAAG,IAAI,CAAC;AAChC;;;GAGG;AACU,QAAA,kBAAkB,GAAG,OAAO,CAAC"}
@@ -1 +1,2 @@
1
- export {};
1
+ import { CliLogLevel } from './types';
2
+ export declare function createVendureApp(name: string | undefined, useNpm: boolean, logLevel: CliLogLevel, isCi?: boolean): Promise<void>;