@contember/create 2.2.0-alpha.2 → 2.2.0-alpha.21
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/CLAUDE.md +22 -0
- package/dist/development/run.cjs +7 -7
- package/dist/development/run.cjs.map +1 -1
- package/dist/development/run.js +8 -8
- package/dist/development/run.js.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs +36 -23
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js +37 -24
- package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/development/src/lib/FileSystem.cjs +10 -4
- package/dist/development/src/lib/FileSystem.cjs.map +1 -1
- package/dist/development/src/lib/FileSystem.js +8 -2
- package/dist/development/src/lib/FileSystem.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +71 -60
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +71 -60
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/development/src/lib/fsErrors.cjs +7 -0
- package/dist/development/src/lib/fsErrors.cjs.map +1 -0
- package/dist/development/src/lib/fsErrors.js +7 -0
- package/dist/development/src/lib/fsErrors.js.map +1 -0
- package/dist/development/src/lib/projectPath.cjs +66 -0
- package/dist/development/src/lib/projectPath.cjs.map +1 -0
- package/dist/development/src/lib/projectPath.js +66 -0
- package/dist/development/src/lib/projectPath.js.map +1 -0
- package/dist/development/src/lib/remoteTemplate.cjs +108 -0
- package/dist/development/src/lib/remoteTemplate.cjs.map +1 -0
- package/dist/development/src/lib/remoteTemplate.js +108 -0
- package/dist/development/src/lib/remoteTemplate.js.map +1 -0
- package/dist/development/src/lib/tar.cjs +243 -0
- package/dist/development/src/lib/tar.cjs.map +1 -0
- package/dist/development/src/lib/tar.js +243 -0
- package/dist/development/src/lib/tar.js.map +1 -0
- package/dist/production/run.cjs +7 -7
- package/dist/production/run.cjs.map +1 -1
- package/dist/production/run.js +8 -8
- package/dist/production/run.js.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs +36 -23
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js +37 -24
- package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/production/src/lib/FileSystem.cjs +10 -4
- package/dist/production/src/lib/FileSystem.cjs.map +1 -1
- package/dist/production/src/lib/FileSystem.js +8 -2
- package/dist/production/src/lib/FileSystem.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +71 -60
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +71 -60
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/production/src/lib/fsErrors.cjs +7 -0
- package/dist/production/src/lib/fsErrors.cjs.map +1 -0
- package/dist/production/src/lib/fsErrors.js +7 -0
- package/dist/production/src/lib/fsErrors.js.map +1 -0
- package/dist/production/src/lib/projectPath.cjs +66 -0
- package/dist/production/src/lib/projectPath.cjs.map +1 -0
- package/dist/production/src/lib/projectPath.js +66 -0
- package/dist/production/src/lib/projectPath.js.map +1 -0
- package/dist/production/src/lib/remoteTemplate.cjs +108 -0
- package/dist/production/src/lib/remoteTemplate.cjs.map +1 -0
- package/dist/production/src/lib/remoteTemplate.js +108 -0
- package/dist/production/src/lib/remoteTemplate.js.map +1 -0
- package/dist/production/src/lib/tar.cjs +243 -0
- package/dist/production/src/lib/tar.cjs.map +1 -0
- package/dist/production/src/lib/tar.js +243 -0
- package/dist/production/src/lib/tar.js.map +1 -0
- package/dist/types/commands/WorkspaceCreateCommand.d.ts +15 -3
- package/dist/types/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/types/lib/FileSystem.d.ts +2 -0
- package/dist/types/lib/FileSystem.d.ts.map +1 -1
- package/dist/types/lib/TemplateInstaller.d.ts +9 -1
- package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
- package/dist/types/lib/fsErrors.d.ts +3 -0
- package/dist/types/lib/fsErrors.d.ts.map +1 -0
- package/dist/types/lib/projectPath.d.ts +12 -0
- package/dist/types/lib/projectPath.d.ts.map +1 -0
- package/dist/types/lib/remoteTemplate.d.ts +15 -0
- package/dist/types/lib/remoteTemplate.d.ts.map +1 -0
- package/dist/types/lib/tar.d.ts +28 -0
- package/dist/types/lib/tar.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -7
- package/resources/templates/default/README.md +3 -1
- package/resources/templates/default/admin/app/components/navigation.tsx +95 -8
- package/resources/templates/default/admin/app/pages/tenant.tsx +328 -77
- package/resources/templates/default/admin/entrypoint/components/login.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLink.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLinkSent.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/passwordReset.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequest.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequestSuccess.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/editor-inline-toolbar.tsx +3 -0
- package/resources/templates/default/admin/lib/editor/sortable-block.tsx +5 -4
- package/resources/templates/default/admin/lib/tenant/config/auth-policy-list.tsx +86 -0
- package/resources/templates/default/admin/lib/tenant/config/common.tsx +71 -0
- package/resources/templates/default/admin/lib/tenant/config/identity-provider-list.tsx +131 -0
- package/resources/templates/default/admin/lib/tenant/config/index.ts +5 -0
- package/resources/templates/default/admin/lib/tenant/config/mail-template-list.tsx +108 -0
- package/resources/templates/default/admin/lib/tenant/config/tenant-config-view.tsx +195 -0
- package/resources/templates/default/admin/lib/tenant/dict.ts +456 -4
- package/resources/templates/default/admin/lib/tenant/errors.ts +10 -0
- package/resources/templates/default/admin/lib/tenant/forms/add-project-member.tsx +57 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-my-profile.tsx +40 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-profile.tsx +55 -0
- package/resources/templates/default/admin/lib/tenant/forms/common.tsx +9 -2
- package/resources/templates/default/admin/lib/tenant/forms/create-global-api-key.tsx +69 -0
- package/resources/templates/default/admin/lib/tenant/forms/global-roles-control.tsx +113 -0
- package/resources/templates/default/admin/lib/tenant/forms/index.ts +11 -0
- package/resources/templates/default/admin/lib/tenant/forms/invite.tsx +42 -4
- package/resources/templates/default/admin/lib/tenant/forms/login.tsx +4 -10
- package/resources/templates/default/admin/lib/tenant/forms/memberships-control.tsx +3 -1
- package/resources/templates/default/admin/lib/tenant/forms/mfa-code-fields.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/forms/passwordless-signin.tsx +4 -10
- package/resources/templates/default/admin/lib/tenant/forms/set-person-password.tsx +58 -0
- package/resources/templates/default/admin/lib/tenant/forms/set-project-secret.tsx +59 -0
- package/resources/templates/default/admin/lib/tenant/forms/sign-up.tsx +73 -0
- package/resources/templates/default/admin/lib/tenant/hooks/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/idp/identity-provider-connections.tsx +124 -0
- package/resources/templates/default/admin/lib/tenant/idp/index.ts +1 -0
- package/resources/templates/default/admin/lib/tenant/index.ts +7 -0
- package/resources/templates/default/admin/lib/tenant/listing/api-key-list.tsx +160 -22
- package/resources/templates/default/admin/lib/tenant/listing/auth-log-list.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/global-api-key-list.tsx +149 -0
- package/resources/templates/default/admin/lib/tenant/listing/index.ts +7 -0
- package/resources/templates/default/admin/lib/tenant/listing/member-delete-dialog.tsx +1 -1
- package/resources/templates/default/admin/lib/tenant/listing/member-list.tsx +20 -11
- package/resources/templates/default/admin/lib/tenant/listing/mfa.tsx +29 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-actions.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-detail.tsx +141 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-list.tsx +13 -2
- package/resources/templates/default/admin/lib/tenant/listing/persons-list.tsx +128 -0
- package/resources/templates/default/admin/lib/tenant/listing/project-secret-list.tsx +82 -0
- package/resources/templates/default/admin/lib/tenant/otp/backup-codes.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/otp/email-otp-setup.tsx +133 -0
- package/resources/templates/default/admin/lib/tenant/otp/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/passwordless-toggle.tsx +63 -0
- package/resources/templates/default/admin/lib/tenant/security/session-list.tsx +143 -0
- package/resources/templates/default/admin/lib/ui/label.tsx +25 -2
- package/resources/templates/default/admin/lib/ui/menu.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/progress.tsx +75 -11
- package/resources/templates/default/admin/lib/ui/separator.tsx +27 -3
- package/resources/templates/default/admin/lib/ui/sidebar.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/toggle.tsx +41 -2
- package/resources/templates/default/admin/lib/utils/classNames.ts +107 -0
- package/resources/templates/default/admin/lib/utils/cn.ts +3 -3
- package/resources/templates/default/admin/lib/utils/index.ts +1 -0
- package/resources/templates/default/admin/lib/utils/uic.tsx +2 -3
- package/resources/templates/default/admin/package.json +1 -7
- package/resources/templates/default/docker/object-storage/README.md +13 -0
- package/resources/templates/default/docker/object-storage/identities.json +13 -0
- package/resources/templates/default/docker-compose.yaml +29 -7
- package/src/commands/WorkspaceCreateCommand.ts +51 -24
- package/src/lib/FileSystem.ts +7 -2
- package/src/lib/TemplateInstaller.ts +87 -69
- package/src/lib/fsErrors.ts +2 -0
- package/src/lib/projectPath.ts +79 -0
- package/src/lib/remoteTemplate.ts +130 -0
- package/src/lib/tar.ts +283 -0
- package/src/run.ts +8 -7
- package/tests/cases/unit/create-process.test.ts +66 -0
- package/tests/cases/unit/fileSystem.test.ts +14 -0
- package/tests/cases/unit/fixtures/template.tar.gz +0 -0
- package/tests/cases/unit/remoteTemplate.test.ts +277 -0
- package/tests/cases/unit/template-installer-cleanup.test.ts +150 -0
- package/tests/cases/unit/template-installer-containment.test.ts +133 -0
- package/tests/cases/unit/template-installer-symlinks.test.ts +37 -0
- package/tests/cases/unit/workspace-create.test.ts +81 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { mkdir, writeFile, symlink, lstat } from "node:fs/promises";
|
|
2
|
+
import { resolve, sep, join } from "node:path";
|
|
3
|
+
import { isNotFound, hasCode } from "./fsErrors.js";
|
|
4
|
+
const blockSize = 512;
|
|
5
|
+
const decoder = new TextDecoder();
|
|
6
|
+
const readString = (block, offset, length) => {
|
|
7
|
+
const field = block.subarray(offset, offset + length);
|
|
8
|
+
const end = field.indexOf(0);
|
|
9
|
+
return decoder.decode(end === -1 ? field : field.subarray(0, end));
|
|
10
|
+
};
|
|
11
|
+
const readOctal = (block, offset, length, field) => {
|
|
12
|
+
const text = readString(block, offset, length).trim();
|
|
13
|
+
if (!/^[0-7]*$/.test(text)) {
|
|
14
|
+
throw new Error(`Invalid tar archive: unreadable ${field} field`);
|
|
15
|
+
}
|
|
16
|
+
return text === "" ? 0 : Number.parseInt(text, 8);
|
|
17
|
+
};
|
|
18
|
+
const verifyChecksum = (block) => {
|
|
19
|
+
const expected = readOctal(block, 148, 8, "checksum");
|
|
20
|
+
let sum = 0;
|
|
21
|
+
for (let i = 0; i < blockSize; i++) {
|
|
22
|
+
sum += i >= 148 && i < 156 ? 32 : block[i];
|
|
23
|
+
}
|
|
24
|
+
if (sum !== expected) {
|
|
25
|
+
throw new Error("Invalid tar archive: header checksum mismatch");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const parsePax = (data) => {
|
|
29
|
+
const records = /* @__PURE__ */ new Map();
|
|
30
|
+
let offset = 0;
|
|
31
|
+
while (offset < data.length) {
|
|
32
|
+
const space = data.indexOf(32, offset);
|
|
33
|
+
const length = space === -1 ? Number.NaN : Number(decoder.decode(data.subarray(offset, space)));
|
|
34
|
+
if (!Number.isSafeInteger(length) || length <= 0 || offset + length > data.length) {
|
|
35
|
+
throw new Error("Invalid tar archive: malformed PAX header");
|
|
36
|
+
}
|
|
37
|
+
const record = decoder.decode(data.subarray(space + 1, offset + length - 1));
|
|
38
|
+
const equals = record.indexOf("=");
|
|
39
|
+
if (equals > 0) {
|
|
40
|
+
records.set(record.slice(0, equals), record.slice(equals + 1));
|
|
41
|
+
}
|
|
42
|
+
offset += length;
|
|
43
|
+
}
|
|
44
|
+
return records;
|
|
45
|
+
};
|
|
46
|
+
const parseTar = (archive) => {
|
|
47
|
+
const entries = [];
|
|
48
|
+
let pax = /* @__PURE__ */ new Map();
|
|
49
|
+
let longName;
|
|
50
|
+
let longLink;
|
|
51
|
+
let offset = 0;
|
|
52
|
+
while (offset + blockSize <= archive.length) {
|
|
53
|
+
const header = archive.subarray(offset, offset + blockSize);
|
|
54
|
+
if (header.every((byte) => byte === 0)) {
|
|
55
|
+
return entries;
|
|
56
|
+
}
|
|
57
|
+
verifyChecksum(header);
|
|
58
|
+
const type = String.fromCharCode(header[156]);
|
|
59
|
+
const paxSize = pax.get("size");
|
|
60
|
+
if (paxSize !== void 0 && !/^\d+$/.test(paxSize)) {
|
|
61
|
+
throw new Error("Invalid tar archive: unreadable PAX size");
|
|
62
|
+
}
|
|
63
|
+
const size = paxSize !== void 0 ? Number(paxSize) : readOctal(header, 124, 12, "size");
|
|
64
|
+
const dataStart = offset + blockSize;
|
|
65
|
+
if (!Number.isSafeInteger(size) || dataStart + size > archive.length) {
|
|
66
|
+
throw new Error("Invalid tar archive: entry exceeds the archive");
|
|
67
|
+
}
|
|
68
|
+
const data = archive.subarray(dataStart, dataStart + size);
|
|
69
|
+
offset = dataStart + Math.ceil(size / blockSize) * blockSize;
|
|
70
|
+
if (type === "x") {
|
|
71
|
+
pax = parsePax(data);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (type === "g") {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (type === "L" || type === "K") {
|
|
78
|
+
const value = readString(data, 0, data.length);
|
|
79
|
+
if (type === "L") {
|
|
80
|
+
longName = value;
|
|
81
|
+
} else {
|
|
82
|
+
longLink = value;
|
|
83
|
+
}
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const isUstar = readString(header, 257, 5) === "ustar";
|
|
87
|
+
const prefix = isUstar ? readString(header, 345, 155) : "";
|
|
88
|
+
const name = readString(header, 0, 100);
|
|
89
|
+
const path = pax.get("path") ?? longName ?? (prefix ? `${prefix}/${name}` : name);
|
|
90
|
+
const linkTarget = pax.get("linkpath") ?? longLink ?? readString(header, 157, 100);
|
|
91
|
+
pax = /* @__PURE__ */ new Map();
|
|
92
|
+
longName = void 0;
|
|
93
|
+
longLink = void 0;
|
|
94
|
+
if (type === "0" || type === "\0" || type === "7") {
|
|
95
|
+
entries.push({ type: "file", path, mode: readOctal(header, 100, 8, "mode"), data });
|
|
96
|
+
} else if (type === "5") {
|
|
97
|
+
entries.push({ type: "directory", path });
|
|
98
|
+
} else if (type === "2") {
|
|
99
|
+
entries.push({ type: "symlink", path, target: linkTarget });
|
|
100
|
+
} else {
|
|
101
|
+
throw new Error(`Unsupported tar entry "${path}" (type ${JSON.stringify(type)})`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw new Error("Invalid tar archive: missing end-of-archive marker");
|
|
105
|
+
};
|
|
106
|
+
const unsafe = (what, value) => new Error(`Refusing ${what} in template archive: ${JSON.stringify(value)}`);
|
|
107
|
+
const maxPathLength = 4096;
|
|
108
|
+
const maxPathDepth = 256;
|
|
109
|
+
const relativeComponents = (path, strip, subdir) => {
|
|
110
|
+
if (path.startsWith("/")) {
|
|
111
|
+
throw unsafe("absolute path", path);
|
|
112
|
+
}
|
|
113
|
+
if (path.length > maxPathLength) {
|
|
114
|
+
throw unsafe("overlong path", path.slice(0, 100));
|
|
115
|
+
}
|
|
116
|
+
const components = path.split("/").filter((it) => it !== "" && it !== ".").slice(strip);
|
|
117
|
+
if (components.length > maxPathDepth) {
|
|
118
|
+
throw unsafe("too deeply nested path", path.slice(0, 100));
|
|
119
|
+
}
|
|
120
|
+
if (components.length <= subdir.length || subdir.some((it, index) => components[index] !== it)) {
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
123
|
+
const relative = components.slice(subdir.length);
|
|
124
|
+
if (relative.some((it) => it === ".." || it.includes("\\"))) {
|
|
125
|
+
throw unsafe("path", path);
|
|
126
|
+
}
|
|
127
|
+
return relative;
|
|
128
|
+
};
|
|
129
|
+
const isContainedLinkTarget = (link, target, links) => {
|
|
130
|
+
if (target.length > maxPathLength || target.startsWith("/") || target.includes("\\") || /^[a-zA-Z]:/.test(target)) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
const resolved = link.slice(0, -1);
|
|
134
|
+
const parts = target.split("/").filter((it) => it !== "" && it !== ".");
|
|
135
|
+
if (parts.length > maxPathDepth) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
for (const [index, part] of parts.entries()) {
|
|
139
|
+
if (part === "..") {
|
|
140
|
+
if (resolved.length === 0) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
resolved.pop();
|
|
144
|
+
} else {
|
|
145
|
+
resolved.push(part);
|
|
146
|
+
if (index < parts.length - 1 && links.has(resolved.join("/"))) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
};
|
|
153
|
+
const ensureDirectory = async (root, components, path) => {
|
|
154
|
+
let current = root;
|
|
155
|
+
for (const component of components) {
|
|
156
|
+
current = join(current, component);
|
|
157
|
+
try {
|
|
158
|
+
const stat = await lstat(current);
|
|
159
|
+
if (stat.isSymbolicLink()) {
|
|
160
|
+
throw unsafe("entry below a symlink", path);
|
|
161
|
+
}
|
|
162
|
+
if (!stat.isDirectory()) {
|
|
163
|
+
throw new Error(`Template archive entry ${JSON.stringify(path)} collides with a file`);
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (!isNotFound(error)) {
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
await mkdir(current);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const assertTargetWithoutLinks = async (root, link, target, path) => {
|
|
174
|
+
const resolved = link.slice(0, -1);
|
|
175
|
+
const parts = target.split("/").filter((it) => it !== "" && it !== ".");
|
|
176
|
+
for (const [index, part] of parts.entries()) {
|
|
177
|
+
if (part === "..") {
|
|
178
|
+
resolved.pop();
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
resolved.push(part);
|
|
182
|
+
if (index === parts.length - 1) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
if ((await lstat(join(root, ...resolved))).isSymbolicLink()) {
|
|
187
|
+
throw unsafe("symlink pointing outside the template", `${path} -> ${target}`);
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (isNotFound(error)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (hasCode(error, "ENOTDIR")) {
|
|
194
|
+
throw unsafe("symlink resolving through a file", `${path} -> ${target}`);
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
const extractTar = async (entries, targetDir, { strip, subdir = [] }) => {
|
|
201
|
+
const root = resolve(targetDir);
|
|
202
|
+
const selected = entries.flatMap((entry) => {
|
|
203
|
+
const relative = relativeComponents(entry.path, strip, subdir);
|
|
204
|
+
return relative ? [{ entry, relative }] : [];
|
|
205
|
+
});
|
|
206
|
+
const links = new Set(selected.filter((it) => it.entry.type === "symlink").map((it) => it.relative.join("/")));
|
|
207
|
+
for (const { entry, relative } of selected) {
|
|
208
|
+
if (relative.some((_, index) => index > 0 && links.has(relative.slice(0, index).join("/")))) {
|
|
209
|
+
throw unsafe("entry below a symlink", entry.path);
|
|
210
|
+
}
|
|
211
|
+
if (entry.type === "symlink" && !isContainedLinkTarget(relative, entry.target, links)) {
|
|
212
|
+
throw unsafe("symlink pointing outside the template", `${entry.path} -> ${entry.target}`);
|
|
213
|
+
}
|
|
214
|
+
if (!resolve(root, ...relative).startsWith(root + sep)) {
|
|
215
|
+
throw unsafe("path", entry.path);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
await mkdir(root, { recursive: true });
|
|
219
|
+
for (const { entry, relative } of selected) {
|
|
220
|
+
if (entry.type === "directory") {
|
|
221
|
+
await ensureDirectory(root, relative, entry.path);
|
|
222
|
+
} else if (entry.type === "file") {
|
|
223
|
+
await ensureDirectory(root, relative.slice(0, -1), entry.path);
|
|
224
|
+
await writeFile(join(root, ...relative), entry.data, { mode: entry.mode & 511 || 420, flag: "wx" });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const created = [];
|
|
228
|
+
for (const { entry, relative } of selected) {
|
|
229
|
+
if (entry.type === "symlink") {
|
|
230
|
+
await ensureDirectory(root, relative.slice(0, -1), entry.path);
|
|
231
|
+
await symlink(entry.target, join(root, ...relative));
|
|
232
|
+
created.push({ relative, target: entry.target, path: entry.path });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
for (const link of created) {
|
|
236
|
+
await assertTargetWithoutLinks(root, link.relative, link.target, link.path);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
export {
|
|
240
|
+
extractTar,
|
|
241
|
+
parseTar
|
|
242
|
+
};
|
|
243
|
+
//# sourceMappingURL=tar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tar.js","sources":["../../../../../packages/create/src/lib/tar.ts"],"sourcesContent":["import { lstat, mkdir, symlink, writeFile } from 'node:fs/promises'\nimport { join, resolve, sep } from 'node:path'\nimport { hasCode, isNotFound } from './fsErrors.js'\n\nexport type TarEntry =\n\t| { readonly type: 'file'; readonly path: string; readonly mode: number; readonly data: Uint8Array }\n\t| { readonly type: 'directory'; readonly path: string }\n\t| { readonly type: 'symlink'; readonly path: string; readonly target: string }\n\nconst blockSize = 512\nconst decoder = new TextDecoder()\n\nconst readString = (block: Uint8Array, offset: number, length: number): string => {\n\tconst field = block.subarray(offset, offset + length)\n\tconst end = field.indexOf(0)\n\treturn decoder.decode(end === -1 ? field : field.subarray(0, end))\n}\n\nconst readOctal = (block: Uint8Array, offset: number, length: number, field: string): number => {\n\tconst text = readString(block, offset, length).trim()\n\tif (!/^[0-7]*$/.test(text)) {\n\t\tthrow new Error(`Invalid tar archive: unreadable ${field} field`)\n\t}\n\treturn text === '' ? 0 : Number.parseInt(text, 8)\n}\n\nconst verifyChecksum = (block: Uint8Array): void => {\n\tconst expected = readOctal(block, 148, 8, 'checksum')\n\tlet sum = 0\n\tfor (let i = 0; i < blockSize; i++) {\n\t\tsum += i >= 148 && i < 156 ? 0x20 : block[i]\n\t}\n\tif (sum !== expected) {\n\t\tthrow new Error('Invalid tar archive: header checksum mismatch')\n\t}\n}\n\n/** PAX extended header records: `<length> <key>=<value>\\n`. */\nconst parsePax = (data: Uint8Array): Map<string, string> => {\n\tconst records = new Map<string, string>()\n\tlet offset = 0\n\twhile (offset < data.length) {\n\t\tconst space = data.indexOf(0x20, offset)\n\t\tconst length = space === -1 ? Number.NaN : Number(decoder.decode(data.subarray(offset, space)))\n\t\tif (!Number.isSafeInteger(length) || length <= 0 || offset + length > data.length) {\n\t\t\tthrow new Error('Invalid tar archive: malformed PAX header')\n\t\t}\n\t\tconst record = decoder.decode(data.subarray(space + 1, offset + length - 1))\n\t\tconst equals = record.indexOf('=')\n\t\tif (equals > 0) {\n\t\t\trecords.set(record.slice(0, equals), record.slice(equals + 1))\n\t\t}\n\t\toffset += length\n\t}\n\treturn records\n}\n\n/** Reads a POSIX (ustar/PAX) or GNU tar archive. Rejects entry types other than files, directories and symlinks. */\nexport const parseTar = (archive: Uint8Array): TarEntry[] => {\n\tconst entries: TarEntry[] = []\n\tlet pax = new Map<string, string>()\n\tlet longName: string | undefined\n\tlet longLink: string | undefined\n\tlet offset = 0\n\twhile (offset + blockSize <= archive.length) {\n\t\tconst header = archive.subarray(offset, offset + blockSize)\n\t\tif (header.every(byte => byte === 0)) {\n\t\t\treturn entries\n\t\t}\n\t\tverifyChecksum(header)\n\t\tconst type = String.fromCharCode(header[156])\n\t\tconst paxSize = pax.get('size')\n\t\tif (paxSize !== undefined && !/^\\d+$/.test(paxSize)) {\n\t\t\tthrow new Error('Invalid tar archive: unreadable PAX size')\n\t\t}\n\t\tconst size = paxSize !== undefined ? Number(paxSize) : readOctal(header, 124, 12, 'size')\n\t\tconst dataStart = offset + blockSize\n\t\tif (!Number.isSafeInteger(size) || dataStart + size > archive.length) {\n\t\t\tthrow new Error('Invalid tar archive: entry exceeds the archive')\n\t\t}\n\t\tconst data = archive.subarray(dataStart, dataStart + size)\n\t\toffset = dataStart + Math.ceil(size / blockSize) * blockSize\n\n\t\tif (type === 'x') {\n\t\t\tpax = parsePax(data)\n\t\t\tcontinue\n\t\t}\n\t\tif (type === 'g') {\n\t\t\tcontinue\n\t\t}\n\t\tif (type === 'L' || type === 'K') {\n\t\t\tconst value = readString(data, 0, data.length)\n\t\t\tif (type === 'L') {\n\t\t\t\tlongName = value\n\t\t\t} else {\n\t\t\t\tlongLink = value\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tconst isUstar = readString(header, 257, 5) === 'ustar'\n\t\tconst prefix = isUstar ? readString(header, 345, 155) : ''\n\t\tconst name = readString(header, 0, 100)\n\t\tconst path = pax.get('path') ?? longName ?? (prefix ? `${prefix}/${name}` : name)\n\t\tconst linkTarget = pax.get('linkpath') ?? longLink ?? readString(header, 157, 100)\n\t\tpax = new Map()\n\t\tlongName = undefined\n\t\tlongLink = undefined\n\n\t\tif (type === '0' || type === '\\0' || type === '7') {\n\t\t\tentries.push({ type: 'file', path, mode: readOctal(header, 100, 8, 'mode'), data })\n\t\t} else if (type === '5') {\n\t\t\tentries.push({ type: 'directory', path })\n\t\t} else if (type === '2') {\n\t\t\tentries.push({ type: 'symlink', path, target: linkTarget })\n\t\t} else {\n\t\t\tthrow new Error(`Unsupported tar entry \"${path}\" (type ${JSON.stringify(type)})`)\n\t\t}\n\t}\n\tthrow new Error('Invalid tar archive: missing end-of-archive marker')\n}\n\nconst unsafe = (what: string, value: string): Error => new Error(`Refusing ${what} in template archive: ${JSON.stringify(value)}`)\n\n/** Longer and deeper than any real template path; together they bound the per-component work for each entry. */\nconst maxPathLength = 4096\nconst maxPathDepth = 256\n\n/** The entry's path components below `subdir`, or `undefined` when it lies outside; throws on paths that could escape. */\nconst relativeComponents = (path: string, strip: number, subdir: readonly string[]): string[] | undefined => {\n\tif (path.startsWith('/')) {\n\t\tthrow unsafe('absolute path', path)\n\t}\n\tif (path.length > maxPathLength) {\n\t\tthrow unsafe('overlong path', path.slice(0, 100))\n\t}\n\tconst components = path.split('/').filter(it => it !== '' && it !== '.').slice(strip)\n\tif (components.length > maxPathDepth) {\n\t\tthrow unsafe('too deeply nested path', path.slice(0, 100))\n\t}\n\tif (components.length <= subdir.length || subdir.some((it, index) => components[index] !== it)) {\n\t\treturn undefined\n\t}\n\tconst relative = components.slice(subdir.length)\n\tif (relative.some(it => it === '..' || it.includes('\\\\'))) {\n\t\tthrow unsafe('path', path)\n\t}\n\treturn relative\n}\n\n/** Resolves `target` from the link's directory; it must stay inside the root and not pass through another archive link. */\nconst isContainedLinkTarget = (link: readonly string[], target: string, links: ReadonlySet<string>): boolean => {\n\tif (target.length > maxPathLength || target.startsWith('/') || target.includes('\\\\') || /^[a-zA-Z]:/.test(target)) {\n\t\treturn false\n\t}\n\tconst resolved = link.slice(0, -1)\n\tconst parts = target.split('/').filter(it => it !== '' && it !== '.')\n\tif (parts.length > maxPathDepth) {\n\t\treturn false\n\t}\n\tfor (const [index, part] of parts.entries()) {\n\t\tif (part === '..') {\n\t\t\tif (resolved.length === 0) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tresolved.pop()\n\t\t} else {\n\t\t\tresolved.push(part)\n\t\t\tif (index < parts.length - 1 && links.has(resolved.join('/'))) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t}\n\treturn true\n}\n\n/**\n * Creates the directories one component at a time and refuses to pass through a symlink. The string checks cannot see\n * aliases a case-insensitive or normalising filesystem makes (`D/L` is `d/l`), the filesystem itself can.\n */\nconst ensureDirectory = async (root: string, components: readonly string[], path: string): Promise<void> => {\n\tlet current = root\n\tfor (const component of components) {\n\t\tcurrent = join(current, component)\n\t\ttry {\n\t\t\tconst stat = await lstat(current)\n\t\t\tif (stat.isSymbolicLink()) {\n\t\t\t\tthrow unsafe('entry below a symlink', path)\n\t\t\t}\n\t\t\tif (!stat.isDirectory()) {\n\t\t\t\tthrow new Error(`Template archive entry ${JSON.stringify(path)} collides with a file`)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (!isNotFound(error)) {\n\t\t\t\tthrow error\n\t\t\t}\n\t\t\tawait mkdir(current)\n\t\t}\n\t}\n}\n\n/** Walks a created link's target on the filesystem: no component before the last may be a symlink. */\nconst assertTargetWithoutLinks = async (root: string, link: readonly string[], target: string, path: string): Promise<void> => {\n\tconst resolved = link.slice(0, -1)\n\tconst parts = target.split('/').filter(it => it !== '' && it !== '.')\n\tfor (const [index, part] of parts.entries()) {\n\t\tif (part === '..') {\n\t\t\tresolved.pop()\n\t\t\tcontinue\n\t\t}\n\t\tresolved.push(part)\n\t\tif (index === parts.length - 1) {\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tif ((await lstat(join(root, ...resolved))).isSymbolicLink()) {\n\t\t\t\tthrow unsafe('symlink pointing outside the template', `${path} -> ${target}`)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (isNotFound(error)) {\n\t\t\t\t// a dangling target; the string check already kept it inside\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (hasCode(error, 'ENOTDIR')) {\n\t\t\t\tthrow unsafe('symlink resolving through a file', `${path} -> ${target}`)\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n}\n\nexport interface ExtractOptions {\n\t/** Leading path components dropped from every entry, e.g. the archive's top-level directory. */\n\treadonly strip: number\n\t/** Only entries below this directory (after `strip`) are extracted, relative to it. */\n\treadonly subdir?: readonly string[]\n}\n\n/**\n * Writes the entries into `targetDir`. Paths stay inside it, no entry may sit below a symlink, and a link target must\n * resolve inside without passing through another link. Checked on the names first, then on the filesystem while\n * writing. Links are created last, so no file is written through one.\n */\nexport const extractTar = async (entries: readonly TarEntry[], targetDir: string, { strip, subdir = [] }: ExtractOptions): Promise<void> => {\n\tconst root = resolve(targetDir)\n\tconst selected = entries.flatMap(entry => {\n\t\tconst relative = relativeComponents(entry.path, strip, subdir)\n\t\treturn relative ? [{ entry, relative }] : []\n\t})\n\tconst links = new Set(selected.filter(it => it.entry.type === 'symlink').map(it => it.relative.join('/')))\n\tfor (const { entry, relative } of selected) {\n\t\tif (relative.some((_, index) => index > 0 && links.has(relative.slice(0, index).join('/')))) {\n\t\t\tthrow unsafe('entry below a symlink', entry.path)\n\t\t}\n\t\tif (entry.type === 'symlink' && !isContainedLinkTarget(relative, entry.target, links)) {\n\t\t\tthrow unsafe('symlink pointing outside the template', `${entry.path} -> ${entry.target}`)\n\t\t}\n\t\tif (!resolve(root, ...relative).startsWith(root + sep)) {\n\t\t\tthrow unsafe('path', entry.path)\n\t\t}\n\t}\n\tawait mkdir(root, { recursive: true })\n\tfor (const { entry, relative } of selected) {\n\t\tif (entry.type === 'directory') {\n\t\t\tawait ensureDirectory(root, relative, entry.path)\n\t\t} else if (entry.type === 'file') {\n\t\t\tawait ensureDirectory(root, relative.slice(0, -1), entry.path)\n\t\t\t// `wx` never follows or replaces an existing entry\n\t\t\tawait writeFile(join(root, ...relative), entry.data, { mode: (entry.mode & 0o777) || 0o644, flag: 'wx' })\n\t\t}\n\t}\n\tconst created: { relative: readonly string[]; target: string; path: string }[] = []\n\tfor (const { entry, relative } of selected) {\n\t\tif (entry.type === 'symlink') {\n\t\t\tawait ensureDirectory(root, relative.slice(0, -1), entry.path)\n\t\t\tawait symlink(entry.target, join(root, ...relative))\n\t\t\tcreated.push({ relative, target: entry.target, path: entry.path })\n\t\t}\n\t}\n\tfor (const link of created) {\n\t\tawait assertTargetWithoutLinks(root, link.relative, link.target, link.path)\n\t}\n}\n"],"names":[],"mappings":";;;AASA,MAAM,YAAY;AAClB,MAAM,UAAU,IAAI,YAAA;AAEpB,MAAM,aAAa,CAAC,OAAmB,QAAgB,WAA2B;AACjF,QAAM,QAAQ,MAAM,SAAS,QAAQ,SAAS,MAAM;AACpD,QAAM,MAAM,MAAM,QAAQ,CAAC;AAC3B,SAAO,QAAQ,OAAO,QAAQ,KAAK,QAAQ,MAAM,SAAS,GAAG,GAAG,CAAC;AAClE;AAEA,MAAM,YAAY,CAAC,OAAmB,QAAgB,QAAgB,UAA0B;AAC/F,QAAM,OAAO,WAAW,OAAO,QAAQ,MAAM,EAAE,KAAA;AAC/C,MAAI,CAAC,WAAW,KAAK,IAAI,GAAG;AAC3B,UAAM,IAAI,MAAM,mCAAmC,KAAK,QAAQ;AAAA,EACjE;AACA,SAAO,SAAS,KAAK,IAAI,OAAO,SAAS,MAAM,CAAC;AACjD;AAEA,MAAM,iBAAiB,CAAC,UAA4B;AACnD,QAAM,WAAW,UAAU,OAAO,KAAK,GAAG,UAAU;AACpD,MAAI,MAAM;AACV,WAAS,IAAI,GAAG,IAAI,WAAW,KAAK;AACnC,WAAO,KAAK,OAAO,IAAI,MAAM,KAAO,MAAM,CAAC;AAAA,EAC5C;AACA,MAAI,QAAQ,UAAU;AACrB,UAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AACD;AAGA,MAAM,WAAW,CAAC,SAA0C;AAC3D,QAAM,8BAAc,IAAA;AACpB,MAAI,SAAS;AACb,SAAO,SAAS,KAAK,QAAQ;AAC5B,UAAM,QAAQ,KAAK,QAAQ,IAAM,MAAM;A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AAU;AAC3C,QAAI,MAAM,SAAS,aAAa;AAC/B,YAAM,gBAAgB,MAAM,UAAU,MAAM,IAAI;AAAA,IACjD,WAAW,MAAM,SAAS,QAAQ;AACjC,YAAM,gBAAgB,MAAM,SAAS,MAAM,GAAG,EAAE,GAAG,MAAM,IAAI;AAE7D,YAAM,UAAU,KAAK,MAAM,GAAG,QAAQ,GAAG,MAAM,MAAM,EAAE,MAAO,MAAM,OAAO,OAAU,KAAO,MAAM,MAAM;AAAA,IACzG;AAAA,EACD;AACA,QAAM,UAA2E,CAAA;AACjF,aAAW,EAAE,OAAO,SAAA,KAAc,UAAU;AAC3C,QAAI,MAAM,SAAS,WAAW;AAC7B,YAAM,gBAAgB,MAAM,SAAS,MAAM,GAAG,EAAE,GAAG,MAAM,IAAI;AAC7D,YAAM,QAAQ,MAAM,QAAQ,KAAK,MAAM,GAAG,QAAQ,CAAC;AACnD,cAAQ,KAAK,EAAE,UAAU,QAAQ,MAAM,QAAQ,MAAM,MAAM,MAAM;AAAA,IAClE;AAAA,EACD;AACA,aAAW,QAAQ,SAAS;AAC3B,UAAM,yBAAyB,MAAM,KAAK,UAAU,KAAK,QAAQ,KAAK,IAAI;AAAA,EAC3E;AACD;"}
|
package/dist/production/run.cjs
CHANGED
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
const cliCommon = require("@contember/cli-common");
|
|
4
4
|
const WorkspaceCreateCommand = require("./src/commands/WorkspaceCreateCommand.cjs");
|
|
5
|
+
const FileSystem = require("./src/lib/FileSystem.cjs");
|
|
5
6
|
const TemplateInstaller = require("./src/lib/TemplateInstaller.cjs");
|
|
6
7
|
const paths = require("./src/paths.cjs");
|
|
7
|
-
const
|
|
8
|
+
const output = new cliCommon.Output();
|
|
9
|
+
output.applyGlobalOptions(cliCommon.readGlobalOptionsFromArgs(process.argv.slice(2)));
|
|
8
10
|
(async () => {
|
|
9
11
|
const commandManager = new cliCommon.CommandManager({
|
|
10
12
|
["workspace"]: () => new WorkspaceCreateCommand.WorkspaceCreateCommand(
|
|
11
13
|
new TemplateInstaller.TemplateInstaller(
|
|
12
14
|
paths.resourcesDir,
|
|
13
|
-
new FileSystem.FileSystem()
|
|
15
|
+
new FileSystem.FileSystem(),
|
|
16
|
+
output
|
|
14
17
|
)
|
|
15
18
|
)
|
|
16
19
|
});
|
|
@@ -18,10 +21,7 @@ const FileSystem = require("./src/lib/FileSystem.cjs");
|
|
|
18
21
|
if (nodeVersion && Number(nodeVersion[1]) < 18) {
|
|
19
22
|
throw `Node >= 18 is required`;
|
|
20
23
|
}
|
|
21
|
-
const app = new cliCommon.Application(commandManager, `Contember installer
|
|
24
|
+
const app = new cliCommon.Application(commandManager, `Contember installer`, output);
|
|
22
25
|
await app.runCommand("workspace", process.argv.slice(2));
|
|
23
|
-
})().catch((
|
|
24
|
-
console.log(e);
|
|
25
|
-
process.exit(1);
|
|
26
|
-
});
|
|
26
|
+
})().catch((error) => cliCommon.exitProcess(cliCommon.renderCliError(error, output)));
|
|
27
27
|
//# sourceMappingURL=run.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.cjs","sources":["../../../packages/create/src/run.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Application, CommandManager } from '@contember/cli-common'\nimport { WorkspaceCreateCommand } from './commands/index.js'\nimport {
|
|
1
|
+
{"version":3,"file":"run.cjs","sources":["../../../packages/create/src/run.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Application, CommandManager, exitProcess, Output, readGlobalOptionsFromArgs, renderCliError } from '@contember/cli-common'\nimport { WorkspaceCreateCommand } from './commands/index.js'\nimport { FileSystem } from './lib/FileSystem.js'\nimport { TemplateInstaller } from './lib/TemplateInstaller.js'\nimport { resourcesDir } from './paths.js'\n\nconst output = new Output()\noutput.applyGlobalOptions(readGlobalOptionsFromArgs(process.argv.slice(2)))\n;(async () => {\n\tconst commandManager = new CommandManager({\n\t\t['workspace']: () =>\n\t\t\tnew WorkspaceCreateCommand(\n\t\t\t\tnew TemplateInstaller(\n\t\t\t\t\tresourcesDir,\n\t\t\t\t\tnew FileSystem(),\n\t\t\t\t\toutput,\n\t\t\t\t),\n\t\t\t),\n\t})\n\n\tconst nodeVersion = process.version.match(/^v?(\\d+)\\..+$/)\n\tif (nodeVersion && Number(nodeVersion[1]) < 18) {\n\t\tthrow `Node >= 18 is required`\n\t}\n\tconst app = new Application(commandManager, `Contember installer`, output)\n\tawait app.runCommand('workspace', process.argv.slice(2))\n})().catch(error => exitProcess(renderCliError(error, output)))\n"],"names":["Output","readGlobalOptionsFromArgs","CommandManager","WorkspaceCreateCommand","TemplateInstaller","resourcesDir","FileSystem","Application","exitProcess","renderCliError"],"mappings":";;;;;;;AAOA,MAAM,SAAS,IAAIA,UAAAA,OAAA;AACnB,OAAO,mBAAmBC,UAAAA,0BAA0B,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC;AAAA,CACxE,YAAY;AACb,QAAM,iBAAiB,IAAIC,yBAAe;AAAA,IACzC,CAAC,WAAW,GAAG,MACd,IAAIC,uBAAAA;AAAAA,MACH,IAAIC,kBAAAA;AAAAA,QACHC,MAAAA;AAAAA,QACA,IAAIC,sBAAA;AAAA,QACJ;AAAA,MAAA;AAAA,IACD;AAAA,EACD,CACD;AAED,QAAM,cAAc,QAAQ,QAAQ,MAAM,eAAe;AACzD,MAAI,eAAe,OAAO,YAAY,CAAC,CAAC,IAAI,IAAI;AAC/C,UAAM;AAAA,EACP;AACA,QAAM,MAAM,IAAIC,UAAAA,YAAY,gBAAgB,uBAAuB,MAAM;AACzE,QAAM,IAAI,WAAW,aAAa,QAAQ,KAAK,MAAM,CAAC,CAAC;AACxD,KAAK,MAAM,CAAA,UAASC,UAAAA,YAAYC,UAAAA,eAAe,OAAO,MAAM,CAAC,CAAC;"}
|
package/dist/production/run.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { CommandManager, Application } from "@contember/cli-common";
|
|
2
|
+
import { Output, readGlobalOptionsFromArgs, CommandManager, Application, exitProcess, renderCliError } from "@contember/cli-common";
|
|
3
3
|
import { WorkspaceCreateCommand } from "./src/commands/WorkspaceCreateCommand.js";
|
|
4
|
+
import { FileSystem } from "./src/lib/FileSystem.js";
|
|
4
5
|
import { TemplateInstaller } from "./src/lib/TemplateInstaller.js";
|
|
5
6
|
import { resourcesDir } from "./src/paths.js";
|
|
6
|
-
|
|
7
|
+
const output = new Output();
|
|
8
|
+
output.applyGlobalOptions(readGlobalOptionsFromArgs(process.argv.slice(2)));
|
|
7
9
|
(async () => {
|
|
8
10
|
const commandManager = new CommandManager({
|
|
9
11
|
["workspace"]: () => new WorkspaceCreateCommand(
|
|
10
12
|
new TemplateInstaller(
|
|
11
13
|
resourcesDir,
|
|
12
|
-
new FileSystem()
|
|
14
|
+
new FileSystem(),
|
|
15
|
+
output
|
|
13
16
|
)
|
|
14
17
|
)
|
|
15
18
|
});
|
|
@@ -17,10 +20,7 @@ import { FileSystem } from "./src/lib/FileSystem.js";
|
|
|
17
20
|
if (nodeVersion && Number(nodeVersion[1]) < 18) {
|
|
18
21
|
throw `Node >= 18 is required`;
|
|
19
22
|
}
|
|
20
|
-
const app = new Application(commandManager, `Contember installer
|
|
23
|
+
const app = new Application(commandManager, `Contember installer`, output);
|
|
21
24
|
await app.runCommand("workspace", process.argv.slice(2));
|
|
22
|
-
})().catch((
|
|
23
|
-
console.log(e);
|
|
24
|
-
process.exit(1);
|
|
25
|
-
});
|
|
25
|
+
})().catch((error) => exitProcess(renderCliError(error, output)));
|
|
26
26
|
//# sourceMappingURL=run.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sources":["../../../packages/create/src/run.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Application, CommandManager } from '@contember/cli-common'\nimport { WorkspaceCreateCommand } from './commands/index.js'\nimport {
|
|
1
|
+
{"version":3,"file":"run.js","sources":["../../../packages/create/src/run.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Application, CommandManager, exitProcess, Output, readGlobalOptionsFromArgs, renderCliError } from '@contember/cli-common'\nimport { WorkspaceCreateCommand } from './commands/index.js'\nimport { FileSystem } from './lib/FileSystem.js'\nimport { TemplateInstaller } from './lib/TemplateInstaller.js'\nimport { resourcesDir } from './paths.js'\n\nconst output = new Output()\noutput.applyGlobalOptions(readGlobalOptionsFromArgs(process.argv.slice(2)))\n;(async () => {\n\tconst commandManager = new CommandManager({\n\t\t['workspace']: () =>\n\t\t\tnew WorkspaceCreateCommand(\n\t\t\t\tnew TemplateInstaller(\n\t\t\t\t\tresourcesDir,\n\t\t\t\t\tnew FileSystem(),\n\t\t\t\t\toutput,\n\t\t\t\t),\n\t\t\t),\n\t})\n\n\tconst nodeVersion = process.version.match(/^v?(\\d+)\\..+$/)\n\tif (nodeVersion && Number(nodeVersion[1]) < 18) {\n\t\tthrow `Node >= 18 is required`\n\t}\n\tconst app = new Application(commandManager, `Contember installer`, output)\n\tawait app.runCommand('workspace', process.argv.slice(2))\n})().catch(error => exitProcess(renderCliError(error, output)))\n"],"names":[],"mappings":";;;;;;AAOA,MAAM,SAAS,IAAI,OAAA;AACnB,OAAO,mBAAmB,0BAA0B,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC;AAAA,CACxE,YAAY;AACb,QAAM,iBAAiB,IAAI,eAAe;AAAA,IACzC,CAAC,WAAW,GAAG,MACd,IAAI;AAAA,MACH,IAAI;AAAA,QACH;AAAA,QACA,IAAI,WAAA;AAAA,QACJ;AAAA,MAAA;AAAA,IACD;AAAA,EACD,CACD;AAED,QAAM,cAAc,QAAQ,QAAQ,MAAM,eAAe;AACzD,MAAI,eAAe,OAAO,YAAY,CAAC,CAAC,IAAI,IAAI;AAC/C,UAAM;AAAA,EACP;AACA,QAAM,MAAM,IAAI,YAAY,gBAAgB,uBAAuB,MAAM;AACzE,QAAM,IAAI,WAAW,aAAa,QAAQ,KAAK,MAAM,CAAC,CAAC;AACxD,KAAK,MAAM,CAAA,UAAS,YAAY,eAAe,OAAO,MAAM,CAAC,CAAC;"}
|
|
@@ -2,63 +2,76 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const cliCommon = require("@contember/cli-common");
|
|
4
4
|
const path = require("node:path");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
5
|
const version = require("../lib/version.cjs");
|
|
7
6
|
const packageManagerDetector = require("../lib/packageManagerDetector.cjs");
|
|
7
|
+
const defaultRuntime = {
|
|
8
|
+
cwd: () => process.cwd(),
|
|
9
|
+
getPackageVersion: version.getPackageVersion,
|
|
10
|
+
detectPackageManager: packageManagerDetector.detectPackageManager
|
|
11
|
+
};
|
|
8
12
|
class WorkspaceCreateCommand extends cliCommon.Command {
|
|
9
|
-
constructor(templateInstaller) {
|
|
13
|
+
constructor(templateInstaller, runtime = defaultRuntime) {
|
|
10
14
|
super();
|
|
11
15
|
this.templateInstaller = templateInstaller;
|
|
16
|
+
this.runtime = runtime;
|
|
12
17
|
}
|
|
13
18
|
configure(configuration) {
|
|
14
19
|
configuration.description("Creates a new Contember project");
|
|
15
20
|
configuration.argument("projectName");
|
|
16
21
|
configuration.option("template").shortcut("t").valueRequired().description("Template name or remote source");
|
|
17
22
|
}
|
|
18
|
-
async execute(input) {
|
|
23
|
+
async execute(input, output) {
|
|
19
24
|
const projectName = input.getArgument("projectName");
|
|
20
|
-
const projectDirectory = path.join(
|
|
21
|
-
const packageManager =
|
|
25
|
+
const projectDirectory = path.join(this.runtime.cwd(), projectName);
|
|
26
|
+
const packageManager = this.runtime.detectPackageManager();
|
|
22
27
|
const template = input.getOption("template") ?? "default";
|
|
23
28
|
await this.templateInstaller.installTemplate(template, projectDirectory, {
|
|
24
|
-
version: await
|
|
29
|
+
version: await this.runtime.getPackageVersion(),
|
|
25
30
|
projectName,
|
|
26
31
|
packageManager
|
|
27
32
|
});
|
|
28
|
-
|
|
33
|
+
const result = { projectName, projectDirectory, template, packageManager };
|
|
34
|
+
output.data(result, {
|
|
35
|
+
human: (value) => createDocs(value),
|
|
36
|
+
quiet: (value) => value.projectDirectory
|
|
37
|
+
});
|
|
29
38
|
}
|
|
30
39
|
}
|
|
31
|
-
const createDocs = (projectDirectory, projectName, packageManager) =>
|
|
32
|
-
|
|
40
|
+
const createDocs = ({ projectDirectory, projectName, packageManager }) => {
|
|
41
|
+
const safeProjectDirectory = cliCommon.escapeTerminalText(projectDirectory);
|
|
42
|
+
const safeProjectName = cliCommon.escapeTerminalText(projectName);
|
|
43
|
+
const safePackageManager = cliCommon.escapeTerminalText(packageManager);
|
|
44
|
+
return `
|
|
45
|
+
Contember project successfully created in ${safeProjectDirectory}
|
|
33
46
|
|
|
34
47
|
Next steps:
|
|
35
48
|
|
|
36
49
|
1. Navigate to the project directory:
|
|
37
|
-
$ ${
|
|
50
|
+
$ ${cliCommon.style("green", `cd ${safeProjectName}`)}
|
|
38
51
|
|
|
39
52
|
2. Install dependencies:
|
|
40
|
-
$ ${
|
|
53
|
+
$ ${cliCommon.style("green", `${safePackageManager} install`)}
|
|
41
54
|
|
|
42
55
|
3. Start the Contember stack:
|
|
43
|
-
$ ${
|
|
56
|
+
$ ${cliCommon.style("green", `${safePackageManager} start`)}
|
|
44
57
|
|
|
45
58
|
Available services:
|
|
46
59
|
|
|
47
|
-
${
|
|
48
|
-
- Contember Admin ${
|
|
60
|
+
${cliCommon.style("bold", "UI & Admin")}
|
|
61
|
+
- Contember Admin ${cliCommon.style("blue", "http://localhost:1480")}
|
|
49
62
|
|
|
50
|
-
${
|
|
51
|
-
- Contember Engine API ${
|
|
63
|
+
${cliCommon.style("bold", "API & Backend")}
|
|
64
|
+
- Contember Engine API ${cliCommon.style("blue", "http://localhost:1481")}
|
|
52
65
|
Auth token: 0000000000000000000000000000000000000000
|
|
53
66
|
|
|
54
|
-
${
|
|
55
|
-
- PostgreSQL database ${
|
|
56
|
-
-
|
|
57
|
-
- Mailpit SMTP testing ${
|
|
58
|
-
- Adminer DB manager ${
|
|
59
|
-
- Minio Dashboard ${chalk.blue("http://localhost:1486")} ${chalk.grey("credentials: contember / contember")}
|
|
67
|
+
${cliCommon.style("bold", "Development Tools")}
|
|
68
|
+
- PostgreSQL database ${cliCommon.style("blue", "http://localhost:1482")} ${cliCommon.style("grey", "credentials: contember / contember")}
|
|
69
|
+
- S3 object storage ${cliCommon.style("blue", "http://localhost:1483")} ${cliCommon.style("grey", "credentials: contember / contember")}
|
|
70
|
+
- Mailpit SMTP testing ${cliCommon.style("blue", "http://localhost:1484")}
|
|
71
|
+
- Adminer DB manager ${cliCommon.style("blue", "http://localhost:1485")}
|
|
60
72
|
|
|
61
|
-
${
|
|
73
|
+
${cliCommon.style("bold", "Need help?")} Ask the community: https://github.com/orgs/contember/discussions
|
|
62
74
|
`;
|
|
75
|
+
};
|
|
63
76
|
exports.WorkspaceCreateCommand = WorkspaceCreateCommand;
|
|
64
77
|
//# sourceMappingURL=WorkspaceCreateCommand.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceCreateCommand.cjs","sources":["../../../../../packages/create/src/commands/WorkspaceCreateCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { join } from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"WorkspaceCreateCommand.cjs","sources":["../../../../../packages/create/src/commands/WorkspaceCreateCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, escapeTerminalText, Input, Output, style } from '@contember/cli-common'\nimport { join } from 'node:path'\nimport { TemplateInstaller } from '../lib/TemplateInstaller.js'\nimport { getPackageVersion } from '../lib/version.js'\nimport { detectPackageManager } from '../lib/packageManagerDetector.js'\n\ntype Args = {\n\tprojectName: string\n}\n\ntype Options = {\n\ttemplate: string\n}\n\nexport interface WorkspaceCreateResult {\n\tprojectName: string\n\tprojectDirectory: string\n\ttemplate: string\n\tpackageManager: string\n}\n\nexport interface WorkspaceCreateRuntime {\n\tcwd(): string\n\tgetPackageVersion(): Promise<string>\n\tdetectPackageManager(): string\n}\n\nconst defaultRuntime: WorkspaceCreateRuntime = {\n\tcwd: () => process.cwd(),\n\tgetPackageVersion,\n\tdetectPackageManager,\n}\n\nexport class WorkspaceCreateCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly templateInstaller: Pick<TemplateInstaller, 'installTemplate'>,\n\t\tprivate readonly runtime: WorkspaceCreateRuntime = defaultRuntime,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Creates a new Contember project')\n\t\tconfiguration.argument('projectName')\n\t\tconfiguration.option('template').shortcut('t').valueRequired().description('Template name or remote source')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>, output: Output): Promise<void> {\n\t\tconst projectName = input.getArgument('projectName')\n\t\tconst projectDirectory = join(this.runtime.cwd(), projectName)\n\t\tconst packageManager = this.runtime.detectPackageManager()\n\t\tconst template = input.getOption('template') ?? 'default'\n\n\t\tawait this.templateInstaller.installTemplate(template, projectDirectory, {\n\t\t\tversion: await this.runtime.getPackageVersion(),\n\t\t\tprojectName: projectName,\n\t\t\tpackageManager: packageManager,\n\t\t})\n\n\t\tconst result: WorkspaceCreateResult = { projectName, projectDirectory, template, packageManager }\n\t\toutput.data(result, {\n\t\t\thuman: value => createDocs(value),\n\t\t\tquiet: value => value.projectDirectory,\n\t\t})\n\t}\n}\n\nconst createDocs = ({ projectDirectory, projectName, packageManager }: WorkspaceCreateResult) => {\n\tconst safeProjectDirectory = escapeTerminalText(projectDirectory)\n\tconst safeProjectName = escapeTerminalText(projectName)\n\tconst safePackageManager = escapeTerminalText(packageManager)\n\treturn `\nContember project successfully created in ${safeProjectDirectory}\n\nNext steps:\n\n1. Navigate to the project directory:\n $ ${style('green', `cd ${safeProjectName}`)}\n\n2. Install dependencies:\n $ ${style('green', `${safePackageManager} install`)}\n\n3. Start the Contember stack:\n $ ${style('green', `${safePackageManager} start`)}\n\nAvailable services:\n\n${style('bold', 'UI & Admin')}\n- Contember Admin ${style('blue', 'http://localhost:1480')}\n\n${style('bold', 'API & Backend')}\n- Contember Engine API ${style('blue', 'http://localhost:1481')}\n Auth token: 0000000000000000000000000000000000000000\n\n${style('bold', 'Development Tools')}\n- PostgreSQL database ${style('blue', 'http://localhost:1482')} ${style('grey', 'credentials: contember / contember')}\n- S3 object storage ${style('blue', 'http://localhost:1483')} ${style('grey', 'credentials: contember / contember')}\n- Mailpit SMTP testing ${style('blue', 'http://localhost:1484')}\n- Adminer DB manager ${style('blue', 'http://localhost:1485')}\n\n${style('bold', 'Need help?')} Ask the community: https://github.com/orgs/contember/discussions\n`\n}\n"],"names":["getPackageVersion","detectPackageManager","Command","join","escapeTerminalText","style"],"mappings":";;;;;;AA2BA,MAAM,iBAAyC;AAAA,EAC9C,KAAK,MAAM,QAAQ,IAAA;AAAA,EAAI,mBACvBA,QAAAA;AAAAA,EAAA,sBACAC,uBAAAA;AACD;AAEO,MAAM,+BAA+BC,UAAAA,QAAuB;AAAA,EAClE,YACkB,mBACA,UAAkC,gBAClD;AACD,UAAA;AAHiB,SAAA,oBAAA;AACA,SAAA,UAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,iCAAiC;AAC3D,kBAAc,SAAS,aAAa;AACpC,kBAAc,OAAO,UAAU,EAAE,SAAS,GAAG,EAAE,cAAA,EAAgB,YAAY,gCAAgC;AAAA,EAC5G;AAAA,EAEA,MAAgB,QAAQ,OAA6B,QAA+B;AACnF,UAAM,cAAc,MAAM,YAAY,aAAa;AACnD,UAAM,mBAAmBC,KAAAA,KAAK,KAAK,QAAQ,IAAA,GAAO,WAAW;AAC7D,UAAM,iBAAiB,KAAK,QAAQ,qBAAA;AACpC,UAAM,WAAW,MAAM,UAAU,UAAU,KAAK;AAEhD,UAAM,KAAK,kBAAkB,gBAAgB,UAAU,kBAAkB;AAAA,MACxE,SAAS,MAAM,KAAK,QAAQ,kBAAA;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AAAA,EAEhEA,gBAAM,QAAQ,YAAY,CAAC;AAAA;AAE7B;;"}
|
|
@@ -1,63 +1,76 @@
|
|
|
1
|
-
import { Command } from "@contember/cli-common";
|
|
1
|
+
import { Command, escapeTerminalText, style } from "@contember/cli-common";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import chalk from "chalk";
|
|
4
3
|
import { getPackageVersion } from "../lib/version.js";
|
|
5
4
|
import { detectPackageManager } from "../lib/packageManagerDetector.js";
|
|
5
|
+
const defaultRuntime = {
|
|
6
|
+
cwd: () => process.cwd(),
|
|
7
|
+
getPackageVersion,
|
|
8
|
+
detectPackageManager
|
|
9
|
+
};
|
|
6
10
|
class WorkspaceCreateCommand extends Command {
|
|
7
|
-
constructor(templateInstaller) {
|
|
11
|
+
constructor(templateInstaller, runtime = defaultRuntime) {
|
|
8
12
|
super();
|
|
9
13
|
this.templateInstaller = templateInstaller;
|
|
14
|
+
this.runtime = runtime;
|
|
10
15
|
}
|
|
11
16
|
configure(configuration) {
|
|
12
17
|
configuration.description("Creates a new Contember project");
|
|
13
18
|
configuration.argument("projectName");
|
|
14
19
|
configuration.option("template").shortcut("t").valueRequired().description("Template name or remote source");
|
|
15
20
|
}
|
|
16
|
-
async execute(input) {
|
|
21
|
+
async execute(input, output) {
|
|
17
22
|
const projectName = input.getArgument("projectName");
|
|
18
|
-
const projectDirectory = join(
|
|
19
|
-
const packageManager = detectPackageManager();
|
|
23
|
+
const projectDirectory = join(this.runtime.cwd(), projectName);
|
|
24
|
+
const packageManager = this.runtime.detectPackageManager();
|
|
20
25
|
const template = input.getOption("template") ?? "default";
|
|
21
26
|
await this.templateInstaller.installTemplate(template, projectDirectory, {
|
|
22
|
-
version: await getPackageVersion(),
|
|
27
|
+
version: await this.runtime.getPackageVersion(),
|
|
23
28
|
projectName,
|
|
24
29
|
packageManager
|
|
25
30
|
});
|
|
26
|
-
|
|
31
|
+
const result = { projectName, projectDirectory, template, packageManager };
|
|
32
|
+
output.data(result, {
|
|
33
|
+
human: (value) => createDocs(value),
|
|
34
|
+
quiet: (value) => value.projectDirectory
|
|
35
|
+
});
|
|
27
36
|
}
|
|
28
37
|
}
|
|
29
|
-
const createDocs = (projectDirectory, projectName, packageManager) =>
|
|
30
|
-
|
|
38
|
+
const createDocs = ({ projectDirectory, projectName, packageManager }) => {
|
|
39
|
+
const safeProjectDirectory = escapeTerminalText(projectDirectory);
|
|
40
|
+
const safeProjectName = escapeTerminalText(projectName);
|
|
41
|
+
const safePackageManager = escapeTerminalText(packageManager);
|
|
42
|
+
return `
|
|
43
|
+
Contember project successfully created in ${safeProjectDirectory}
|
|
31
44
|
|
|
32
45
|
Next steps:
|
|
33
46
|
|
|
34
47
|
1. Navigate to the project directory:
|
|
35
|
-
$ ${
|
|
48
|
+
$ ${style("green", `cd ${safeProjectName}`)}
|
|
36
49
|
|
|
37
50
|
2. Install dependencies:
|
|
38
|
-
$ ${
|
|
51
|
+
$ ${style("green", `${safePackageManager} install`)}
|
|
39
52
|
|
|
40
53
|
3. Start the Contember stack:
|
|
41
|
-
$ ${
|
|
54
|
+
$ ${style("green", `${safePackageManager} start`)}
|
|
42
55
|
|
|
43
56
|
Available services:
|
|
44
57
|
|
|
45
|
-
${
|
|
46
|
-
- Contember Admin ${
|
|
58
|
+
${style("bold", "UI & Admin")}
|
|
59
|
+
- Contember Admin ${style("blue", "http://localhost:1480")}
|
|
47
60
|
|
|
48
|
-
${
|
|
49
|
-
- Contember Engine API ${
|
|
61
|
+
${style("bold", "API & Backend")}
|
|
62
|
+
- Contember Engine API ${style("blue", "http://localhost:1481")}
|
|
50
63
|
Auth token: 0000000000000000000000000000000000000000
|
|
51
64
|
|
|
52
|
-
${
|
|
53
|
-
- PostgreSQL database ${
|
|
54
|
-
-
|
|
55
|
-
- Mailpit SMTP testing ${
|
|
56
|
-
- Adminer DB manager ${
|
|
57
|
-
- Minio Dashboard ${chalk.blue("http://localhost:1486")} ${chalk.grey("credentials: contember / contember")}
|
|
65
|
+
${style("bold", "Development Tools")}
|
|
66
|
+
- PostgreSQL database ${style("blue", "http://localhost:1482")} ${style("grey", "credentials: contember / contember")}
|
|
67
|
+
- S3 object storage ${style("blue", "http://localhost:1483")} ${style("grey", "credentials: contember / contember")}
|
|
68
|
+
- Mailpit SMTP testing ${style("blue", "http://localhost:1484")}
|
|
69
|
+
- Adminer DB manager ${style("blue", "http://localhost:1485")}
|
|
58
70
|
|
|
59
|
-
${
|
|
71
|
+
${style("bold", "Need help?")} Ask the community: https://github.com/orgs/contember/discussions
|
|
60
72
|
`;
|
|
73
|
+
};
|
|
61
74
|
export {
|
|
62
75
|
WorkspaceCreateCommand
|
|
63
76
|
};
|