Skip to content

Commit 2d70aaf

Browse files
committed
chore: Optimizing the startup command
1 parent 8bd9f95 commit 2d70aaf

File tree

5 files changed

+19531
-136
lines changed

5 files changed

+19531
-136
lines changed

dev/main/src/config.ts

+50-50
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
// import GarfishInstance, { interfaces } from 'garfish';
2-
// import './monitoring';
1+
import GarfishInstance, { interfaces } from 'garfish';
2+
import './monitoring';
33

4-
// (window as any).__GARFISH_PARENT__ = true;
4+
(window as any).__GARFISH_PARENT__ = true;
55

6-
// // let asyncTime = function () {
7-
// // return new Promise((resolve) => {
8-
// // setTimeout(() => {
9-
// // resolve(true);
10-
// // }, 3000);
11-
// // });
12-
// // };
13-
// let defaultConfig: interfaces.Options = {
14-
// basename: '/garfish_master',
15-
// domGetter: () => {
16-
// // await asyncTime();
17-
// return document.querySelector('#submoduleByRouter');
18-
// },
19-
// apps: [
20-
// {
21-
// name: 'react',
22-
// activeWhen: '/react',
23-
// // cache: true,
24-
// entry: 'http://localhost:2444',
25-
// },
26-
// {
27-
// name: 'vue',
28-
// activeWhen: '/vue',
29-
// // cache: true,
30-
// entry: 'http://localhost:2666',
31-
// },
32-
// {
33-
// name: 'vue2',
34-
// activeWhen: '/vue2',
35-
// // cache: true,
36-
// entry: 'http://localhost:2777',
37-
// },
38-
// ],
39-
// autoRefreshApp: true,
40-
// disablePreloadApp: true,
41-
// protectVariable: ['MonitoringInstance', 'Garfish'],
42-
// // sandbox: {
43-
// // snapshot: false
44-
// // },
6+
// let asyncTime = function () {
7+
// return new Promise((resolve) => {
8+
// setTimeout(() => {
9+
// resolve(true);
10+
// }, 3000);
11+
// });
4512
// };
13+
let defaultConfig: interfaces.Options = {
14+
basename: '/garfish_master',
15+
domGetter: () => {
16+
// await asyncTime();
17+
return document.querySelector('#submoduleByRouter');
18+
},
19+
apps: [
20+
{
21+
name: 'react',
22+
activeWhen: '/react',
23+
// cache: true,
24+
entry: 'http://localhost:2444',
25+
},
26+
{
27+
name: 'vue',
28+
activeWhen: '/vue',
29+
// cache: true,
30+
entry: 'http://localhost:2666',
31+
},
32+
{
33+
name: 'vue2',
34+
activeWhen: '/vue2',
35+
// cache: true,
36+
entry: 'http://localhost:2777',
37+
},
38+
],
39+
autoRefreshApp: true,
40+
disablePreloadApp: true,
41+
protectVariable: ['MonitoringInstance', 'Garfish'],
42+
// sandbox: {
43+
// snapshot: false
44+
// },
45+
};
4646

47-
// // The test environment into
48-
// if (typeof Cypress !== 'undefined') {
49-
// defaultConfig = {
50-
// ...defaultConfig,
51-
// ...Cypress.env().garfishRunConfig,
52-
// };
53-
// }
47+
// The test environment into
48+
if (typeof Cypress !== 'undefined') {
49+
defaultConfig = {
50+
...defaultConfig,
51+
...Cypress.env().garfishRunConfig,
52+
};
53+
}
5454

55-
// export const Config = defaultConfig;
55+
export const Config = defaultConfig;

dev/main/src/index.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
// /// <reference types="cypress" />
2-
// import GarfishInstance from 'garfish';
3-
// import { Config } from './config';
1+
/// <reference types="cypress" />
2+
import GarfishInstance from 'garfish';
3+
import { Config } from './config';
44

5-
// GarfishInstance.run(Config);
5+
GarfishInstance.run(Config);
66

7-
// const useRouterMode = true;
7+
const useRouterMode = true;
88

9-
// document.getElementById('vueBtn').onclick = async () => {
10-
// if (useRouterMode) {
11-
// history.pushState({}, 'vue', '/garfish_master/vue'); // use router to load app
12-
// } else {
13-
// let prevApp = await GarfishInstance.loadApp('vue', {
14-
// entry: 'http://localhost:9090',
15-
// domGetter: '#submoduleByCunstom',
16-
// });
17-
// console.log(prevApp);
18-
// await prevApp.mount();
19-
// }
20-
// };
9+
document.getElementById('vueBtn').onclick = async () => {
10+
if (useRouterMode) {
11+
history.pushState({}, 'vue', '/garfish_master/vue'); // use router to load app
12+
} else {
13+
let prevApp = await GarfishInstance.loadApp('vue', {
14+
entry: 'http://localhost:9090',
15+
domGetter: '#submoduleByCunstom',
16+
});
17+
console.log(prevApp);
18+
await prevApp.mount();
19+
}
20+
};
2121

