1 |
|
2 |
|
3 | import {PluginManager} from "../index";
|
4 |
|
5 | const manager = new PluginManager();
|
6 |
|
7 | async function run() {
|
8 | console.log("Installing express...");
|
9 | await manager.install("express", "4.16.2");
|
10 | console.log("Installing react...");
|
11 | await manager.install("react", "16.0.0");
|
12 | console.log("Installing react-dom...");
|
13 | await manager.install("react-dom", "16.0.0");
|
14 |
|
15 | const express = manager.require("express");
|
16 | const React = manager.require("react");
|
17 | const ReactDOMServer = manager.require("react-dom/server");
|
18 |
|
19 | const app = express();
|
20 |
|
21 | app.get("/", function(req: any, res: any) {
|
22 |
|
23 | class Hello extends React.Component {
|
24 | render() {
|
25 | return React.createElement("div", null, `Hello ${this.props.toWhat} from React!`);
|
26 | }
|
27 | }
|
28 |
|
29 | const elementToRender = React.createElement(Hello, {toWhat: "World"}, null);
|
30 | const reactResult = ReactDOMServer.renderToString(elementToRender);
|
31 | res.send(reactResult);
|
32 | });
|
33 |
|
34 | const server = app.listen(3000, function() {
|
35 | console.log("Example app listening on port 3000, closing after 20 secs.!");
|
36 | });
|
37 |
|
38 | setTimeout(async () => {
|
39 | server.close();
|
40 | console.log("Uninstalling plugins...");
|
41 | await manager.uninstallAll();
|
42 | }, 20000);
|
43 | }
|
44 |
|
45 | run()
|
46 | .catch(console.error.bind(console));
|