From 81eb44fd94d96928dc113da9e8cceb63a251c078 Mon Sep 17 00:00:00 2001 From: Marc Fornos Date: Fri, 30 Jun 2023 18:33:35 +0200 Subject: [PATCH] multi-command cli for dev tools --- tools/README.md | 8 +++++++- tools/package.json | 9 +++++++-- tools/src/{ => commands}/capture.ts | 7 ++----- tools/src/main.ts | 17 +++++++++++++++++ yarn.lock | 3 +-- 5 files changed, 34 insertions(+), 10 deletions(-) rename tools/src/{ => commands}/capture.ts (95%) create mode 100644 tools/src/main.ts diff --git a/tools/README.md b/tools/README.md index 67a2d12..7831383 100644 --- a/tools/README.md +++ b/tools/README.md @@ -1,5 +1,11 @@ # Development Support Tools +TBD + +``` +yarn octools -h +``` + ## Capture The capture tool is a command line tool that allows you to download blocks from a network, enhance them as extended signed blocks, and output a CBOR representation. @@ -9,6 +15,6 @@ This tool is useful for capturing blockchain data to be used in tests. To use the capture tool, run the following command: ```shell -./capture.ts ./out.cbor --start="2841323" --count="20" --url="wss://rococo-contracts-rpc.polkadot.io" +yarn octools capture ./out.cbor --start="2841323" --count="20" --url="wss://rococo-contracts-rpc.polkadot.io" ``` In the above example, it downloads 20 blocks from the Rococo Contracts network and saves the enhanced blocks in the `out.cbor` file. diff --git a/tools/package.json b/tools/package.json index 46b4ee6..32e48a9 100644 --- a/tools/package.json +++ b/tools/package.json @@ -13,8 +13,7 @@ "url": "https://github.com/sodazone/ocelloids.git" }, "bin": { - "capture": "src/capture.ts", - "cdump": "src/cdump.ts" + "octools": "lib/main.cjs" }, "dependencies": { "@sodazone/ocelloids": "1.0.0-dev.0", @@ -22,5 +21,11 @@ "cbor-x": "^1.5.3", "citty": "^0.1.1" }, + "tsup": { + "shims": true + }, + "scripts": { + "build": "tsup src/main.ts --clean --minify -d lib/" + }, "stableVersion": "1.0.0" } diff --git a/tools/src/capture.ts b/tools/src/commands/capture.ts similarity index 95% rename from tools/src/capture.ts rename to tools/src/commands/capture.ts index af3a9d2..4fd1ab4 100755 --- a/tools/src/capture.ts +++ b/tools/src/commands/capture.ts @@ -1,4 +1,3 @@ -#!/usr/bin/env ts-node-esm /* * Copyright 2023 SO/DA zone - Marc Fornós & Xueying Wang * @@ -20,7 +19,7 @@ import { writeFileSync } from 'node:fs'; import { Observer } from 'rxjs'; import { encode } from 'cbor-x'; -import { defineCommand, runMain } from 'citty'; +import { defineCommand } from 'citty'; import { WsProvider } from '@polkadot/api'; import { SignedBlockExtended } from '@polkadot/api-derive/types'; @@ -78,7 +77,7 @@ function downloadBlocks({ ); } -const main = defineCommand({ +export default defineCommand({ meta: { name: 'capture', version: '0.0.1', @@ -107,5 +106,3 @@ const main = defineCommand({ downloadBlocks(args); }, }); - -runMain(main as any); diff --git a/tools/src/main.ts b/tools/src/main.ts new file mode 100644 index 0000000..f8fbc10 --- /dev/null +++ b/tools/src/main.ts @@ -0,0 +1,17 @@ +#!/usr/bin/env node + +import { defineCommand, runMain } from 'citty'; +import capture from './commands/capture.js'; + +const main = defineCommand({ + meta: { + name: 'octools', + version: '1.0.0', + description: 'Ocelloids development support tools', + }, + subCommands: { + capture, + }, +}); + +runMain(main); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 6cf1dc2..0aeadbf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1556,8 +1556,7 @@ __metadata: cbor-x: ^1.5.3 citty: ^0.1.1 bin: - capture: src/capture.ts - cdump: src/cdump.ts + octools: lib/main.cjs languageName: unknown linkType: soft