react-mfe-gen 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/constants/constants.js +267 -0
  2. package/dist/creation/container-creation.js +67 -0
  3. package/dist/creation/index.js +12 -0
  4. package/dist/creation/new-pro-creation.js +85 -0
  5. package/dist/creation/single-mfe-creation.js +41 -0
  6. package/dist/mfe-gen.js +25 -0
  7. package/dist/templates/container/app-comp-template.js +14 -0
  8. package/dist/templates/container/container-comp-template.js +26 -0
  9. package/dist/templates/container/env-template.js +11 -0
  10. package/dist/templates/container/heart-template.js +64 -0
  11. package/dist/templates/container/index.js +13 -0
  12. package/dist/templates/container/mfe-comp-template.js +12 -0
  13. package/dist/templates/mfe/app-comp-template.js +18 -0
  14. package/dist/templates/mfe/config-overrides-template.js +17 -0
  15. package/dist/templates/mfe/index.js +9 -0
  16. package/dist/templates/mfe/mfe-index-template.js +41 -0
  17. package/dist/types/type.js +2 -0
  18. package/dist/utils/utility.js +161 -0
  19. package/docs/ANSI-COLOR-CODES.md +1 -0
  20. package/package.json +17 -5
  21. package/{constants.js → src/constants/constants.ts} +14 -17
  22. package/{creation/container-creation.js → src/creation/container-creation.ts} +6 -5
  23. package/src/creation/index.ts +5 -0
  24. package/{creation/new-pro-creation.js → src/creation/new-pro-creation.ts} +3 -3
  25. package/{creation/single-mfe-creation.js → src/creation/single-mfe-creation.ts} +4 -3
  26. package/{mfe-gen.js → src/mfe-gen.ts} +3 -3
  27. package/{templates/container/container-comp-template.js → src/templates/container/container-comp-template.ts} +2 -2
  28. package/{templates/container/env-template.js → src/templates/container/env-template.ts} +1 -1
  29. package/{templates/container/mfe-comp-template.js → src/templates/container/mfe-comp-template.ts} +1 -1
  30. package/{templates/mfe/app-comp-template.js → src/templates/mfe/app-comp-template.ts} +1 -1
  31. package/{templates/mfe/mfe-index-template.js → src/templates/mfe/mfe-index-template.ts} +4 -3
  32. package/src/types/type.ts +3 -0
  33. package/{utility.js → src/utils/utility.ts} +28 -19
  34. package/tsconfig.json +14 -0
  35. package/creation/index.js +0 -5
  36. package/index.js +0 -4
  37. /package/{templates/container/app-comp-template.js → src/templates/container/app-comp-template.ts} +0 -0
  38. /package/{templates/container/heart-template.js → src/templates/container/heart-template.ts} +0 -0
  39. /package/{templates/container/index.js → src/templates/container/index.ts} +0 -0
  40. /package/{templates/mfe/config-overrides-template.js → src/templates/mfe/config-overrides-template.ts} +0 -0
  41. /package/{templates/mfe/index.js → src/templates/mfe/index.ts} +0 -0
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_DEV_DEPENDENCIES = exports.DEFAULT_DEPENDENCIES = exports.LIBRARY_PAIR = exports.INFO_MESSAGE = exports.PROMPT = exports.CHOICES = exports.CHOICE_CONSTANTS = exports.QUESTION = void 0;
4
+ exports.QUESTION = {
5
+ ACTION: "Select an action:",
6
+ LANGUAGE: "Choose your preferred language:",
7
+ PROJECT_NAME: "Enter your project name:",
8
+ PROJECT_DESCRIPTION: "Enter your project description:",
9
+ NUMBER_OF_MFES: "How many micro-frontends do you plan to include?",
10
+ MFE_NAME: "Enter your micro-frontend name:\n**Note:** This will be used as a prefix in window functions.\n:",
11
+ MFE_DESCRIPTION: "Enter a description for your micro-frontend:",
12
+ CONTAINER_NAME: "Enter your container app name:\n**Note:** This should be prefix word in your microfrontends window functions.\n:",
13
+ CONTAINER_DESCRIPTION: "Enter a description for your container app:",
14
+ STYLING: "Select a styling solution:",
15
+ STATE_MANAGEMENT: "Select a state management library:",
16
+ FORM_MANAGEMENT: "Select a form management library:",
17
+ CONDITIONAL_MFE_NAME: "Enter your micro-frontend name:",
18
+ CONTAINER_PATH: "Please enter a path to create container:\ne.g:\n for windows os: G:\\workspace\\sample-mfe ,\n for macOS/Linux: /Users/Me/workspace/sample-mfe\n:",
19
+ MFE_PATH: "Please enter a path to create microfront end:\ne.g:\n for windows os: G:\\workspace\\sample-mfe ,\n for macOS/Linux: /Users/Me/workspace/sample-mfe\n:",
20
+ PATH: "Please enter a path to create ",
21
+ };
22
+ exports.CHOICE_CONSTANTS = {
23
+ ACTION: {
24
+ NEW_PROJECT: "Create a new project 🚀",
25
+ CONTAINER: "Create only a container 📦",
26
+ SINGLE_MFE: "Create a single micro-frontend 🌐",
27
+ },
28
+ STYLING: {
29
+ SASS: "Sass 🎨",
30
+ TAILWIND: "Tailwind 🌊",
31
+ MATERIAL_UI: "Material UI 🧩",
32
+ BOOTSTRAP: "Bootstrap 🥾",
33
+ STYLED_COMPONENTS: "Styled Components ✍️",
34
+ },
35
+ LANGUAGE: {
36
+ JAVA_SCRIPT: "JavaScript 🟨",
37
+ TYPE_SCRIPT: "TypeScript 🔷",
38
+ },
39
+ STATE_MANAGEMENT: {
40
+ REDUX: "Redux 🔄",
41
+ ZUSTAND: "Zustand 🐻",
42
+ },
43
+ FORM_MANAGEMENT: {
44
+ REACT_HOOK_FORM: "React-hook-form 🪝",
45
+ FORMIK: "Formik 📝",
46
+ },
47
+ NONE: "None ❌",
48
+ };
49
+ exports.CHOICES = {
50
+ ACTION: [
51
+ exports.CHOICE_CONSTANTS.ACTION.NEW_PROJECT,
52
+ exports.CHOICE_CONSTANTS.ACTION.CONTAINER,
53
+ exports.CHOICE_CONSTANTS.ACTION.SINGLE_MFE,
54
+ ],
55
+ STYLING: [
56
+ exports.CHOICE_CONSTANTS.NONE,
57
+ exports.CHOICE_CONSTANTS.STYLING.SASS,
58
+ exports.CHOICE_CONSTANTS.STYLING.BOOTSTRAP,
59
+ exports.CHOICE_CONSTANTS.STYLING.MATERIAL_UI,
60
+ exports.CHOICE_CONSTANTS.STYLING.TAILWIND,
61
+ exports.CHOICE_CONSTANTS.STYLING.STYLED_COMPONENTS,
62
+ ],
63
+ LANGUAGE: [
64
+ exports.CHOICE_CONSTANTS.LANGUAGE.JAVA_SCRIPT,
65
+ exports.CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT,
66
+ ],
67
+ STATE_MANAGEMENT: [
68
+ exports.CHOICE_CONSTANTS.NONE,
69
+ exports.CHOICE_CONSTANTS.STATE_MANAGEMENT.REDUX,
70
+ exports.CHOICE_CONSTANTS.STATE_MANAGEMENT.ZUSTAND,
71
+ ],
72
+ FORM_MANAGEMENT: [
73
+ exports.CHOICE_CONSTANTS.NONE,
74
+ exports.CHOICE_CONSTANTS.FORM_MANAGEMENT.REACT_HOOK_FORM,
75
+ exports.CHOICE_CONSTANTS.FORM_MANAGEMENT.FORMIK,
76
+ ],
77
+ };
78
+ exports.PROMPT = {
79
+ USER_NEED: [
80
+ {
81
+ message: exports.QUESTION.ACTION,
82
+ type: "list",
83
+ name: "typeOfAction",
84
+ choices: exports.CHOICES.ACTION,
85
+ },
86
+ {
87
+ message: exports.QUESTION.LANGUAGE,
88
+ type: "list",
89
+ name: "language",
90
+ choices: exports.CHOICES.LANGUAGE,
91
+ },
92
+ ],
93
+ ENTIRE_PROJECT: [
94
+ {
95
+ message: exports.QUESTION.PROJECT_NAME,
96
+ type: "input",
97
+ name: "projectName",
98
+ validate(value) {
99
+ if (!/^[a-z-]+$/.test(value)) {
100
+ return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
101
+ }
102
+ return true;
103
+ },
104
+ },
105
+ {
106
+ message: exports.QUESTION.PROJECT_DESCRIPTION,
107
+ type: "input",
108
+ name: "projectDescription",
109
+ },
110
+ {
111
+ type: "input",
112
+ name: "numberOfMfes",
113
+ message: exports.QUESTION.NUMBER_OF_MFES,
114
+ validate(value) {
115
+ const isNumber = !Number.isNaN(Number.parseFloat(value));
116
+ return isNumber || "Please enter a valid number";
117
+ },
118
+ filter: Number,
119
+ },
120
+ ],
121
+ ONE_MFE: [
122
+ {
123
+ message: exports.QUESTION.MFE_NAME,
124
+ type: "input",
125
+ name: "mfeName",
126
+ validate(value) {
127
+ if (!/^[a-z-]+$/.test(value)) {
128
+ return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
129
+ }
130
+ return true;
131
+ },
132
+ },
133
+ {
134
+ message: exports.QUESTION.MFE_DESCRIPTION,
135
+ type: "input",
136
+ name: "mfeDescription",
137
+ },
138
+ ],
139
+ CONTAINER: [
140
+ {
141
+ message: exports.QUESTION.CONTAINER_NAME,
142
+ type: "input",
143
+ name: "containerName",
144
+ validate(value) {
145
+ if (!/^[a-z-]+$/.test(value)) {
146
+ return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
147
+ }
148
+ return true;
149
+ },
150
+ },
151
+ {
152
+ message: exports.QUESTION.CONTAINER_DESCRIPTION,
153
+ type: "input",
154
+ name: "containerDescription",
155
+ },
156
+ {
157
+ type: "input",
158
+ name: "numberOfMfes",
159
+ message: exports.QUESTION.NUMBER_OF_MFES,
160
+ validate(value) {
161
+ const isNumber = !Number.isNaN(Number.parseFloat(value));
162
+ return isNumber || "Please enter a valid number";
163
+ },
164
+ filter: Number,
165
+ },
166
+ ],
167
+ COMMON: [
168
+ {
169
+ message: exports.QUESTION.STYLING,
170
+ type: "list",
171
+ name: "styling",
172
+ choices: exports.CHOICES.STYLING,
173
+ },
174
+ {
175
+ message: exports.QUESTION.STATE_MANAGEMENT,
176
+ type: "list",
177
+ name: "stateManagement",
178
+ choices: exports.CHOICES.STATE_MANAGEMENT,
179
+ },
180
+ ],
181
+ CONDITIONAL: {
182
+ MICROFRONT_END_NAME: {
183
+ message: exports.QUESTION.CONDITIONAL_MFE_NAME,
184
+ type: "input",
185
+ name: "mfeName",
186
+ validate(value) {
187
+ if (!/^[a-z-]+$/.test(value)) {
188
+ return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
189
+ }
190
+ return true;
191
+ },
192
+ },
193
+ CONTAINER_PATH: {
194
+ message: exports.QUESTION.CONTAINER_PATH,
195
+ type: "input",
196
+ name: "containerPath",
197
+ },
198
+ MFE_PATH: {
199
+ message: exports.QUESTION.MFE_PATH,
200
+ type: "input",
201
+ name: "mfePath",
202
+ },
203
+ PATH: {
204
+ message: exports.QUESTION.PATH,
205
+ type: "input",
206
+ name: "path",
207
+ },
208
+ FORM_MANAGEMENT: {
209
+ message: exports.QUESTION.FORM_MANAGEMENT,
210
+ type: "list",
211
+ name: "formManagement",
212
+ choices: exports.CHOICES.FORM_MANAGEMENT,
213
+ },
214
+ },
215
+ };
216
+ exports.INFO_MESSAGE = {
217
+ DISCLAIMER: "Hello there! 👋\n\nThis tool currently supports micro-frontend creation using runtime integration via custom script injection ⚙️.\nPlease keep this limitation in mind when developing your MFE applications 📌.\n",
218
+ CREATE_APP: "Let's create ",
219
+ CONFIGURE_CONTAINER: "Configuring the container... 🛠️",
220
+ APP_CREATION: "Creating your React app... ⚛️ ",
221
+ i_DEPENDENCIES: "Installing dependencies... 📦 ",
222
+ i_DEV_DEPENDENCIES: "Installing dev dependencies... 🧩 ",
223
+ SUCCESS: {
224
+ NEW_PRO: "New project created successfully! 🎉",
225
+ CONTAINER: "Container created successfully! 📦",
226
+ ONE_MFE: "Microfront end created successfully! 🌐",
227
+ },
228
+ HAPPY_CODING: "Happy coding! 💻✨",
229
+ };
230
+ exports.LIBRARY_PAIR = {
231
+ STYLING: {
232
+ [exports.CHOICE_CONSTANTS.STYLING.TAILWIND]: [
233
+ "tailwindcss",
234
+ "postcss",
235
+ "autoprefixer",
236
+ ],
237
+ [exports.CHOICE_CONSTANTS.STYLING.SASS]: ["sass"],
238
+ [exports.CHOICE_CONSTANTS.STYLING.MATERIAL_UI]: [
239
+ "@mui/material",
240
+ "@emotion/react",
241
+ "@emotion/styled",
242
+ "@mui/icons-material",
243
+ ],
244
+ [exports.CHOICE_CONSTANTS.STYLING.BOOTSTRAP]: ["bootstrap"],
245
+ [exports.CHOICE_CONSTANTS.STYLING.STYLED_COMPONENTS]: ["styled-components"],
246
+ [exports.CHOICE_CONSTANTS.NONE]: [],
247
+ },
248
+ STATE_MANAGEMENT: {
249
+ [exports.CHOICE_CONSTANTS.NONE]: [],
250
+ [exports.CHOICE_CONSTANTS.STATE_MANAGEMENT.REDUX]: [
251
+ "@reduxjs/toolkit",
252
+ "react-redux",
253
+ ],
254
+ [exports.CHOICE_CONSTANTS.STATE_MANAGEMENT.ZUSTAND]: ["zustand"],
255
+ },
256
+ FORM_MANAGEMENT: {
257
+ [exports.CHOICE_CONSTANTS.NONE]: [],
258
+ [exports.CHOICE_CONSTANTS.FORM_MANAGEMENT.REACT_HOOK_FORM]: [
259
+ "react-hook-form",
260
+ "@hookform/resolvers",
261
+ "yup",
262
+ ],
263
+ [exports.CHOICE_CONSTANTS.FORM_MANAGEMENT.FORMIK]: ["formik", "yup"],
264
+ },
265
+ };
266
+ exports.DEFAULT_DEPENDENCIES = ["axios", "react-router-dom"];
267
+ exports.DEFAULT_DEV_DEPENDENCIES = ["cross-env", "react-app-rewired"];
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const inquirer_1 = __importDefault(require("inquirer"));
7
+ const constants_1 = require("../constants/constants");
8
+ const utility_1 = require("../utils/utility");
9
+ const path_1 = __importDefault(require("path"));
10
+ const containerCreation = async (language) => {
11
+ // To store different working dir
12
+ const workingDirectories = [];
13
+ try {
14
+ // Get typescript flag
15
+ const isTypeScript = language === constants_1.CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT;
16
+ // Declare array to store list of mfe names
17
+ const mfeNames = [];
18
+ const { containerName, containerDescription, numberOfMfes } = await inquirer_1.default.prompt(constants_1.PROMPT.CONTAINER);
19
+ // Interate to get each mfe name
20
+ for (let i = 0; i < numberOfMfes; i++) {
21
+ const { mfeName } = await inquirer_1.default.prompt([
22
+ {
23
+ message: `Enter your name of Microfront end ${i + 1}:`,
24
+ type: "input",
25
+ name: "mfeName",
26
+ validate(value) {
27
+ if (!/^[a-z-]+$/.test(value)) {
28
+ return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
29
+ }
30
+ return true;
31
+ },
32
+ },
33
+ ]);
34
+ mfeNames.push(mfeName);
35
+ }
36
+ console.log(`${constants_1.INFO_MESSAGE.CREATE_APP}${containerName} as container`);
37
+ // Get container path and app requirements
38
+ const commonInfo = await inquirer_1.default.prompt([
39
+ constants_1.PROMPT.CONDITIONAL.CONTAINER_PATH,
40
+ ...constants_1.PROMPT.COMMON,
41
+ ]);
42
+ // store working dir
43
+ // store working dir
44
+ const containerFullPath = path_1.default.join(commonInfo.containerPath, containerName);
45
+ workingDirectories.push(containerFullPath);
46
+ // Go inside user specified dir
47
+ process.chdir(commonInfo.containerPath);
48
+ // Array to store CRA command
49
+ const appCommand = utility_1.utils.getLanguageTemplate(containerName, isTypeScript);
50
+ // Create container react app
51
+ await utility_1.utils.createReactApp(appCommand);
52
+ // Make normal react app into MFE container
53
+ await utility_1.utils.configureContainer({
54
+ projectName: containerName,
55
+ projectDescription: containerDescription,
56
+ ...commonInfo,
57
+ isTypeScript,
58
+ }, mfeNames);
59
+ // Let user know container created status
60
+ utility_1.mfeGenLogger.successLog(`${constants_1.INFO_MESSAGE.SUCCESS.CONTAINER}\n${constants_1.INFO_MESSAGE.HAPPY_CODING}`);
61
+ }
62
+ catch (e) {
63
+ utility_1.mfeGenLogger.ErrorLog(`Error: ${e}`);
64
+ utility_1.utils.cleanupProject(workingDirectories);
65
+ }
66
+ };
67
+ exports.default = containerCreation;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.singleMfeCreation = exports.containerCreation = exports.newProjectCreation = void 0;
7
+ const new_pro_creation_1 = __importDefault(require("./new-pro-creation"));
8
+ exports.newProjectCreation = new_pro_creation_1.default;
9
+ const container_creation_1 = __importDefault(require("./container-creation"));
10
+ exports.containerCreation = container_creation_1.default;
11
+ const single_mfe_creation_1 = __importDefault(require("./single-mfe-creation"));
12
+ exports.singleMfeCreation = single_mfe_creation_1.default;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const inquirer_1 = __importDefault(require("inquirer"));
8
+ const constants_1 = require("../constants/constants");
9
+ const utility_1 = require("../utils/utility");
10
+ const newProjectCreation = async (language) => {
11
+ // To store different working dir
12
+ const workingDirectories = [];
13
+ try {
14
+ // Get typescript flag
15
+ const isTypeScript = language === constants_1.CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT;
16
+ // Declare array to store list of mfe names
17
+ const mfeNames = [];
18
+ // Get basic project info
19
+ const projectInfo = await inquirer_1.default.prompt(constants_1.PROMPT.ENTIRE_PROJECT);
20
+ // Interate to get each mfe name
21
+ for (let i = 0; i < projectInfo.numberOfMfes; i++) {
22
+ const { mfeName } = await inquirer_1.default.prompt([
23
+ {
24
+ message: `Enter your name of Microfront end ${i + 1}:`,
25
+ type: "input",
26
+ name: "mfeName",
27
+ validate(value) {
28
+ if (!/^[a-z-]+$/.test(value)) {
29
+ return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
30
+ }
31
+ return true;
32
+ },
33
+ },
34
+ ]);
35
+ mfeNames.push(mfeName);
36
+ }
37
+ console.log(`${constants_1.INFO_MESSAGE.CREATE_APP}${projectInfo.projectName} as container`);
38
+ // Get container path and app requirements
39
+ const commonInfo = await inquirer_1.default.prompt([
40
+ constants_1.PROMPT.CONDITIONAL.CONTAINER_PATH,
41
+ ...constants_1.PROMPT.COMMON,
42
+ ]);
43
+ // store working dir
44
+ const containerFullPath = path_1.default.join(commonInfo.containerPath, projectInfo.projectName);
45
+ workingDirectories.push(containerFullPath);
46
+ // Go inside user specified dir
47
+ process.chdir(commonInfo.containerPath);
48
+ // Array to store CRA command
49
+ const appCommand = utility_1.utils.getLanguageTemplate(projectInfo.projectName, isTypeScript);
50
+ // Create container react app
51
+ await utility_1.utils.createReactApp(appCommand);
52
+ // Make normal react app into MFE container
53
+ await utility_1.utils.configureContainer({ ...projectInfo, ...commonInfo, isTypeScript }, mfeNames);
54
+ // Get mfe requirements for each mfe
55
+ for (let i = 0; i < mfeNames.length; i++) {
56
+ const mfeName = mfeNames[i];
57
+ console.log(`${constants_1.INFO_MESSAGE.CREATE_APP}${mfeName}\n`);
58
+ const mfeInfo = await inquirer_1.default.prompt([
59
+ {
60
+ message: `${constants_1.QUESTION.PATH}${mfeName} as microfront end\ne.g:\n for windows os: G:/workspace/sample-mfe ,\n for macOS/Linux: /Users/Me/workspace/sample-mfe\n:`,
61
+ type: "input",
62
+ name: "path",
63
+ },
64
+ constants_1.PROMPT.CONDITIONAL.FORM_MANAGEMENT,
65
+ ...constants_1.PROMPT.COMMON,
66
+ ]);
67
+ // store working dir
68
+ const mfeFullPath = path_1.default.join(mfeInfo.path, mfeName);
69
+ workingDirectories.push(mfeFullPath);
70
+ // Go inside user specified mfe dir
71
+ process.chdir(mfeInfo.path);
72
+ const mfeAppCommand = utility_1.utils.getLanguageTemplate(mfeName, isTypeScript);
73
+ // Create mfe react app
74
+ await utility_1.utils.createReactApp(mfeAppCommand);
75
+ // Make normal react app into MFE container
76
+ await utility_1.utils.configureMfe({ ...mfeInfo, projectName: projectInfo.projectName, isTypeScript }, mfeName, i);
77
+ }
78
+ utility_1.mfeGenLogger.successLog(`${constants_1.INFO_MESSAGE.SUCCESS.NEW_PRO}\n${constants_1.INFO_MESSAGE.HAPPY_CODING}`);
79
+ }
80
+ catch (e) {
81
+ utility_1.mfeGenLogger.ErrorLog(`Error: ${e}`);
82
+ utility_1.utils.cleanupProject(workingDirectories);
83
+ }
84
+ };
85
+ exports.default = newProjectCreation;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const inquirer_1 = __importDefault(require("inquirer"));
7
+ const constants_1 = require("../constants/constants");
8
+ const utility_1 = require("../utils/utility");
9
+ const path_1 = __importDefault(require("path"));
10
+ const singleMfeCreation = async (language) => {
11
+ // To store different working dir
12
+ const workingDirectories = [];
13
+ try {
14
+ // Get typescript flag
15
+ const isTypeScript = language === constants_1.CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT;
16
+ const { mfeName, mfeDescription } = await inquirer_1.default.prompt(constants_1.PROMPT.ONE_MFE);
17
+ console.log(`${constants_1.INFO_MESSAGE.CREATE_APP}${mfeName} as microfront end`);
18
+ const mfeInfo = await inquirer_1.default.prompt([
19
+ constants_1.PROMPT.CONDITIONAL.MFE_PATH,
20
+ ...constants_1.PROMPT.COMMON,
21
+ constants_1.PROMPT.CONDITIONAL.FORM_MANAGEMENT,
22
+ ]);
23
+ // store working dir
24
+ const mfepPath = path_1.default.join(mfeInfo.mfePath, mfeName);
25
+ workingDirectories.push(mfepPath);
26
+ // Go inside user specified dir
27
+ process.chdir(mfeInfo.mfePath);
28
+ // Array to store CRA command
29
+ const appCommand = utility_1.utils.getLanguageTemplate(mfeName, isTypeScript);
30
+ // Create container react app
31
+ await utility_1.utils.createReactApp(appCommand);
32
+ // Make normal react app into MFE container
33
+ await utility_1.utils.configureMfe({ ...mfeInfo, projectName: mfeName, mfeDescription, isTypeScript }, mfeName, 0);
34
+ utility_1.mfeGenLogger.successLog(`${constants_1.INFO_MESSAGE.SUCCESS.ONE_MFE}\n${constants_1.INFO_MESSAGE.HAPPY_CODING}`);
35
+ }
36
+ catch (e) {
37
+ utility_1.mfeGenLogger.ErrorLog(`Error: ${e}`);
38
+ utility_1.utils.cleanupProject(workingDirectories);
39
+ }
40
+ };
41
+ exports.default = singleMfeCreation;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const inquirer_1 = __importDefault(require("inquirer"));
7
+ const constants_1 = require("./constants/constants");
8
+ const index_js_1 = require("./creation/index.js");
9
+ const utility_1 = require("./utils/utility");
10
+ const mfeGen = async () => {
11
+ utility_1.mfeGenLogger.notifyLog(constants_1.INFO_MESSAGE.DISCLAIMER);
12
+ const { typeOfAction, language } = await inquirer_1.default.prompt(constants_1.PROMPT.USER_NEED);
13
+ switch (typeOfAction) {
14
+ case constants_1.CHOICE_CONSTANTS.ACTION.NEW_PROJECT:
15
+ (0, index_js_1.newProjectCreation)(language);
16
+ break;
17
+ case constants_1.CHOICE_CONSTANTS.ACTION.CONTAINER:
18
+ (0, index_js_1.containerCreation)(language);
19
+ break;
20
+ case constants_1.CHOICE_CONSTANTS.ACTION.SINGLE_MFE:
21
+ (0, index_js_1.singleMfeCreation)(language);
22
+ break;
23
+ }
24
+ };
25
+ mfeGen();
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAppContent = void 0;
4
+ const getAppContent = (containerName = 'container') => {
5
+ return `import ${containerName} from "./${containerName}";
6
+
7
+ function App() {
8
+ return <${containerName} />;
9
+ }
10
+
11
+ export default App;
12
+ `;
13
+ };
14
+ exports.getAppContent = getAppContent;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContainerCompContent = void 0;
4
+ const utility_1 = require("../../utils/utility");
5
+ const getContainerCompContent = (containerCompName, mfes) => {
6
+ let containerComp = `import React from "react";\n`;
7
+ for (let i = 0; i < mfes.length; i++) {
8
+ containerComp += `import {${utility_1.utils.toCompName(mfes[i])}} from "./microfrontends/${utility_1.utils.toCompName(mfes[i])}";\n`;
9
+ }
10
+ containerComp += `\n\nfunction ${containerCompName}() {
11
+ const getMfeOrigin =(port:string|undefined='')=> \`\${window.location.protocol}//\${window.location.hostname}:\${port}\`;
12
+
13
+ return (
14
+ <div>
15
+ <h1>Hello from ${containerCompName}</h1>\n`;
16
+ for (let i = 0; i < mfes.length; i++) {
17
+ containerComp += ` <${utility_1.utils.toCompName(mfes[i])} name={"${utility_1.utils.toCompName(mfes[i])}"} host={getMfeOrigin(process.env.REACT_APP_${mfes[i].toUpperCase()})} />\n`;
18
+ }
19
+ containerComp += `</div>
20
+ );
21
+ };
22
+
23
+ export default ${containerCompName};`;
24
+ return containerComp;
25
+ };
26
+ exports.getContainerCompContent = getContainerCompContent;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEnvContent = void 0;
4
+ const getEnvContent = (mfes) => {
5
+ let envTemplate = "";
6
+ for (let i = 0; i < mfes.length; i++) {
7
+ envTemplate += `REACT_APP_${mfes[i].toUpperCase()} = 900${i}\n`;
8
+ }
9
+ return envTemplate;
10
+ };
11
+ exports.getEnvContent = getEnvContent;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHeartContent = void 0;
4
+ const getHeartContent = (containerName = 'container') => {
5
+ return `
6
+ import React from "react";
7
+
8
+ class MicroFrontend extends React.Component {
9
+ componentDidMount() {
10
+ const { name, host, document } = this.props;
11
+ const scriptId = \`micro-frontend-script-\${name}\`;
12
+
13
+ if (document.getElementById(scriptId)) {
14
+ this.renderMicroFrontend();
15
+ return;
16
+ }
17
+
18
+ fetch(\`\${host}/asset-manifest.json\`)
19
+ .then((res) => res.json())
20
+ .then((manifest) => {
21
+ const script = document.createElement("script");
22
+ script.id = scriptId;
23
+ script.crossOrigin = "";
24
+ script.src = \`\${host}\${manifest["files"]["main.js"]}\`;
25
+ script.onload = this.renderMicroFrontend;
26
+ document.head.appendChild(script);
27
+ const link = document.createElement("link");
28
+ link.id = scriptId;
29
+ link.href = \`\${host}\${manifest["files"]["main.css"]}\`;
30
+ link.onload = this.renderMicroFrontend;
31
+ link.rel = "stylesheet";
32
+ document.head.appendChild(link);
33
+ });
34
+ }
35
+
36
+ componentWillUnmount() {
37
+ const { name, window } = this.props;
38
+
39
+ window[\`unmount\${name}\`] && window[\`unmount\${name}\`](
40
+ \`\${name}-${containerName}\`
41
+ );
42
+ }
43
+
44
+ renderMicroFrontend = () => {
45
+ const { name, window, history } = this.props;
46
+
47
+ window[\`render\${name}\`] &&
48
+ window[\`render\${name}\`](\`\${name}-${containerName}\`, history);
49
+ };
50
+
51
+ render() {
52
+ return <main id={\`\${this.props.name}-${containerName}\`} />;
53
+ }
54
+ }
55
+
56
+ MicroFrontend.defaultProps = {
57
+ document,
58
+ window,
59
+ };
60
+
61
+ export default MicroFrontend;
62
+ `;
63
+ };
64
+ exports.getHeartContent = getHeartContent;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMfeCompContent = exports.getHeartContent = exports.getEnvContent = exports.getContainerCompContent = exports.getAppContent = void 0;
4
+ const app_comp_template_js_1 = require("./app-comp-template.js");
5
+ Object.defineProperty(exports, "getAppContent", { enumerable: true, get: function () { return app_comp_template_js_1.getAppContent; } });
6
+ const container_comp_template_js_1 = require("./container-comp-template.js");
7
+ Object.defineProperty(exports, "getContainerCompContent", { enumerable: true, get: function () { return container_comp_template_js_1.getContainerCompContent; } });
8
+ const env_template_js_1 = require("./env-template.js");
9
+ Object.defineProperty(exports, "getEnvContent", { enumerable: true, get: function () { return env_template_js_1.getEnvContent; } });
10
+ const heart_template_js_1 = require("./heart-template.js");
11
+ Object.defineProperty(exports, "getHeartContent", { enumerable: true, get: function () { return heart_template_js_1.getHeartContent; } });
12
+ const mfe_comp_template_js_1 = require("./mfe-comp-template.js");
13
+ Object.defineProperty(exports, "getMfeCompContent", { enumerable: true, get: function () { return mfe_comp_template_js_1.getMfeCompContent; } });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMfeCompContent = void 0;
4
+ const getMfeCompContent = (mfeName, isTypeScript) => {
5
+ return `import MicroFrontend from "../MicroFrontend";
6
+
7
+ export const ${mfeName} = (props${isTypeScript ? ": any" : ""}) => {
8
+ return <MicroFrontend name={props.name} host={props.host} />;
9
+ };
10
+ `;
11
+ };
12
+ exports.getMfeCompContent = getMfeCompContent;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMfeAppContent = void 0;
4
+ const getMfeAppContent = (mfeName = 'mfe', isTs) => {
5
+ return `import React from 'react';
6
+
7
+ function App(prop${isTs ? ": any" : ""}) {
8
+ return (
9
+ <div>
10
+ <h1>Hello from ${mfeName}</h1>
11
+ </div>
12
+ );
13
+ }
14
+
15
+ export default App;
16
+ `;
17
+ };
18
+ exports.getMfeAppContent = getMfeAppContent;