UNPKG

@re-shell/cli

Version:

Full-stack development platform uniting microservices and microfrontends. Build complete applications with .NET (ASP.NET Core Web API, Minimal API), Java (Spring Boot, Quarkus, Micronaut, Vert.x), Rust (Actix-Web, Warp, Rocket, Axum), Python (FastAPI, Dja

200 lines (199 loc) 7.21 kB
"use strict"; /** * Lazy loading system for heavy dependencies */ 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; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.deferredOps = exports.DeferredOperations = exports.compiledCache = exports.lazyModules = void 0; exports.lazy = lazy; exports.preloadCriticalModules = preloadCriticalModules; exports.getLazyModule = getLazyModule; class LazyModuleImpl { constructor(loader) { this.loader = loader; } async load() { if (this._module) { return this._module; } if (!this._promise) { this._promise = this.loader().then(module => { this._module = module; return module; }); } return this._promise; } get() { return this._module; } } /** * Create a lazy-loaded module */ function lazy(loader) { return new LazyModuleImpl(loader); } /** * Common heavy dependencies with lazy loading */ exports.lazyModules = { // UI libraries chalk: lazy(() => Promise.resolve().then(() => __importStar(require('chalk'))).then(m => m.default)), ora: lazy(() => Promise.resolve().then(() => __importStar(require('ora'))).then(m => m.default)), // inquirer: lazy(() => import('inquirer').then(m => m.default).catch(() => null)), // File system utilities globby: lazy(() => Promise.resolve().then(() => __importStar(require('globby'))).then(m => m)), rimraf: lazy(() => Promise.resolve().then(() => __importStar(require('rimraf'))).then(m => m)), fsExtra: lazy(() => Promise.resolve().then(() => __importStar(require('fs-extra'))).then(m => m)), // Development tools chokidar: lazy(() => Promise.resolve().then(() => __importStar(require('chokidar')))), // webpack: lazy(() => import('webpack').catch(() => null)), vite: lazy(() => Promise.resolve().then(() => __importStar(require('vite')))), // Parsing and validation yaml: lazy(() => Promise.resolve().then(() => __importStar(require('js-yaml')))), ajv: lazy(() => Promise.resolve().then(() => __importStar(require('ajv'))).then(m => m.default)), // zod: lazy(() => import('zod').catch(() => null)), // Network and API // axios: lazy(() => import('axios').then(m => m.default).catch(() => null)), // graphqlRequest: lazy(() => import('graphql-request').catch(() => null)), // Template engines handlebars: lazy(() => Promise.resolve().then(() => __importStar(require('handlebars')))), ejs: lazy(() => Promise.resolve().then(() => __importStar(require('ejs')))), // Other utilities lodash: lazy(() => Promise.resolve().then(() => __importStar(require('lodash')))), dayjs: lazy(() => Promise.resolve().then(() => __importStar(require('dayjs'))).then(m => m.default)), semver: lazy(() => Promise.resolve().then(() => __importStar(require('semver')))), // Docker and containerization dockerode: lazy(() => Promise.resolve().then(() => __importStar(require('dockerode'))).then(m => m.default)), // Git operations simpleGit: lazy(() => Promise.resolve().then(() => __importStar(require('simple-git'))).then(m => m.default)), // Terminal UI cliTable3: lazy(() => Promise.resolve().then(() => __importStar(require('cli-table3'))).then(m => m.default)), boxen: lazy(() => Promise.resolve().then(() => __importStar(require('boxen'))).then(m => m.default)), // Configuration cosmiconfig: lazy(() => Promise.resolve().then(() => __importStar(require('cosmiconfig')))), dotenv: lazy(() => Promise.resolve().then(() => __importStar(require('dotenv')))) }; /** * Preload critical modules in background */ async function preloadCriticalModules() { // Preload only the most commonly used modules const criticalModules = [ exports.lazyModules.chalk.load(), exports.lazyModules.ora.load() ]; // Load in background without blocking Promise.all(criticalModules).catch(() => { // Ignore preload errors }); } /** * Get a lazy module with fallback */ async function getLazyModule(module, fallback) { try { return await module.load(); } catch (error) { if (fallback !== undefined) { return fallback; } throw error; } } /** * Cache for compiled templates and schemas */ class CompiledCache { constructor() { this.cache = new Map(); } get(key) { return this.cache.get(key); } set(key, value) { // Limit cache size if (this.cache.size > 100) { const firstKey = this.cache.keys().next().value; this.cache.delete(firstKey); } this.cache.set(key, value); } has(key) { return this.cache.has(key); } clear() { this.cache.clear(); } } exports.compiledCache = new CompiledCache(); /** * Defer expensive operations until after startup */ class DeferredOperations { constructor() { this.operations = []; this.running = false; } add(operation) { this.operations.push(operation); // Start processing after a delay if (!this.running) { setTimeout(() => this.process(), 100); } } async process() { this.running = true; while (this.operations.length > 0) { const op = this.operations.shift(); if (op) { try { await op(); } catch (error) { // Log but don't fail if (process.env.DEBUG === 'true') { console.error('Deferred operation failed:', error); } } } } this.running = false; } } exports.DeferredOperations = DeferredOperations; exports.deferredOps = new DeferredOperations();