create-payload-app 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/createProject.test.js +8 -2
- package/dist/utils/messages.js +1 -1
- package/package.json +1 -1
- package/dist/lib/github.js +0 -130
@@ -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/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
|
-
}
|