react-mfe-gen 1.2.5 → 1.2.9

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 (34) hide show
  1. package/.github/PULL_REQUEST_TEMPLATE.md +8 -8
  2. package/.github/workflows/npm-publish.yml +23 -54
  3. package/README.md +34 -36
  4. package/dist/constants/constants.js +24 -24
  5. package/dist/templates/container/app-comp-template.js +7 -7
  6. package/dist/templates/container/container-comp-template.js +9 -9
  7. package/dist/templates/container/heart-template.js +57 -57
  8. package/dist/templates/container/mfe-comp-template.js +5 -5
  9. package/dist/templates/mfe/app-comp-template.js +11 -11
  10. package/dist/templates/mfe/config-overrides-template.js +10 -10
  11. package/dist/templates/mfe/mfe-index-template.js +34 -34
  12. package/dist/utils/utility.js +1 -1
  13. package/docs/ANSI-COLOR-CODES.md +14 -14
  14. package/package.json +58 -58
  15. package/src/constants/constants.ts +277 -277
  16. package/src/creation/container-creation.ts +82 -82
  17. package/src/creation/index.ts +5 -5
  18. package/src/creation/new-pro-creation.ts +114 -114
  19. package/src/creation/single-mfe-creation.ts +52 -52
  20. package/src/mfe-gen.ts +28 -28
  21. package/src/templates/container/app-comp-template.ts +9 -9
  22. package/src/templates/container/container-comp-template.ts +36 -36
  23. package/src/templates/container/env-template.ts +7 -7
  24. package/src/templates/container/heart-template.ts +59 -59
  25. package/src/templates/container/index.ts +17 -17
  26. package/src/templates/container/mfe-comp-template.ts +8 -8
  27. package/src/templates/mfe/app-comp-template.ts +13 -13
  28. package/src/templates/mfe/config-overrides-template.ts +12 -12
  29. package/src/templates/mfe/index.ts +8 -8
  30. package/src/templates/mfe/mfe-index-template.ts +36 -36
  31. package/src/types/type.ts +3 -3
  32. package/src/utils/utility.ts +248 -248
  33. package/tsconfig.json +15 -15
  34. package/images/react-mfe-gen-package.png +0 -0
@@ -1,8 +1,8 @@
1
- export const getEnvContent = (mfes:string[]) => {
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:string[]) => {
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
  };
