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

153 lines (152 loc) 5.82 kB
"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 }); exports.listMicrofrontends = listMicrofrontends; const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const chalk_1 = __importDefault(require("chalk")); /** * Lists all microfrontends in the current Re-Shell project * * @param options - Options for listing microfrontends * @version 0.1.0 */ async function listMicrofrontends(options = {}) { const { spinner } = options; try { // Validate we're in a Re-Shell project if (spinner) { spinner.setText('Validating Re-Shell project...'); } // Determine if we're in a Re-Shell project const isInReshellProject = fs.existsSync('package.json') && (fs.existsSync('apps') || fs.existsSync('packages')); if (!isInReshellProject) { if (spinner) { spinner.stop(); } throw new Error('Not in a Re-Shell project. Please run this command from the root of a Re-Shell project.'); } if (spinner) { spinner.setText('Scanning for microfrontends...'); } // Check for apps directory const appsDir = path.resolve(process.cwd(), 'apps'); if (!fs.existsSync(appsDir)) { if (spinner) { spinner.stop(); } throw new Error('Apps directory not found. Is this a valid Re-Shell project?'); } // Get all directories in the apps folder const appDirs = fs .readdirSync(appsDir, { withFileTypes: true }) .filter(dirent => dirent.isDirectory()) .filter(dirent => dirent.name !== 'shell') // Exclude shell application .map(dirent => dirent.name); if (appDirs.length === 0) { if (spinner) { spinner.stop(); } const message = 'No microfrontends found in this project.'; if (options.json) { console.log(JSON.stringify({ microfrontends: [] })); } else { console.log(chalk_1.default.yellow(message)); } return; } if (spinner) { spinner.setText('Loading microfrontend information...'); } // Collect information about each microfrontend const microfrontends = []; for (const appName of appDirs) { const appPath = path.join(appsDir, appName); const packageJsonPath = path.join(appPath, 'package.json'); if (fs.existsSync(packageJsonPath)) { try { const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const info = { name: appName, path: appPath, version: packageJson.version, team: packageJson.author, route: packageJson.reshell?.route || `/${appName}`, }; microfrontends.push(info); } catch (error) { console.error(`Error reading package.json for ${appName}:`, error); } } else { // Include even without package.json microfrontends.push({ name: appName, path: appPath, }); } } if (spinner) { spinner.stop(); } // Output the results if (options.json) { console.log(JSON.stringify({ microfrontends }, null, 2)); } else { console.log(chalk_1.default.cyan(`Found ${microfrontends.length} microfrontends:`)); microfrontends.forEach(mf => { console.log(chalk_1.default.green(`\n- ${mf.name}`)); if (mf.version) console.log(` Version: ${mf.version}`); if (mf.team) console.log(` Team: ${mf.team}`); if (mf.route) console.log(` Route: ${mf.route}`); }); } } catch (error) { if (spinner) { spinner.stop(); } throw error; } }