@zrhsh/wukong-cli
v0.3.0
Published
Wukong CLI - TypeScript with auto token refresh
Readme
Wukong CLI
TypeScript CLI tool for Oceanet/NRP system with OAuth Device PKCE Flow authentication and automatic token refresh.
Features
- 🔐 Secure Authentication - OAuth Device PKCE Flow without password input
- 🔄 Auto Token Refresh - Automatic token refresh before expiration
- 🌍 Multi-Environment - Support for dev, beta, uat, and prod environments
- 🐛 Debug Mode - Show HTTP requests and responses with
--debugflag - 💾 Secure Storage - Platform native credential managers with file fallback
- 🛠️ HTTP Client - Built-in HTTP client with automatic authentication
- ⚙️ Smart Configuration - Built-in defaults with fallback to user configuration
- 🔍 Structured Errors - Clear error messages with actionable fix suggestions
Quick Start
# Install
npm install -g @zrhsh/wukong-cli
# Initialize configuration
wukong-cli init
# Login
wukong-cli auth login
# Check status
wukong-cli auth status
# Make API request
wukong-cli http get "/oceanet-auth/web/userInfo"Development
# Clone repository
git clone <repository-url>
cd wukong-ts-cli
# Install dependencies (自动构建项目)
npm install
# Development mode (直接运行 TypeScript)
npm run dev <args>
# Build for production
npm run build
# Link globally for testing
npm run link
# Run tests
npm test
# Verify before publishing
npm run verify注意:项目配置了自动构建脚本(prepare 和 prepack),在 npm install 和 npm publish 时会自动构建。如果遇到 MODULE_NOT_FOUND 错误,请运行 npm run build 手动构建。
Deprecation Notices
⚠️ Device Flow API: 某些内部 API 已标记为弃用,将在 v1.0.0 中移除。这不会影响终端用户的使用。详见 弃用文档。
Commands
Configuration Commands
wukong-cli init # Initialize configuration fileAuthentication Commands
wukong-cli auth login # OAuth Device PKCE Flow login
wukong-cli auth status # Show authentication status
wukong-cli auth refresh # Refresh access token
wukong-cli auth logout # Logout and clear tokensHTTP Commands
wukong-cli http get "/endpoint" # GET request
wukong-cli http post "/endpoint" -d '{"key":"value"}' # POST request
wukong-cli http put "/endpoint" -d '{"key":"value"}' # PUT request
wukong-cli http delete "/endpoint" # DELETE requestGlobal Options
--debug # Enable debug mode (show HTTP requests)
-V, --version # Show version number
-h, --help # Show help informationEnvironment Switching
# PowerShell
$env:WUKONG_CLI_ENV="beta"
wukong-cli auth login
# Bash/Zsh
export WUKONG_CLI_ENV="beta"
wukong-cli auth login
# CMD
set WUKONG_CLI_ENV=beta
wukong-cli auth loginConfiguration
Wukong CLI uses intelligent configuration with built-in defaults:
- No Configuration Required: CLI works out of the box with built-in environment defaults
- Custom Configuration: Optional
wukong-cli.jsonfor custom endpoints - Smart Fallback: Uses built-in defaults when environments are not configured
- Clear Errors: Structured error messages guide you to fix configuration issues
Configuration File Location
~/wukong-cli.json # User home directoryInitialize Configuration
wukong-cli init # Creates or resets configuration fileExample Configuration
{
"defaultEnv": "prod",
"environments": {
"prod": {
"authBaseUrl": "https://portal.zrhsh.com",
"apiBaseUrl": "https://nrp.zrhsh.com",
"clientId": "wukong-cli-prod"
},
"dev": {
"authBaseUrl": "https://portal-dev.zrhsh.com",
"apiBaseUrl": "https://nrp-dev.zrhsh.com",
"clientId": "wukong-cli-dev"
}
}
}Configuration Errors
If your configuration is incomplete, you'll see structured error messages:
[ERROR] Configuration Error
Incomplete configuration for environment 'prod'
Environment: prod
Missing fields: apiBaseUrl, clientId
Edit your wukong-cli.json or run 'wukong-cli init' to resetDocumentation
Getting Started
- 📖 Installation Guide - Detailed installation steps
- 📖 Quick Start - 5-minute quick start guide
- 📖 Configuration - Environment configuration
User Guide
- 📖 Command Reference - Complete command reference
- 📖 Authentication - OAuth Device PKCE Flow details
- 📖 Environments - Multi-environment configuration
- 📖 Troubleshooting - Common issues and solutions
Development
- 📖 Development Setup - Development environment setup
- 📖 Coding Standards - Coding standards and best practices
- 📖 Testing Guide - Testing strategies
- 📖 Contributing - Contribution guide
Architecture
- 📖 Architecture Overview - System architecture documentation
- 📖 Design Patterns - SOLID principles application
- 📖 HTTP Client - HTTP client architecture
Publishing
- 📖 Publishing Guide - Version management and publishing
Project Information
- Version: 0.1.12
- Package: @zrhsh/wukong-cli
- Organization: @zrhsh
- License: MIT
- Node.js: v18+
- TypeScript: 5.x+
Installation
# Global installation from npm
npm install -g @zzhsh/wukong-cli
# Development installation from source
git clone <repository-url>
cd wukong-ts-cli
npm install
npm run build
npm run linkDevelopment
# Clone repository
git clone <repository-url>
cd wukong-ts-cli
# Install dependencies
npm install
# Development mode
npm run dev auth login
# Build
npm run build
# Test
npm run link
wukong-cli --version
# Unit tests
npm test
# E2E tests - Automated (无需用户交互,CI/CD 推荐)
npm run test:e2e:automated # 默认环境自动化测试
npm run test:e2e:automated:dev # 开发环境自动化测试
npm run test:e2e:automated:beta # 测试环境自动化测试
npm run test:e2e:automated:prod # 生产环境自动化测试
# E2E tests - Interactive (需要用户OAuth授权)
npm run test:e2e:interactive # 默认环境交互式测试
npm run test:e2e:interactive:dev # 开发环境交互式测试
npm run test:e2e:interactive:beta # 测试环境交互式测试
npm run test:e2e:interactive:prod # 生产环境交互式测试
npm run test:e2e:interactive:run # 带用户引导的交互式测试Contributing
Contributions are welcome! Please see:
License
MIT License - see LICENSE file for details
Support
- Issues: (GitHub Issues URL)
- Documentation: (in docs/ directory)
- Debug Mode: Use
--debugflag for detailed logs
Version History
See Release Notes for version history and changes.
Current Version: 0.1.12 | Package: @zrhsh/wukong-cli | Organization: @zrhsh
