hsync-cli 1.1.5 → 1.1.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/bin.js +31 -15
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -68409,9 +68409,8 @@ class RemoteClient {
|
|
|
68409
68409
|
const response = await this.client.get(`/api/buckets/${slug}/files/tree`, {
|
|
68410
68410
|
params: { path: cleanPath }
|
|
68411
68411
|
});
|
|
68412
|
-
const
|
|
68413
|
-
if (
|
|
68414
|
-
const f = response.data.files[0];
|
|
68412
|
+
const f = response.data.files.find((file) => file.path === cleanPath && !file.isDirectory);
|
|
68413
|
+
if (cleanPath && f) {
|
|
68415
68414
|
return [
|
|
68416
68415
|
{
|
|
68417
68416
|
path: "",
|
|
@@ -68422,7 +68421,7 @@ class RemoteClient {
|
|
|
68422
68421
|
];
|
|
68423
68422
|
}
|
|
68424
68423
|
const prefix = cleanPath ? cleanPath + "/" : "";
|
|
68425
|
-
return response.data.files.filter((f) => !f.isDirectory).map((f) => ({
|
|
68424
|
+
return response.data.files.filter((f) => !f.isDirectory && f.path.startsWith(prefix)).map((f) => ({
|
|
68426
68425
|
path: prefix ? f.path.slice(prefix.length) : f.path,
|
|
68427
68426
|
hash: f.hash || "",
|
|
68428
68427
|
size: f.size,
|
|
@@ -70437,13 +70436,14 @@ async function push(localPath, remoteTarget, options) {
|
|
|
70437
70436
|
const remoteClient = new RemoteClient(serverUrl, apiKey);
|
|
70438
70437
|
const remoteFiles = await remoteClient.getTree(remote.slug, remote.remotePath);
|
|
70439
70438
|
spinner.stop();
|
|
70439
|
+
const isFileToFile = !!remote.remotePath && (await fs6.stat(resolvedLocalPath)).isFile() && (remoteFiles.length === 1 && remoteFiles[0].path === "" || remoteFiles.length === 0 && path8.posix.basename(remote.remotePath) === localFiles[0].relativePath);
|
|
70440
70440
|
console.log(source_default.cyan(`Found ${localFiles.length} local files, ${remoteFiles.length} remote files.`));
|
|
70441
70441
|
const prompter = new OverwritePrompter(forceYes);
|
|
70442
70442
|
let pushCount = 0;
|
|
70443
70443
|
let skipCount = 0;
|
|
70444
70444
|
for (const localFile of localFiles) {
|
|
70445
|
-
const remoteFile = remoteFiles.find((f) => f.path === localFile.relativePath);
|
|
70446
|
-
const destinationPath = remote.remotePath ? `${remote.remotePath}/${localFile.relativePath}` : localFile.relativePath;
|
|
70445
|
+
const remoteFile = remoteFiles.find((f) => f.path === (isFileToFile ? "" : localFile.relativePath));
|
|
70446
|
+
const destinationPath = isFileToFile ? remote.remotePath : remote.remotePath ? `${remote.remotePath}/${localFile.relativePath}` : localFile.relativePath;
|
|
70447
70447
|
let shouldUpload = false;
|
|
70448
70448
|
if (!remoteFile) {
|
|
70449
70449
|
shouldUpload = true;
|
|
@@ -70491,8 +70491,24 @@ async function pull(remoteTarget, localPath, options) {
|
|
|
70491
70491
|
const remoteClient = new RemoteClient(serverUrl, apiKey);
|
|
70492
70492
|
const remoteFiles = await remoteClient.getTree(remote.slug, remote.remotePath);
|
|
70493
70493
|
spinner.text = "Scanning local files...";
|
|
70494
|
-
|
|
70495
|
-
|
|
70494
|
+
let singleFileDest = "";
|
|
70495
|
+
let localFiles = [];
|
|
70496
|
+
if (remoteFiles.length === 1 && remoteFiles[0].path === "") {
|
|
70497
|
+
singleFileDest = resolvedLocalPath;
|
|
70498
|
+
let isDir = localPath.endsWith("/");
|
|
70499
|
+
try {
|
|
70500
|
+
isDir = isDir || (await fs6.stat(resolvedLocalPath)).isDirectory();
|
|
70501
|
+
} catch {}
|
|
70502
|
+
if (isDir) {
|
|
70503
|
+
singleFileDest = path8.join(resolvedLocalPath, path8.posix.basename(remote.remotePath));
|
|
70504
|
+
}
|
|
70505
|
+
try {
|
|
70506
|
+
localFiles = [{ ...(await scanLocalPath(singleFileDest, singleFileDest))[0], relativePath: "" }];
|
|
70507
|
+
} catch {}
|
|
70508
|
+
} else {
|
|
70509
|
+
await fs6.mkdir(resolvedLocalPath, { recursive: true });
|
|
70510
|
+
localFiles = await scanLocalPath(resolvedLocalPath, resolvedLocalPath);
|
|
70511
|
+
}
|
|
70496
70512
|
spinner.stop();
|
|
70497
70513
|
console.log(source_default.cyan(`Found ${remoteFiles.length} remote files, ${localFiles.length} local files.`));
|
|
70498
70514
|
const prompter = new OverwritePrompter(forceYes);
|
|
@@ -70500,13 +70516,13 @@ async function pull(remoteTarget, localPath, options) {
|
|
|
70500
70516
|
let skipCount = 0;
|
|
70501
70517
|
for (const remoteFile of remoteFiles) {
|
|
70502
70518
|
const localFile = localFiles.find((f) => f.relativePath === remoteFile.path);
|
|
70503
|
-
const localDestPath = path8.join(resolvedLocalPath, remoteFile.path);
|
|
70504
|
-
const sourcePath = remote.remotePath ? `${remote.remotePath}/${remoteFile.path}` : remoteFile.path;
|
|
70519
|
+
const localDestPath = singleFileDest || path8.join(resolvedLocalPath, remoteFile.path);
|
|
70520
|
+
const sourcePath = singleFileDest ? remote.remotePath : remote.remotePath ? `${remote.remotePath}/${remoteFile.path}` : remoteFile.path;
|
|
70505
70521
|
let shouldDownload = false;
|
|
70506
70522
|
if (!localFile) {
|
|
70507
70523
|
shouldDownload = true;
|
|
70508
70524
|
} else if (localFile.hash !== remoteFile.hash) {
|
|
70509
|
-
const confirm = await prompter.shouldOverwrite(remoteFile.path);
|
|
70525
|
+
const confirm = await prompter.shouldOverwrite(remoteFile.path || remote.remotePath);
|
|
70510
70526
|
if (confirm) {
|
|
70511
70527
|
shouldDownload = true;
|
|
70512
70528
|
} else {
|
|
@@ -70516,13 +70532,13 @@ async function pull(remoteTarget, localPath, options) {
|
|
|
70516
70532
|
skipCount++;
|
|
70517
70533
|
}
|
|
70518
70534
|
if (shouldDownload) {
|
|
70519
|
-
const fileSpinner = ora2(`Pulling ${remoteFile.path}...`).start();
|
|
70535
|
+
const fileSpinner = ora2(`Pulling ${remoteFile.path || remote.remotePath}...`).start();
|
|
70520
70536
|
try {
|
|
70521
70537
|
await remoteClient.downloadFile(remote.slug, sourcePath, localDestPath);
|
|
70522
|
-
fileSpinner.succeed(source_default.green(`Pulled ${remoteFile.path}`));
|
|
70538
|
+
fileSpinner.succeed(source_default.green(`Pulled ${remoteFile.path || remote.remotePath}`));
|
|
70523
70539
|
pullCount++;
|
|
70524
70540
|
} catch (downloadErr) {
|
|
70525
|
-
fileSpinner.fail(source_default.red(`Failed to pull ${remoteFile.path}: ${downloadErr.message}`));
|
|
70541
|
+
fileSpinner.fail(source_default.red(`Failed to pull ${remoteFile.path || remote.remotePath}: ${downloadErr.message}`));
|
|
70526
70542
|
}
|
|
70527
70543
|
}
|
|
70528
70544
|
}
|
|
@@ -71488,7 +71504,7 @@ Press Ctrl+C to stop the server...
|
|
|
71488
71504
|
// package.json
|
|
71489
71505
|
var package_default = {
|
|
71490
71506
|
name: "hsync-cli",
|
|
71491
|
-
version: "1.1.
|
|
71507
|
+
version: "1.1.6",
|
|
71492
71508
|
description: "hsync CLI for file sync operations",
|
|
71493
71509
|
bin: {
|
|
71494
71510
|
hsync: "./dist/bin.js"
|