react-mfe-gen 1.0.2 → 1.0.5

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.
@@ -1,75 +1,75 @@
1
- import inquirer from "inquirer";
2
- import { PROMPT, INFO_MESSAGE, CHOICE_CONSTANTS } from "../constants.js";
3
- import utils from "../utility.js";
4
-
5
- const containerCreation = async (language) => {
6
- // To store different working dir
7
- const wrokingDirectories = [];
8
- try {
9
- // Get typescript flag
10
- const isTypeScript = language === CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT;
11
- // Declare array to store list of mfe names
12
- const mfeNames = [];
13
-
14
- const { containerName, containerDescription, numberOfMfes } =
15
- await inquirer.prompt(PROMPT.CONTAINER);
16
-
17
- // Interate to get each mfe name
18
- for (let i = 0; i < numberOfMfes; i++) {
19
- const { mfeName } = await inquirer.prompt([
20
- {
21
- message: `Enter your name of Microfront end ${i + 1}:`,
22
- type: "input",
23
- name: "mfeName",
24
- validate(value) {
25
- if (!/^[a-z-]+$/.test(value)) {
26
- return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
27
- }
28
- return true;
29
- },
30
- },
31
- ]);
32
- mfeNames.push(mfeName);
33
- }
34
-
35
- console.log(`${INFO_MESSAGE.CREATE_APP}${containerName} as container`);
36
-
37
- // Get container path and app requirements
38
- const commonInfo = await inquirer.prompt([
39
- PROMPT.CONDITIONAL.CONTAINER_PATH,
40
- ...PROMPT.COMMON,
41
- ]);
42
-
43
- // store working dir
44
- wrokingDirectories.push(commonInfo.containerPath);
45
-
46
- // Go inside user specified dir
47
- process.chdir(commonInfo.containerPath);
48
-
49
- // Array to store CRA command
50
- const appCommand = utils.getLanguageTemplate(containerName, isTypeScript);
51
-
52
- // Create container react app
53
- await utils.createReactApp(appCommand);
54
-
55
- // Make normal react app into MFE container
56
- await utils.configureContainer(
57
- {
58
- projectName: containerName,
59
- projectDescription: containerDescription,
60
- ...commonInfo,
61
- isTypeScript,
62
- },
63
- mfeNames
64
- );
65
-
66
- // Let user know container created status
67
- console.log(
68
- `${INFO_MESSAGE.SUCCESS.CONTAINER}\n${INFO_MESSAGE.HAPPY_CODING}`
69
- );
70
- } catch {
71
- utils.cleanupProject(wrokingDirectories);
72
- }
73
- };
74
-
75
- export default containerCreation;
1
+ import inquirer from "inquirer";
2
+ import { PROMPT, INFO_MESSAGE, CHOICE_CONSTANTS } from "../constants.js";
3
+ import utils from "../utility.js";
4
+
5
+ const containerCreation = async (language) => {
6
+ // To store different working dir
7
+ const wrokingDirectories = [];
8
+ try {
9
+ // Get typescript flag
10
+ const isTypeScript = language === CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT;
11
+ // Declare array to store list of mfe names
12
+ const mfeNames = [];
13
+
14
+ const { containerName, containerDescription, numberOfMfes } =
15
+ await inquirer.prompt(PROMPT.CONTAINER);
16
+
17
+ // Interate to get each mfe name
18
+ for (let i = 0; i < numberOfMfes; i++) {
19
+ const { mfeName } = await inquirer.prompt([
20
+ {
21
+ message: `Enter your name of Microfront end ${i + 1}:`,
22
+ type: "input",
23
+ name: "mfeName",
24
+ validate(value) {
25
+ if (!/^[a-z-]+$/.test(value)) {
26
+ return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
27
+ }
28
+ return true;
29
+ },
30
+ },
31
+ ]);
32
+ mfeNames.push(mfeName);
33
+ }
34
+
35
+ console.log(`${INFO_MESSAGE.CREATE_APP}${containerName} as container`);
36
+
37
+ // Get container path and app requirements
38
+ const commonInfo = await inquirer.prompt([
39
+ PROMPT.CONDITIONAL.CONTAINER_PATH,
40
+ ...PROMPT.COMMON,
41
+ ]);
42
+
43
+ // store working dir
44
+ wrokingDirectories.push(commonInfo.containerPath);
45
+
46
+ // Go inside user specified dir
47
+ process.chdir(commonInfo.containerPath);
48
+
49
+ // Array to store CRA command
50
+ const appCommand = utils.getLanguageTemplate(containerName, isTypeScript);
51
+
52
+ // Create container react app
53
+ await utils.createReactApp(appCommand);
54
+
55
+ // Make normal react app into MFE container
56
+ await utils.configureContainer(
57
+ {
58
+ projectName: containerName,
59
+ projectDescription: containerDescription,
60
+ ...commonInfo,
61
+ isTypeScript,
62
+ },
63
+ mfeNames
64
+ );
65
+
66
+ // Let user know container created status
67
+ console.log(
68
+ `${INFO_MESSAGE.SUCCESS.CONTAINER}\n${INFO_MESSAGE.HAPPY_CODING}`
69
+ );
70
+ } catch {
71
+ utils.cleanupProject(wrokingDirectories);
72
+ }
73
+ };
74
+
75
+ export default containerCreation;
package/creation/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import newProjectCreation from "./new-pro-creation.js";
2
- import containerCreation from "./container-creation.js";
3
- import singleMfeCreation from "./single-mfe-creation.js";
4
-
5
- export { newProjectCreation, containerCreation, singleMfeCreation };
1
+ import newProjectCreation from "./new-pro-creation.js";
2
+ import containerCreation from "./container-creation.js";
3
+ import singleMfeCreation from "./single-mfe-creation.js";
4
+
5
+ export { newProjectCreation, containerCreation, singleMfeCreation };
@@ -1,109 +1,109 @@
1
- import inquirer from "inquirer";
2
- import {
3
- PROMPT,
4
- INFO_MESSAGE,
5
- QUESTION,
6
- CHOICE_CONSTANTS,
7
- } from "../constants.js";
8
- import utils from "../utility.js";
9
-
10
- const newProjectCreation = async (language) => {
11
- // To store different working dir
12
- const wrokingDirectories = [];
13
- try {
14
- // Get typescript flag
15
- const isTypeScript = language === 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.prompt(PROMPT.ENTIRE_PROJECT);
20
-
21
- // Interate to get each mfe name
22
- for (let i = 0; i < projectInfo.numberOfMfes; i++) {
23
- const { mfeName } = await inquirer.prompt([
24
- {
25
- message: `Enter your name of Microfront end ${i + 1}:`,
26
- type: "input",
27
- name: "mfeName",
28
- validate(value) {
29
- if (!/^[a-z-]+$/.test(value)) {
30
- return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
31
- }
32
- return true;
33
- },
34
- },
35
- ]);
36
- mfeNames.push(mfeName);
37
- }
38
-
39
- console.log(
40
- `${INFO_MESSAGE.CREATE_APP}${projectInfo.projectName} as container`
41
- );
42
-
43
- // Get container path and app requirements
44
- const commonInfo = await inquirer.prompt([
45
- PROMPT.CONDITIONAL.CONTAINER_PATH,
46
- ...PROMPT.COMMON,
47
- ]);
48
-
49
- // store working dir
50
- wrokingDirectories.push(commonInfo.containerPath);
51
- // Go inside user specified dir
52
- process.chdir(commonInfo.containerPath);
53
-
54
- // Array to store CRA command
55
- const appCommand = utils.getLanguageTemplate(
56
- projectInfo.projectName,
57
- isTypeScript
58
- );
59
-
60
- // Create container react app
61
- await utils.createReactApp(appCommand);
62
-
63
- // Make normal react app into MFE container
64
- await utils.configureContainer(
65
- { ...projectInfo, ...commonInfo, isTypeScript },
66
- mfeNames
67
- );
68
-
69
- // Get mfe requirements for each mfe
70
- for (let i = 0; i < mfeNames.length; i++) {
71
- const mfeName = mfeNames[i];
72
-
73
- console.log(`${INFO_MESSAGE.CREATE_APP}${mfeName}\n`);
74
-
75
- const mfeInfo = await inquirer.prompt([
76
- {
77
- message: `${QUESTION.PATH}${mfeName} as microfront end\ne.g: G:\\workspace\\sample-mfe\n:`,
78
- type: "input",
79
- name: "path",
80
- },
81
- PROMPT.CONDITIONAL.FORM_MANAGEMENT,
82
- ...PROMPT.COMMON,
83
- ]);
84
- // store working dir
85
- wrokingDirectories.push(mfeInfo.path);
86
- // Go inside user specified mfe dir
87
- process.chdir(mfeInfo.path);
88
- const mfeAppCommand = utils.getLanguageTemplate(mfeName, isTypeScript);
89
-
90
- // Create mfe react app
91
- await utils.createReactApp(mfeAppCommand);
92
-
93
- // Make normal react app into MFE container
94
- await utils.configureMfe(
95
- { ...mfeInfo, projectName: projectInfo.projectName, isTypeScript },
96
- mfeName,
97
- i
98
- );
99
- }
100
-
101
- console.log(
102
- `${INFO_MESSAGE.SUCCESS.NEW_PRO}\n${INFO_MESSAGE.HAPPY_CODING}`
103
- );
104
- } catch {
105
- utils.cleanupProject(wrokingDirectories);
106
- }
107
- };
108
-
109
- export default newProjectCreation;
1
+ import inquirer from "inquirer";
2
+ import {
3
+ PROMPT,
4
+ INFO_MESSAGE,
5
+ QUESTION,
6
+ CHOICE_CONSTANTS,
7
+ } from "../constants.js";
8
+ import utils from "../utility.js";
9
+
10
+ const newProjectCreation = async (language) => {
11
+ // To store different working dir
12
+ const wrokingDirectories = [];
13
+ try {
14
+ // Get typescript flag
15
+ const isTypeScript = language === 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.prompt(PROMPT.ENTIRE_PROJECT);
20
+
21
+ // Interate to get each mfe name
22
+ for (let i = 0; i < projectInfo.numberOfMfes; i++) {
23
+ const { mfeName } = await inquirer.prompt([
24
+ {
25
+ message: `Enter your name of Microfront end ${i + 1}:`,
26
+ type: "input",
27
+ name: "mfeName",
28
+ validate(value) {
29
+ if (!/^[a-z-]+$/.test(value)) {
30
+ return "Please use only lowercase letters and '-' (numbers, capital letters, and other symbols are not allowed).";
31
+ }
32
+ return true;
33
+ },
34
+ },
35
+ ]);
36
+ mfeNames.push(mfeName);
37
+ }
38
+
39
+ console.log(
40
+ `${INFO_MESSAGE.CREATE_APP}${projectInfo.projectName} as container`
41
+ );
42
+
43
+ // Get container path and app requirements
44
+ const commonInfo = await inquirer.prompt([
45
+ PROMPT.CONDITIONAL.CONTAINER_PATH,
46
+ ...PROMPT.COMMON,
47
+ ]);
48
+
49
+ // store working dir
50
+ wrokingDirectories.push(commonInfo.containerPath);
51
+ // Go inside user specified dir
52
+ process.chdir(commonInfo.containerPath);
53
+
54
+ // Array to store CRA command
55
+ const appCommand = utils.getLanguageTemplate(
56
+ projectInfo.projectName,
57
+ isTypeScript
58
+ );
59
+
60
+ // Create container react app
61
+ await utils.createReactApp(appCommand);
62
+
63
+ // Make normal react app into MFE container
64
+ await utils.configureContainer(
65
+ { ...projectInfo, ...commonInfo, isTypeScript },
66
+ mfeNames
67
+ );
68
+
69
+ // Get mfe requirements for each mfe
70
+ for (let i = 0; i < mfeNames.length; i++) {
71
+ const mfeName = mfeNames[i];
72
+
73
+ console.log(`${INFO_MESSAGE.CREATE_APP}${mfeName}\n`);
74
+
75
+ const mfeInfo = await inquirer.prompt([
76
+ {
77
+ message: `${QUESTION.PATH}${mfeName} as microfront end\ne.g: G:\\workspace\\sample-mfe\n:`,
78
+ type: "input",
79
+ name: "path",
80
+ },
81
+ PROMPT.CONDITIONAL.FORM_MANAGEMENT,
82
+ ...PROMPT.COMMON,
83
+ ]);
84
+ // store working dir
85
+ wrokingDirectories.push(mfeInfo.path);
86
+ // Go inside user specified mfe dir
87
+ process.chdir(mfeInfo.path);
88
+ const mfeAppCommand = utils.getLanguageTemplate(mfeName, isTypeScript);
89
+
90
+ // Create mfe react app
91
+ await utils.createReactApp(mfeAppCommand);
92
+
93
+ // Make normal react app into MFE container
94
+ await utils.configureMfe(
95
+ { ...mfeInfo, projectName: projectInfo.projectName, isTypeScript },
96
+ mfeName,
97
+ i
98
+ );
99
+ }
100
+
101
+ console.log(
102
+ `${INFO_MESSAGE.SUCCESS.NEW_PRO}\n${INFO_MESSAGE.HAPPY_CODING}`
103
+ );
104
+ } catch {
105
+ utils.cleanupProject(wrokingDirectories);
106
+ }
107
+ };
108
+
109
+ export default newProjectCreation;
@@ -1,49 +1,49 @@
1
- import inquirer from "inquirer";
2
- import { PROMPT, INFO_MESSAGE, CHOICE_CONSTANTS } from "../constants.js";
3
- import utils from "../utility.js";
4
-
5
- const singleMfeCreation = async (language) => {
6
- // To store different working dir
7
- const wrokingDirectories = [];
8
- try {
9
- // Get typescript flag
10
- const isTypeScript = language === CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT;
11
-
12
- const { mfeName, mfeDescription } = await inquirer.prompt(PROMPT.ONE_MFE);
13
-
14
- console.log(`${INFO_MESSAGE.CREATE_APP}${mfeName} as microfront end`);
15
-
16
- const mfeInfo = await inquirer.prompt([
17
- PROMPT.CONDITIONAL.MFE_PATH,
18
- ...PROMPT.COMMON,
19
- PROMPT.CONDITIONAL.FORM_MANAGEMENT,
20
- ]);
21
-
22
- // store working dir
23
- wrokingDirectories.push(mfeInfo.mfePath);
24
-
25
- // Go inside user specified dir
26
- process.chdir(mfeInfo.mfePath);
27
-
28
- // Array to store CRA command
29
- const appCommand = utils.getLanguageTemplate(mfeName, isTypeScript);
30
-
31
- // Create container react app
32
- await utils.createReactApp(appCommand);
33
-
34
- // Make normal react app into MFE container
35
- await utils.configureMfe(
36
- { ...mfeInfo, projectName: mfeName, isTypeScript },
37
- mfeName,
38
- 0
39
- );
40
-
41
- console.log(
42
- `${INFO_MESSAGE.SUCCESS.ONE_MFE}\n${INFO_MESSAGE.HAPPY_CODING}`
43
- );
44
- } catch {
45
- utils.cleanupProject(wrokingDirectories)
46
- }
47
- };
48
-
49
- export default singleMfeCreation;
1
+ import inquirer from "inquirer";
2
+ import { PROMPT, INFO_MESSAGE, CHOICE_CONSTANTS } from "../constants.js";
3
+ import utils from "../utility.js";
4
+
5
+ const singleMfeCreation = async (language) => {
6
+ // To store different working dir
7
+ const wrokingDirectories = [];
8
+ try {
9
+ // Get typescript flag
10
+ const isTypeScript = language === CHOICE_CONSTANTS.LANGUAGE.TYPE_SCRIPT;
11
+
12
+ const { mfeName, mfeDescription } = await inquirer.prompt(PROMPT.ONE_MFE);
13
+
14
+ console.log(`${INFO_MESSAGE.CREATE_APP}${mfeName} as microfront end`);
15
+
16
+ const mfeInfo = await inquirer.prompt([
17
+ PROMPT.CONDITIONAL.MFE_PATH,
18
+ ...PROMPT.COMMON,
19
+ PROMPT.CONDITIONAL.FORM_MANAGEMENT,
20
+ ]);
21
+
22
+ // store working dir
23
+ wrokingDirectories.push(mfeInfo.mfePath);
24
+
25
+ // Go inside user specified dir
26
+ process.chdir(mfeInfo.mfePath);
27
+
28
+ // Array to store CRA command
29
+ const appCommand = utils.getLanguageTemplate(mfeName, isTypeScript);
30
+
31
+ // Create container react app
32
+ await utils.createReactApp(appCommand);
33
+
34
+ // Make normal react app into MFE container
35
+ await utils.configureMfe(
36
+ { ...mfeInfo, projectName: mfeName, isTypeScript },
37
+ mfeName,
38
+ 0
39
+ );
40
+
41
+ console.log(
42
+ `${INFO_MESSAGE.SUCCESS.ONE_MFE}\n${INFO_MESSAGE.HAPPY_CODING}`
43
+ );
44
+ } catch {
45
+ utils.cleanupProject(wrokingDirectories)
46
+ }
47
+ };
48
+
49
+ export default singleMfeCreation;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import mfeGen from './mfe-gen.js';
3
-
2
+ import mfeGen from './mfe-gen.js';
3
+
4
4
  mfeGen();
