create-payload-app 0.3.13 → 0.3.15

Sign up to get free protection for your applications and to get access to all the features.
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,220 @@
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 write_common_files_1 = require("./write-common-files");
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
+ (0, log_1.error)("The project directory '".concat(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, err_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
+ err_1 = _a.sent();
92
+ return [2 /*return*/, false];
93
+ case 4: return [2 /*return*/];
94
+ }
95
+ });
96
+ });
97
+ }
98
+ function getLatestPayloadVersion(betaFlag) {
99
+ if (betaFlag === void 0) { betaFlag = false; }
100
+ return __awaiter(this, void 0, void 0, function () {
101
+ var packageWithTag, stdout, err_2;
102
+ return __generator(this, function (_a) {
103
+ switch (_a.label) {
104
+ case 0:
105
+ _a.trys.push([0, 2, , 3]);
106
+ packageWithTag = 'payload';
107
+ if (betaFlag)
108
+ packageWithTag += '@beta';
109
+ return [4 /*yield*/, (0, execa_1.default)("npm info ".concat(packageWithTag, " version"), [], {
110
+ shell: true,
111
+ })];
112
+ case 1:
113
+ stdout = (_a.sent()).stdout;
114
+ return [2 /*return*/, "^".concat(stdout)];
115
+ case 2:
116
+ err_2 = _a.sent();
117
+ if (err_2 instanceof Error) {
118
+ console.error(err_2.message);
119
+ console.error(err_2.stack);
120
+ }
121
+ return [2 /*return*/, false];
122
+ case 3: return [2 /*return*/];
123
+ }
124
+ });
125
+ });
126
+ }
127
+ exports.getLatestPayloadVersion = getLatestPayloadVersion;
128
+ function updatePayloadVersion(projectDir, betaFlag) {
129
+ if (betaFlag === void 0) { betaFlag = false; }
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ var payloadVersion, packageJsonPath, packageObj, err_3;
132
+ return __generator(this, function (_a) {
133
+ switch (_a.label) {
134
+ case 0: return [4 /*yield*/, getLatestPayloadVersion(betaFlag)];
135
+ case 1:
136
+ payloadVersion = _a.sent();
137
+ if (!payloadVersion) {
138
+ (0, log_1.warning)('Error retrieving latest Payload version. Please update your package.json manually.');
139
+ return [2 /*return*/];
140
+ }
141
+ packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
142
+ _a.label = 2;
143
+ case 2:
144
+ _a.trys.push([2, 5, , 6]);
145
+ return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
146
+ case 3:
147
+ packageObj = _a.sent();
148
+ packageObj.dependencies.payload = payloadVersion;
149
+ return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, packageObj, { spaces: 2 })];
150
+ case 4:
151
+ _a.sent();
152
+ return [3 /*break*/, 6];
153
+ case 5:
154
+ err_3 = _a.sent();
155
+ (0, log_1.warning)('Unable to write Payload version to package.json. Please update your package.json manually.');
156
+ return [3 /*break*/, 6];
157
+ case 6: return [2 /*return*/];
158
+ }
159
+ });
160
+ });
161
+ }
162
+ exports.updatePayloadVersion = updatePayloadVersion;
163
+ function createProject(args, projectDir, template, packageManager) {
164
+ return __awaiter(this, void 0, void 0, function () {
165
+ var templateDir, emitter, err_4, msg, spinner, result;
166
+ return __generator(this, function (_a) {
167
+ switch (_a.label) {
168
+ case 0: return [4 /*yield*/, createProjectDir(projectDir)];
169
+ case 1:
170
+ _a.sent();
171
+ templateDir = path_1.default.resolve(__dirname, "../templates/".concat(template.name));
172
+ console.log("\n Creating a new Payload app in ".concat(chalk_1.default.green(path_1.default.resolve(projectDir)), "\n"));
173
+ if (!(template.type === 'starter')) return [3 /*break*/, 3];
174
+ emitter = (0, degit_1.default)(template.url);
175
+ return [4 /*yield*/, emitter.clone(projectDir)];
176
+ case 2:
177
+ _a.sent();
178
+ return [3 /*break*/, 7];
179
+ case 3:
180
+ _a.trys.push([3, 6, , 7]);
181
+ return [4 /*yield*/, fs_extra_1.default.copy(templateDir, projectDir, { recursive: true })];
182
+ case 4:
183
+ _a.sent();
184
+ return [4 /*yield*/, (0, write_common_files_1.writeCommonFiles)(projectDir, template, packageManager)];
185
+ case 5:
186
+ _a.sent();
187
+ (0, log_1.success)('Project directory created');
188
+ return [3 /*break*/, 7];
189
+ case 6:
190
+ err_4 = _a.sent();
191
+ msg = 'Unable to copy template files. Please check template name or directory permissions.';
192
+ (0, log_1.error)(msg);
193
+ if (err_4 instanceof Error) {
194
+ console.error({ err: err_4 });
195
+ }
196
+ process.exit(1);
197
+ return [3 /*break*/, 7];
198
+ case 7:
199
+ spinner = (0, ora_1.default)('Checking latest Payload version...').start();
200
+ return [4 /*yield*/, updatePayloadVersion(projectDir, args['--beta'])];
201
+ case 8:
202
+ _a.sent();
203
+ spinner.text = 'Installing dependencies...';
204
+ return [4 /*yield*/, installDeps(args, projectDir, packageManager)];
205
+ case 9:
206
+ result = _a.sent();
207
+ spinner.stop();
208
+ spinner.clear();
209
+ if (result) {
210
+ (0, log_1.success)('Dependencies installed');
211
+ }
212
+ else {
213
+ (0, log_1.error)('Error installing dependencies');
214
+ }
215
+ return [2 /*return*/];
216
+ }
217
+ });
218
+ });
219
+ }
220
+ exports.createProject = createProject;
@@ -0,0 +1,137 @@
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 create_project_1 = require("./create-project");
45
+ var projectDir = path_1.default.resolve(__dirname, './tmp');
46
+ describe('createProject', function () {
47
+ beforeAll(function () {
48
+ console.log = jest.fn();
49
+ });
50
+ beforeEach(function () {
51
+ if (fs_extra_1.default.existsSync(projectDir)) {
52
+ fs_extra_1.default.rmdirSync(projectDir, { recursive: true });
53
+ }
54
+ });
55
+ afterEach(function () {
56
+ if (fs_extra_1.default.existsSync(projectDir)) {
57
+ fs_extra_1.default.rmdirSync(projectDir, { recursive: true });
58
+ }
59
+ });
60
+ describe('#createProject', function () {
61
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
62
+ var args = { _: ['project-name'], '--no-deps': true };
63
+ var packageManager = 'yarn';
64
+ it('creates static project', function () { return __awaiter(void 0, void 0, void 0, function () {
65
+ var expectedPayloadVersion, template, packageJsonPath, packageJson;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0: return [4 /*yield*/, (0, create_project_1.getLatestPayloadVersion)()];
69
+ case 1:
70
+ expectedPayloadVersion = _a.sent();
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)];
77
+ case 2:
78
+ _a.sent();
79
+ packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
80
+ packageJson = fs_extra_1.default.readJsonSync(packageJsonPath);
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');
91
+ return [2 /*return*/];
92
+ }
93
+ });
94
+ }); });
95
+ });
96
+ describe('#updatePayloadVersion', function () {
97
+ it('updates payload version in package.json', function () { return __awaiter(void 0, void 0, void 0, function () {
98
+ var packageJsonPath, modified;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0:
102
+ packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
103
+ return [4 /*yield*/, fs_extra_1.default.mkdir(projectDir)];
104
+ case 1:
105
+ _a.sent();
106
+ return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, { dependencies: { payload: '0.0.1' } }, { spaces: 2 })];
107
+ case 2:
108
+ _a.sent();
109
+ return [4 /*yield*/, (0, create_project_1.updatePayloadVersion)(projectDir)];
110
+ case 3:
111
+ _a.sent();
112
+ return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
113
+ case 4:
114
+ modified = _a.sent();
115
+ expect(modified.dependencies.payload).not.toBe('0.0.1');
116
+ return [2 /*return*/];
117
+ }
118
+ });
119
+ }); });
120
+ });
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
+ }
@@ -0,0 +1,48 @@
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
+ exports.generateSecret = void 0;
40
+ var crypto_1 = require("crypto");
41
+ function generateSecret() {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ return __generator(this, function (_a) {
44
+ return [2 /*return*/, (0, crypto_1.randomBytes)(32).toString('hex').slice(0, 24)];
45
+ });
46
+ });
47
+ }
48
+ exports.generateSecret = generateSecret;
@@ -0,0 +1,48 @@
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
+ exports.generateSecret = void 0;
40
+ var crypto_1 = require("crypto");
41
+ function generateSecret() {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ return __generator(this, function (_a) {
44
+ return [2 /*return*/, (0, crypto_1.randomBytes)(32).toString('hex').slice(0, 24)];
45
+ });
46
+ });
47
+ }
48
+ exports.generateSecret = generateSecret;
@@ -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*/, (0, prompts_1.default)({
54
+ type: 'text',
55
+ name: 'value',
56
+ message: 'Enter MongoDB connection',
57
+ initial: "mongodb://localhost/".concat((0, 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,79 @@
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.parseLanguage = void 0;
43
+ var prompts_1 = __importDefault(require("prompts"));
44
+ function parseLanguage(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['--template'])
51
+ return [2 /*return*/, args['--template']];
52
+ return [4 /*yield*/, (0, prompts_1.default)({
53
+ type: 'select',
54
+ name: 'value',
55
+ message: 'Choose language',
56
+ choices: [
57
+ {
58
+ title: 'javascript',
59
+ value: 'js',
60
+ },
61
+ {
62
+ title: 'typescript',
63
+ value: 'ts',
64
+ },
65
+ ],
66
+ validate: function (value) { return value.length; },
67
+ }, {
68
+ onCancel: function () {
69
+ process.exit(0);
70
+ },
71
+ })];
72
+ case 1:
73
+ response = _a.sent();
74
+ return [2 /*return*/, response.value];
75
+ }
76
+ });
77
+ });
78
+ }
79
+ exports.parseLanguage = parseLanguage;