create-payload-app 0.3.18-beta.1 → 0.3.19

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",
@@ -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,6 +68,7 @@ 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,
72
73
  });
73
74
  return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'package.json'), packageJson)
@@ -107,8 +108,19 @@ function writeCommonFiles(projectDir, template, packageManager) {
107
108
  dockerCompose = handlebars_1.default.compile(dockerComposeTemplate)(packageManager === 'yarn'
108
109
  ? { installCmd: 'yarn install', devCmd: 'yarn dev' }
109
110
  : { 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)];
111
+ return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'docker-compose.yml'), dockerCompose)
112
+ // Dockerfile
113
+ ];
111
114
  case 11:
115
+ _a.sent();
116
+ return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'Dockerfile.template'), 'utf8')];
117
+ case 12:
118
+ dockerfileTemplate = _a.sent();
119
+ dockerfile = handlebars_1.default.compile(dockerfileTemplate)(packageManager === 'yarn'
120
+ ? { installCmd: 'yarn install', buildCmd: 'yarn build' }
121
+ : { installCmd: 'npm install', buildCmd: 'npm run build' });
122
+ return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'Dockerfile'), dockerfile)];
123
+ case 13:
112
124
  _a.sent();
113
125
  return [2 /*return*/];
114
126
  }
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-beta.1",
39
+ "version": "0.3.19",
40
40
  "devDependencies": {
41
41
  "@types/command-exists": "^1.2.0",
42
42
  "@types/degit": "^2.8.3",