create-payload-app 0.3.3 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/lib/createProject.js +13 -6
- package/dist/lib/createProject.test.js +8 -2
- package/dist/main.js +1 -0
- package/dist/templates/js-blog/collections/Users.js +0 -11
- package/dist/templates/ts-blog/src/collections/Users.ts +0 -12
- package/dist/utils/messages.js +1 -1
- package/package.json +1 -1
- package/dist/lib/github.js +0 -130
@@ -95,14 +95,20 @@ function installDeps(args, dir, packageManager) {
|
|
95
95
|
});
|
96
96
|
});
|
97
97
|
}
|
98
|
-
function getLatestPayloadVersion() {
|
98
|
+
function getLatestPayloadVersion(betaFlag) {
|
99
|
+
if (betaFlag === void 0) { betaFlag = false; }
|
99
100
|
return __awaiter(this, void 0, void 0, function () {
|
100
|
-
var stdout, error_2;
|
101
|
+
var packageWithTag, stdout, error_2;
|
101
102
|
return __generator(this, function (_a) {
|
102
103
|
switch (_a.label) {
|
103
104
|
case 0:
|
104
105
|
_a.trys.push([0, 2, , 3]);
|
105
|
-
|
106
|
+
packageWithTag = 'payload';
|
107
|
+
if (betaFlag)
|
108
|
+
packageWithTag += '@beta';
|
109
|
+
return [4 /*yield*/, execa_1.default("npm info " + packageWithTag + " version", [], {
|
110
|
+
shell: true,
|
111
|
+
})];
|
106
112
|
case 1:
|
107
113
|
stdout = (_a.sent()).stdout;
|
108
114
|
return [2 /*return*/, "^" + stdout];
|
@@ -115,12 +121,13 @@ function getLatestPayloadVersion() {
|
|
115
121
|
});
|
116
122
|
}
|
117
123
|
exports.getLatestPayloadVersion = getLatestPayloadVersion;
|
118
|
-
function updatePayloadVersion(projectDir) {
|
124
|
+
function updatePayloadVersion(projectDir, betaFlag) {
|
125
|
+
if (betaFlag === void 0) { betaFlag = false; }
|
119
126
|
return __awaiter(this, void 0, void 0, function () {
|
120
127
|
var payloadVersion, packageJsonPath, packageObj, err_1;
|
121
128
|
return __generator(this, function (_a) {
|
122
129
|
switch (_a.label) {
|
123
|
-
case 0: return [4 /*yield*/, getLatestPayloadVersion()];
|
130
|
+
case 0: return [4 /*yield*/, getLatestPayloadVersion(betaFlag)];
|
124
131
|
case 1:
|
125
132
|
payloadVersion = _a.sent();
|
126
133
|
if (!payloadVersion) {
|
@@ -181,7 +188,7 @@ function createProject(args, projectDir, template, packageManager) {
|
|
181
188
|
return [3 /*break*/, 6];
|
182
189
|
case 6:
|
183
190
|
spinner = ora_1.default('Checking latest Payload version...').start();
|
184
|
-
return [4 /*yield*/, updatePayloadVersion(projectDir)];
|
191
|
+
return [4 /*yield*/, updatePayloadVersion(projectDir, args['--beta'])];
|
185
192
|
case 7:
|
186
193
|
_a.sent();
|
187
194
|
spinner.text = 'Installing dependencies...';
|
@@ -46,10 +46,16 @@ describe('createProject', function () {
|
|
46
46
|
var projectDir = path_1.default.resolve(__dirname, './tmp');
|
47
47
|
beforeAll(function () {
|
48
48
|
console.log = jest.fn();
|
49
|
-
|
49
|
+
});
|
50
|
+
beforeEach(function () {
|
51
|
+
if (fs_extra_1.default.existsSync(projectDir)) {
|
52
|
+
fs_extra_1.default.rmdirSync(projectDir, { recursive: true });
|
53
|
+
}
|
50
54
|
});
|
51
55
|
afterEach(function () {
|
52
|
-
fs_extra_1.default.
|
56
|
+
if (fs_extra_1.default.existsSync(projectDir)) {
|
57
|
+
fs_extra_1.default.rmdirSync(projectDir, { recursive: true });
|
58
|
+
}
|
53
59
|
});
|
54
60
|
describe('#createProject', function () {
|
55
61
|
var args = { _: ['project-name'], '--no-deps': true };
|
package/dist/main.js
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
const onlyNameIfPublic = ({ req: { user }, doc }) => {
|
2
|
-
// Only return name if not logged in
|
3
|
-
if (!user) {
|
4
|
-
return { name: doc.name };
|
5
|
-
}
|
6
|
-
return doc;
|
7
|
-
};
|
8
|
-
|
9
1
|
const Users = {
|
10
2
|
slug: 'users',
|
11
3
|
auth: true,
|
@@ -15,9 +7,6 @@ const Users = {
|
|
15
7
|
access: {
|
16
8
|
read: () => true,
|
17
9
|
},
|
18
|
-
hooks: {
|
19
|
-
beforeRead: [onlyNameIfPublic]
|
20
|
-
},
|
21
10
|
fields: [
|
22
11
|
// Email added by default
|
23
12
|
{
|
@@ -1,14 +1,5 @@
|
|
1
|
-
import { BeforeReadHook } from 'payload/dist/collections/config/types';
|
2
1
|
import { CollectionConfig } from 'payload/types';
|
3
2
|
|
4
|
-
const onlyNameIfPublic: BeforeReadHook = ({ req: { user }, doc }) => {
|
5
|
-
// Only return name if not logged in
|
6
|
-
if (!user) {
|
7
|
-
return { name: doc.name };
|
8
|
-
}
|
9
|
-
return doc;
|
10
|
-
};
|
11
|
-
|
12
3
|
const Users: CollectionConfig = {
|
13
4
|
slug: 'users',
|
14
5
|
auth: true,
|
@@ -18,9 +9,6 @@ const Users: CollectionConfig = {
|
|
18
9
|
access: {
|
19
10
|
read: () => true,
|
20
11
|
},
|
21
|
-
hooks: {
|
22
|
-
beforeRead: [onlyNameIfPublic]
|
23
|
-
},
|
24
12
|
fields: [
|
25
13
|
// Email added by default
|
26
14
|
{
|
package/dist/utils/messages.js
CHANGED
@@ -60,7 +60,7 @@ function helpMessage() {
|
|
60
60
|
case 0: return [4 /*yield*/, templates_1.getValidTemplates()];
|
61
61
|
case 1:
|
62
62
|
validTemplates = _a.sent();
|
63
|
-
return [2 /*return*/, chalk_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n\n {bold OPTIONS}\n\n --name {underline my-payload-app} Set project name\n --template {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --no-deps Do not install any dependencies\n --help Show help\n"], ["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n\n {bold OPTIONS}\n\n --name {underline my-payload-app} Set project name\n --template {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --no-deps Do not install any dependencies\n --help Show help\n"])), validTemplates.join(', '))];
|
63
|
+
return [2 /*return*/, chalk_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n\n {bold OPTIONS}\n\n --name {underline my-payload-app} Set project name\n --template {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --no-deps Do not install any dependencies\n --help Show help\n"], ["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n\n {bold OPTIONS}\n\n --name {underline my-payload-app} Set project name\n --template {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --no-deps Do not install any dependencies\n --help Show help\n"])), validTemplates.map(function (t) { return t.name; }).join(', '))];
|
64
64
|
}
|
65
65
|
});
|
66
66
|
});
|
package/package.json
CHANGED
package/dist/lib/github.js
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
-
}) : (function(o, m, k, k2) {
|
6
|
-
if (k2 === undefined) k2 = k;
|
7
|
-
o[k2] = m[k];
|
8
|
-
}));
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
-
}) : function(o, v) {
|
12
|
-
o["default"] = v;
|
13
|
-
});
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
-
if (mod && mod.__esModule) return mod;
|
16
|
-
var result = {};
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
-
__setModuleDefault(result, mod);
|
19
|
-
return result;
|
20
|
-
};
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
28
|
-
});
|
29
|
-
};
|
30
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
31
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
32
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
33
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
34
|
-
function step(op) {
|
35
|
-
if (f) throw new TypeError("Generator is already executing.");
|
36
|
-
while (_) try {
|
37
|
-
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;
|
38
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
39
|
-
switch (op[0]) {
|
40
|
-
case 0: case 1: t = op; break;
|
41
|
-
case 4: _.label++; return { value: op[1], done: false };
|
42
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
43
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
44
|
-
default:
|
45
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
46
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
47
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
48
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
49
|
-
if (t[2]) _.ops.pop();
|
50
|
-
_.trys.pop(); continue;
|
51
|
-
}
|
52
|
-
op = body.call(thisArg, _);
|
53
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
54
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
55
|
-
}
|
56
|
-
};
|
57
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
58
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
59
|
-
};
|
60
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
61
|
-
exports.createProjectFromGitHub = void 0;
|
62
|
-
var node_fetch_1 = __importDefault(require("node-fetch"));
|
63
|
-
var path_1 = __importDefault(require("path"));
|
64
|
-
var fs_extra_1 = __importStar(require("fs-extra"));
|
65
|
-
var stream_1 = require("stream");
|
66
|
-
var util_1 = require("util");
|
67
|
-
var streamPipeline = util_1.promisify(stream_1.pipeline);
|
68
|
-
function createProjectFromGitHub(sha, remoteFilePath, dest) {
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
70
|
-
var latestCommitSha, res, tree;
|
71
|
-
var _this = this;
|
72
|
-
return __generator(this, function (_a) {
|
73
|
-
switch (_a.label) {
|
74
|
-
case 0: return [4 /*yield*/, getLatestCommitSha()];
|
75
|
-
case 1:
|
76
|
-
latestCommitSha = _a.sent();
|
77
|
-
return [4 /*yield*/, node_fetch_1.default("https://api.github.com/repos/payloadcms/payload/git/trees/" + latestCommitSha + "?recursive=1")];
|
78
|
-
case 2:
|
79
|
-
res = _a.sent();
|
80
|
-
return [4 /*yield*/, res.json()];
|
81
|
-
case 3:
|
82
|
-
tree = (_a.sent()).tree;
|
83
|
-
return [4 /*yield*/, Promise.all(tree.map(function (item) { return __awaiter(_this, void 0, void 0, function () {
|
84
|
-
var destFile, fileDetails, fileContent;
|
85
|
-
return __generator(this, function (_a) {
|
86
|
-
switch (_a.label) {
|
87
|
-
case 0:
|
88
|
-
console.log(item.path);
|
89
|
-
if (!(item.type === 'blob' && item.path.startsWith(remoteFilePath))) return [3 /*break*/, 5];
|
90
|
-
destFile = path_1.default.join(dest, item.path.replace(remoteFilePath, ''));
|
91
|
-
return [4 /*yield*/, fs_extra_1.default.ensureDir(path_1.default.dirname(destFile))];
|
92
|
-
case 1:
|
93
|
-
_a.sent();
|
94
|
-
return [4 /*yield*/, node_fetch_1.default(item.url)];
|
95
|
-
case 2: return [4 /*yield*/, (_a.sent()).json()];
|
96
|
-
case 3:
|
97
|
-
fileDetails = (_a.sent());
|
98
|
-
fileContent = Buffer.from(fileDetails.content, 'base64').toString();
|
99
|
-
return [4 /*yield*/, streamPipeline(fileContent, fs_extra_1.createWriteStream(destFile))];
|
100
|
-
case 4:
|
101
|
-
_a.sent();
|
102
|
-
_a.label = 5;
|
103
|
-
case 5: return [2 /*return*/];
|
104
|
-
}
|
105
|
-
});
|
106
|
-
}); }))];
|
107
|
-
case 4:
|
108
|
-
_a.sent();
|
109
|
-
return [2 /*return*/];
|
110
|
-
}
|
111
|
-
});
|
112
|
-
});
|
113
|
-
}
|
114
|
-
exports.createProjectFromGitHub = createProjectFromGitHub;
|
115
|
-
function getLatestCommitSha() {
|
116
|
-
return __awaiter(this, void 0, void 0, function () {
|
117
|
-
var res, commits;
|
118
|
-
return __generator(this, function (_a) {
|
119
|
-
switch (_a.label) {
|
120
|
-
case 0: return [4 /*yield*/, node_fetch_1.default("https://api.github.com/repos/payloadcms/payload/commits")];
|
121
|
-
case 1:
|
122
|
-
res = _a.sent();
|
123
|
-
return [4 /*yield*/, res.json()];
|
124
|
-
case 2:
|
125
|
-
commits = _a.sent();
|
126
|
-
return [2 /*return*/, commits[0].sha];
|
127
|
-
}
|
128
|
-
});
|
129
|
-
});
|
130
|
-
}
|