UNPKG

@quell/server

Version:

Quell is an open-source NPM package providing a light-weight caching layer implementation and cache invalidation for GraphQL responses on both the client- and server-side. Use Quell to prevent redundant client-side API requests and to minimize costly serv

150 lines (144 loc) 6.08 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const init_1 = require("./commands/init"); /** * Display the CLI banner */ function showBanner() { console.log(chalk_1.default.cyan(` ██████╗ ██╗ ██╗███████╗██╗ ██╗ ██╔═══██╗██║ ██║██╔════╝██║ ██║ ██║ ██║██║ ██║█████╗ ██║ ██║ ██║▄▄ ██║██║ ██║██╔══╝ ██║ ██║ ╚██████╔╝╚██████╔╝███████╗███████╗███████╗ ╚══▀▀═╝ ╚═════╝ ╚══════╝╚══════╝╚══════╝ `)); console.log(chalk_1.default.white('GraphQL Caching for all schema formats\n')); } /** * Display help information */ function displayHelp() { console.log(chalk_1.default.cyan(` Quell CLI - GraphQL Caching Made Easy ${chalk_1.default.bold('USAGE:')} quell <command> [options] ${chalk_1.default.bold('COMMANDS:')} init Initialize Quell in your project help Display this help message version Show version information ${chalk_1.default.bold('INIT OPTIONS:')} -e, --example Create example server and schema files -f, --force Overwrite existing files -t, --typescript Use TypeScript templates (default) -j, --javascript Use JavaScript templates --skip-install Skip automatic dependency installation --redis-host <host> Redis host (default: 127.0.0.1) --redis-port <port> Redis port (default: 6379) ${chalk_1.default.bold('EXAMPLES:')} quell init ${chalk_1.default.gray('# Basic initialization with auto-install')} quell init --example ${chalk_1.default.gray('# Initialize with example files')} quell init --skip-install ${chalk_1.default.gray('# Initialize without installing dependencies')} quell init --force ${chalk_1.default.gray('# Overwrite existing files')} quell init --javascript ${chalk_1.default.gray('# Use JavaScript templates instead of TypeScript')} ${chalk_1.default.bold('MORE INFO:')} Documentation: https://github.com/open-source-labs/Quell Issues: https://github.com/open-source-labs/Quell/issues `)); } /** * Main CLI program setup */ function createProgram() { const program = new commander_1.Command(); program .name('quell') .description('CLI for Quell GraphQL caching') .version('1.0.0') .hook('preAction', () => { // Only show banner for actual commands, not for --help or --version const args = process.argv.slice(2); if (!args.includes('--help') && !args.includes('-h') && !args.includes('--version') && !args.includes('-V')) { showBanner(); } }); // Init command program .command('init') .description('Initialize Quell in your project') .option('-e, --example', 'Create example server and schema files') .option('-f, --force', 'Overwrite existing files') .option('-t, --typescript', 'Use TypeScript templates (default)', true) .option('-j, --javascript', 'Use JavaScript templates') .option('--skip-install', 'Skip automatic dependency installation') .option('--redis-host <host>', 'Redis host', "'127.0.0.1'") .option('--redis-port <port>', 'Redis port', '6379') .action(init_1.initCommand); // Help command program .command('help') .description('Display detailed help information') .action(() => { displayHelp(); }); // Version command program .command('version') .description('Show version information') .action(() => { console.log(chalk_1.default.cyan('Quell CLI v1.0.0')); console.log(chalk_1.default.gray('GraphQL Caching Library')); }); return program; } /** * Handle unhandled promise rejections */ process.on('unhandledRejection', (reason, promise) => { console.error(chalk_1.default.red('❌ Unhandled Rejection at:'), promise, chalk_1.default.red('reason:'), reason); process.exit(1); }); /** * Handle uncaught exceptions */ process.on('uncaughtException', (error) => { console.error(chalk_1.default.red('❌ Uncaught Exception:'), error); process.exit(1); }); /** * Main entry point */ function main() { return __awaiter(this, void 0, void 0, function* () { try { const program = createProgram(); // Parse command line arguments yield program.parseAsync(); // If no command provided, show help if (!process.argv.slice(2).length) { showBanner(); displayHelp(); } } catch (error) { console.error(chalk_1.default.red('❌ CLI Error:'), error instanceof Error ? error.message : String(error)); process.exit(1); } }); } // Run the CLI main();