@@ -1,60 +1,60 @@
1
- export const getHeartContent=(containerName='container')=>{
2
- return `
3
- import React from "react";
4
-
5
- class MicroFrontend extends React.Component {
6
- componentDidMount() {
7
- const { name, host, document } = this.props;
8
- const scriptId = \`micro-frontend-script-\${name}\`;
9
-
10
- if (document.getElementById(scriptId)) {
11
- this.renderMicroFrontend();
12
- return;
13
- }
14
-
15
- fetch(\`\${host}/asset-manifest.json\`)
16
- .then((res) => res.json())
17
- .then((manifest) => {
18
- const script = document.createElement("script");
19
- script.id = scriptId;
20
- script.crossOrigin = "";
21
- script.src = \`\${host}\${manifest["files"]["main.js"]}\`;
22
- script.onload = this.renderMicroFrontend;
23
- document.head.appendChild(script);
24
- const link = document.createElement("link");
25
- link.id = scriptId;
26
- link.href = \`\${host}\${manifest["files"]["main.css"]}\`;
27
- link.onload = this.renderMicroFrontend;
28
- link.rel = "stylesheet";
29
- document.head.appendChild(link);
30
- });
31
- }
32
-
33
- componentWillUnmount() {
34
- const { name, window } = this.props;
35
-
36
- window[\`unmount\${name}\`] && window[\`unmount\${name}\`](
37
- \`\${name}-${containerName}\`
38
- );
39
- }
40
-
41
- renderMicroFrontend = () => {
42
- const { name, window, history } = this.props;
43
-
44
- window[\`render\${name}\`] &&
45
- window[\`render\${name}\`](\`\${name}-${containerName}\`, history);
46
- };
47
-
48
- render() {
49
- return <main id={\`\${this.props.name}-${containerName}\`} />;
50
- }
51
- }
52
-
53
- MicroFrontend.defaultProps = {
54
- document,
55
- window,
56
- };
57
-
58
- export default MicroFrontend;
59
- `
1
+ export const getHeartContent=(containerName='container')=>{
2
+ return `
3
+ import React from "react";
4
+
5
+ class MicroFrontend extends React.Component {
6
+ componentDidMount() {
7
+ const { name, host, document } = this.props;
8
+ const scriptId = \`micro-frontend-script-\${name}\`;
9
+
10
+ if (document.getElementById(scriptId)) {
11
+ this.renderMicroFrontend();
12
+ return;
13
+ }
14
+
15
+ fetch(\`\${host}/asset-manifest.json\`)
16
+ .then((res) => res.json())
17
+ .then((manifest) => {
18
+ const script = document.createElement("script");
19
+ script.id = scriptId;
20
+ script.crossOrigin = "";
21
+ script.src = \`\${host}\${manifest["files"]["main.js"]}\`;
22
+ script.onload = this.renderMicroFrontend;
23
+ document.head.appendChild(script);
24
+ const link = document.createElement("link");
25
+ link.id = scriptId;
26
+ link.href = \`\${host}\${manifest["files"]["main.css"]}\`;
27
+ link.onload = this.renderMicroFrontend;
28
+ link.rel = "stylesheet";
29
+ document.head.appendChild(link);
30
+ });
31
+ }
32
+
33
+ componentWillUnmount() {
34
+ const { name, window } = this.props;
35
+
36
+ window[\`unmount\${name}\`] && window[\`unmount\${name}\`](
37
+ \`\${name}-${containerName}\`
38
+ );
39
+ }
40
+
41
+ renderMicroFrontend = () => {
42
+ const { name, window, history } = this.props;
43
+
44
+ window[\`render\${name}\`] &&
45
+ window[\`render\${name}\`](\`\${name}-${containerName}\`, history);
46
+ };
47
+
48
+ render() {
49
+ return <main id={\`\${this.props.name}-${containerName}\`} />;
50
+ }
51
+ }
52
+
53
+ MicroFrontend.defaultProps = {
54
+ document,
55
+ window,
56
+ };
57
+
58
+ export default MicroFrontend;
59
+ `
60
60
  }
@@ -1,17 +1,17 @@
1
- import { getAppContent } from "./app-comp-template.js";
2
-
3
- import { getContainerCompContent } from "./container-comp-template.js";
4
-
5
- import { getEnvContent } from "./env-template.js";
6
-
7
- import { getHeartContent } from "./heart-template.js";
8
-
9
- import { getMfeCompContent } from "./mfe-comp-template.js";
10
-
11
- export {
12
- getAppContent,
13
- getContainerCompContent,
14
- getEnvContent,
15
- getHeartContent,
16
- getMfeCompContent,
17
- };
1
+ import { getAppContent } from "./app-comp-template.js";
2
+
3
+ import { getContainerCompContent } from "./container-comp-template.js";
4
+
5
+ import { getEnvContent } from "./env-template.js";
6
+
7
+ import { getHeartContent } from "./heart-template.js";
8
+
9
+ import { getMfeCompContent } from "./mfe-comp-template.js";
10
+
11
+ export {
12
+ getAppContent,
13
+ getContainerCompContent,
14
+ getEnvContent,
15
+ getHeartContent,
16
+ getMfeCompContent,
17
+ };
@@ -1,8 +1,8 @@
1
- export const getMfeCompContent = (mfeName:string, isTypeScript:boolean) => {
2
- return `import MicroFrontend from "../MicroFrontend";
3
-
4
- export const ${mfeName} = (props${isTypeScript ? ": any" : ""}) => {
5
- return <MicroFrontend name={props.name} host={props.host} />;
6
- };
7
- `;
8
- };
1
+ export const getMfeCompContent = (mfeName:string, isTypeScript:boolean) => {
2
+ return `import MicroFrontend from "../MicroFrontend";
3
+
4
+ export const ${mfeName} = (props${isTypeScript ? ": any" : ""}) => {
5
+ return <MicroFrontend name={props.name} host={props.host} />;
6
+ };
7
+ `;
8
+ };
@@ -1,14 +1,14 @@
1
- export const getMfeAppContent=(mfeName='mfe',isTs:boolean)=>{
2
- return`import React from 'react';
3
-
4
- function App(prop${isTs ? ": any" : ""}) {
5
- return (
6
- <div>
7
- <h1>Hello from ${mfeName}</h1>
8
- </div>
9
- );
10
- }
11
-
12
- export default App;
13
- `
1
+ export const getMfeAppContent=(mfeName='mfe',isTs:boolean)=>{
2
+ return`import React from 'react';
3
+
4
+ function App(prop${isTs ? ": any" : ""}) {
5
+ return (
6
+ <div>
7
+ <h1>Hello from ${mfeName}</h1>
8
+ </div>
9
+ );
10
+ }
11
+
12
+ export default App;
13
+ `
14
14
  }
@@ -1,13 +1,13 @@
1
- export const getConfigOverridesContent =()=>{
2
- return`module.exports = {
3
- webpack: (config, env) => {
4
- config.optimization.runtimeChunk = false;
5
- config.optimization.splitChunks = {
6
- cacheGroups: {
7
- default: false,
8
- },
9
- };
10
- return config;
11
- },
12
- };`
1
+ export const getConfigOverridesContent =()=>{
2
+ return`module.exports = {
3
+ webpack: (config, env) => {
4
+ config.optimization.runtimeChunk = false;
5
+ config.optimization.splitChunks = {
6
+ cacheGroups: {
7
+ default: false,
8
+ },
9
+ };
10
+ return config;
11
+ },
12
+ };`
13
13
  }
@@ -1,9 +1,9 @@
1
- import { getMfeAppContent } from "./app-comp-template.js";
2
- import { getConfigOverridesContent } from "./config-overrides-template.js";
3
- import { getmfeIndexContent } from "./mfe-index-template.js";
4
-
5
- export {
6
- getMfeAppContent,
7
- getConfigOverridesContent,
8
- getmfeIndexContent
1
+ import { getMfeAppContent } from "./app-comp-template.js";
2
+ import { getConfigOverridesContent } from "./config-overrides-template.js";
3
+ import { getmfeIndexContent } from "./mfe-index-template.js";
4
+
5
+ export {
6
+ getMfeAppContent,
7
+ getConfigOverridesContent,
8
+ getmfeIndexContent
9
9
  };
@@ -1,37 +1,37 @@
1
- export const getmfeIndexContent=(mfeName='mfe',container:string,isTs:boolean)=>{
2
- return`import React from "react";
3
- import { createRoot } from "react-dom/client";
4
- import App from "./App";
5
-
6
- ${isTs?`declare global {
7
- interface Window {
8
- render${mfeName}: (containerId${isTs?": string":""}, history${isTs?"?: any":""}) => void;
9
- unmount${mfeName}: (containerId${isTs?": string":""}) => void;
10
- }
11
- }`:''}
12
-
13
-
14
- window.render${mfeName} = (containerId${isTs?": string":""}, history${isTs?"?: any":""}) => {
15
- const container${isTs?": any":""} = document.getElementById(containerId);
16
- if (container) {
17
- const root = createRoot(container);
18
- root.render(<App history={history} />);
19
- }
20
- };
21
-
22
- window.unmount${mfeName} = (containerId${isTs?": string":""}) => {
23
- const container = document.getElementById(containerId);
24
- if (container) {
25
- const root = createRoot(container);
26
- root.unmount();
27
- }
28
- };
29
-
30
- const rootContainer = document.getElementById("root");
31
- if (rootContainer && !document.getElementById("${mfeName}-${container}")) {
32
- createRoot(rootContainer).render(<App />);
33
- }
34
-
35
-
36
- `
1
+ export const getmfeIndexContent=(mfeName='mfe',container:string,isTs:boolean)=>{
2
+ return`import React from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import App from "./App";
5
+
6
+ ${isTs?`declare global {
7
+ interface Window {
8
+ render${mfeName}: (containerId${isTs?": string":""}, history${isTs?"?: any":""}) => void;
9
+ unmount${mfeName}: (containerId${isTs?": string":""}) => void;
10
+ }
11
+ }`:''}
12
+
13
+
14
+ window.render${mfeName} = (containerId${isTs?": string":""}, history${isTs?"?: any":""}) => {
15
+ const container${isTs?": any":""} = document.getElementById(containerId);
16
+ if (container) {
17
+ const root = createRoot(container);
18
+ root.render(<App history={history} />);
19
+ }
20
+ };
21
+
22
+ window.unmount${mfeName} = (containerId${isTs?": string":""}) => {
23
+ const container = document.getElementById(containerId);
24
+ if (container) {
25
+ const root = createRoot(container);
26
+ root.unmount();
27
+ }
28
+ };
29
+
30
+ const rootContainer = document.getElementById("root");
31
+ if (rootContainer && !document.getElementById("${mfeName}-${container}")) {
32
+ createRoot(rootContainer).render(<App />);
33
+ }
34
+
35
+
36
+ `
37
37
  }
package/src/types/type.ts CHANGED
@@ -1,3 +1,3 @@
1
- export type Constant = {
2
- [key: string]: any;
3
- };
1
+ export type Constant = {
2
+ [key: string]: any;
3
+ };