@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
114 lines (113 loc) • 4.85 kB
JavaScript
;
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.removeMicrofrontend = removeMicrofrontend;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const prompts_1 = __importDefault(require("prompts"));
const chalk_1 = __importDefault(require("chalk"));
const spinner_1 = require("../utils/spinner");
/**
* Removes a microfrontend from a Re-Shell project
*
* @param name - Name of the microfrontend to remove
* @param options - Additional options for removal
* @version 0.1.0
*/
async function removeMicrofrontend(name, options) {
const { force, spinner } = options;
// Normalize name to kebab-case for consistency
const normalizedName = name.toLowerCase().replace(/\s+/g, '-');
console.log(chalk_1.default.cyan(`Removing microfrontend "${normalizedName}"...`));
// Determine if we're in a Re-Shell project
const isInReshellProject = fs.existsSync('package.json') && (fs.existsSync('apps') || fs.existsSync('packages'));
if (!isInReshellProject) {
throw new Error('Not in a Re-Shell project. Please run this command from the root of a Re-Shell project.');
}
// Check if the microfrontend exists
const mfPath = path.resolve(process.cwd(), 'apps', normalizedName);
if (!fs.existsSync(mfPath)) {
throw new Error(`Microfrontend "${normalizedName}" not found in apps directory.`);
}
// Stop spinner for interactive prompts
if (spinner) {
spinner.stop();
}
// Confirm deletion unless --force flag is used
if (!force) {
const confirmation = await (0, prompts_1.default)({
type: 'confirm',
name: 'confirm',
message: `Are you sure you want to remove the microfrontend "${normalizedName}"? This cannot be undone.`,
initial: false,
});
if (!confirmation.confirm) {
console.log(chalk_1.default.yellow('Operation cancelled.'));
return;
}
}
// Restart spinner for file operations
if (spinner) {
spinner.start();
spinner.setText('Checking for dependencies...');
(0, spinner_1.flushOutput)();
}
// Check if the microfrontend is referenced in shell application
const shellAppPath = path.resolve(process.cwd(), 'apps', 'shell');
if (fs.existsSync(shellAppPath)) {
const shellAppFiles = [
path.join(shellAppPath, 'src', 'App.tsx'),
path.join(shellAppPath, 'src', 'App.jsx'),
path.join(shellAppPath, 'src', 'config.ts'),
path.join(shellAppPath, 'src', 'config.js'),
];
for (const file of shellAppFiles) {
if (fs.existsSync(file)) {
const content = fs.readFileSync(file, 'utf8');
if (content.includes(normalizedName)) {
console.log(chalk_1.default.yellow(`Warning: The microfrontend "${normalizedName}" appears to be referenced in ${file}.`));
console.log(chalk_1.default.yellow(`You should manually remove references to it to prevent errors.`));
break;
}
}
}
}
// Remove the microfrontend directory
fs.removeSync(mfPath);
console.log(chalk_1.default.green(`Successfully removed microfrontend "${normalizedName}".`));
}