create-payload-app 0.3.18 → 0.3.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ FROM node:18.8-alpine as base
2
+
3
+ FROM base as builder
4
+
5
+ WORKDIR /home/node/app
6
+ COPY package*.json ./
7
+
8
+ COPY . .
9
+ RUN {{installCmd}}
10
+ RUN {{buildCmd}}
11
+
12
+ FROM base as runtime
13
+
14
+ ENV NODE_ENV=production
15
+ ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js
16
+
17
+ WORKDIR /home/node/app
18
+ COPY package*.json ./
19
+
20
+ RUN {{installCmd}} --production
21
+ COPY --from=builder /home/node/app/dist ./dist
22
+ COPY --from=builder /home/node/app/build ./build
23
+
24
+ EXPOSE 3000
25
+
26
+ CMD ["node", "dist/server.js"]
@@ -6,4 +6,14 @@ This project was created using create-payload-app using the {{templateName}} tem
6
6
 
7
7
  `yarn dev` will start up your application and reload on any changes.
8
8
 
9
+ ### Docker
10
+
9
11
  If you have docker and docker-compose installed, you can run `docker-compose up`
12
+
13
+ To build the docker image, run `docker build -t my-tag .`
14
+
15
+ Ensure you are passing all needed environment variables when starting up your container via `--env-file` or setting them with your deployment.
16
+
17
+ The 3 typical env vars will be `MONGODB_URI`, `PAYLOAD_SECRET`, and `PAYLOAD_CONFIG_PATH`
18
+
19
+ `docker run --env-file .env -p 3000:3000 my-tag`
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "payload-template-{{templateName}}",
2
+ "name": "{{projectName}}",
3
3
  "description": "Payload project created from {{templateName}} template",
4
4
  "version": "1.0.0",
5
5
  "main": "dist/server.js",
@@ -8,7 +8,7 @@
8
8
  "dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon",
9
9
  "build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
10
10
  "build:server": "tsc",
11
- "build": "yarn copyfiles && yarn build:payload && yarn build:server",
11
+ "build": "{{runCommand}} copyfiles && {{runCommand}} build:payload && {{runCommand}} build:server",
12
12
  "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
13
13
  "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
14
14
  "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
@@ -79,8 +79,9 @@ describe('createProject', function () {
79
79
  packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
80
80
  packageJson = fs_extra_1.default.readJsonSync(packageJsonPath);
81
81
  expect(packageJson.dependencies.payload).toBe(expectedPayloadVersion);
82
- // Check package name comtains template name
83
- expect(packageJson.name).toContain('ts-todo');
82
+ // Check package name and description
83
+ expect(packageJson.name).toEqual(path_1.default.basename(projectDir));
84
+ expect(packageJson.description).toContain('ts-todo');
84
85
  // Check all common files are create
85
86
  assertProjectFileExists('.npmrc');
86
87
  assertProjectFileExists('.gitignore');
@@ -57,7 +57,7 @@ function getDatabaseConnection(args, projectName) {
57
57
  initial: "mongodb://localhost/".concat(projectName === '.'
58
58
  ? "payload-".concat(getRandomDigitSuffix())
59
59
  : (0, slugify_1.default)(projectName)),
60
- validate: function (value) { return value.length; },
60
+ validate: function (value) { return !!value.length; },
61
61
  }, {
62
62
  onCancel: function () {
63
63
  process.exit(0);
@@ -63,7 +63,7 @@ function parseLanguage(args) {
63
63
  value: 'ts',
64
64
  },
65
65
  ],
66
- validate: function (value) { return value.length; },
66
+ validate: function (value) { return !!value.length; },
67
67
  }, {
68
68
  onCancel: function () {
69
69
  process.exit(0);
@@ -55,7 +55,7 @@ function parseProjectName(args) {
55
55
  type: 'text',
56
56
  name: 'value',
57
57
  message: 'Project name?',
58
- validate: function (value) { return value.length; },
58
+ validate: function (value) { return !!value.length; },
59
59
  }, {
60
60
  onCancel: function () {
61
61
  process.exit(0);
@@ -64,7 +64,7 @@ function parseTemplate(args, validTemplates, language) {
64
64
  choices: filteredTemplates.map(function (p) {
65
65
  return { title: p, value: "".concat(language, "-").concat(p) };
66
66
  }),
67
- validate: function (value) { return value.length; },
67
+ validate: function (value) { return !!value.length; },
68
68
  }, {
69
69
  onCancel: function () {
70
70
  process.exit(0);
@@ -45,7 +45,7 @@ var fs_extra_1 = __importDefault(require("fs-extra"));
45
45
  var handlebars_1 = __importDefault(require("handlebars"));
46
46
  function writeCommonFiles(projectDir, template, packageManager) {
47
47
  return __awaiter(this, void 0, void 0, function () {
48
- var commonFilesDir, npmrc, npmrcDest, gi, giDest, packageJsonTemplate, packageJson, nodemon, nodemonDest, readmeTemplate, readme, tsconfig, tsconfigDest, dockerComposeTemplate, dockerCompose;
48
+ var commonFilesDir, npmrc, npmrcDest, gi, giDest, packageJsonTemplate, packageJson, nodemon, nodemonDest, readmeTemplate, readme, tsconfig, tsconfigDest, dockerComposeTemplate, dockerCompose, dockerfileTemplate, dockerfile;
49
49
  return __generator(this, function (_a) {
50
50
  switch (_a.label) {
51
51
  case 0:
@@ -68,7 +68,9 @@ function writeCommonFiles(projectDir, template, packageManager) {
68
68
  case 3:
69
69
  packageJsonTemplate = _a.sent();
70
70
  packageJson = handlebars_1.default.compile(packageJsonTemplate)({
71
+ projectName: path_1.default.basename(projectDir),
71
72
  templateName: template.name,
73
+ runCommand: packageManager === 'yarn' ? 'yarn' : 'npm run',
72
74
  });
73
75
  return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'package.json'), packageJson)
74
76
  // nodemon.json
@@ -107,8 +109,19 @@ function writeCommonFiles(projectDir, template, packageManager) {
107
109
  dockerCompose = handlebars_1.default.compile(dockerComposeTemplate)(packageManager === 'yarn'
108
110
  ? { installCmd: 'yarn install', devCmd: 'yarn dev' }
109
111
  : { installCmd: 'npm install', devCmd: 'npm run dev' });
110
- return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'docker-compose.yml'), dockerCompose)];
112
+ return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'docker-compose.yml'), dockerCompose)
113
+ // Dockerfile
114
+ ];
111
115
  case 11:
116
+ _a.sent();
117
+ return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'Dockerfile.template'), 'utf8')];
118
+ case 12:
119
+ dockerfileTemplate = _a.sent();
120
+ dockerfile = handlebars_1.default.compile(dockerfileTemplate)(packageManager === 'yarn'
121
+ ? { installCmd: 'yarn install', buildCmd: 'yarn build' }
122
+ : { installCmd: 'npm install', buildCmd: 'npm run build' });
123
+ return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'Dockerfile'), dockerfile)];
124
+ case 13:
112
125
  _a.sent();
113
126
  return [2 /*return*/];
114
127
  }
package/package.json CHANGED
@@ -36,7 +36,7 @@
36
36
  "prompts": "^2.4.0",
37
37
  "terminal-link": "^2.1.1"
38
38
  },
39
- "version": "0.3.18",
39
+ "version": "0.3.20",
40
40
  "devDependencies": {
41
41
  "@types/command-exists": "^1.2.0",
42
42
  "@types/degit": "^2.8.3",