@lidhium/cli
Version:
micro-frontend cli packed with webpack
76 lines (75 loc) • 3.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateExposedComponents = exports.getConfigFile = exports.updateAppConfig = exports.printLibraryHeader = void 0;
exports.getAppName = getAppName;
const chalk_1 = __importDefault(require("chalk"));
const config_1 = require("../config");
const figlet_1 = __importDefault(require("figlet"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const printLibraryHeader = () => {
console.log(chalk_1.default.yellow(figlet_1.default.textSync("Lidhium", {
horizontalLayout: "full",
font: "Big Money-ne",
whitespaceBreak: true,
})));
};
exports.printLibraryHeader = printLibraryHeader;
const updateAppConfig = ({ port, appType, appName, currentConfig, remotes = {}, exposedComponents = {}, }) => {
const configJsonPath = `./lidhium.config.json`;
const baseURL = process.env.baseURL
? process.env.baseURL
: `http://localhost:${port}`;
const appConfig = {
port,
appType,
remotes,
exposedComponents,
url: baseURL,
};
currentConfig.apps[appName] = appConfig;
fs_1.default.writeFileSync(configJsonPath, JSON.stringify(currentConfig, null, 2));
};
exports.updateAppConfig = updateAppConfig;
const getConfigFile = (configPath, skipLog = false) => {
let fileContent = {};
let isFileExist = false;
isFileExist = fs_1.default.existsSync(configPath || `./lidhium.config.json`);
if (!isFileExist) {
!skipLog &&
console.error(chalk_1.default.red(`lidhium.config.json not found`), chalk_1.default.green(`Run ${chalk_1.default.magenta(`'lidhium init'`)}`));
return;
}
fileContent = fs_1.default.readFileSync(configPath || `./lidhium.config.json`, "utf-8");
return JSON.parse(fileContent);
};
exports.getConfigFile = getConfigFile;
const updateExposedComponents = ({ appName, componentName, componentPath, }) => {
const configJsonPath = `./../../lidhium.config.json`;
const currentConfig = (0, exports.getConfigFile)(configJsonPath, true);
if (!currentConfig) {
console.log(chalk_1.default.red("Please run this command from the app directory"));
console.log(chalk_1.default.green(`For more details visit ${chalk_1.default.magenta(`${config_1.config.docs.webUrl}/docs/getting-started#expose-the-remote-app`)}`));
return;
}
if (!currentConfig.apps[appName]) {
console.error(`App ${appName} not exists`);
console.log(chalk_1.default.green(`For more details visit ${chalk_1.default.magenta(`${config_1.config.docs.webUrl}/docs/getting-started#expose-the-remote-app`)}`));
return;
}
const exposedComponents = currentConfig.apps[appName].exposedComponents;
exposedComponents[componentName] = {
source: componentPath,
remoteComponentValue: `${appName}/${componentName}`,
};
fs_1.default.writeFileSync(configJsonPath, JSON.stringify(currentConfig, null, 2));
};
exports.updateExposedComponents = updateExposedComponents;
function getAppName() {
const currentDir = process.cwd(); // Gets full path
const folderName = path_1.default.basename(currentDir); // Extracts folder name
return folderName;
}