npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xarunoba/uplink.js

v0.1.23

Published

JavaScript API for Uplink CLI

Downloads

3

Readme

Uplink.js

Node.js Workflow

The JavaScript API to the official Storj CLI, Uplink.

The code is forked from rclone.js and edited to work with Uplink CLI.

Besides providing a way to install uplink on different platforms, a CLI and a JavaScript API are included.

Special thanks to @sntran for developing rclone.js

As this is my first ever package, contributions/PRs are highly welcomed.

Installation

NPM:

npm install -D @xarunoba/uplink.js

PNPM:

pnpm install -D @xarunoba/uplink.js

After installation, the latest binary of uplink is also fetched based on your system environment.

If a custom version of uplink binary is needed, use UPLINK_EXECUTABLE environment variable to set the path to that custom binary.

Usage

Node.js

All API functions return a child process whose events we can listen to. Optional flags can be passed as an object to the last argument of the function call. Except removing the -- prefix, there is no other conversion to the flag name. JSON values are stringified before passed to uplink.

Each API functions can also take options for the spawned child process. See https://nodejs.org/api/child_process.html#child_processspawncommand-args-options for their documentation.

const uplink = require("uplink.js");

const ls = uplink.ls("source:", {
  // Spawn options:
  "env": {

  },
  "shell": "/bin/sh",
});

ls.stdout.on("data", (data) => {
  console.log(data.toString());
});

ls.stderr.on("data", (data) => {
  console.error(data.toString());
});

There is also a Promise-based API:

const uplink = require("uplink.js").promises;

(async function() {
  const results = await uplink.ls("source:", {
    // Spawn options:
    "env": {

    },
    "shell": "/bin/sh",
  });

  console.log(results);
})();

When the official uplink adds new command that has not been provided here, we can still use the command through the default exported functions, passing the command name as first argument:

const uplink = require("uplink.js");

uplink("newcommand", "source:", "target:", {
  "flag": true,
});

(async function() {
  const results = await uplink.promises("newcommand", "source:", "target:", {
    "flag": true,
  });

  console.log(results);
})();

CLI

This simple CLI calls the JS API above and outputs stdout and stderr.

NPM:

$ npx uplink ls
CREATED                NAME
2022-04-03 15:53:40    something1
2022-03-31 15:06:35    something2
2022-04-02 21:02:41    something3

PNPM:

$ pnpm exec uplink ls
CREATED                NAME
2022-04-03 15:53:40    something1
2022-03-31 15:06:35    something2
2022-04-02 21:02:41    something3

Custom command

The CLI also supports executing a custom JS-based command to further extend usage outside of what the official uplink offers:

NPM:

$ npx uplink echo.js arg1 --string value arg2 --boolean

PNPM:

$ pnpm exec uplink echo.js arg1 --string value arg2 --boolean

The custom JS file just needs to export a function that takes the arguments and flags parsed from the CLI. It can either return a child process, or a Promise. For a child process, its stdout and stderr are piped to the caller process.

Inside the function, this is set to uplink.js module.

const { spawn } = require("child_process");

module.exports = function echo(arg1, arg2, flags = {}) {
  return spawn("echo", [arg1, arg2, JSON.stringify(flags)]);
}

The custom module is loaded through require, so it has some nice advantages when locating module:

  • Does not need to specify .js extension, custom is same as custom.js.
  • Considers both foobar.js and foobar/index.js.
  • Can be extended through NODE_PATH environment variable.
  • Can also use module from node_modules by its name.

With that, there are a few things custom commands can be used:

  • Wraps existing API to add new functionality, such as archive.
  • Defines a module with the same name as existing API to extend it with new flags and/or backends.

For publishing a custom uplink command as NPM package, consider prefixing the package name with uplink- so it's clearer and not conflicting.

Example Custom Commands

This is an example from rclone.js but since this package is a fork of rclone.js, creating a custom command for uplink.js is almost exactly the same.

  • rclone-archive: Tracking https://github.com/rclone/rclone/issues/2815.