create-payload-app 0.1.22 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +1 -52
  3. package/dist/index.js +67 -0
  4. package/dist/lib/createProject.js +204 -0
  5. package/dist/lib/createProject.test.js +101 -0
  6. package/dist/lib/getDatabaseConnection.js +71 -0
  7. package/dist/lib/getPayloadSecret.js +69 -0
  8. package/dist/lib/github.js +130 -0
  9. package/dist/lib/parseLanguage.js +79 -0
  10. package/dist/lib/parseProjectName.js +71 -0
  11. package/dist/lib/parseTemplate.js +88 -0
  12. package/dist/lib/templates.js +83 -0
  13. package/dist/lib/writeEnvFile.js +73 -0
  14. package/dist/main.js +177 -0
  15. package/{templates → dist/templates}/js-blank/collections/Examples.js +0 -0
  16. package/{templates → dist/templates}/js-blank/collections/Users.js +0 -0
  17. package/{templates → dist/templates}/js-blank/nodemon.json +0 -0
  18. package/{templates → dist/templates}/js-blank/package.json +1 -1
  19. package/{templates → dist/templates}/js-blank/payload.config.js +0 -0
  20. package/{templates/js-todo → dist/templates/js-blank}/server.js +5 -0
  21. package/{templates → dist/templates}/js-blog/collections/Categories.js +0 -0
  22. package/{templates → dist/templates}/js-blog/collections/Posts.js +0 -0
  23. package/{templates → dist/templates}/js-blog/collections/Tags.js +0 -0
  24. package/{templates → dist/templates}/js-blog/collections/Users.js +0 -0
  25. package/{templates → dist/templates}/js-blog/nodemon.json +0 -0
  26. package/{templates → dist/templates}/js-blog/package.json +1 -1
  27. package/{templates → dist/templates}/js-blog/payload.config.js +0 -0
  28. package/{templates/js-blank → dist/templates/js-blog}/server.js +5 -0
  29. package/{templates → dist/templates}/js-todo/collections/TodoLists.js +0 -0
  30. package/{templates → dist/templates}/js-todo/collections/Users.js +0 -0
  31. package/{templates → dist/templates}/js-todo/nodemon.json +0 -0
  32. package/{templates → dist/templates}/js-todo/package.json +1 -1
  33. package/{templates → dist/templates}/js-todo/payload.config.js +0 -0
  34. package/{templates/js-blog → dist/templates/js-todo}/server.js +5 -0
  35. package/{templates → dist/templates}/ts-blank/nodemon.json +0 -0
  36. package/{templates → dist/templates}/ts-blank/package.json +3 -2
  37. package/{templates → dist/templates}/ts-blank/src/collections/Examples.ts +0 -0
  38. package/{templates → dist/templates}/ts-blank/src/collections/Users.ts +0 -0
  39. package/{templates → dist/templates}/ts-blank/src/payload.config.ts +4 -0
  40. package/{templates/ts-blog → dist/templates/ts-blank}/src/server.ts +5 -0
  41. package/{templates → dist/templates}/ts-blank/tsconfig.json +0 -0
  42. package/{templates → dist/templates}/ts-blog/nodemon.json +0 -0
  43. package/{templates → dist/templates}/ts-blog/package.json +3 -2
  44. package/{templates → dist/templates}/ts-blog/src/collections/Categories.ts +0 -0
  45. package/{templates → dist/templates}/ts-blog/src/collections/Posts.ts +0 -0
  46. package/{templates → dist/templates}/ts-blog/src/collections/Tags.ts +0 -0
  47. package/{templates → dist/templates}/ts-blog/src/collections/Users.ts +0 -0
  48. package/{templates → dist/templates}/ts-blog/src/payload.config.ts +4 -0
  49. package/{templates/ts-blank → dist/templates/ts-blog}/src/server.ts +5 -0
  50. package/{templates → dist/templates}/ts-blog/tsconfig.json +0 -0
  51. package/{templates → dist/templates}/ts-todo/nodemon.json +0 -0
  52. package/{templates → dist/templates}/ts-todo/package.json +3 -2
  53. package/{templates → dist/templates}/ts-todo/src/collections/TodoLists.ts +0 -0
  54. package/{templates → dist/templates}/ts-todo/src/collections/Users.ts +0 -0
  55. package/{templates → dist/templates}/ts-todo/src/payload.config.ts +4 -0
  56. package/{templates → dist/templates}/ts-todo/src/server.ts +5 -0
  57. package/{templates → dist/templates}/ts-todo/tsconfig.json +0 -0
  58. package/dist/types.js +2 -0
  59. package/dist/utils/log.js +24 -0
  60. package/dist/utils/messages.js +73 -0
  61. package/dist/utils/usage.js +63 -0
  62. package/package.json +31 -4
  63. package/utils/createProject.js +0 -101
  64. package/utils/getArgs.js +0 -28
  65. package/utils/getDatabaseConnection.js +0 -37
  66. package/utils/getLanguage.js +0 -43
  67. package/utils/getPackageManager.js +0 -27
  68. package/utils/getPayloadSecret.js +0 -34
  69. package/utils/getProjectDir.js +0 -8
  70. package/utils/getProjectName.js +0 -39
  71. package/utils/getTemplate.js +0 -49
  72. package/utils/getValidTemplates.js +0 -29
  73. package/utils/log.js +0 -27
  74. package/utils/messages.js +0 -51
  75. package/utils/usage.js +0 -35
  76. package/utils/writeEnvFile.js +0 -25
