UNPKG

navskit

Version:

Deploy TypeScript logic on Ethereum. Includes core library, CLI tools, and utilities.

182 lines (172 loc) 7.03 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /** * NAVS CLI - Unified tool for running operators and generating Solidity bindings */ const commander_1 = require("commander"); const dotenv = __importStar(require("dotenv")); const accounts_1 = require("viem/accounts"); const operator_1 = require("./cli/commands/operator"); const gen_1 = require("./cli/commands/gen"); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); // Load environment variables dotenv.config(); // Package information const packageInfo = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, '../package.json'), 'utf8')); // Create main CLI program const program = new commander_1.Command(); program .name('navskit') .description('NAVS Toolkit - Run operators and generate Solidity bindings') .version(packageInfo.version); // Operator command program .command('operator') .description('Run a NAVS operator that listens for tasks from any package') .option('-v, --verbose', 'Enable verbose logging') .option('--rpc <url>', 'RPC URL to use for Ethereum connection', process.env.RPC_URL) .option('--tmp-dir <path>', 'Directory to use for temporary files', process.env.TMP_DIR) .option('--local', 'Monitor for local tasks that match the current package directory') .option('--watch', 'Watch mode: execute tasks without private key to gauge accuracy (JSON output only)') .action(async (options) => { try { // Check for RPC URL if (!options.rpc) { console.error('Error: RPC URL is required. Provide it via --rpc option or RPC_URL environment variable'); process.exit(1); } if (options.watch) { // Watch mode - no private key required, just output JSON console.log(`🚀 Starting NAVS operator in watch mode`); console.log(`👁️ Tasks will be executed locally and compared with onchain results`); // Run the operator in watch mode await (0, operator_1.runOperator)({ rpcUrl: options.rpc, verbose: options.verbose, tempDir: options.tmpDir, local: options.local, watch: true }); } else { // Full operator mode - requires private key const privateKey = process.env.WALLET_PK; if (!privateKey) { console.error('Error: WALLET_PK environment variable is required'); console.error('Set it by running: export WALLET_PK=your_private_key'); console.error('Or use --watch flag to run in watch mode without private key'); process.exit(1); } // Create an account from the private key const account = (0, accounts_1.privateKeyToAccount)(privateKey); console.log(`🚀 Starting NAVS operator (listening for all packages)`); console.log(`👤 Using account: ${account.address}`); // Run the operator await (0, operator_1.runOperator)({ account, rpcUrl: options.rpc, verbose: options.verbose, tempDir: options.tmpDir, local: options.local }); } } catch (error) { console.error('❌ Failed to start operator:', error); process.exit(1); } }); // Gen command program .command('gen') .description('Generate Solidity bindings for your @navs functions') .argument('[directory]', 'Target directory (defaults to current directory)', '.') .option('--local', 'Generate bindings for local task execution') .action(async (directory, options) => { try { console.log('🔨 Starting NAVS code generation...'); const generator = new gen_1.NavsGenerator(directory, options.local); await generator.generate(); console.log('✅ Code generation complete!'); } catch (error) { console.error('❌ Code generation failed:', error instanceof Error ? error.message : String(error)); process.exit(1); } }); // Help command to show usage examples program .command('help') .description('Show detailed help and examples') .action(() => { console.log(` NAVS Toolkit v${packageInfo.version} USAGE: npx navskit <command> [options] COMMANDS: operator Run a NAVS operator that listens for tasks gen Generate Solidity bindings for @navs functions help Show this help message EXAMPLES: 🔧 Run an operator: export WALLET_PK=your_private_key export RPC_URL=your_rpc_url npx navskit operator 🔧 Run operator with custom options: npx navskit operator --rpc https://base-sepolia.infura.io/v3/YOUR_KEY --verbose 👁️ Run operator in watch mode (no private key needed): npx navskit operator --watch --rpc https://base-sepolia.infura.io/v3/YOUR_KEY 📄 Generate Solidity bindings: npx navskit gen npx navskit gen ./my-project ENVIRONMENT VARIABLES: WALLET_PK Private key for the operator account (required for operator) RPC_URL RPC URL for blockchain connection (can also use --rpc) TMP_DIR Directory for temporary files (optional) For more information, visit: https://docs.navs.org `); }); // Parse command line arguments program.parse(); // If no command is provided, show help if (!process.argv.slice(2).length) { program.outputHelp(); }