create-payload-app 0.3.14 → 0.3.15-beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. package/bin/cli.js +0 -0
  2. package/dist/index.js +14 -26
  3. package/dist/lib/common-files/README.template.md +9 -0
  4. package/dist/lib/common-files/docker-compose.template.yml +35 -0
  5. package/dist/{templates → lib/common-files}/gitignore.template +0 -0
  6. package/dist/{templates/js-blank → lib/common-files/javascript}/nodemon.json +0 -0
  7. package/dist/{templates/js-blank/package.json → lib/common-files/javascript/package.template.json} +3 -3
  8. package/dist/{templates → lib/common-files}/npmrc.template +0 -0
  9. package/dist/{templates/ts-blank → lib/common-files/typescript}/nodemon.json +0 -0
  10. package/dist/{templates/ts-blank/package.json → lib/common-files/typescript/package.template.json} +4 -4
  11. package/dist/{templates/ts-blank → lib/common-files/typescript}/tsconfig.json +0 -0
  12. package/dist/lib/{createProject.js → create-project.js} +25 -26
  13. package/dist/lib/{createProject.test.js → create-project.test.js} +36 -6
  14. package/dist/lib/{generateSecret.js → generate-secret.js} +0 -0
  15. package/dist/lib/{getDatabaseConnection.js → get-db-connection.js} +0 -0
  16. package/dist/lib/{parseLanguage.js → parse-language.js} +0 -0
  17. package/dist/lib/{parseProjectName.js → parse-project-name.js} +0 -0
  18. package/dist/lib/{parseTemplate.js → parse-template.js} +1 -4
  19. package/dist/lib/templates.js +6 -2
  20. package/dist/lib/write-common-files.js +118 -0
  21. package/dist/lib/{writeEnvFile.js → write-env-file.js} +0 -0
  22. package/dist/main.js +40 -45
  23. package/dist/utils/log.js +3 -3
  24. package/dist/utils/messages.js +1 -1
  25. package/package.json +22 -7
  26. package/dist/lib/constants.js +0 -4
  27. package/dist/lib/getPackageManager.js +0 -69
  28. package/dist/lib/getPayloadSecret.js +0 -69
  29. package/dist/lib/getPayloadVersion.js +0 -75
  30. package/dist/templates/js-blog/nodemon.json +0 -3
  31. package/dist/templates/js-blog/package.json +0 -20
  32. package/dist/templates/js-todo/nodemon.json +0 -3
  33. package/dist/templates/js-todo/package.json +0 -20
  34. package/dist/templates/ts-blog/nodemon.json +0 -4
  35. package/dist/templates/ts-blog/package.json +0 -30
  36. package/dist/templates/ts-blog/tsconfig.json +0 -28
  37. package/dist/templates/ts-todo/nodemon.json +0 -4
  38. package/dist/templates/ts-todo/package.json +0 -30
  39. package/dist/templates/ts-todo/tsconfig.json +0 -28
  40. package/dist/utils/telemetry.js +0 -44
  41. package/dist/utils/usage.js +0 -67
package/bin/cli.js CHANGED
File without changes
package/dist/index.js CHANGED
@@ -37,31 +37,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var main_1 = require("./main");
40
- var usage_1 = require("./utils/usage");
41
40
  var log_1 = require("./utils/log");
