@vexblocks/cli 2.0.5 → 2.0.8
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/index.js +82 -9
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -138,6 +138,23 @@ async function mergePackageJson(targetPath, sourcePackageJson) {
|
|
|
138
138
|
// src/utils/github.ts
|
|
139
139
|
import path2 from "path";
|
|
140
140
|
import fs2 from "fs-extra";
|
|
141
|
+
var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
142
|
+
".png",
|
|
143
|
+
".jpg",
|
|
144
|
+
".jpeg",
|
|
145
|
+
".gif",
|
|
146
|
+
".webp",
|
|
147
|
+
".ico",
|
|
148
|
+
".woff",
|
|
149
|
+
".woff2",
|
|
150
|
+
".ttf",
|
|
151
|
+
".otf",
|
|
152
|
+
".eot",
|
|
153
|
+
".pdf",
|
|
154
|
+
".zip",
|
|
155
|
+
".tar",
|
|
156
|
+
".gz"
|
|
157
|
+
]);
|
|
141
158
|
async function fetchRemoteManifest() {
|
|
142
159
|
const url = `${GITHUB_RAW_URL}/templates/manifest.json`;
|
|
143
160
|
const response = await fetch(url);
|
|
@@ -164,10 +181,42 @@ async function downloadFile(remotePath, localPath, options) {
|
|
|
164
181
|
throw new Error(`Failed to download ${remotePath}: ${response.statusText}`);
|
|
165
182
|
}
|
|
166
183
|
await fs2.ensureDir(path2.dirname(localPath));
|
|
167
|
-
const
|
|
168
|
-
|
|
184
|
+
const ext = path2.extname(localPath).toLowerCase();
|
|
185
|
+
if (BINARY_EXTENSIONS.has(ext)) {
|
|
186
|
+
const buffer = await response.arrayBuffer();
|
|
187
|
+
await fs2.writeFile(localPath, Buffer.from(buffer));
|
|
188
|
+
} else {
|
|
189
|
+
const content = await response.text();
|
|
190
|
+
await fs2.writeFile(localPath, content, "utf-8");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async function collectLocalFiles(dir) {
|
|
194
|
+
const entries = await fs2.readdir(dir, { withFileTypes: true });
|
|
195
|
+
const files = [];
|
|
196
|
+
for (const entry of entries) {
|
|
197
|
+
const full = path2.join(dir, entry.name);
|
|
198
|
+
if (entry.isDirectory()) {
|
|
199
|
+
files.push(...await collectLocalFiles(full));
|
|
200
|
+
} else {
|
|
201
|
+
files.push(full);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return files;
|
|
169
205
|
}
|
|
170
|
-
async function
|
|
206
|
+
async function removeEmptyDirs(dir) {
|
|
207
|
+
const entries = await fs2.readdir(dir, { withFileTypes: true });
|
|
208
|
+
for (const entry of entries) {
|
|
209
|
+
if (entry.isDirectory()) {
|
|
210
|
+
const full = path2.join(dir, entry.name);
|
|
211
|
+
await removeEmptyDirs(full);
|
|
212
|
+
const remaining = await fs2.readdir(full);
|
|
213
|
+
if (remaining.length === 0) {
|
|
214
|
+
await fs2.remove(full);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async function downloadAndExtractPackage(packagePath, targetDir, onProgress, options) {
|
|
171
220
|
const treeUrl = `https://api.github.com/repos/${GITHUB_REPO}/git/trees/${GITHUB_BRANCH}?recursive=1`;
|
|
172
221
|
const response = await fetch(treeUrl, {
|
|
173
222
|
headers: {
|
|
@@ -182,6 +231,9 @@ async function downloadAndExtractPackage(packagePath, targetDir, onProgress) {
|
|
|
182
231
|
const files = data.tree.filter(
|
|
183
232
|
(item) => item.type === "blob" && item.path.startsWith(`${packagePath}/`)
|
|
184
233
|
);
|
|
234
|
+
const remoteRelativePaths = new Set(
|
|
235
|
+
files.map((f) => f.path.slice(packagePath.length + 1))
|
|
236
|
+
);
|
|
185
237
|
for (const file of files) {
|
|
186
238
|
const relativePath = file.path.slice(packagePath.length + 1);
|
|
187
239
|
const localPath = path2.join(targetDir, relativePath);
|
|
@@ -193,6 +245,17 @@ async function downloadAndExtractPackage(packagePath, targetDir, onProgress) {
|
|
|
193
245
|
skipIfExists: isProtectedFile
|
|
194
246
|
});
|
|
195
247
|
}
|
|
248
|
+
if (options?.sync && await fs2.pathExists(targetDir)) {
|
|
249
|
+
const localFiles = await collectLocalFiles(targetDir);
|
|
250
|
+
for (const localFile of localFiles) {
|
|
251
|
+
const relPath = path2.relative(targetDir, localFile);
|
|
252
|
+
const isHidden = relPath.split(path2.sep).some((segment) => segment.startsWith("."));
|
|
253
|
+
if (!isHidden && !remoteRelativePaths.has(relPath)) {
|
|
254
|
+
await fs2.remove(localFile);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
await removeEmptyDirs(targetDir);
|
|
258
|
+
}
|
|
196
259
|
}
|
|
197
260
|
async function getPackageFiles(packagePath) {
|
|
198
261
|
const treeUrl = `https://api.github.com/repos/${GITHUB_REPO}/git/trees/${GITHUB_BRANCH}?recursive=1`;
|
|
@@ -498,9 +561,14 @@ async function installPackage(cwd, pkg, version, manifest) {
|
|
|
498
561
|
await installBackendPackage(targetPath, sourcePath, spinner);
|
|
499
562
|
} else {
|
|
500
563
|
await fs4.ensureDir(targetPath);
|
|
501
|
-
await downloadAndExtractPackage(
|
|
502
|
-
|
|
503
|
-
|
|
564
|
+
await downloadAndExtractPackage(
|
|
565
|
+
sourcePath,
|
|
566
|
+
targetPath,
|
|
567
|
+
(file) => {
|
|
568
|
+
spinner.text = `Installing ${PACKAGE_NAMES[pkg]}... ${pc2.dim(file)}`;
|
|
569
|
+
},
|
|
570
|
+
{ sync: true }
|
|
571
|
+
);
|
|
504
572
|
}
|
|
505
573
|
const config = {
|
|
506
574
|
version,
|
|
@@ -551,9 +619,14 @@ async function installBackendPackage(targetPath, sourcePath, spinner) {
|
|
|
551
619
|
await mergeSchemaFile(existingSchemaPath, spinner);
|
|
552
620
|
} else {
|
|
553
621
|
await fs4.ensureDir(targetPath);
|
|
554
|
-
await downloadAndExtractPackage(
|
|
555
|
-
|
|
556
|
-
|
|
622
|
+
await downloadAndExtractPackage(
|
|
623
|
+
sourcePath,
|
|
624
|
+
targetPath,
|
|
625
|
+
(file) => {
|
|
626
|
+
spinner.text = `Installing backend... ${pc2.dim(file)}`;
|
|
627
|
+
},
|
|
628
|
+
{ sync: true }
|
|
629
|
+
);
|
|
557
630
|
}
|
|
558
631
|
spinner.text = "Merging package.json...";
|
|
559
632
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vexblocks/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "CLI for adding VexBlocks Headless CMS to your Turborepo project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"@inquirer/prompts": "^8.3.0",
|
|
47
47
|
"commander": "^14.0.3",
|
|
48
48
|
"diff": "^8.0.3",
|
|
49
|
-
"fs-extra": "^11.3.
|
|
49
|
+
"fs-extra": "^11.3.4",
|
|
50
50
|
"ora": "^9.3.0",
|
|
51
51
|
"picocolors": "^1.1.1",
|
|
52
|
-
"tar": "^7.5.
|
|
52
|
+
"tar": "^7.5.10"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/diff": "^8.0.0",
|
|
56
56
|
"@types/fs-extra": "^11.0.4",
|
|
57
|
-
"@types/node": "^25.3.
|
|
57
|
+
"@types/node": "^25.3.5",
|
|
58
58
|
"tsup": "^8.5.1",
|
|
59
59
|
"typescript": "^5.9.3"
|
|
60
60
|
},
|