Skip to content

Commit

Permalink
chore: Optimizing the startup command
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Aug 27, 2021
1 parent 8bd9f95 commit 2d70aaf
Show file tree
Hide file tree
Showing 5 changed files with 19,531 additions and 136 deletions.
100 changes: 50 additions & 50 deletions dev/main/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
// import GarfishInstance, { interfaces } from 'garfish';
// import './monitoring';
import GarfishInstance, { interfaces } from 'garfish';
import './monitoring';

// (window as any).__GARFISH_PARENT__ = true;
(window as any).__GARFISH_PARENT__ = true;

// // let asyncTime = function () {
// // return new Promise((resolve) => {
// // setTimeout(() => {
// // resolve(true);
// // }, 3000);
// // });
// // };
// let defaultConfig: interfaces.Options = {
// basename: '/garfish_master',
// domGetter: () => {
// // await asyncTime();
// return document.querySelector('#submoduleByRouter');
// },
// apps: [
// {
// name: 'react',
// activeWhen: '/react',
// // cache: true,
// entry: 'http://localhost:2444',
// },
// {
// name: 'vue',
// activeWhen: '/vue',
// // cache: true,
// entry: 'http://localhost:2666',
// },
// {
// name: 'vue2',
// activeWhen: '/vue2',
// // cache: true,
// entry: 'http://localhost:2777',
// },
// ],
// autoRefreshApp: true,
// disablePreloadApp: true,
// protectVariable: ['MonitoringInstance', 'Garfish'],
// // sandbox: {
// // snapshot: false
// // },
// let asyncTime = function () {
// return new Promise((resolve) => {
// setTimeout(() => {
// resolve(true);
// }, 3000);
// });
// };
let defaultConfig: interfaces.Options = {
basename: '/garfish_master',
domGetter: () => {
// await asyncTime();
return document.querySelector('#submoduleByRouter');
},
apps: [
{
name: 'react',
activeWhen: '/react',
// cache: true,
entry: 'http://localhost:2444',
},
{
name: 'vue',
activeWhen: '/vue',
// cache: true,
entry: 'http://localhost:2666',
},
{
name: 'vue2',
activeWhen: '/vue2',
// cache: true,
entry: 'http://localhost:2777',
},
],
autoRefreshApp: true,
disablePreloadApp: true,
protectVariable: ['MonitoringInstance', 'Garfish'],
// sandbox: {
// snapshot: false
// },
};

// // The test environment into
// if (typeof Cypress !== 'undefined') {
// defaultConfig = {
// ...defaultConfig,
// ...Cypress.env().garfishRunConfig,
// };
// }
// The test environment into
if (typeof Cypress !== 'undefined') {
defaultConfig = {
...defaultConfig,
...Cypress.env().garfishRunConfig,
};
}

// export const Config = defaultConfig;
export const Config = defaultConfig;
58 changes: 29 additions & 29 deletions dev/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
// /// <reference types="cypress" />
// import GarfishInstance from 'garfish';
// import { Config } from './config';
/// <reference types="cypress" />
import GarfishInstance from 'garfish';
import { Config } from './config';

// GarfishInstance.run(Config);
GarfishInstance.run(Config);

// const useRouterMode = true;
const useRouterMode = true;

// document.getElementById('vueBtn').onclick = async () => {
// if (useRouterMode) {
// history.pushState({}, 'vue', '/garfish_master/vue'); // use router to load app
// } else {
// let prevApp = await GarfishInstance.loadApp('vue', {
// entry: 'http://localhost:9090',
// domGetter: '#submoduleByCunstom',
// });
// console.log(prevApp);
// await prevApp.mount();
// }
// };
document.getElementById('vueBtn').onclick = async () => {
if (useRouterMode) {
history.pushState({}, 'vue', '/garfish_master/vue'); // use router to load app
} else {
let prevApp = await GarfishInstance.loadApp('vue', {
entry: 'http://localhost:9090',
domGetter: '#submoduleByCunstom',
});
console.log(prevApp);
await prevApp.mount();
}
};