22-
// document.getElementById('reactBtn').onclick = async () => {
23-
// if (useRouterMode) {
24-
// history.pushState({}, 'react', '/garfish_master/react');
25-
// } else {
26-
// let prevApp = await GarfishInstance.loadApp('react', {
27-
// entry: 'http://localhost:3000',
28-
// domGetter: '#submoduleByCunstom',
29-
// });
30-
// console.log(prevApp);
31-
// await prevApp.mount();
32-
// }
33-
// };
22+
document.getElementById('reactBtn').onclick = async () => {
23+
if (useRouterMode) {
24+
history.pushState({}, 'react', '/garfish_master/react');
25+
} else {
26+
let prevApp = await GarfishInstance.loadApp('react', {
27+
entry: 'http://localhost:3000',
28+
domGetter: '#submoduleByCunstom',
29+
});
30+
console.log(prevApp);
31+
await prevApp.mount();
32+
}
33+
};
3434

3535
console.log(111);

dev/main/src/monitoring.ts

+56-56
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
// import ConfigCommon from '../../config.json';
2-
3-
// declare global {
4-
// interface Window {
5-
// fetchM: Function;
6-
// unhandledrejectionError: Function;
7-
// normalError: Function;
8-
// DynamicResource: Function;
9-
// resourceError: Function;
10-
// }
11-
// }
12-
13-
// window.fetchM = function fetchM() {
14-
// const xhr = new XMLHttpRequest();
15-
// xhr.open('get', `http://localhost:${ConfigCommon.mainPort}/mainApp`, true);
16-
// xhr.onreadystatechange = function () {
17-
// if (xhr.readyState !== 4) {
18-
// return;
19-
// }
20-
// if (xhr.status >= 200 && xhr.status < 300) {
21-
// // console.log('mainApp xhr');
22-
// }
23-
// };
24-
// xhr.send(null);
25-
26-
// fetch(
27-
// `http://localhost:${ConfigCommon.mainPort}/fetch/mainApp`,
28-
// ).then((res) => {});
29-
// };
30-
31-
// window.unhandledrejectionError = function unhandledrejectionError() {
32-
// setTimeout(() => {
33-
// throw Error('mainApp: unhandledrejection error');
34-
// }, 500);
35-
// };
36-
37-
// window.normalError = function normalError() {
38-
// throw Error('mainApp: normal error');
39-
// };
40-
41-
// window.DynamicResource = function DynamicResource() {
42-
// const sc = document.createElement('script');
43-
// sc.src = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicScript.js`;
44-
// document.body.appendChild(sc);
45-
46-
// const link = document.createElement('link');
47-
// link.href = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicLink.css`;
48-
// document.body.appendChild(link);
49-
// };
50-
51-
// window.resourceError = function resourceError() {
52-
// // resource error
53-
// const sc = document.createElement('script');
54-
// sc.src = `http://localhost:1111/monitoring/xxxxx.js`;
55-
// document.body.appendChild(sc);
56-
// };
1+
import ConfigCommon from '../../config.json';
2+
3+
declare global {
4+
interface Window {
5+
fetchM: Function;
6+
unhandledrejectionError: Function;
7+
normalError: Function;
8+
DynamicResource: Function;
9+
resourceError: Function;
10+
}
11+
}
12+
13+
window.fetchM = function fetchM() {
14+
const xhr = new XMLHttpRequest();
15+
xhr.open('get', `http://localhost:${ConfigCommon.mainPort}/mainApp`, true);
16+
xhr.onreadystatechange = function () {
17+
if (xhr.readyState !== 4) {
18+
return;
19+
}
20+
if (xhr.status >= 200 && xhr.status < 300) {
21+
// console.log('mainApp xhr');
22+
}
23+
};
24+
xhr.send(null);
25+
26+
fetch(
27+
`http://localhost:${ConfigCommon.mainPort}/fetch/mainApp`,
28+
).then((res) => {});
29+
};
30+
31+
window.unhandledrejectionError = function unhandledrejectionError() {
32+
setTimeout(() => {
33+
throw Error('mainApp: unhandledrejection error');
34+
}, 500);
35+
};
36+
37+
window.normalError = function normalError() {
38+
throw Error('mainApp: normal error');
39+
};
40+
41+
window.DynamicResource = function DynamicResource() {
42+
const sc = document.createElement('script');
43+
sc.src = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicScript.js`;
44+
document.body.appendChild(sc);
45+
46+
const link = document.createElement('link');
47+
link.href = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicLink.css`;
48+
document.body.appendChild(link);
49+
};
50+
51+
window.resourceError = function resourceError() {
52+
// resource error
53+
const sc = document.createElement('script');
54+
sc.src = `http://localhost:1111/monitoring/xxxxx.js`;
55+
document.body.appendChild(sc);
56+
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"description": "a powerful micro front-end framework",
1515
"scripts": {
16-
"dev": "cross-env TEST_ENV=true lerna exec --scope '{@garfish-dev/main,@garfish-dev/sub-react,@garfish-dev/sub-app,@garfish-dev/sub-vue,@garfish-dev/sub-vue2}' -- yarn start",
16+
"dev": "cross-env TEST_ENV=true lerna exec --parallel --scope '@garfish-dev/*' -- yarn start",
1717
"dev:core": "yarn dev core",
1818
"dev:docs": "yarn workspace garfish-docs start",
1919
"test:e2e": "cross-env node scripts/e2e.js & cross-env TEST_ENV=true yarn dev",

0 commit comments

Comments
 (0)