package/README.md CHANGED
@@ -15,7 +15,7 @@ CLI for easily starting new Payload project
15
15
  --name my-payload-app Set project name
16
16
  --template template_name Choose specific template
17
17
 
18
- Available templates: js-blog, js-todo, ts-blog, ts-todo
18
+ Available templates: js-blank, js-blog, js-todo, ts-blank, ts-blog, ts-todo
19
19
 
20
20
  --use-npm Use npm to install dependencies
21
21
  --no-deps Do not install any dependencies
package/bin/cli.js CHANGED
@@ -1,53 +1,2 @@
1
1
  #!/usr/bin/env node
2
-
3
- const { getArgs } = require('../utils/getArgs');
4
- const { getTemplate } = require('../utils/getTemplate');
5
- const { getProjectName } = require('../utils/getProjectName');
6
- const { createProject } = require('../utils/createProject');
7
- const { welcomeMessage, helpMessage, successMessage } = require('../utils/messages');
8
- const { success } = require('../utils/log');
9
- const { getDatabaseConnection } = require('../utils/getDatabaseConnection');
10
- const { getPayloadSecret } = require('../utils/getPayloadSecret');
11
- const { writeEnvFile } = require('../utils/writeEnvFile');
12
- const { getLanguage } = require('../utils/getLanguage');
13
- const { validateTemplate } = require('../utils/getValidTemplates');
14
- const { error } = require('../utils/log');
15
- const { init, handleException } = require('../utils/usage');
16
-
17
- const trx = init();
18
-
19
- (async () => {
20
- const args = getArgs();
21
- if (args['--help'] || args.count === 0) {
22
- console.log(await helpMessage());
23
- return 0;
24
- }
25
- const templateArg = args['--template'];
26
- if (templateArg) {
27
- const valid = await validateTemplate(templateArg);
28
- if (!valid) {
29
- console.log(await helpMessage());
30
- process.exit(1);
31
- }
32
- }
33
-
34
- console.log(welcomeMessage);
35
- try {
36
- await getProjectName();
37
- await getLanguage();
38
- await getTemplate();
39
- await getDatabaseConnection();
40
- await getPayloadSecret();
41
- if (!args['--dry-run']) {
42
- await createProject();
43
- await writeEnvFile();
44
- }
45
- success('Payload project successfully created');
46
- console.log(await successMessage());
47
- } catch (e) {
48
- handleException(e);
49
- error(`An error has occurred: ${e && e.message}`);
50
- } finally {
51
- trx.finish();
52
- }
53
- })();
2
+ require('../dist/index.js')
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var main_1 = require("./main");
40
+ var usage_1 = require("./utils/usage");
41
+ 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 = 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
+ usage_1.handleException(e_1);
59
+ log_1.error("An error has occurred: " + (e_1 && e_1.message));
60
+ return [3 /*break*/, 5];
61
+ case 4:
62
+ trx.finish();
63
+ return [7 /*endfinally*/];
64
+ case 5: return [2 /*return*/];
65
+ }
66
+ });
67
+ }); })();
@@ -0,0 +1,204 @@
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.createProject = exports.updatePayloadVersion = exports.getLatestPayloadVersion = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var chalk_1 = __importDefault(require("chalk"));
45
+ var fs_extra_1 = __importDefault(require("fs-extra"));
46
+ var execa_1 = __importDefault(require("execa"));
47
+ var ora_1 = __importDefault(require("ora"));
48
+ var degit_1 = __importDefault(require("degit"));
49
+ var log_1 = require("../utils/log");
50
+ var usage_1 = require("../utils/usage");
51
+ function createProjectDir(projectDir) {
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ var pathExists;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(projectDir)];
57
+ case 1:
58
+ pathExists = _a.sent();
59
+ if (pathExists) {
60
+ log_1.error("The project directory '" + projectDir + "' already exists");
61
+ process.exit(1);
62
+ }
63
+ return [4 /*yield*/, fs_extra_1.default.mkdir(projectDir)];
64
+ case 2:
65
+ _a.sent();
66
+ return [2 /*return*/];
67
+ }
68
+ });
69
+ });
70
+ }
71
+ function installDeps(args, dir, packageManager) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ var cmd, error_1;
74
+ return __generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0:
77
+ if (args['--no-deps']) {
78
+ return [2 /*return*/, true];
79
+ }
80
+ cmd = packageManager === 'yarn' ? 'yarn' : 'npm install --legacy-peer-deps';
81
+ _a.label = 1;
82
+ case 1:
83
+ _a.trys.push([1, 3, , 4]);
84
+ return [4 /*yield*/, execa_1.default.command(cmd, {
85
+ cwd: path_1.default.resolve(dir),
86
+ })];
87
+ case 2:
88
+ _a.sent();
89
+ return [2 /*return*/, true];
90
+ case 3:
91
+ error_1 = _a.sent();
92
+ return [2 /*return*/, false];
93
+ case 4: return [2 /*return*/];
94
+ }
95
+ });
96
+ });
97
+ }
98
+ function getLatestPayloadVersion() {
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ var stdout, error_2;
101
+ return __generator(this, function (_a) {
102
+ switch (_a.label) {
103
+ case 0:
104
+ _a.trys.push([0, 2, , 3]);
105
+ return [4 /*yield*/, execa_1.default('npm info payload version', [], { shell: true })];
106
+ case 1:
107
+ stdout = (_a.sent()).stdout;
108
+ return [2 /*return*/, "^" + stdout];
109
+ case 2:
110
+ error_2 = _a.sent();
111
+ return [2 /*return*/, false];
112
+ case 3: return [2 /*return*/];
113
+ }
114
+ });
115
+ });
116
+ }
117
+ exports.getLatestPayloadVersion = getLatestPayloadVersion;
118
+ function updatePayloadVersion(projectDir) {
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ var payloadVersion, packageJsonPath, packageObj, err_1;
121
+ return __generator(this, function (_a) {
122
+ switch (_a.label) {
123
+ case 0: return [4 /*yield*/, getLatestPayloadVersion()];
124
+ case 1:
125
+ payloadVersion = _a.sent();
126
+ if (!payloadVersion) {
127
+ log_1.warning('Error retrieving latest Payload version. Please update your package.json manually.');
128
+ return [2 /*return*/];
129
+ }
130
+ usage_1.setTags({ payload_version: payloadVersion });
131
+ packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
132
+ _a.label = 2;
133
+ case 2:
134
+ _a.trys.push([2, 5, , 6]);
135
+ return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
136
+ case 3:
137
+ packageObj = _a.sent();
138
+ packageObj.dependencies.payload = payloadVersion;
139
+ return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, packageObj, { spaces: 2 })];
140
+ case 4:
141
+ _a.sent();
142
+ return [3 /*break*/, 6];
143
+ case 5:
144
+ err_1 = _a.sent();
145
+ log_1.warning('Unable to write Payload version to package.json. Please update your package.json manually.');
146
+ return [3 /*break*/, 6];
147
+ case 6: return [2 /*return*/];
148
+ }
149
+ });
150
+ });
151
+ }
152
+ exports.updatePayloadVersion = updatePayloadVersion;
153
+ function createProject(args, projectDir, template, packageManager) {
154
+ return __awaiter(this, void 0, void 0, function () {
155
+ var templateDir, emitter, err_2, msg, spinner, result;
156
+ return __generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0: return [4 /*yield*/, createProjectDir(projectDir)];
159
+ case 1:
160
+ _a.sent();
161
+ templateDir = path_1.default.resolve(__dirname, "../templates/" + template.name);
162
+ console.log("\n Creating a new Payload app in " + chalk_1.default.green(path_1.default.resolve(projectDir)) + "\n");
163
+ if (!(template.type === 'starter')) return [3 /*break*/, 3];
164
+ emitter = degit_1.default(template.url);
165
+ return [4 /*yield*/, emitter.clone(projectDir)];
166
+ case 2:
167
+ _a.sent();
168
+ return [3 /*break*/, 6];
169
+ case 3:
170
+ _a.trys.push([3, 5, , 6]);
171
+ return [4 /*yield*/, fs_extra_1.default.copy(templateDir, projectDir, { recursive: true })];
172
+ case 4:
173
+ _a.sent();
174
+ log_1.success('Project directory created');
175
+ return [3 /*break*/, 6];
176
+ case 5:
177
+ err_2 = _a.sent();
178
+ msg = 'Unable to copy template files. Please check template name or directory permissions.';
179
+ log_1.error(msg);
180
+ process.exit(1);
181
+ return [3 /*break*/, 6];
182
+ case 6:
183
+ spinner = ora_1.default('Checking latest Payload version...').start();
184
+ return [4 /*yield*/, updatePayloadVersion(projectDir)];
185
+ case 7:
186
+ _a.sent();
187
+ spinner.text = 'Installing dependencies...';
188
+ return [4 /*yield*/, installDeps(args, projectDir, packageManager)];
189
+ case 8:
190
+ result = _a.sent();
191
+ spinner.stop();
192
+ spinner.clear();
193
+ if (result) {
194
+ log_1.success('Dependencies installed');
195
+ }
196
+ else {
197
+ log_1.error('Error installing dependencies');
198
+ }
199
+ return [2 /*return*/];
200
+ }
201
+ });
202
+ });
203
+ }
204
+ exports.createProject = createProject;
@@ -0,0 +1,101 @@
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
+ var fs_extra_1 = __importDefault(require("fs-extra"));
43
+ var path_1 = __importDefault(require("path"));
44
+ var createProject_1 = require("./createProject");
45
+ describe('createProject', function () {
46
+ var projectDir = path_1.default.resolve(__dirname, './tmp');
47
+ beforeAll(function () {
48
+ console.log = jest.fn();
49
+ fs_extra_1.default.rmdirSync(projectDir, { recursive: true });
50
+ });
51
+ afterEach(function () {
52
+ fs_extra_1.default.rmdirSync(projectDir, { recursive: true });
53
+ });
54
+ describe('#createProject', function () {
55
+ var args = { _: ['project-name'], '--no-deps': true };
56
+ var packageManager = 'yarn';
57
+ it('creates static project', function () { return __awaiter(void 0, void 0, void 0, function () {
58
+ var expectedPayloadVersion, template, packageJsonPath, packageJson;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0: return [4 /*yield*/, createProject_1.getLatestPayloadVersion()];
62
+ case 1:
63
+ expectedPayloadVersion = _a.sent();
64
+ template = { name: 'ts-todo', type: 'static' };
65
+ return [4 /*yield*/, createProject_1.createProject(args, projectDir, template, packageManager)];
66
+ case 2:
67
+ _a.sent();
68
+ packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
69
+ packageJson = fs_extra_1.default.readJsonSync(packageJsonPath);
70
+ expect(packageJson.dependencies.payload).toBe(expectedPayloadVersion);
71
+ return [2 /*return*/];
72
+ }
73
+ });
74
+ }); });
75
+ });
76
+ describe('#updatePayloadVersion', function () {
77
+ it('updates payload version in package.json', function () { return __awaiter(void 0, void 0, void 0, function () {
78
+ var packageJsonPath, modified;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0:
82
+ packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
83
+ return [4 /*yield*/, fs_extra_1.default.mkdir(projectDir)];
84
+ case 1:
85
+ _a.sent();
86
+ return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, { dependencies: { payload: '0.0.1' } }, { spaces: 2 })];
87
+ case 2:
88
+ _a.sent();
89
+ return [4 /*yield*/, createProject_1.updatePayloadVersion(projectDir)];
90
+ case 3:
91
+ _a.sent();
92
+ return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
93
+ case 4:
94
+ modified = _a.sent();
95
+ expect(modified.dependencies.payload).not.toBe('0.0.1');
96
+ return [2 /*return*/];
97
+ }
98
+ });
99
+ }); });
100
+ });
101
+ });
@@ -0,0 +1,71 @@
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.getDatabaseConnection = void 0;
43
+ var prompts_1 = __importDefault(require("prompts"));
44
+ var slugify_1 = __importDefault(require("@sindresorhus/slugify"));
45
+ function getDatabaseConnection(args, projectName) {
46
+ return __awaiter(this, void 0, void 0, function () {
47
+ var response;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0:
51
+ if (args['--db'])
52
+ return [2 /*return*/, args['--db']];
53
+ return [4 /*yield*/, prompts_1.default({
54
+ type: 'text',
55
+ name: 'value',
56
+ message: 'Enter MongoDB connection',
57
+ initial: "mongodb://localhost/" + slugify_1.default(projectName),
58
+ validate: function (value) { return value.length; },
59
+ }, {
60
+ onCancel: function () {
61
+ process.exit(0);
62
+ },
63
+ })];
64
+ case 1:
65
+ response = _a.sent();
66
+ return [2 /*return*/, response.value];
67
+ }
68
+ });
69
+ });
70
+ }
71
+ exports.getDatabaseConnection = getDatabaseConnection;
@@ -0,0 +1,69 @@
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.getPayloadSecret = void 0;
43
+ var prompts_1 = __importDefault(require("prompts"));
44
+ function getPayloadSecret(args) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var response;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0:
50
+ if (args['--secret'])
51
+ return [2 /*return*/, args['--secret']];
52
+ return [4 /*yield*/, prompts_1.default({
53
+ type: 'password',
54
+ name: 'value',
55
+ message: 'Enter a long, complex string for Payload’s encryption key',
56
+ validate: function (value) { return value.length; },
57
+ }, {
58
+ onCancel: function () {
59
+ process.exit(0);
60
+ },
61
+ })];
62
+ case 1:
63
+ response = _a.sent();
64
+ return [2 /*return*/, response.value];
65
+ }
66
+ });
67
+ });
68
+ }
69
+ exports.getPayloadSecret = getPayloadSecret;