create-payload-app 0.3.7-beta.0 → 0.3.9-beta.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +5 -11
- package/dist/lib/constants.js +4 -0
- package/dist/lib/createProject.js +14 -46
- package/dist/lib/createProject.test.js +8 -6
- package/dist/lib/getPackageManager.js +69 -0
- package/dist/lib/getPayloadVersion.js +75 -0
- package/dist/lib/parseTemplate.js +1 -6
- package/dist/main.js +37 -57
- package/dist/templates/js-blank/server.js +1 -5
- package/dist/templates/js-blog/server.js +1 -5
- package/dist/templates/js-todo/server.js +1 -5
- package/dist/templates/ts-blank/src/server.ts +1 -5
- package/dist/templates/ts-blog/src/server.ts +1 -5
- package/dist/templates/ts-todo/src/server.ts +1 -5
- package/dist/utils/telemetry.js +44 -0
- package/package.json +4 -3
package/dist/index.js
CHANGED
@@ -37,31 +37,25 @@ 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
41
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
43
|
-
var
|
42
|
+
var main, e_1;
|
44
43
|
return __generator(this, function (_a) {
|
45
44
|
switch (_a.label) {
|
46
45
|
case 0:
|
47
|
-
trx = (0, usage_1.init)();
|
48
46
|
main = new main_1.Main();
|
49
47
|
_a.label = 1;
|
50
48
|
case 1:
|
51
|
-
_a.trys.push([1, 3,
|
49
|
+
_a.trys.push([1, 3, , 4]);
|
52
50
|
return [4 /*yield*/, main.init()];
|
53
51
|
case 2:
|
54
52
|
_a.sent();
|
55
|
-
return [3 /*break*/,
|
53
|
+
return [3 /*break*/, 4];
|
56
54
|
case 3:
|
57
55
|
e_1 = _a.sent();
|
58
|
-
(0, usage_1.handleException)(e_1);
|
59
56
|
(0, log_1.error)("An error has occurred: ".concat(e_1 instanceof Error ? e_1.message : e_1));
|
60
|
-
return [3 /*break*/,
|
61
|
-
case 4:
|
62
|
-
trx === null || trx === void 0 ? void 0 : trx.finish();
|
63
|
-
return [7 /*endfinally*/];
|
64
|
-
case 5: return [2 /*return*/];
|
57
|
+
return [3 /*break*/, 4];
|
58
|
+
case 4: return [2 /*return*/];
|
65
59
|
}
|
66
60
|
});
|
67
61
|
}); })();
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
40
40
|
};
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
42
|
-
exports.createProject = exports.updatePayloadVersion =
|
42
|
+
exports.createProject = exports.updatePayloadVersion = void 0;
|
43
43
|
var path_1 = __importDefault(require("path"));
|
44
44
|
var chalk_1 = __importDefault(require("chalk"));
|
45
45
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
@@ -47,7 +47,6 @@ 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");
|
51
50
|
function createProjectDir(projectDir) {
|
52
51
|
return __awaiter(this, void 0, void 0, function () {
|
53
52
|
var pathExists;
|
@@ -95,69 +94,38 @@ function installDeps(args, dir, packageManager) {
|
|
95
94
|
});
|
96
95
|
});
|
97
96
|
}
|
98
|
-
function
|
99
|
-
if (betaFlag === void 0) { betaFlag = false; }
|
97
|
+
function updatePayloadVersion(projectDir, payloadVersion) {
|
100
98
|
return __awaiter(this, void 0, void 0, function () {
|
101
|
-
var
|
99
|
+
var packageJsonPath, packageObj, err_1;
|
102
100
|
return __generator(this, function (_a) {
|
103
101
|
switch (_a.label) {
|
104
102
|
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
|
-
error_2 = _a.sent();
|
117
|
-
return [2 /*return*/, false];
|
118
|
-
case 3: return [2 /*return*/];
|
119
|
-
}
|
120
|
-
});
|
121
|
-
});
|
122
|
-
}
|
123
|
-
exports.getLatestPayloadVersion = getLatestPayloadVersion;
|
124
|
-
function updatePayloadVersion(projectDir, betaFlag) {
|
125
|
-
if (betaFlag === void 0) { betaFlag = false; }
|
126
|
-
return __awaiter(this, void 0, void 0, function () {
|
127
|
-
var payloadVersion, packageJsonPath, packageObj, err_1;
|
128
|
-
return __generator(this, function (_a) {
|
129
|
-
switch (_a.label) {
|
130
|
-
case 0: return [4 /*yield*/, getLatestPayloadVersion(betaFlag)];
|
131
|
-
case 1:
|
132
|
-
payloadVersion = _a.sent();
|
133
103
|
if (!payloadVersion) {
|
134
104
|
(0, log_1.warning)('Error retrieving latest Payload version. Please update your package.json manually.');
|
135
|
-
return [2 /*return*/];
|
136
105
|
}
|
137
|
-
(0, usage_1.setTags)({ payload_version: payloadVersion });
|
138
106
|
packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
|
139
|
-
_a.label =
|
140
|
-
case
|
141
|
-
_a.trys.push([
|
107
|
+
_a.label = 1;
|
108
|
+
case 1:
|
109
|
+
_a.trys.push([1, 4, , 5]);
|
142
110
|
return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
|
143
|
-
case
|
111
|
+
case 2:
|
144
112
|
packageObj = _a.sent();
|
145
113
|
packageObj.dependencies.payload = payloadVersion;
|
146
114
|
return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, packageObj, { spaces: 2 })];
|
147
|
-
case
|
115
|
+
case 3:
|
148
116
|
_a.sent();
|
149
|
-
return [3 /*break*/,
|
150
|
-
case
|
117
|
+
return [3 /*break*/, 5];
|
118
|
+
case 4:
|
151
119
|
err_1 = _a.sent();
|
152
120
|
(0, log_1.warning)('Unable to write Payload version to package.json. Please update your package.json manually.');
|
153
|
-
return [3 /*break*/,
|
154
|
-
case
|
121
|
+
return [3 /*break*/, 5];
|
122
|
+
case 5: return [2 /*return*/];
|
155
123
|
}
|
156
124
|
});
|
157
125
|
});
|
158
126
|
}
|
159
127
|
exports.updatePayloadVersion = updatePayloadVersion;
|
160
|
-
function createProject(args, projectDir, template, packageManager) {
|
128
|
+
function createProject(args, projectDir, template, packageManager, payloadVersion) {
|
161
129
|
return __awaiter(this, void 0, void 0, function () {
|
162
130
|
var templateDir, emitter, err_2, msg, spinner, result;
|
163
131
|
return __generator(this, function (_a) {
|
@@ -188,7 +156,7 @@ function createProject(args, projectDir, template, packageManager) {
|
|
188
156
|
return [3 /*break*/, 6];
|
189
157
|
case 6:
|
190
158
|
spinner = (0, ora_1.default)('Checking latest Payload version...').start();
|
191
|
-
return [4 /*yield*/, updatePayloadVersion(projectDir,
|
159
|
+
return [4 /*yield*/, updatePayloadVersion(projectDir, payloadVersion)];
|
192
160
|
case 7:
|
193
161
|
_a.sent();
|
194
162
|
spinner.text = 'Installing dependencies...';
|
@@ -42,6 +42,7 @@ 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
44
|
var createProject_1 = require("./createProject");
|
45
|
+
var getPayloadVersion_1 = require("./getPayloadVersion");
|
45
46
|
describe('createProject', function () {
|
46
47
|
var projectDir = path_1.default.resolve(__dirname, './tmp');
|
47
48
|
beforeAll(function () {
|
@@ -64,11 +65,11 @@ describe('createProject', 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,
|
68
|
+
case 0: return [4 /*yield*/, (0, getPayloadVersion_1.getLatestPayloadVersion)()];
|
68
69
|
case 1:
|
69
70
|
expectedPayloadVersion = _a.sent();
|
70
71
|
template = { name: 'ts-todo', type: 'static' };
|
71
|
-
return [4 /*yield*/, (0, createProject_1.createProject)(args, projectDir, template, packageManager)];
|
72
|
+
return [4 /*yield*/, (0, createProject_1.createProject)(args, projectDir, template, packageManager, expectedPayloadVersion)];
|
72
73
|
case 2:
|
73
74
|
_a.sent();
|
74
75
|
packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
|
@@ -81,24 +82,25 @@ describe('createProject', function () {
|
|
81
82
|
});
|
82
83
|
describe('#updatePayloadVersion', function () {
|
83
84
|
it('updates payload version in package.json', function () { return __awaiter(void 0, void 0, void 0, function () {
|
84
|
-
var packageJsonPath, modified;
|
85
|
+
var originalPayloadVersion, packageJsonPath, modified;
|
85
86
|
return __generator(this, function (_a) {
|
86
87
|
switch (_a.label) {
|
87
88
|
case 0:
|
89
|
+
originalPayloadVersion = '0.0.1';
|
88
90
|
packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
|
89
91
|
return [4 /*yield*/, fs_extra_1.default.mkdir(projectDir)];
|
90
92
|
case 1:
|
91
93
|
_a.sent();
|
92
|
-
return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, { dependencies: { payload:
|
94
|
+
return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, { dependencies: { payload: originalPayloadVersion } }, { spaces: 2 })];
|
93
95
|
case 2:
|
94
96
|
_a.sent();
|
95
|
-
return [4 /*yield*/, (0, createProject_1.updatePayloadVersion)(projectDir)];
|
97
|
+
return [4 /*yield*/, (0, createProject_1.updatePayloadVersion)(projectDir, '0.0.2')];
|
96
98
|
case 3:
|
97
99
|
_a.sent();
|
98
100
|
return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
|
99
101
|
case 4:
|
100
102
|
modified = _a.sent();
|
101
|
-
expect(modified.dependencies.payload).not.toBe(
|
103
|
+
expect(modified.dependencies.payload).not.toBe(originalPayloadVersion);
|
102
104
|
return [2 /*return*/];
|
103
105
|
}
|
104
106
|
});
|
@@ -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.getPackageManager = void 0;
|
43
|
+
var command_exists_1 = __importDefault(require("command-exists"));
|
44
|
+
function getPackageManager(args) {
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
46
|
+
var packageManager, error_1;
|
47
|
+
return __generator(this, function (_a) {
|
48
|
+
switch (_a.label) {
|
49
|
+
case 0:
|
50
|
+
if (!args['--use-npm']) return [3 /*break*/, 1];
|
51
|
+
packageManager = 'npm';
|
52
|
+
return [3 /*break*/, 4];
|
53
|
+
case 1:
|
54
|
+
_a.trys.push([1, 3, , 4]);
|
55
|
+
return [4 /*yield*/, (0, command_exists_1.default)('yarn')];
|
56
|
+
case 2:
|
57
|
+
_a.sent();
|
58
|
+
packageManager = 'yarn';
|
59
|
+
return [3 /*break*/, 4];
|
60
|
+
case 3:
|
61
|
+
error_1 = _a.sent();
|
62
|
+
packageManager = 'npm';
|
63
|
+
return [3 /*break*/, 4];
|
64
|
+
case 4: return [2 /*return*/, packageManager];
|
65
|
+
}
|
66
|
+
});
|
67
|
+
});
|
68
|
+
}
|
69
|
+
exports.getPackageManager = getPackageManager;
|
@@ -0,0 +1,75 @@
|
|
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.getLatestPayloadVersion = void 0;
|
43
|
+
var execa_1 = __importDefault(require("execa"));
|
44
|
+
var log_1 = require("../utils/log");
|
45
|
+
function getLatestPayloadVersion(betaFlag) {
|
46
|
+
if (betaFlag === void 0) { betaFlag = false; }
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
48
|
+
var packageWithTag, stdout, err_1, msg;
|
49
|
+
return __generator(this, function (_a) {
|
50
|
+
switch (_a.label) {
|
51
|
+
case 0:
|
52
|
+
_a.trys.push([0, 2, , 3]);
|
53
|
+
packageWithTag = 'payload';
|
54
|
+
if (betaFlag)
|
55
|
+
packageWithTag += '@beta';
|
56
|
+
return [4 /*yield*/, (0, execa_1.default)("npm info ".concat(packageWithTag, " version"), [], {
|
57
|
+
shell: true,
|
58
|
+
})];
|
59
|
+
case 1:
|
60
|
+
stdout = (_a.sent()).stdout;
|
61
|
+
return [2 /*return*/, "^".concat(stdout)];
|
62
|
+
case 2:
|
63
|
+
err_1 = _a.sent();
|
64
|
+
msg = "Unable to get latest Payload version.";
|
65
|
+
if (err_1 instanceof Error)
|
66
|
+
msg += " ".concat(err_1.message);
|
67
|
+
(0, log_1.error)(msg);
|
68
|
+
process.exit(1);
|
69
|
+
return [3 /*break*/, 3];
|
70
|
+
case 3: return [2 /*return*/];
|
71
|
+
}
|
72
|
+
});
|
73
|
+
});
|
74
|
+
}
|
75
|
+
exports.getLatestPayloadVersion = getLatestPayloadVersion;
|
@@ -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;
|
@@ -53,7 +52,6 @@ function parseTemplate(args, validTemplates, language) {
|
|
53
52
|
template_1 = validTemplates.find(function (template) { return template.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
|
@@ -71,15 +69,12 @@ function parseTemplate(args, validTemplates, language) {
|
|
71
69
|
onCancel: function () {
|
72
70
|
process.exit(0);
|
73
71
|
},
|
74
|
-
})
|
75
|
-
// const template = `${language}-${response.value}`
|
76
|
-
];
|
72
|
+
})];
|
77
73
|
case 1:
|
78
74
|
response = _a.sent();
|
79
75
|
template = validTemplates.find(function (t) { return t.name === response.value; });
|
80
76
|
if (!template)
|
81
77
|
throw new Error('Template is undefined');
|
82
|
-
(0, usage_1.setTags)({ template: template.name });
|
83
78
|
return [2 /*return*/, template];
|
84
79
|
}
|
85
80
|
});
|
package/dist/main.js
CHANGED
@@ -42,18 +42,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.Main = void 0;
|
43
43
|
var slugify_1 = __importDefault(require("@sindresorhus/slugify"));
|
44
44
|
var arg_1 = __importDefault(require("arg"));
|
45
|
-
var command_exists_1 = __importDefault(require("command-exists"));
|
46
45
|
var createProject_1 = require("./lib/createProject");
|
47
46
|
var getDatabaseConnection_1 = require("./lib/getDatabaseConnection");
|
48
47
|
var getPayloadSecret_1 = require("./lib/getPayloadSecret");
|
49
48
|
var parseLanguage_1 = require("./lib/parseLanguage");
|
50
49
|
var parseProjectName_1 = require("./lib/parseProjectName");
|
51
50
|
var parseTemplate_1 = require("./lib/parseTemplate");
|
51
|
+
var telemetry_1 = require("./utils/telemetry");
|
52
52
|
var templates_1 = require("./lib/templates");
|
53
53
|
var writeEnvFile_1 = require("./lib/writeEnvFile");
|
54
54
|
var log_1 = require("./utils/log");
|
55
55
|
var messages_1 = require("./utils/messages");
|
56
|
-
var
|
56
|
+
var getPayloadVersion_1 = require("./lib/getPayloadVersion");
|
57
|
+
var getPackageManager_1 = require("./lib/getPackageManager");
|
57
58
|
var Main = /** @class */ (function () {
|
58
59
|
function Main() {
|
59
60
|
this.args = (0, arg_1.default)({
|
@@ -73,72 +74,78 @@ var Main = /** @class */ (function () {
|
|
73
74
|
}
|
74
75
|
Main.prototype.init = function () {
|
75
76
|
return __awaiter(this, void 0, void 0, function () {
|
76
|
-
var _a, _b, templateArg, valid, _c, _d, projectName, language, validTemplates, template, databaseUri, payloadSecret, projectDir, packageManager,
|
77
|
-
return __generator(this, function (
|
78
|
-
switch (
|
77
|
+
var _a, _b, templateArg, valid, _c, _d, projectName, language, validTemplates, template, databaseUri, payloadSecret, projectDir, packageManager, payloadVersion, error_1;
|
78
|
+
return __generator(this, function (_e) {
|
79
|
+
switch (_e.label) {
|
79
80
|
case 0:
|
80
|
-
|
81
|
+
_e.trys.push([0, 17, , 18]);
|
81
82
|
if (!this.args['--help']) return [3 /*break*/, 2];
|
82
83
|
_b = (_a = console).log;
|
83
84
|
return [4 /*yield*/, (0, messages_1.helpMessage)()];
|
84
85
|
case 1:
|
85
|
-
_b.apply(_a, [
|
86
|
+
_b.apply(_a, [_e.sent()]);
|
86
87
|
process.exit(0);
|
87
|
-
|
88
|
+
_e.label = 2;
|
88
89
|
case 2:
|
89
90
|
templateArg = this.args['--template'];
|
90
91
|
if (!templateArg) return [3 /*break*/, 5];
|
91
92
|
return [4 /*yield*/, (0, templates_1.validateTemplate)(templateArg)];
|
92
93
|
case 3:
|
93
|
-
valid =
|
94
|
+
valid = _e.sent();
|
94
95
|
if (!!valid) return [3 /*break*/, 5];
|
95
96
|
_d = (_c = console).log;
|
96
97
|
return [4 /*yield*/, (0, messages_1.helpMessage)()];
|
97
98
|
case 4:
|
98
|
-
_d.apply(_c, [
|
99
|
+
_d.apply(_c, [_e.sent()]);
|
99
100
|
process.exit(1);
|
100
|
-
|
101
|
+
_e.label = 5;
|
101
102
|
case 5:
|
102
103
|
console.log(messages_1.welcomeMessage);
|
103
104
|
return [4 /*yield*/, (0, parseProjectName_1.parseProjectName)(this.args)];
|
104
105
|
case 6:
|
105
|
-
projectName =
|
106
|
+
projectName = _e.sent();
|
106
107
|
return [4 /*yield*/, (0, parseLanguage_1.parseLanguage)(this.args)];
|
107
108
|
case 7:
|
108
|
-
language =
|
109
|
+
language = _e.sent();
|
109
110
|
return [4 /*yield*/, (0, templates_1.getValidTemplates)()];
|
110
111
|
case 8:
|
111
|
-
validTemplates =
|
112
|
+
validTemplates = _e.sent();
|
112
113
|
return [4 /*yield*/, (0, parseTemplate_1.parseTemplate)(this.args, validTemplates, language)];
|
113
114
|
case 9:
|
114
|
-
template =
|
115
|
+
template = _e.sent();
|
115
116
|
return [4 /*yield*/, (0, getDatabaseConnection_1.getDatabaseConnection)(this.args, projectName)];
|
116
117
|
case 10:
|
117
|
-
databaseUri =
|
118
|
+
databaseUri = _e.sent();
|
118
119
|
return [4 /*yield*/, (0, getPayloadSecret_1.getPayloadSecret)(this.args)];
|
119
120
|
case 11:
|
120
|
-
payloadSecret =
|
121
|
+
payloadSecret = _e.sent();
|
121
122
|
projectDir = "./".concat((0, slugify_1.default)(projectName));
|
122
|
-
return [4 /*yield*/, getPackageManager(this.args)];
|
123
|
+
return [4 /*yield*/, (0, getPackageManager_1.getPackageManager)(this.args)];
|
123
124
|
case 12:
|
124
|
-
packageManager =
|
125
|
-
|
126
|
-
return [4 /*yield*/, (0, createProject_1.createProject)(this.args, projectDir, template, packageManager)];
|
125
|
+
packageManager = _e.sent();
|
126
|
+
return [4 /*yield*/, (0, getPayloadVersion_1.getLatestPayloadVersion)(this.args['--beta'])];
|
127
127
|
case 13:
|
128
|
-
|
129
|
-
return [
|
128
|
+
payloadVersion = _e.sent();
|
129
|
+
if (!!this.args['--dry-run']) return [3 /*break*/, 16];
|
130
|
+
return [4 /*yield*/, (0, createProject_1.createProject)(this.args, projectDir, template, packageManager, payloadVersion)];
|
130
131
|
case 14:
|
131
|
-
|
132
|
-
|
132
|
+
_e.sent();
|
133
|
+
return [4 /*yield*/, (0, writeEnvFile_1.writeEnvFile)(projectName, databaseUri, payloadSecret)];
|
133
134
|
case 15:
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
_e.sent();
|
136
|
+
(0, telemetry_1.sendAnonymousAnalytics)({
|
137
|
+
projectDir: projectDir,
|
138
|
+
packageManager: packageManager,
|
139
|
+
template: template.name,
|
140
|
+
payloadVersion: payloadVersion,
|
141
|
+
});
|
142
|
+
_e.label = 16;
|
137
143
|
case 16:
|
138
|
-
|
144
|
+
(0, log_1.success)('Payload project successfully created');
|
145
|
+
console.log((0, messages_1.successMessage)(projectDir, packageManager));
|
139
146
|
return [3 /*break*/, 18];
|
140
147
|
case 17:
|
141
|
-
error_1 =
|
148
|
+
error_1 = _e.sent();
|
142
149
|
console.log(error_1);
|
143
150
|
return [3 /*break*/, 18];
|
144
151
|
case 18: return [2 /*return*/];
|
@@ -149,30 +156,3 @@ var Main = /** @class */ (function () {
|
|
149
156
|
return Main;
|
150
157
|
}());
|
151
158
|
exports.Main = Main;
|
152
|
-
function getPackageManager(args) {
|
153
|
-
return __awaiter(this, void 0, void 0, function () {
|
154
|
-
var packageManager, error_2;
|
155
|
-
return __generator(this, function (_a) {
|
156
|
-
switch (_a.label) {
|
157
|
-
case 0:
|
158
|
-
if (!args['--use-npm']) return [3 /*break*/, 1];
|
159
|
-
packageManager = 'npm';
|
160
|
-
return [3 /*break*/, 4];
|
161
|
-
case 1:
|
162
|
-
_a.trys.push([1, 3, , 4]);
|
163
|
-
return [4 /*yield*/, (0, command_exists_1.default)('yarn')];
|
164
|
-
case 2:
|
165
|
-
_a.sent();
|
166
|
-
packageManager = 'yarn';
|
167
|
-
return [3 /*break*/, 4];
|
168
|
-
case 3:
|
169
|
-
error_2 = _a.sent();
|
170
|
-
packageManager = 'npm';
|
171
|
-
return [3 /*break*/, 4];
|
172
|
-
case 4:
|
173
|
-
(0, usage_1.setTags)({ package_manager: packageManager });
|
174
|
-
return [2 /*return*/, packageManager];
|
175
|
-
}
|
176
|
-
});
|
177
|
-
});
|
178
|
-
}
|
@@ -13,10 +13,6 @@ app.get('/', (_, res) => {
|
|
13
13
|
payload.init({
|
14
14
|
secret: process.env.PAYLOAD_SECRET,
|
15
15
|
mongoURL: process.env.MONGODB_URI,
|
16
|
-
|
17
|
-
// Only needed to deploy publicly. Get free Personal license at https://payloadcms.com.
|
18
|
-
// license: process.env.PAYLOAD_LICENSE_KEY,
|
19
|
-
|
20
16
|
express: app,
|
21
17
|
onInit: () => {
|
22
18
|
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
|
@@ -25,4 +21,4 @@ payload.init({
|
|
25
21
|
|
26
22
|
// Add your own express routes here
|
27
23
|
|
28
|
-
app.listen(3000);
|
24
|
+
app.listen(3000);
|
@@ -13,10 +13,6 @@ app.get('/', (_, res) => {
|
|
13
13
|
payload.init({
|
14
14
|
secret: process.env.PAYLOAD_SECRET,
|
15
15
|
mongoURL: process.env.MONGODB_URI,
|
16
|
-
|
17
|
-
// Only needed to deploy publicly. Get free Personal license at https://payloadcms.com.
|
18
|
-
// license: process.env.PAYLOAD_LICENSE_KEY,
|
19
|
-
|
20
16
|
express: app,
|
21
17
|
onInit: () => {
|
22
18
|
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
|
@@ -25,4 +21,4 @@ payload.init({
|
|
25
21
|
|
26
22
|
// Add your own express routes here
|
27
23
|
|
28
|
-
app.listen(3000);
|
24
|
+
app.listen(3000);
|
@@ -13,10 +13,6 @@ app.get('/', (_, res) => {
|
|
13
13
|
payload.init({
|
14
14
|
secret: process.env.PAYLOAD_SECRET,
|
15
15
|
mongoURL: process.env.MONGODB_URI,
|
16
|
-
|
17
|
-
// Only needed to deploy publicly. Get free Personal license at https://payloadcms.com.
|
18
|
-
// license: process.env.PAYLOAD_LICENSE_KEY,
|
19
|
-
|
20
16
|
express: app,
|
21
17
|
onInit: () => {
|
22
18
|
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
|
@@ -25,4 +21,4 @@ payload.init({
|
|
25
21
|
|
26
22
|
// Add your own express routes here
|
27
23
|
|
28
|
-
app.listen(3000);
|
24
|
+
app.listen(3000);
|
@@ -13,10 +13,6 @@ app.get('/', (_, res) => {
|
|
13
13
|
payload.init({
|
14
14
|
secret: process.env.PAYLOAD_SECRET,
|
15
15
|
mongoURL: process.env.MONGODB_URI,
|
16
|
-
|
17
|
-
// Only needed to deploy publicly. Get free Personal license at https://payloadcms.com.
|
18
|
-
// license: process.env.PAYLOAD_LICENSE_KEY,
|
19
|
-
|
20
16
|
express: app,
|
21
17
|
onInit: () => {
|
22
18
|
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
@@ -25,4 +21,4 @@ payload.init({
|
|
25
21
|
|
26
22
|
// Add your own express routes here
|
27
23
|
|
28
|
-
app.listen(3000);
|
24
|
+
app.listen(3000);
|
@@ -13,10 +13,6 @@ app.get('/', (_, res) => {
|
|
13
13
|
payload.init({
|
14
14
|
secret: process.env.PAYLOAD_SECRET,
|
15
15
|
mongoURL: process.env.MONGODB_URI,
|
16
|
-
|
17
|
-
// Only needed to deploy publicly. Get free Personal license at https://payloadcms.com.
|
18
|
-
// license: process.env.PAYLOAD_LICENSE_KEY,
|
19
|
-
|
20
16
|
express: app,
|
21
17
|
onInit: () => {
|
22
18
|
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
@@ -25,4 +21,4 @@ payload.init({
|
|
25
21
|
|
26
22
|
// Add your own express routes here
|
27
23
|
|
28
|
-
app.listen(3000);
|
24
|
+
app.listen(3000);
|
@@ -13,10 +13,6 @@ app.get('/', (_, res) => {
|
|
13
13
|
payload.init({
|
14
14
|
secret: process.env.PAYLOAD_SECRET,
|
15
15
|
mongoURL: process.env.MONGODB_URI,
|
16
|
-
|
17
|
-
// Only needed to deploy publicly. Get free Personal license at https://payloadcms.com.
|
18
|
-
// license: process.env.PAYLOAD_LICENSE_KEY,
|
19
|
-
|
20
16
|
express: app,
|
21
17
|
onInit: () => {
|
22
18
|
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
@@ -25,4 +21,4 @@ payload.init({
|
|
25
21
|
|
26
22
|
// Add your own express routes here
|
27
23
|
|
28
|
-
app.listen(3000);
|
24
|
+
app.listen(3000);
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.sendAnonymousAnalytics = void 0;
|
7
|
+
var analytics_node_1 = __importDefault(require("analytics-node"));
|
8
|
+
var crypto_1 = require("crypto");
|
9
|
+
var os_1 = __importDefault(require("os"));
|
10
|
+
var constants_1 = require("../lib/constants");
|
11
|
+
var analytics = new analytics_node_1.default(constants_1.SEGMENT_WRITE_KEY, { flushAt: 1 });
|
12
|
+
var userId;
|
13
|
+
function sendAnonymousAnalytics(meta) {
|
14
|
+
try {
|
15
|
+
var projectDir = meta.projectDir, template = meta.template, packageManager = meta.packageManager;
|
16
|
+
userId = userId !== null && userId !== void 0 ? userId : oneWayHash(projectDir);
|
17
|
+
analytics.track({
|
18
|
+
userId: userId,
|
19
|
+
event: 'ProjectInitiated',
|
20
|
+
properties: {
|
21
|
+
systemPlatform: os_1.default.platform(),
|
22
|
+
systemRelease: os_1.default.release(),
|
23
|
+
systemArchitecture: os_1.default.arch(),
|
24
|
+
nodeVersion: process.version,
|
25
|
+
nodeEnv: process.env.NODE_ENV,
|
26
|
+
template: template,
|
27
|
+
packageManager: packageManager,
|
28
|
+
},
|
29
|
+
});
|
30
|
+
}
|
31
|
+
catch (error) {
|
32
|
+
// Eat any errors
|
33
|
+
}
|
34
|
+
}
|
35
|
+
exports.sendAnonymousAnalytics = sendAnonymousAnalytics;
|
36
|
+
/** Hash values one-way to ensure anonymity */
|
37
|
+
function oneWayHash(payload) {
|
38
|
+
var hash = (0, crypto_1.createHash)('sha256');
|
39
|
+
// Prepend salt to ensure truly one-way hashing.
|
40
|
+
hash.update((0, crypto_1.randomBytes)(16).toString('hex'));
|
41
|
+
// This appends the payload to the hash. The salt is from prior update still present!
|
42
|
+
hash.update(payload);
|
43
|
+
return hash.digest('hex');
|
44
|
+
}
|
package/package.json
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
"typecheck": "tsc --noEmit",
|
11
11
|
"lint": "eslint \"src/**/*.ts\"",
|
12
12
|
"test": "jest",
|
13
|
-
"
|
13
|
+
"prepublishOnly": "yarn test && yarn build"
|
14
14
|
},
|
15
15
|
"files": [
|
16
16
|
"package.json",
|
@@ -18,8 +18,8 @@
|
|
18
18
|
"bin"
|
19
19
|
],
|
20
20
|
"dependencies": {
|
21
|
-
"@sentry/node": "^6.18.2",
|
22
21
|
"@sindresorhus/slugify": "^1.1.0",
|
22
|
+
"analytics-node": "^6.0.0",
|
23
23
|
"arg": "^5.0.0",
|
24
24
|
"chalk": "^4.1.0",
|
25
25
|
"command-exists": "^1.2.9",
|
@@ -31,8 +31,9 @@
|
|
31
31
|
"prompts": "^2.4.0",
|
32
32
|
"terminal-link": "^2.1.1"
|
33
33
|
},
|
34
|
-
"version": "0.3.
|
34
|
+
"version": "0.3.9-beta.0",
|
35
35
|
"devDependencies": {
|
36
|
+
"@types/analytics-node": "^3.1.9",
|
36
37
|
"@types/command-exists": "^1.2.0",
|
37
38
|
"@types/degit": "^2.8.3",
|
38
39
|
"@types/fs-extra": "^9.0.12",
|