// document.getElementById('reactBtn').onclick = async () => {
// if (useRouterMode) {
// history.pushState({}, 'react', '/garfish_master/react');
// } else {
// let prevApp = await GarfishInstance.loadApp('react', {
// entry: 'http://localhost:3000',
// domGetter: '#submoduleByCunstom',
// });
// console.log(prevApp);
// await prevApp.mount();
// }
// };
document.getElementById('reactBtn').onclick = async () => {
if (useRouterMode) {
history.pushState({}, 'react', '/garfish_master/react');
} else {
let prevApp = await GarfishInstance.loadApp('react', {
entry: 'http://localhost:3000',
domGetter: '#submoduleByCunstom',
});
console.log(prevApp);
await prevApp.mount();
}
};

console.log(111);
112 changes: 56 additions & 56 deletions dev/main/src/monitoring.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
// import ConfigCommon from '../../config.json';

// declare global {
// interface Window {
// fetchM: Function;
// unhandledrejectionError: Function;
// normalError: Function;
// DynamicResource: Function;
// resourceError: Function;
// }
// }

// window.fetchM = function fetchM() {
// const xhr = new XMLHttpRequest();
// xhr.open('get', `http://localhost:${ConfigCommon.mainPort}/mainApp`, true);
// xhr.onreadystatechange = function () {
// if (xhr.readyState !== 4) {
// return;
// }
// if (xhr.status >= 200 && xhr.status < 300) {
// // console.log('mainApp xhr');
// }
// };
// xhr.send(null);

// fetch(
// `http://localhost:${ConfigCommon.mainPort}/fetch/mainApp`,
// ).then((res) => {});
// };

// window.unhandledrejectionError = function unhandledrejectionError() {
// setTimeout(() => {
// throw Error('mainApp: unhandledrejection error');
// }, 500);
// };

// window.normalError = function normalError() {
// throw Error('mainApp: normal error');
// };

// window.DynamicResource = function DynamicResource() {
// const sc = document.createElement('script');
// sc.src = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicScript.js`;
// document.body.appendChild(sc);

// const link = document.createElement('link');
// link.href = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicLink.css`;
// document.body.appendChild(link);
// };

// window.resourceError = function resourceError() {
// // resource error
// const sc = document.createElement('script');
// sc.src = `http://localhost:1111/monitoring/xxxxx.js`;
// document.body.appendChild(sc);
// };
import ConfigCommon from '../../config.json';

declare global {
interface Window {
fetchM: Function;
unhandledrejectionError: Function;
normalError: Function;
DynamicResource: Function;
resourceError: Function;
}
}

window.fetchM = function fetchM() {
const xhr = new XMLHttpRequest();
xhr.open('get', `http://localhost:${ConfigCommon.mainPort}/mainApp`, true);
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) {
return;
}
if (xhr.status >= 200 && xhr.status < 300) {
// console.log('mainApp xhr');
}
};
xhr.send(null);

fetch(
`http://localhost:${ConfigCommon.mainPort}/fetch/mainApp`,
).then((res) => {});
};

window.unhandledrejectionError = function unhandledrejectionError() {
setTimeout(() => {
throw Error('mainApp: unhandledrejection error');
}, 500);
};

window.normalError = function normalError() {
throw Error('mainApp: normal error');
};

window.DynamicResource = function DynamicResource() {
const sc = document.createElement('script');
sc.src = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicScript.js`;
document.body.appendChild(sc);

const link = document.createElement('link');
link.href = `http://localhost:${ConfigCommon.mainPort}/monitoring/dynamicLink.css`;
document.body.appendChild(link);
};

window.resourceError = function resourceError() {
// resource error
const sc = document.createElement('script');
sc.src = `http://localhost:1111/monitoring/xxxxx.js`;
document.body.appendChild(sc);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"description": "a powerful micro front-end framework",
"scripts": {
"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",
"dev": "cross-env TEST_ENV=true lerna exec --parallel --scope '@garfish-dev/*' -- yarn start",
"dev:core": "yarn dev core",
"dev:docs": "yarn workspace garfish-docs start",
"test:e2e": "cross-env node scripts/e2e.js & cross-env TEST_ENV=true yarn dev",
Expand Down
Loading

0 comments on commit 2d70aaf

Please sign in to comment.