@macrof/cli
Version:
React MicroFrontend compiler, Typescript, Webpack 5, ModuleFederation
54 lines (53 loc) • 2.16 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;
};
import { resolve } from 'path';
import { execSync } from 'child_process';
import { Plugins, MFConfig, Constants } from './index';
export default class {
constructor(_a) {
var { configPath = Constants.DEFAULT_CONFIG_PATH, isShell = false } = _a, configuration = __rest(_a, ["configPath", "isShell"]);
if (isShell) {
this.execJsonFile();
}
this.configs = configuration;
this.currentPath = resolve(process.cwd(), configPath);
this.mfConfig = MFConfig(this.currentPath);
this.webPackPlugins = new 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";
}
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: resolve(__dirname, relativePath) });
}
if (!this.configs.plugins) {
this.configs.plugins = [];
}
this.configs.plugins.push(this.webPackPlugins.plugins());
}
configure() {
return this.configs;
}
}