hsync-cli 1.1.2 → 1.1.3

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/README.md CHANGED
File without changes
package/dist/bin.js CHANGED
@@ -69670,16 +69670,15 @@ async function scanLocalPath(targetPath, rootDir) {
69670
69670
  function parseRemoteTarget(target) {
69671
69671
  const parts = target.split(":");
69672
69672
  const slug = parts[0];
69673
- const remotePath = (parts.slice(1).join(":") || "").replace(/^\/+|\/+$/g, "");
69674
- return { slug, remotePath };
69673
+ const rawPath = parts.slice(1).join(":") || "";
69674
+ const endsWithSlash = rawPath.endsWith("/");
69675
+ const remotePath = rawPath.replace(/^\/+|\/+$/g, "");
69676
+ return { slug, remotePath, endsWithSlash };
69675
69677
  }
69676
69678
  async function push(localPath, remoteTarget, options) {
69677
- const forceYes = options.yes || false;
69678
69679
  try {
69679
69680
  const config = await loadConfig();
69680
- const serverUrl = config.serverUrl;
69681
- const apiKey = config.apiKey;
69682
- if (!serverUrl || !apiKey) {
69681
+ if (!config.serverUrl || !config.apiKey) {
69683
69682
  console.error(source_default.red("Error: CLI not authenticated. Please run: hsync config set-server <url> && hsync login"));
69684
69683
  process.exit(1);
69685
69684
  }
@@ -69694,22 +69693,28 @@ async function push(localPath, remoteTarget, options) {
69694
69693
  const spinner = ora2("Scanning local files...").start();
69695
69694
  const localFiles = await scanLocalPath(resolvedLocalPath, resolvedLocalPath);
69696
69695
  spinner.text = "Fetching remote file tree...";
69697
- const remoteClient = new RemoteClient(serverUrl, apiKey);
69696
+ const remoteClient = new RemoteClient(config.serverUrl, config.apiKey);
69698
69697
  const remoteFiles = await remoteClient.getTree(remote.slug, remote.remotePath);
69699
69698
  spinner.stop();
69700
69699
  console.log(source_default.cyan(`Found ${localFiles.length} local files, ${remoteFiles.length} remote files.`));
69701
- const prompter = new OverwritePrompter(forceYes);
69700
+ let isRemoteDir = !(await fs3.stat(resolvedLocalPath)).isFile() || remote.endsWithSlash;
69701
+ if (!isRemoteDir) {
69702
+ if (remoteFiles.length > 1) {
69703
+ isRemoteDir = true;
69704
+ } else if (remoteFiles.length === 1 && remoteFiles[0].path !== "") {
69705
+ isRemoteDir = true;
69706
+ }
69707
+ }
69708
+ const prompter = new OverwritePrompter(options.yes || false);
69702
69709
  let pushCount = 0;
69703
69710
  let skipCount = 0;
69704
69711
  for (const localFile of localFiles) {
69705
- const remoteFile = remoteFiles.find((f) => f.path === localFile.relativePath);
69706
- const destinationPath = remote.remotePath ? `${remote.remotePath}/${localFile.relativePath}` : localFile.relativePath;
69712
+ const remoteFile = remoteFiles.find((f) => f.path === (isRemoteDir ? localFile.relativePath : ""));
69707
69713
  let shouldUpload = false;
69708
69714
  if (!remoteFile) {
69709
69715
  shouldUpload = true;
69710
69716
  } else if (remoteFile.hash !== localFile.hash) {
69711
- const confirm = await prompter.shouldOverwrite(localFile.relativePath);
69712
- if (confirm) {
69717
+ if (await prompter.shouldOverwrite(localFile.relativePath)) {
69713
69718
  shouldUpload = true;
69714
69719
  } else {
69715
69720
  skipCount++;
@@ -69720,7 +69725,7 @@ async function push(localPath, remoteTarget, options) {
69720
69725
  if (shouldUpload) {
69721
69726
  const fileSpinner = ora2(`Pushing ${localFile.relativePath}...`).start();
69722
69727
  try {
69723
- await remoteClient.uploadFile(remote.slug, destinationPath, localFile.absolutePath);
69728
+ await remoteClient.uploadFile(remote.slug, isRemoteDir ? remote.remotePath ? `${remote.remotePath}/${localFile.relativePath}` : localFile.relativePath : remote.remotePath, localFile.absolutePath);
69724
69729
  fileSpinner.succeed(source_default.green(`Pushed ${localFile.relativePath}`));
69725
69730
  pushCount++;
69726
69731
  } catch (uploadErr) {
@@ -69736,38 +69741,65 @@ async function push(localPath, remoteTarget, options) {
69736
69741
  }
69737
69742
  }
69738
69743
  async function pull(remoteTarget, localPath, options) {
69739
- const forceYes = options.yes || false;
69740
69744
  try {
69741
69745
  const config = await loadConfig();
69742
- const serverUrl = config.serverUrl;
69743
- const apiKey = config.apiKey;
69744
- if (!serverUrl || !apiKey) {
69746
+ if (!config.serverUrl || !config.apiKey) {
69745
69747
  console.error(source_default.red("Error: CLI not authenticated. Please run: hsync config set-server <url> && hsync login"));
69746
69748
  process.exit(1);
69747
69749
  }
69748
69750
  const remote = parseRemoteTarget(remoteTarget);
69749
69751
  const resolvedLocalPath = path4.resolve(localPath);
69750
69752
  const spinner = ora2("Fetching remote file tree...").start();
69751
- const remoteClient = new RemoteClient(serverUrl, apiKey);
69753
+ const remoteClient = new RemoteClient(config.serverUrl, config.apiKey);
69752
69754
  const remoteFiles = await remoteClient.getTree(remote.slug, remote.remotePath);
69753
69755
  spinner.text = "Scanning local files...";
69754
- await fs3.mkdir(resolvedLocalPath, { recursive: true });
69755
- const localFiles = await scanLocalPath(resolvedLocalPath, resolvedLocalPath);
69756
+ const isRemoteFile = remoteFiles.length === 1 && remoteFiles[0].path === "";
69757
+ let isLocalDir = false;
69758
+ try {
69759
+ const localStat = await fs3.stat(resolvedLocalPath);
69760
+ isLocalDir = localStat.isDirectory();
69761
+ } catch {
69762
+ isLocalDir = localPath.endsWith("/") || localPath.endsWith(path4.sep);
69763
+ }
69764
+ if (isRemoteFile && !isLocalDir) {
69765
+ await fs3.mkdir(path4.dirname(resolvedLocalPath), { recursive: true });
69766
+ } else {
69767
+ await fs3.mkdir(resolvedLocalPath, { recursive: true });
69768
+ }
69769
+ let localFiles = [];
69770
+ try {
69771
+ localFiles = await scanLocalPath(resolvedLocalPath, resolvedLocalPath);
69772
+ } catch (err) {
69773
+ if (err.code !== "ENOENT") {
69774
+ throw err;
69775
+ }
69776
+ }
69756
69777
  spinner.stop();
69757
69778
  console.log(source_default.cyan(`Found ${remoteFiles.length} remote files, ${localFiles.length} local files.`));
69758
- const prompter = new OverwritePrompter(forceYes);
69779
+ const prompter = new OverwritePrompter(options.yes || false);
69759
69780
  let pullCount = 0;
69760
69781
  let skipCount = 0;
69761
69782
  for (const remoteFile of remoteFiles) {
69762
- const localFile = localFiles.find((f) => f.relativePath === remoteFile.path);
69763
- const localDestPath = path4.join(resolvedLocalPath, remoteFile.path);
69764
- const sourcePath = remote.remotePath ? `${remote.remotePath}/${remoteFile.path}` : remoteFile.path;
69783
+ let localDestPath;
69784
+ let localFile;
69785
+ if (isRemoteFile) {
69786
+ if (isLocalDir) {
69787
+ localDestPath = path4.join(resolvedLocalPath, path4.basename(remote.remotePath));
69788
+ localFile = localFiles.find((f) => f.relativePath === path4.basename(remote.remotePath));
69789
+ } else {
69790
+ localDestPath = resolvedLocalPath;
69791
+ localFile = localFiles.length > 0 ? localFiles[0] : undefined;
69792
+ }
69793
+ } else {
69794
+ localDestPath = path4.join(resolvedLocalPath, remoteFile.path);
69795
+ localFile = localFiles.find((f) => f.relativePath === remoteFile.path);
69796
+ }
69765
69797
  let shouldDownload = false;
69766
69798
  if (!localFile) {
69767
69799
  shouldDownload = true;
69768
69800
  } else if (localFile.hash !== remoteFile.hash) {
69769
- const confirm = await prompter.shouldOverwrite(remoteFile.path);
69770
- if (confirm) {
69801
+ const promptPath = isRemoteFile ? remote.remotePath || path4.basename(localDestPath) : remoteFile.path;
69802
+ if (await prompter.shouldOverwrite(promptPath)) {
69771
69803
  shouldDownload = true;
69772
69804
  } else {
69773
69805
  skipCount++;
@@ -69776,13 +69808,14 @@ async function pull(remoteTarget, localPath, options) {
69776
69808
  skipCount++;
69777
69809
  }
69778
69810
  if (shouldDownload) {
69779
- const fileSpinner = ora2(`Pulling ${remoteFile.path}...`).start();
69811
+ const logPath = isRemoteFile ? remote.remotePath || path4.basename(localDestPath) : remoteFile.path;
69812
+ const fileSpinner = ora2(`Pulling ${logPath}...`).start();
69780
69813
  try {
69781
- await remoteClient.downloadFile(remote.slug, sourcePath, localDestPath);
69782
- fileSpinner.succeed(source_default.green(`Pulled ${remoteFile.path}`));
69814
+ await remoteClient.downloadFile(remote.slug, isRemoteFile ? remote.remotePath : remote.remotePath ? `${remote.remotePath}/${remoteFile.path}` : remoteFile.path, localDestPath);
69815
+ fileSpinner.succeed(source_default.green(`Pulled ${logPath}`));
69783
69816
  pullCount++;
69784
69817
  } catch (downloadErr) {
69785
- fileSpinner.fail(source_default.red(`Failed to pull ${remoteFile.path}: ${downloadErr.message}`));
69818
+ fileSpinner.fail(source_default.red(`Failed to pull ${logPath}: ${downloadErr.message}`));
69786
69819
  }
69787
69820
  }
69788
69821
  }
@@ -71190,7 +71223,7 @@ async function editSyncJob2(name, options) {
71190
71223
  }
71191
71224
 
71192
71225
  // src/commands/ui.ts
71193
- var __dirname = "/media/hyper2/HYPER/projects/node/hmd/file-sync-v2/packages/cli/src/commands";
71226
+ var __dirname = "/home/hamid/packages/node/hmd/file-sync/packages/cli/src/commands";
71194
71227
  function openBrowser(url2) {
71195
71228
  const start = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
71196
71229
  exec(`${start} ${url2}`).unref();
@@ -71415,7 +71448,7 @@ Press Ctrl+C to stop the server...
71415
71448
  // package.json
71416
71449
  var package_default = {
71417
71450
  name: "hsync-cli",
71418
- version: "1.1.2",
71451
+ version: "1.1.3",
71419
71452
  description: "hsync CLI for file sync operations",
71420
71453
  bin: {
71421
71454
  hsync: "./dist/bin.js"
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hsync-cli",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "hsync CLI for file sync operations",
5
5
  "bin": {
6
6
  "hsync": "./dist/bin.js"