42
- (function () { return __awaiter(void 0, void 0, void 0, function () {
43
- var trx, main, e_1;
44
- return __generator(this, function (_a) {
45
- switch (_a.label) {
46
- case 0:
47
- trx = (0, usage_1.init)();
48
- main = new main_1.Main();
49
- _a.label = 1;
50
- case 1:
51
- _a.trys.push([1, 3, 4, 5]);
52
- return [4 /*yield*/, main.init()];
53
- case 2:
54
- _a.sent();
55
- return [3 /*break*/, 5];
56
- case 3:
57
- e_1 = _a.sent();
58
- (0, usage_1.handleException)(e_1);
59
- (0, log_1.error)("An error has occurred: ".concat(e_1 instanceof Error ? e_1.message : e_1));
60
- return [3 /*break*/, 5];
61
- case 4:
62
- trx === null || trx === void 0 ? void 0 : trx.finish();
63
- return [7 /*endfinally*/];
64
- case 5: return [2 /*return*/];
65
- }
41
+ function main() {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0: return [4 /*yield*/, new main_1.Main().init()];
46
+ case 1:
47
+ _a.sent();
48
+ return [2 /*return*/];
49
+ }
50
+ });
66
51
  });
67
- }); })();
52
+ }
53
+ main().catch(function (e) {
54
+ return (0, log_1.error)("An error has occurred: ".concat(e instanceof Error ? e.message : e));
55
+ });
@@ -0,0 +1,9 @@
1
+ # {{projectName}}
2
+
3
+ This project was created using create-payload-app using the {{templateName}} template.
4
+
5
+ ## How to Use
6
+
7
+ `yarn dev` will start up your application and reload on any changes.
8
+
9
+ If you have docker and docker-compose installed, you can run `docker-compose up`
@@ -0,0 +1,35 @@
1
+ version: '3'
2
+
3
+ services:
4
+
5
+ payload:
6
+ image: node:18-alpine
7
+ ports:
8
+ - "3000:3000"
9
+ volumes:
10
+ - .:/home/node/app
11
+ - node_modules:/home/node/app/node_modules
12
+ working_dir: /home/node/app/
13
+ command: sh -c "{{installCmd}} && {{devCmd}}"
14
+ depends_on:
15
+ - mongo
16
+ environment:
17
+ MONGODB_URI: mongodb://mongo:27017/payload
18
+ PORT: 3000
19
+ NODE_ENV: development
20
+ PAYLOAD_SECRET: TESTING
21
+
22
+ mongo:
23
+ image: mongo:latest
24
+ ports:
25
+ - "27017:27017"
26
+ command:
27
+ - --storageEngine=wiredTiger
28
+ volumes:
29
+ - data:/data/db
30
+ logging:
31
+ driver: none
32
+
33
+ volumes:
34
+ data:
35
+ node_modules:
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "payload-starter-javascript",
3
- "description": "Blank template - no collections",
2
+ "name": "payload-template-{{templateName}}",
3
+ "description": "Payload project created from {{templateName}} template",
4
4
  "version": "1.0.0",
5
5
  "main": "server.js",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "serve": "NODE_ENV=production node server.js"
11
11
  },
12
12
  "dependencies": {
13
- "payload": "1.0.8",
13
+ "payload": "1.1.17",
14
14
  "dotenv": "^8.2.0",
15
15
  "express": "^4.17.1"
16
16
  },
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "payload-starter-typescript",
3
- "description": "Blank template - no collections",
2
+ "name": "payload-template-{{templateName}}",
3
+ "description": "Payload project created from {{templateName}} template",
4
4
  "version": "1.0.0",
5
5
  "main": "dist/server.js",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  "generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema"
16
16
  },
17
17
  "dependencies": {
18
- "payload": "1.0.8",
18
+ "payload": "1.1.17",
19
19
  "dotenv": "^8.2.0",
20
20
  "express": "^4.17.1"
21
21
  },
@@ -25,6 +25,6 @@
25
25
  "nodemon": "^2.0.6",
26
26
  "ts-node": "^9.1.1",
27
27
  "copyfiles": "^2.4.1",
28
- "typescript": "^4.1.3"
28
+ "typescript": "^4.8.4"
29
29
  }
30
30
  }
@@ -47,7 +47,7 @@ var execa_1 = __importDefault(require("execa"));
47
47
  var ora_1 = __importDefault(require("ora"));
48
48
  var degit_1 = __importDefault(require("degit"));
49
49
  var log_1 = require("../utils/log");
