-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewerTemplate.js
47 lines (36 loc) · 1.51 KB
/
viewerTemplate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Created by cashsun on 2016/10/19.
*/
const _ = require('lodash');
module.exports = {
build: function (componentsMetadata, props) {
const componentImports = _.map(componentsMetadata, (info, componentKey) => {
return `import $${componentKey} from '${info.path}';
allComponents['${componentKey}'] = {component: $${componentKey}, displayName:'${info.displayName}'}`
}).join(';\n');
return `
import { AppContainer } from 'react-hot-loader';
import React from 'react';
import {render} from 'react-dom';
import Viewer from 'rehearse/viewer';
import ComponentFrame from 'rehearse/componentFrame';
const allComponents = {};
${componentImports};
import componentProps from '${props}';
const viewerProps = {
allComponents,
allProps: componentProps,
target: window.target,
scenario: window.scenario
};
const subView = window.isFrame?<ComponentFrame {...viewerProps}/>:<Viewer {...viewerProps}/>;
const container = <AppContainer>{subView}</AppContainer>;
render(container, document.getElementById('viewer'));
if (module.hot&&window.isFrame) {
module.hot.accept();
}
export default window.isFrame?ComponentFrame:Viewer;
export {viewerProps}
`;
}
};