UNPKG

@stoar/cli

Version:

CLI tool for STOAR - decentralized file storage on Arweave

93 lines 3.8 kB
#!/usr/bin/env node import { Command } from 'commander'; import dotenv from 'dotenv'; import updateNotifier from 'update-notifier'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; // Load environment variables dotenv.config(); // Get package.json path const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8')); // Check for updates using update-notifier if (!process.argv.includes('--skip-update-check') && !process.env.STOAR_SKIP_UPDATE_CHECK) { const notifier = updateNotifier({ pkg: packageJson, updateCheckInterval: 1000 * 60 * 60 * 24, // 24 hours }); // Custom notification message notifier.notify({ defer: false, message: 'Update available {currentVersion} → {latestVersion}\n' + 'Run {updateCommand} to update\n\n' + 'Changelog: https://github.com/stoar/cli/releases/tag/v{latestVersion}', boxenOptions: { padding: 1, margin: 1, align: 'center', borderColor: 'yellow', borderStyle: 'round' } }); } // Create main program const program = new Command(); program .name('stoar') .description('CLI tool for STOAR - decentralized file storage on Arweave') .version(packageJson.version) .option('-w, --wallet <path>', 'Path to wallet JSON file (or use STOAR_WALLET env var)') .option('--gateway <url>', 'Arweave gateway URL', 'https://arweave.net') .option('--json', 'Output results in JSON format') .option('--quiet', 'Only output essential information') .option('--verbose', 'Show detailed output') .option('--skip-update-check', 'Skip automatic update check') .hook('preAction', (thisCommand) => { // Global pre-action hook to validate wallet configuration const options = thisCommand.opts(); const parentOptions = thisCommand.parent?.opts() || {}; const globalOptions = { ...parentOptions, ...options }; // Store global options for use in commands thisCommand.globalOptions = globalOptions; }); // Import and register commands import { uploadCommand } from './commands/upload.js'; import { downloadCommand } from './commands/download.js'; import { listCommand } from './commands/list.js'; import { walletCommand } from './commands/wallet.js'; import { batchCommand } from './commands/batch.js'; import { s3Command } from './commands/s3.js'; import { deployCommand } from './commands/deploy.js'; import { configCommand } from './commands/config.js'; import { infoCommand } from './commands/info.js'; import { searchCommand } from './commands/search.js'; import { estimateCommand } from './commands/estimate.js'; import { monitorCommand } from './commands/monitor.js'; import { interactiveCommand } from './commands/interactive.js'; import { updateCommand } from './commands/update.js'; import { versionCommand } from './commands/version.js'; // Register all commands program.addCommand(uploadCommand); program.addCommand(downloadCommand); program.addCommand(listCommand); program.addCommand(walletCommand); program.addCommand(batchCommand); program.addCommand(s3Command); program.addCommand(deployCommand); program.addCommand(configCommand); program.addCommand(infoCommand); program.addCommand(searchCommand); program.addCommand(estimateCommand); program.addCommand(monitorCommand); program.addCommand(interactiveCommand); program.addCommand(updateCommand); program.addCommand(versionCommand); // Parse command line arguments program.parse(); // If no command provided, show help if (!process.argv.slice(2).length) { program.outputHelp(); } //# sourceMappingURL=index.js.map