50
- var usage_1 = require("../utils/usage");
50
+ var write_common_files_1 = require("./write-common-files");
51
51
  function createProjectDir(projectDir) {
52
52
  return __awaiter(this, void 0, void 0, function () {
53
53
  var pathExists;
@@ -70,7 +70,7 @@ function createProjectDir(projectDir) {
70
70
  }
71
71
  function installDeps(args, dir, packageManager) {
72
72
  return __awaiter(this, void 0, void 0, function () {
73
- var cmd, error_1;
73
+ var cmd, err_1;
74
74
  return __generator(this, function (_a) {
75
75
  switch (_a.label) {
76
76
  case 0:
@@ -88,7 +88,7 @@ function installDeps(args, dir, packageManager) {
88
88
  _a.sent();
89
89
  return [2 /*return*/, true];
90
90
  case 3:
91
- error_1 = _a.sent();
91
+ err_1 = _a.sent();
92
92
  return [2 /*return*/, false];
93
93
  case 4: return [2 /*return*/];
94
94
  }
@@ -98,7 +98,7 @@ function installDeps(args, dir, packageManager) {
98
98
  function getLatestPayloadVersion(betaFlag) {
99
99
  if (betaFlag === void 0) { betaFlag = false; }
100
100
  return __awaiter(this, void 0, void 0, function () {
101
- var packageWithTag, stdout, error_2;
101
+ var packageWithTag, stdout, err_2;
102
102
  return __generator(this, function (_a) {
103
103
  switch (_a.label) {
104
104
  case 0:
@@ -113,7 +113,11 @@ function getLatestPayloadVersion(betaFlag) {
113
113
  stdout = (_a.sent()).stdout;
114
114
  return [2 /*return*/, "^".concat(stdout)];
115
115
  case 2:
116
- error_2 = _a.sent();
116
+ err_2 = _a.sent();
117
+ if (err_2 instanceof Error) {
118
+ console.error(err_2.message);
119
+ console.error(err_2.stack);
120
+ }
117
121
  return [2 /*return*/, false];
118
122
  case 3: return [2 /*return*/];
119
123
  }
@@ -124,7 +128,7 @@ exports.getLatestPayloadVersion = getLatestPayloadVersion;
124
128
  function updatePayloadVersion(projectDir, betaFlag) {
125
129
  if (betaFlag === void 0) { betaFlag = false; }
126
130
  return __awaiter(this, void 0, void 0, function () {
127
- var payloadVersion, packageJsonPath, packageObj, err_1;
131
+ var payloadVersion, packageJsonPath, packageObj, err_3;
128
132
  return __generator(this, function (_a) {
129
133
  switch (_a.label) {
130
134
  case 0: return [4 /*yield*/, getLatestPayloadVersion(betaFlag)];
@@ -134,7 +138,6 @@ function updatePayloadVersion(projectDir, betaFlag) {
134
138
  (0, log_1.warning)('Error retrieving latest Payload version. Please update your package.json manually.');
135
139
  return [2 /*return*/];
136
140
  }
137
- (0, usage_1.setTags)({ payload_version: payloadVersion });
138
141
  packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
139
142
  _a.label = 2;
140
143
  case 2:
@@ -148,7 +151,7 @@ function updatePayloadVersion(projectDir, betaFlag) {
148
151
  _a.sent();
149
152
  return [3 /*break*/, 6];
150
153
  case 5:
151
- err_1 = _a.sent();
154
+ err_3 = _a.sent();
152
155
  (0, log_1.warning)('Unable to write Payload version to package.json. Please update your package.json manually.');
153
156
  return [3 /*break*/, 6];
154
157
  case 6: return [2 /*return*/];
@@ -159,7 +162,7 @@ function updatePayloadVersion(projectDir, betaFlag) {
159
162
  exports.updatePayloadVersion = updatePayloadVersion;
160
163
  function createProject(args, projectDir, template, packageManager) {
161
164
  return __awaiter(this, void 0, void 0, function () {
162
- var templateDir, emitter, src, dest, gi, giDest, err_2, msg, spinner, result;
165
+ var templateDir, emitter, err_4, msg, spinner, result;
163
166
  return __generator(this, function (_a) {
164
167
  switch (_a.label) {
165
168
  case 0: return [4 /*yield*/, createProjectDir(projectDir)];
@@ -172,38 +175,34 @@ function createProject(args, projectDir, template, packageManager) {
172
175
  return [4 /*yield*/, emitter.clone(projectDir)];
173
176
  case 2:
174
177
  _a.sent();
175
- return [3 /*break*/, 8];
178
+ return [3 /*break*/, 7];
176
179
  case 3:
177
- _a.trys.push([3, 7, , 8]);
180
+ _a.trys.push([3, 6, , 7]);
178
181
  return [4 /*yield*/, fs_extra_1.default.copy(templateDir, projectDir, { recursive: true })];
179
182
  case 4:
180
183
  _a.sent();
181
- src = path_1.default.resolve(templateDir, '..', 'npmrc.template');
182
- dest = path_1.default.resolve(projectDir, '.npmrc');
183
- return [4 /*yield*/, fs_extra_1.default.copy(src, dest)];
184
+ return [4 /*yield*/, (0, write_common_files_1.writeCommonFiles)(projectDir, template, packageManager)];
184
185
  case 5:
185
- _a.sent();
186
- gi = path_1.default.resolve(templateDir, '..', 'gitignore.template');
187
- giDest = path_1.default.resolve(projectDir, '.gitignore');
188
- return [4 /*yield*/, fs_extra_1.default.copy(gi, giDest)];
189
- case 6:
190
186
  _a.sent();
191
187
  (0, log_1.success)('Project directory created');
192
- return [3 /*break*/, 8];
193
- case 7:
194
- err_2 = _a.sent();
188
+ return [3 /*break*/, 7];
189
+ case 6:
190
+ err_4 = _a.sent();
195
191
  msg = 'Unable to copy template files. Please check template name or directory permissions.';
196
192
  (0, log_1.error)(msg);
193
+ if (err_4 instanceof Error) {
194
+ console.error({ err: err_4 });
195
+ }
197
196
  process.exit(1);
198
- return [3 /*break*/, 8];
199
- case 8:
197
+ return [3 /*break*/, 7];
198
+ case 7:
200
199
  spinner = (0, ora_1.default)('Checking latest Payload version...').start();
201
200
  return [4 /*yield*/, updatePayloadVersion(projectDir, args['--beta'])];
202
- case 9:
201
+ case 8:
203
202
  _a.sent();
204
203
  spinner.text = 'Installing dependencies...';
205
204
  return [4 /*yield*/, installDeps(args, projectDir, packageManager)];
206
- case 10:
205
+ case 9:
207
206
  result = _a.sent();
208
207
  spinner.stop();
209
208
  spinner.clear();
@@ -41,9 +41,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var fs_extra_1 = __importDefault(require("fs-extra"));
43
43
  var path_1 = __importDefault(require("path"));
44
- var createProject_1 = require("./createProject");
44
+ var create_project_1 = require("./create-project");
45
+ var projectDir = path_1.default.resolve(__dirname, './tmp');
45
46
  describe('createProject', function () {
46
- var projectDir = path_1.default.resolve(__dirname, './tmp');
47
47
  beforeAll(function () {
48
48
  console.log = jest.fn();
49
49
  });
@@ -58,22 +58,36 @@ describe('createProject', function () {
58
58
  }
59
59
  });
60
60
  describe('#createProject', function () {
61
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
61
62
  var args = { _: ['project-name'], '--no-deps': true };
62
63
  var packageManager = 'yarn';
63
64
  it('creates static project', function () { return __awaiter(void 0, void 0, void 0, function () {
64
65
  var expectedPayloadVersion, template, packageJsonPath, packageJson;
65
66
  return __generator(this, function (_a) {
66
67
  switch (_a.label) {
67
- case 0: return [4 /*yield*/, (0, createProject_1.getLatestPayloadVersion)()];
68
+ case 0: return [4 /*yield*/, (0, create_project_1.getLatestPayloadVersion)()];
68
69
  case 1:
69
70
  expectedPayloadVersion = _a.sent();
70
- template = { name: 'ts-todo', type: 'static' };
71
- return [4 /*yield*/, (0, createProject_1.createProject)(args, projectDir, template, packageManager)];
71
+ template = {
72
+ name: 'ts-todo',
73
+ type: 'static',
74
+ language: 'typescript',
75
+ };
76
+ return [4 /*yield*/, (0, create_project_1.createProject)(args, projectDir, template, packageManager)];
72
77
  case 2:
73
78
  _a.sent();
74
79
  packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
75
80
  packageJson = fs_extra_1.default.readJsonSync(packageJsonPath);
76
81
  expect(packageJson.dependencies.payload).toBe(expectedPayloadVersion);
82
+ // Check package name comtains template name
83
+ expect(packageJson.name).toContain('ts-todo');
84
+ // Check all common files are create
85
+ assertProjectFileExists('.npmrc');
86
+ assertProjectFileExists('.gitignore');
87
+ assertProjectFileExists('nodemon.json');
88
+ assertProjectFileExists('README.md');
89
+ assertProjectFileExists('tsconfig.json');
90
+ assertProjectFileExists('docker-compose.yml');
77
91
  return [2 /*return*/];
78
92
  }
79
93
  });
@@ -92,7 +106,7 @@ describe('createProject', function () {
92
106
  return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, { dependencies: { payload: '0.0.1' } }, { spaces: 2 })];
93
107
  case 2:
94
108
  _a.sent();
95
- return [4 /*yield*/, (0, createProject_1.updatePayloadVersion)(projectDir)];
109
+ return [4 /*yield*/, (0, create_project_1.updatePayloadVersion)(projectDir)];
96
110
  case 3:
97
111
  _a.sent();
98
112
  return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
@@ -105,3 +119,19 @@ describe('createProject', function () {
105
119
  }); });
106
120
  });
107
121
  });
122
+ function assertProjectFileExists(fileName) {
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ var filePath, _a;
125
+ return __generator(this, function (_b) {
126
+ switch (_b.label) {
127
+ case 0:
128
+ filePath = path_1.default.resolve(projectDir, fileName);
129
+ _a = expect;
130
+ return [4 /*yield*/, fs_extra_1.default.pathExists(filePath)];
131
+ case 1:
132
+ _a.apply(void 0, [_b.sent()]).toBe(true);
133
+ return [2 /*return*/];
134
+ }
135
+ });
136
+ });
137
+ }
File without changes
@@ -41,7 +41,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.parseTemplate = void 0;
43
43
  var prompts_1 = __importDefault(require("prompts"));
44
- var usage_1 = require("../utils/usage");
45
44
  function parseTemplate(args, validTemplates, language) {
46
45
  return __awaiter(this, void 0, void 0, function () {
47
46
  var templateName_1, template_1, filteredTemplates, response, template;
@@ -50,10 +49,9 @@ function parseTemplate(args, validTemplates, language) {
50
49
  case 0:
51
50
  if (args['--template']) {
52
51
  templateName_1 = args['--template'];
53
- template_1 = validTemplates.find(function (template) { return template.name === templateName_1; });
52
+ template_1 = validTemplates.find(function (t) { return t.name === templateName_1; });
54
53
  if (!template_1)
55
54
  throw new Error('Invalid template given');
56
- (0, usage_1.setTags)({ template: template_1.name });
57
55
  return [2 /*return*/, template_1];
58
56
  }
59
57
  filteredTemplates = validTemplates
@@ -79,7 +77,6 @@ function parseTemplate(args, validTemplates, language) {
79
77
  template = validTemplates.find(function (t) { return t.name === response.value; });
80
78
  if (!template)
81
79
  throw new Error('Template is undefined');
82
- (0, usage_1.setTags)({ template: template.name });
83
80
  return [2 /*return*/, template];
84
81
  }
85
82
  });
@@ -69,7 +69,11 @@ function getValidTemplates() {
69
69
  templateDir = path_1.default.resolve(__dirname, '../templates');
70
70
  dirs = getDirectories(templateDir);
71
71
  templates = dirs.map(function (name) {
72
- return { name: name, type: 'static' };
72
+ return {
73
+ name: name,
74
+ type: 'static',
75
+ language: name.startsWith('js-') ? 'javascript' : 'typescript',
76
+ };
73
77
  });
74
78
  return [2 /*return*/, templates];
75
79
  });
@@ -78,6 +82,6 @@ function getValidTemplates() {
78
82
  exports.getValidTemplates = getValidTemplates;
79
83
  function getDirectories(dir) {
80
84
  return fs_1.default.readdirSync(dir).filter(function (file) {
81
- return fs_1.default.statSync(dir + '/' + file).isDirectory();
85
+ return fs_1.default.statSync("".concat(dir, "/").concat(file)).isDirectory();
82
86
  });
83
87
  }
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.writeCommonFiles = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var fs_extra_1 = __importDefault(require("fs-extra"));
45
+ var handlebars_1 = __importDefault(require("handlebars"));
46
+ function writeCommonFiles(projectDir, template, packageManager) {
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;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ commonFilesDir = path_1.default.resolve(__dirname, 'common-files');
53
+ npmrc = path_1.default.resolve(commonFilesDir, 'npmrc.template');
54
+ npmrcDest = path_1.default.resolve(projectDir, '.npmrc');
55
+ return [4 /*yield*/, fs_extra_1.default.copy(npmrc, npmrcDest)
56
+ // .gitignore
57
+ ];
58
+ case 1:
59
+ _a.sent();
60
+ gi = path_1.default.resolve(commonFilesDir, 'gitignore.template');
61
+ giDest = path_1.default.resolve(projectDir, '.gitignore');
62
+ return [4 /*yield*/, fs_extra_1.default.copy(gi, giDest)
63
+ // package.json
64
+ ];
65
+ case 2:
66
+ _a.sent();
67
+ return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, template.language, 'package.template.json'), 'utf8')];
68
+ case 3:
69
+ packageJsonTemplate = _a.sent();
70
+ packageJson = handlebars_1.default.compile(packageJsonTemplate)({
71
+ templateName: template.name,
72
+ });
73
+ return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'package.json'), packageJson)
74
+ // nodemon.json
75
+ ];
76
+ case 4:
77
+ _a.sent();
78
+ nodemon = path_1.default.resolve(commonFilesDir, template.language, 'nodemon.json');
79
+ nodemonDest = path_1.default.resolve(projectDir, 'nodemon.json');
80
+ return [4 /*yield*/, fs_extra_1.default.copy(nodemon, nodemonDest)
81
+ // README.md
82
+ ];
83
+ case 5:
84
+ _a.sent();
85
+ return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'README.template.md'), 'utf8')];
86
+ case 6:
87
+ readmeTemplate = _a.sent();
88
+ readme = handlebars_1.default.compile(readmeTemplate)({
89
+ projectName: path_1.default.basename(projectDir),
90
+ templateName: template.name,
91
+ });
92
+ return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'README.md'), readme)
93
+ // tsconfig.json
94
+ ];
95
+ case 7:
96
+ _a.sent();
97
+ if (!(template.language === 'typescript')) return [3 /*break*/, 9];
98
+ tsconfig = path_1.default.resolve(commonFilesDir, template.language, 'tsconfig.json');
99
+ tsconfigDest = path_1.default.resolve(projectDir, 'tsconfig.json');
100
+ return [4 /*yield*/, fs_extra_1.default.copy(tsconfig, tsconfigDest)];
101
+ case 8:
102
+ _a.sent();
103
+ _a.label = 9;
104
+ case 9: return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'docker-compose.template.yml'), 'utf8')];
105
+ case 10:
106
+ dockerComposeTemplate = _a.sent();
107
+ dockerCompose = handlebars_1.default.compile(dockerComposeTemplate)(packageManager === 'yarn'
108
+ ? { installCmd: 'yarn install', devCmd: 'yarn dev' }
109
+ : { 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
+ case 11:
112
+ _a.sent();
113
+ return [2 /*return*/];
114
+ }
115
+ });
116
+ });
117
+ }
118
+ exports.writeCommonFiles = writeCommonFiles;
File without changes