From 36fdc081f04b9bdf39b7b8bdd8f183d6b4adb79b Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Tue, 7 Feb 2023 10:41:38 +0100 Subject: [PATCH] feat(ksuid): add CLI wrapper --- packages/ksuid/bin/ksuid | 12 ++++++++++++ packages/ksuid/package.json | 1 + packages/ksuid/src/cli.ts | 5 +++++ yarn.lock | 2 ++ 4 files changed, 20 insertions(+) create mode 100755 packages/ksuid/bin/ksuid create mode 100644 packages/ksuid/src/cli.ts diff --git a/packages/ksuid/bin/ksuid b/packages/ksuid/bin/ksuid new file mode 100755 index 0000000000..bcd8061883 --- /dev/null +++ b/packages/ksuid/bin/ksuid @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# https://stackoverflow.com/a/246128/294515 +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do + DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" +done +DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" + +/usr/bin/env node "$DIR/../cli.js" "$DIR" "$@" diff --git a/packages/ksuid/package.json b/packages/ksuid/package.json index 4fda324947..be3d8a8199 100644 --- a/packages/ksuid/package.json +++ b/packages/ksuid/package.json @@ -5,6 +5,7 @@ "type": "module", "module": "./index.js", "typings": "./index.d.ts", + "bin": "bin/ksuid", "sideEffects": false, "repository": { "type": "git", diff --git a/packages/ksuid/src/cli.ts b/packages/ksuid/src/cli.ts new file mode 100644 index 0000000000..4fac0a5250 --- /dev/null +++ b/packages/ksuid/src/cli.ts @@ -0,0 +1,5 @@ +import { defKSUID32 } from "./ksuid32.js"; + +const bytes = parseInt(process.argv[3] || "16"); + +process.stdout.write(defKSUID32({ bytes }).next() + "\n"); diff --git a/yarn.lock b/yarn.lock index 32b946d846..7a25f30561 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4165,6 +4165,8 @@ __metadata: tools: "workspace:^" typedoc: ^0.23.24 typescript: ^4.9.5 + bin: + ksuid: bin/ksuid languageName: unknown linkType: soft