@macrof/cli
Version:
React MicroFrontend compiler, Typescript, Webpack 5, ModuleFederation
57 lines (56 loc) • 2.33 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const child_process_1 = require("child_process");
const index_1 = require("./index");
class default_1 {
constructor(_a) {
var { configPath = index_1.Constants.DEFAULT_CONFIG_PATH, isShell = false } = _a, configuration = __rest(_a, ["configPath", "isShell"]);
if (isShell) {
this.execJsonFile();
}
this.configs = configuration;
this.currentPath = (0, path_1.resolve)(process.cwd(), configPath);
this.mfConfig = (0, index_1.MFConfig)(this.currentPath);
this.webPackPlugins = new index_1.Plugins(this.currentPath, isShell);
this.init();
}
execJsonFile() {
let execCommand = "mfcli createShellJson";
if ((process.env.REACT_APP_DEV_AS_PROD === "TRUE" &&
process.env.NODE_ENV === "development") ||
process.env.NODE_ENV !== "development") {
execCommand += " prod";
}
(0, child_process_1.execSync)(execCommand, {
stdio: 'inherit',
encoding: 'utf8'
});
}
init() {
var _a, _b;
if (!((_a = this.configs.output) === null || _a === void 0 ? void 0 : _a.path) && this.mfConfig.version) {
const relativePath = this.mfConfig.version ? `dist/${this.mfConfig.version}` : `dist`;
this.configs.output = Object.assign(Object.assign({}, ((_b = this.configs.output) !== null && _b !== void 0 ? _b : {})), { path: (0, path_1.resolve)(__dirname, relativePath) });
}
if (!this.configs.plugins) {
this.configs.plugins = [];
}
this.configs.plugins.push(this.webPackPlugins.plugins());
}
configure() {
return this.configs;
}
}
exports.default = default_1;