react-mfe-gen
Version:
Generate React micro-frontends, containers, and projects using a simple CLI with runtime integration support.
52 lines (40 loc) • 1.48 kB
JavaScript
import inquirer from "inquirer";
import { PROMPT, INFO_MESSAGE, CHOICE_CONSTANTS } from "../constants.js";
import utils from "../utility.js";
const singleMfeCreation = async (language) => {
// To store different working dir
const workingDirectories = [];
try {
// Get typescript flag
const isTypeScript = language === CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT;
const { mfeName, mfeDescription } = await inquirer.prompt(PROMPT.ONE_MFE);
console.log(`${INFO_MESSAGE.CREATE_APP}${mfeName} as microfront end`);
const mfeInfo = await inquirer.prompt([
PROMPT.CONDITIONAL.MFE_PATH,
...PROMPT.COMMON,
PROMPT.CONDITIONAL.FORM_MANAGEMENT,
]);
// store working dir
const mfepPath = path.join(mfeInfo.mfePath, mfeName);
workingDirectories.push(mfepPath);
// Go inside user specified dir
process.chdir(mfeInfo.mfePath);
// Array to store CRA command
const appCommand = utils.getLanguageTemplate(mfeName, isTypeScript);
// Create container react app
await utils.createReactApp(appCommand);
// Make normal react app into MFE container
await utils.configureMfe(
{ ...mfeInfo, projectName: mfeName, mfeDescription, isTypeScript },
mfeName,
0
);
console.log(
`${INFO_MESSAGE.SUCCESS.ONE_MFE}\n${INFO_MESSAGE.HAPPY_CODING}`
);
} catch (e) {
console.log("Error:", e);
utils.cleanupProject(workingDirectories);
}
};
export default singleMfeCreation;