package/mfe-gen.js CHANGED
@@ -1,22 +1,22 @@
1
- import inquirer from "inquirer";
2
- import { PROMPT, INFO_MESSAGE, CHOICE_CONSTANTS } from "./constants.js";
3
- import {newProjectCreation,containerCreation,singleMfeCreation} from "./creation/index.js";
4
-
5
- const mfeGen = async () => {
6
- console.log(INFO_MESSAGE.DISCLAIMER);
7
-
8
- const { typeOfAction, language } = await inquirer.prompt(PROMPT.USER_NEED);
9
- switch (typeOfAction) {
10
- case CHOICE_CONSTANTS.ACTION.NEW_PROJECT:
11
- newProjectCreation(language);
12
- break;
13
- case CHOICE_CONSTANTS.ACTION.CONTAINER:
14
- containerCreation(language);
15
- break;
16
- case CHOICE_CONSTANTS.ACTION.SINGLE_MFE:
17
- singleMfeCreation(language);
18
- break;
19
- }
20
- };
21
-
22
- export default mfeGen;
1
+ import inquirer from "inquirer";
2
+ import { PROMPT, INFO_MESSAGE, CHOICE_CONSTANTS } from "./constants.js";
3
+ import {newProjectCreation,containerCreation,singleMfeCreation} from "./creation/index.js";
4
+
5
+ const mfeGen = async () => {
6
+ console.log(INFO_MESSAGE.DISCLAIMER);
7
+
8
+ const { typeOfAction, language } = await inquirer.prompt(PROMPT.USER_NEED);
9
+ switch (typeOfAction) {
10
+ case CHOICE_CONSTANTS.ACTION.NEW_PROJECT:
11
+ newProjectCreation(language);
12
+ break;
13
+ case CHOICE_CONSTANTS.ACTION.CONTAINER:
14
+ containerCreation(language);
15
+ break;
16
+ case CHOICE_CONSTANTS.ACTION.SINGLE_MFE:
17
+ singleMfeCreation(language);
18
+ break;
19
+ }
20
+ };
21
+
22
+ export default mfeGen;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-mfe-gen",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "CLI tool for react Microfront end initial setup",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,10 +1,10 @@
1
- export const getAppContent=(containerName='container')=>{
2
- return`import ${containerName} from "./${containerName}";
3
-
4
- function App() {
5
- return <${containerName} />;
6
- }
7
-
8
- export default App;
9
- `
1
+ export const getAppContent=(containerName='container')=>{
2
+ return`import ${containerName} from "./${containerName}";
3
+
4
+ function App() {
5
+ return <${containerName} />;
6
+ }
7
+
8
+ export default App;
9
+ `
10
10
  }
@@ -1,28 +1,28 @@
1
- import utils from "../../utility.js";
2
-
3
- export const getContainerCompContent = (containerCompName, mfes) => {
4
- let containerComp = `import React from "react";\n`;
5
-
6
- for (let i = 0; i < mfes.length; i++) {
7
- containerComp += `import {${utils.toCompName(mfes[i])}} from "./microfrontends/${utils.toCompName(mfes[i])}";\n`;
8
- }
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
-
17
- for (let i = 0; i < mfes.length; i++) {
18
- containerComp += ` <${utils.toCompName(mfes[i]) } name={"${utils.toCompName(mfes[i])}"} host={getMfeOrigin(process.env.REACT_APP_${mfes[i].toUpperCase()})} />\n`;
19
- }
20
-
21
- containerComp += `</div>
22
- );
23
- };
24
-
25
- export default ${containerCompName};`;
26
-
27
- return containerComp;
28
- };
1
+ import utils from "../../utility.js";
2
+
3
+ export const getContainerCompContent = (containerCompName, mfes) => {
4
+ let containerComp = `import React from "react";\n`;
5
+
6
+ for (let i = 0; i < mfes.length; i++) {
7
+ containerComp += `import {${utils.toCompName(mfes[i])}} from "./microfrontends/${utils.toCompName(mfes[i])}";\n`;
8
+ }
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
+
17
+ for (let i = 0; i < mfes.length; i++) {
18
+ containerComp += ` <${utils.toCompName(mfes[i]) } name={"${utils.toCompName(mfes[i])}"} host={getMfeOrigin(process.env.REACT_APP_${mfes[i].toUpperCase()})} />\n`;
19
+ }
20
+
21
+ containerComp += `</div>
22
+ );
23
+ };
24
+
25
+ export default ${containerCompName};`;
26
+
27
+ return containerComp;
28
+ };
@@ -1,8 +1,8 @@
1
- export const getEnvContent = (mfes) => {
2
- let envTemplate = "";
3
-
4
- for (let i = 0; i < mfes.length; i++) {
5
- envTemplate += `REACT_APP_${mfes[i].toUpperCase()} = 900${i}\n`
6
- }
7
- return envTemplate;
1
+ export const getEnvContent = (mfes) => {
2
+ let envTemplate = "";
3
+
4
+ for (let i = 0; i < mfes.length; i++) {
5
+ envTemplate += `REACT_APP_${mfes[i].toUpperCase()} = 900${i}\n`
6
+ }
7
+ return envTemplate;
8
8
  };