@merkur/create-widget 0.31.1 → 0.32.0
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.
- package/README.md +1 -1
- package/package.json +7 -7
- package/scripts/create.mjs +0 -12
- package/template/package.json +7 -7
- package/template/server/app.js +1 -0
- package/template/server/routes/widgetAPI/widgetAPI.js +1 -1
- package/views/preact/template/webpack.config.js +0 -7
- package/views/preact/template.json +4 -4
- package/views/svelte/template/webpack.config.js +0 -7
- package/views/svelte/template.json +2 -2
- package/views/uhtml/template/webpack.config.js +0 -2
- package/views/uhtml/template.json +1 -1
- package/views/vanilla/template/webpack.config.js +0 -2
- package/views/hyper/template/src/client.js +0 -66
- package/views/hyper/template/src/components/Counter.js +0 -14
- package/views/hyper/template/src/components/Welcome.js +0 -12
- package/views/hyper/template/src/components/WidgetDescription.js +0 -5
- package/views/hyper/template/src/server.js +0 -33
- package/views/hyper/template/src/slots/HeadlineSlot.js +0 -30
- package/views/hyper/template/src/views/ErrorView.js +0 -9
- package/views/hyper/template/src/views/View.js +0 -36
- package/views/hyper/template/webpack.config.js +0 -18
- package/views/hyper/template.json +0 -6
- package/views/react/template/babel.config.js +0 -12
- package/views/react/template/jest.config.js +0 -7
- package/views/react/template/jest.setup.js +0 -4
- package/views/react/template/src/client.js +0 -55
- package/views/react/template/src/components/Counter.jsx +0 -16
- package/views/react/template/src/components/Welcome.jsx +0 -10
- package/views/react/template/src/components/WidgetContext.js +0 -5
- package/views/react/template/src/components/WidgetDescription.jsx +0 -11
- package/views/react/template/src/server.js +0 -31
- package/views/react/template/src/slots/HeadlineSlot.jsx +0 -31
- package/views/react/template/src/views/ErrorView.jsx +0 -9
- package/views/react/template/src/views/View.jsx +0 -39
- package/views/react/template/src/views/__tests__/ViewSpec.jsx +0 -25
- package/views/react/template/webpack.config.js +0 -66
- package/views/react/template.json +0 -12
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|

|
|
12
12
|
[](https://github.com/prettier/prettier)
|
|
13
13
|
|
|
14
|
-
The [Merkur](https://merkur.js.org/) is tiny extensible javascript library for front-end microservices(micro frontends). It allows by default server side rendering for loading performance boost. You can connect it with other frameworks or languages because merkur defines easy API. You can use one of six predefined template's library [
|
|
14
|
+
The [Merkur](https://merkur.js.org/) is tiny extensible javascript library for front-end microservices(micro frontends). It allows by default server side rendering for loading performance boost. You can connect it with other frameworks or languages because merkur defines easy API. You can use one of six predefined template's library [Preact](https://preactjs.com/), [µhtml](https://github.com/WebReflection/uhtml#readme), [Svelte](https://svelte.dev/) and [vanilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) but you can easily extend for others.
|
|
15
15
|
|
|
16
16
|
## Features
|
|
17
17
|
- Flexible templating engine
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/create-widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "CLI for creating merkur widget easily.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"merkur-create-widget": "./bin/createWidget.mjs"
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"node": ">=12"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"chalk": "^5.0
|
|
42
|
-
"execa": "^
|
|
43
|
-
"fs-extra": "^
|
|
44
|
-
"inquirer": "^
|
|
45
|
-
"yargs": "^17.
|
|
41
|
+
"chalk": "^5.2.0",
|
|
42
|
+
"execa": "^7.1.1",
|
|
43
|
+
"fs-extra": "^11.1.1",
|
|
44
|
+
"inquirer": "^9.2.2",
|
|
45
|
+
"yargs": "^17.7.2"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "c45ffe12725e3c4afcf7f13869a25a96f6807055"
|
|
48
48
|
}
|
package/scripts/create.mjs
CHANGED
|
@@ -24,12 +24,6 @@ let viewResolver = argv.view
|
|
|
24
24
|
name: 'view',
|
|
25
25
|
message: 'Choose a view configuration:',
|
|
26
26
|
choices: [
|
|
27
|
-
{
|
|
28
|
-
name: `${chalk.bold.blue(
|
|
29
|
-
'Hyper'
|
|
30
|
-
)} - The basic counter example with hyper.`,
|
|
31
|
-
value: 'hyper',
|
|
32
|
-
},
|
|
33
27
|
{
|
|
34
28
|
name: `${chalk.bold.blue(
|
|
35
29
|
'µhtml'
|
|
@@ -42,12 +36,6 @@ let viewResolver = argv.view
|
|
|
42
36
|
)} - The basic counter example with preact.`,
|
|
43
37
|
value: 'preact',
|
|
44
38
|
},
|
|
45
|
-
{
|
|
46
|
-
name: `${chalk.bold.blue(
|
|
47
|
-
'React'
|
|
48
|
-
)} - The basic counter example with react.`,
|
|
49
|
-
value: 'react',
|
|
50
|
-
},
|
|
51
39
|
{
|
|
52
40
|
name: `${chalk.bold.blue(
|
|
53
41
|
'Svelte'
|
package/template/package.json
CHANGED
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@merkur/core": "0.
|
|
21
|
-
"@merkur/integration": "0.
|
|
22
|
-
"@merkur/plugin-component": "0.
|
|
23
|
-
"@merkur/plugin-error": "0.
|
|
24
|
-
"@merkur/plugin-event-emitter": "0.
|
|
20
|
+
"@merkur/core": "0.32.0",
|
|
21
|
+
"@merkur/integration": "0.32.0",
|
|
22
|
+
"@merkur/plugin-component": "0.32.0",
|
|
23
|
+
"@merkur/plugin-error": "0.32.0",
|
|
24
|
+
"@merkur/plugin-event-emitter": "0.32.0",
|
|
25
25
|
"compression": "^1.7.4",
|
|
26
26
|
"config": "^3.3.7",
|
|
27
27
|
"cors": "^2.8.5",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"morgan": "^1.10.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@merkur/tools": "0.
|
|
38
|
-
"@merkur/tool-webpack": "0.
|
|
37
|
+
"@merkur/tools": "0.32.0",
|
|
38
|
+
"@merkur/tool-webpack": "0.32.0",
|
|
39
39
|
"nodemon": "^2.0.15",
|
|
40
40
|
"webpack": "^5.72.0",
|
|
41
41
|
"webpack-cli": "^4.9.2"
|
package/template/server/app.js
CHANGED
|
@@ -2,7 +2,6 @@ const {
|
|
|
2
2
|
createLiveReloadServer,
|
|
3
3
|
createWebConfig,
|
|
4
4
|
createNodeConfig,
|
|
5
|
-
applyES5Transformation,
|
|
6
5
|
applyES9Transformation,
|
|
7
6
|
applyStyleLoaders,
|
|
8
7
|
createCacheKey,
|
|
@@ -48,12 +47,6 @@ function applyBabelLoader(config, { isProduction, environment, cache }) {
|
|
|
48
47
|
module.exports = createLiveReloadServer().then(() =>
|
|
49
48
|
Promise.all([
|
|
50
49
|
pipe(createWebConfig, applyStyleLoaders, applyBabelLoader)(),
|
|
51
|
-
pipe(
|
|
52
|
-
createWebConfig,
|
|
53
|
-
applyStyleLoaders,
|
|
54
|
-
applyBabelLoader,
|
|
55
|
-
applyES5Transformation
|
|
56
|
-
)(),
|
|
57
50
|
pipe(
|
|
58
51
|
createWebConfig,
|
|
59
52
|
applyStyleLoaders,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"preact": "10.
|
|
4
|
-
"preact-render-to-string": "
|
|
3
|
+
"preact": "10.13.2",
|
|
4
|
+
"preact-render-to-string": "6.0.3"
|
|
5
5
|
},
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@babel/preset-react": "7.
|
|
7
|
+
"@babel/preset-react": "7.18.6",
|
|
8
8
|
"babel-loader": "9.1.2",
|
|
9
9
|
"enzyme": "3.11.0",
|
|
10
|
-
"enzyme-adapter-preact-pure": "
|
|
10
|
+
"enzyme-adapter-preact-pure": "4.1.0",
|
|
11
11
|
"enzyme-to-json": "3.6.2"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -2,7 +2,6 @@ const {
|
|
|
2
2
|
createLiveReloadServer,
|
|
3
3
|
createWebConfig,
|
|
4
4
|
createNodeConfig,
|
|
5
|
-
applyES5Transformation,
|
|
6
5
|
applyES9Transformation,
|
|
7
6
|
applyStyleLoaders,
|
|
8
7
|
pipe,
|
|
@@ -51,12 +50,6 @@ function applySvelteNode(config) {
|
|
|
51
50
|
module.exports = createLiveReloadServer().then(() =>
|
|
52
51
|
Promise.all([
|
|
53
52
|
pipe(createWebConfig, applyStyleLoaders, applySvelteWeb)(),
|
|
54
|
-
pipe(
|
|
55
|
-
createWebConfig,
|
|
56
|
-
applyStyleLoaders,
|
|
57
|
-
applySvelteWeb,
|
|
58
|
-
applyES5Transformation
|
|
59
|
-
)(),
|
|
60
53
|
pipe(
|
|
61
54
|
createWebConfig,
|
|
62
55
|
applyStyleLoaders,
|
|
@@ -2,7 +2,6 @@ const {
|
|
|
2
2
|
createLiveReloadServer,
|
|
3
3
|
createWebConfig,
|
|
4
4
|
createNodeConfig,
|
|
5
|
-
applyES5Transformation,
|
|
6
5
|
applyES9Transformation,
|
|
7
6
|
applyStyleLoaders,
|
|
8
7
|
pipe,
|
|
@@ -11,7 +10,6 @@ const {
|
|
|
11
10
|
module.exports = createLiveReloadServer().then(() =>
|
|
12
11
|
Promise.all([
|
|
13
12
|
pipe(createWebConfig, applyStyleLoaders)(),
|
|
14
|
-
pipe(createWebConfig, applyStyleLoaders, applyES5Transformation)(),
|
|
15
13
|
pipe(createWebConfig, applyStyleLoaders, applyES9Transformation)(),
|
|
16
14
|
pipe(createNodeConfig, applyStyleLoaders)(),
|
|
17
15
|
])
|
|
@@ -2,7 +2,6 @@ const {
|
|
|
2
2
|
createLiveReloadServer,
|
|
3
3
|
createWebConfig,
|
|
4
4
|
createNodeConfig,
|
|
5
|
-
applyES5Transformation,
|
|
6
5
|
applyES9Transformation,
|
|
7
6
|
applyStyleLoaders,
|
|
8
7
|
pipe,
|
|
@@ -11,7 +10,6 @@ const {
|
|
|
11
10
|
module.exports = createLiveReloadServer().then(() =>
|
|
12
11
|
Promise.all([
|
|
13
12
|
pipe(createWebConfig, applyStyleLoaders)(),
|
|
14
|
-
pipe(createWebConfig, applyStyleLoaders, applyES5Transformation)(),
|
|
15
13
|
pipe(createWebConfig, applyStyleLoaders, applyES9Transformation)(),
|
|
16
14
|
pipe(createNodeConfig, applyStyleLoaders)(),
|
|
17
15
|
])
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import hyper from 'hyperhtml';
|
|
2
|
-
|
|
3
|
-
import { createMerkurWidget, createMerkur } from '@merkur/core';
|
|
4
|
-
|
|
5
|
-
import { mapViews } from './lib/utils';
|
|
6
|
-
import { viewFactory } from './views/View';
|
|
7
|
-
import widgetProperties from './widget';
|
|
8
|
-
|
|
9
|
-
import './style.css';
|
|
10
|
-
|
|
11
|
-
function createWidget(widgetParams) {
|
|
12
|
-
return createMerkurWidget({
|
|
13
|
-
...widgetProperties,
|
|
14
|
-
...widgetParams,
|
|
15
|
-
$dependencies: {
|
|
16
|
-
bind: hyper.bind,
|
|
17
|
-
wire: hyper.wire,
|
|
18
|
-
},
|
|
19
|
-
mount(widget) {
|
|
20
|
-
widget.$external.render = {};
|
|
21
|
-
|
|
22
|
-
return mapViews(
|
|
23
|
-
widget,
|
|
24
|
-
viewFactory,
|
|
25
|
-
({ View, containerSelector, container }) => {
|
|
26
|
-
if (!container) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
widget.$external.render[containerSelector] =
|
|
31
|
-
widget.$dependencies.bind(container);
|
|
32
|
-
|
|
33
|
-
View(widget, widget.$external.render[containerSelector]);
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
},
|
|
37
|
-
unmount(widget) {
|
|
38
|
-
mapViews(widget, viewFactory, ({ container }) => {
|
|
39
|
-
if (!container) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
container.innerHTML = '';
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
update(widget) {
|
|
47
|
-
mapViews(
|
|
48
|
-
widget,
|
|
49
|
-
viewFactory,
|
|
50
|
-
({ View, containerSelector, container }) => {
|
|
51
|
-
if (!container) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
View(widget, widget.$external.render[containerSelector]);
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const merkur = createMerkur();
|
|
63
|
-
merkur.register({
|
|
64
|
-
...widgetProperties,
|
|
65
|
-
createWidget,
|
|
66
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default function Counter(widget) {
|
|
2
|
-
return widget.$dependencies.wire()`
|
|
3
|
-
<div>
|
|
4
|
-
<h3>Counter widget:</h3>
|
|
5
|
-
<p>Count: ${widget.state.counter}</p>
|
|
6
|
-
<button onclick=${widget.onClick}>
|
|
7
|
-
increase counter
|
|
8
|
-
</button>
|
|
9
|
-
<button onclick=${widget.onReset}>
|
|
10
|
-
reset counter
|
|
11
|
-
</button>
|
|
12
|
-
</div>
|
|
13
|
-
`;
|
|
14
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export default function Welcome(widget) {
|
|
2
|
-
return widget.$dependencies.wire(widget.props, ':welcome')`
|
|
3
|
-
<div>
|
|
4
|
-
<h1>
|
|
5
|
-
<a href="https://github.com/mjancarik/merkur">MERKUR</a>
|
|
6
|
-
</h1>
|
|
7
|
-
<h2>
|
|
8
|
-
a tiny extensible javascript library for front-end microservices
|
|
9
|
-
</h2>
|
|
10
|
-
</div>
|
|
11
|
-
`;
|
|
12
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import viper from 'viperhtml';
|
|
2
|
-
|
|
3
|
-
import { createMerkurWidget } from '@merkur/core';
|
|
4
|
-
|
|
5
|
-
import { viewFactory } from './views/View';
|
|
6
|
-
import widgetProperties from './widget';
|
|
7
|
-
|
|
8
|
-
export function createWidget(widgetParams) {
|
|
9
|
-
return createMerkurWidget({
|
|
10
|
-
...widgetProperties,
|
|
11
|
-
...widgetParams,
|
|
12
|
-
$dependencies: {
|
|
13
|
-
bind: viper.bind,
|
|
14
|
-
wire: viper.wire,
|
|
15
|
-
},
|
|
16
|
-
async mount(widget) {
|
|
17
|
-
const { View, slot = {} } = await viewFactory(widget);
|
|
18
|
-
const render = widget.$dependencies.bind(widget.state);
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
html: View(widget, render).toString(),
|
|
22
|
-
slot: Object.keys(slot).reduce((acc, cur) => {
|
|
23
|
-
acc[cur] = {
|
|
24
|
-
name: slot[cur].name,
|
|
25
|
-
html: slot[cur].View(widget, render).toString(),
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return acc;
|
|
29
|
-
}, {}),
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import Welcome from '../components/Welcome';
|
|
2
|
-
import WidgetDescription from '../components/WidgetDescription';
|
|
3
|
-
|
|
4
|
-
async function headlineSlotFactory() {
|
|
5
|
-
return {
|
|
6
|
-
name: 'headline',
|
|
7
|
-
View: HeadlineSlot,
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function HeadlineSlot(widget, render) {
|
|
12
|
-
if (widget.error && widget.error.status) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return render`
|
|
17
|
-
<div class='merkur__page'>
|
|
18
|
-
<div class='merkur__headline'>
|
|
19
|
-
<div class='merkur__view'>
|
|
20
|
-
${Welcome(widget)}
|
|
21
|
-
<h3>Current count: ${widget.state.counter}</h3>
|
|
22
|
-
${WidgetDescription(widget)}
|
|
23
|
-
</div>
|
|
24
|
-
</div>
|
|
25
|
-
</div>
|
|
26
|
-
`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { headlineSlotFactory };
|
|
30
|
-
export default HeadlineSlot;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import Counter from '../components/Counter';
|
|
2
|
-
import { headlineSlotFactory } from '../slots/HeadlineSlot';
|
|
3
|
-
import ErrorView from './ErrorView';
|
|
4
|
-
|
|
5
|
-
async function viewFactory(widget) {
|
|
6
|
-
const slot = (await Promise.all([headlineSlotFactory(widget)])).reduce(
|
|
7
|
-
(acc, cur) => {
|
|
8
|
-
acc[cur.name] = cur;
|
|
9
|
-
|
|
10
|
-
return acc;
|
|
11
|
-
},
|
|
12
|
-
{}
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
View,
|
|
17
|
-
slot,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function View(widget, render) {
|
|
22
|
-
if (widget.error && widget.error.status) {
|
|
23
|
-
return render`${ErrorView(widget)}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return render`
|
|
27
|
-
<div class='merkur__page'>
|
|
28
|
-
<div class='merkur__view'>
|
|
29
|
-
${Counter(widget)}
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { viewFactory };
|
|
36
|
-
export default View;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
createLiveReloadServer,
|
|
3
|
-
createWebConfig,
|
|
4
|
-
createNodeConfig,
|
|
5
|
-
applyES5Transformation,
|
|
6
|
-
applyES9Transformation,
|
|
7
|
-
applyStyleLoaders,
|
|
8
|
-
pipe,
|
|
9
|
-
} = require('@merkur/tool-webpack');
|
|
10
|
-
|
|
11
|
-
module.exports = createLiveReloadServer().then(() =>
|
|
12
|
-
Promise.all([
|
|
13
|
-
pipe(createWebConfig, applyStyleLoaders)(),
|
|
14
|
-
pipe(createWebConfig, applyStyleLoaders, applyES5Transformation)(),
|
|
15
|
-
pipe(createWebConfig, applyStyleLoaders, applyES9Transformation)(),
|
|
16
|
-
pipe(createNodeConfig, applyStyleLoaders)(),
|
|
17
|
-
])
|
|
18
|
-
);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { render, hydrate, unmountComponentAtNode } from 'react-dom';
|
|
2
|
-
|
|
3
|
-
import { createMerkurWidget, createMerkur } from '@merkur/core';
|
|
4
|
-
|
|
5
|
-
import { mapViews } from './lib/utils';
|
|
6
|
-
import { viewFactory } from './views/View.jsx';
|
|
7
|
-
import widgetProperties from './widget';
|
|
8
|
-
|
|
9
|
-
import './style.css';
|
|
10
|
-
|
|
11
|
-
function createWidget(widgetParams) {
|
|
12
|
-
return createMerkurWidget({
|
|
13
|
-
...widgetProperties,
|
|
14
|
-
...widgetParams,
|
|
15
|
-
$dependencies: {
|
|
16
|
-
hydrate,
|
|
17
|
-
render,
|
|
18
|
-
unmountComponentAtNode,
|
|
19
|
-
},
|
|
20
|
-
async mount(widget) {
|
|
21
|
-
return mapViews(widget, viewFactory, ({ View, container, isSlot }) => {
|
|
22
|
-
if (!container) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
container?.children?.length && !isSlot
|
|
28
|
-
? widget.$dependencies.hydrate
|
|
29
|
-
: widget.$dependencies.render
|
|
30
|
-
)(View(widget), container);
|
|
31
|
-
});
|
|
32
|
-
},
|
|
33
|
-
async unmount(widget) {
|
|
34
|
-
mapViews(widget, viewFactory, ({ container }) => {
|
|
35
|
-
if (container) {
|
|
36
|
-
widget.$dependencies.unmountComponentAtNode(container);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
async update(widget) {
|
|
41
|
-
return mapViews(
|
|
42
|
-
widget,
|
|
43
|
-
viewFactory,
|
|
44
|
-
({ View, container }) =>
|
|
45
|
-
container && widget.$dependencies.render(View(widget), container)
|
|
46
|
-
);
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const merkur = createMerkur();
|
|
52
|
-
merkur.register({
|
|
53
|
-
...widgetProperties,
|
|
54
|
-
createWidget,
|
|
55
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
import WidgetContext from './WidgetContext';
|
|
4
|
-
|
|
5
|
-
export default function Counter({ counter }) {
|
|
6
|
-
const widget = useContext(WidgetContext);
|
|
7
|
-
|
|
8
|
-
return (
|
|
9
|
-
<div>
|
|
10
|
-
<h3>Counter widget:</h3>
|
|
11
|
-
<p>Count: {counter}</p>
|
|
12
|
-
<button onClick={widget.onClick}>increase counter</button>
|
|
13
|
-
<button onClick={widget.onReset}>reset counter</button>
|
|
14
|
-
</div>
|
|
15
|
-
);
|
|
16
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { renderToString } from 'react-dom/server';
|
|
2
|
-
|
|
3
|
-
import { createMerkurWidget } from '@merkur/core';
|
|
4
|
-
|
|
5
|
-
import { viewFactory } from './views/View';
|
|
6
|
-
import widgetProperties from './widget';
|
|
7
|
-
|
|
8
|
-
export function createWidget(widgetParams) {
|
|
9
|
-
return createMerkurWidget({
|
|
10
|
-
...widgetProperties,
|
|
11
|
-
...widgetParams,
|
|
12
|
-
$dependencies: {
|
|
13
|
-
render: renderToString,
|
|
14
|
-
},
|
|
15
|
-
async mount(widget) {
|
|
16
|
-
const { View, slot = {} } = await viewFactory(widget);
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
html: widget.$dependencies.render(View(widget)),
|
|
20
|
-
slot: Object.keys(slot).reduce((acc, cur) => {
|
|
21
|
-
acc[cur] = {
|
|
22
|
-
name: slot[cur].name,
|
|
23
|
-
html: widget.$dependencies.render(slot[cur].View(widget)),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return acc;
|
|
27
|
-
}, {}),
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Welcome from '../components/Welcome';
|
|
2
|
-
import WidgetContext from '../components/WidgetContext';
|
|
3
|
-
import WidgetDescription from '../components/WidgetDescription';
|
|
4
|
-
|
|
5
|
-
async function headlineSlotFactory() {
|
|
6
|
-
return {
|
|
7
|
-
name: 'headline',
|
|
8
|
-
View: HeadlineSlot,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function HeadlineSlot(widget) {
|
|
13
|
-
if (widget.error && widget.error.status) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<WidgetContext.Provider value={widget}>
|
|
19
|
-
<div className='merkur__headline'>
|
|
20
|
-
<div className='merkur__view'>
|
|
21
|
-
<Welcome />
|
|
22
|
-
<h3>Current count: {widget.state.counter}</h3>
|
|
23
|
-
<WidgetDescription name={widget.name} version={widget.version} />
|
|
24
|
-
</div>
|
|
25
|
-
</div>
|
|
26
|
-
</WidgetContext.Provider>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { headlineSlotFactory };
|
|
31
|
-
export default HeadlineSlot;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import Counter from '../components/Counter';
|
|
2
|
-
import WidgetContext from '../components/WidgetContext';
|
|
3
|
-
import { headlineSlotFactory } from '../slots/HeadlineSlot';
|
|
4
|
-
import ErrorView from './ErrorView';
|
|
5
|
-
|
|
6
|
-
async function viewFactory(widget) {
|
|
7
|
-
const slot = (await Promise.all([headlineSlotFactory(widget)])).reduce(
|
|
8
|
-
(acc, cur) => {
|
|
9
|
-
acc[cur.name] = cur;
|
|
10
|
-
|
|
11
|
-
return acc;
|
|
12
|
-
},
|
|
13
|
-
{}
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
View,
|
|
18
|
-
slot,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function View(widget) {
|
|
23
|
-
if (widget.error && widget.error.status) {
|
|
24
|
-
return <ErrorView error={widget.error} />;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<WidgetContext.Provider value={widget}>
|
|
29
|
-
<div className='merkur__page'>
|
|
30
|
-
<div className='merkur__view'>
|
|
31
|
-
<Counter counter={widget.state.counter} />
|
|
32
|
-
</div>
|
|
33
|
-
</div>
|
|
34
|
-
</WidgetContext.Provider>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { viewFactory };
|
|
39
|
-
export default View;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import { createMerkurWidget } from '@merkur/core';
|
|
4
|
-
|
|
5
|
-
import widgetProperties from '../../widget';
|
|
6
|
-
import View from '../View';
|
|
7
|
-
|
|
8
|
-
describe('View', () => {
|
|
9
|
-
let widget = null;
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
widget = await createMerkurWidget({
|
|
13
|
-
...widgetProperties,
|
|
14
|
-
mount() {
|
|
15
|
-
return shallow(View(widget));
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should display main view', async () => {
|
|
21
|
-
const wrapper = await widget.mount();
|
|
22
|
-
|
|
23
|
-
expect(wrapper).toMatchInlineSnapshot();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
createLiveReloadServer,
|
|
3
|
-
createWebConfig,
|
|
4
|
-
createNodeConfig,
|
|
5
|
-
applyES5Transformation,
|
|
6
|
-
applyES9Transformation,
|
|
7
|
-
applyStyleLoaders,
|
|
8
|
-
createCacheKey,
|
|
9
|
-
pipe,
|
|
10
|
-
} = require('@merkur/tool-webpack');
|
|
11
|
-
|
|
12
|
-
function applyBabelLoader(config, { isProduction, environment, cache }) {
|
|
13
|
-
config.module.rules.push({
|
|
14
|
-
test: /\.(js|ts|tsx|mjs|jsx)$/,
|
|
15
|
-
exclude: (modulePath) =>
|
|
16
|
-
/node_modules/.test(modulePath) &&
|
|
17
|
-
!/node_modules\/(abort-controller|event-target-shim)/.test(modulePath),
|
|
18
|
-
use: {
|
|
19
|
-
loader: 'babel-loader',
|
|
20
|
-
options: {
|
|
21
|
-
presets: [
|
|
22
|
-
[
|
|
23
|
-
'@babel/preset-react',
|
|
24
|
-
{
|
|
25
|
-
runtime: 'automatic',
|
|
26
|
-
development: !isProduction,
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
],
|
|
30
|
-
cacheIdentifier: createCacheKey(
|
|
31
|
-
environment,
|
|
32
|
-
config?.name,
|
|
33
|
-
...(cache?.versionDependencies ?? [])
|
|
34
|
-
),
|
|
35
|
-
cacheDirectory: true,
|
|
36
|
-
cacheCompression: false,
|
|
37
|
-
compact: isProduction,
|
|
38
|
-
sourceMaps: !isProduction,
|
|
39
|
-
inputSourceMap: !isProduction,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return config;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = createLiveReloadServer().then(() =>
|
|
48
|
-
Promise.all([
|
|
49
|
-
pipe(createWebConfig, applyStyleLoaders, applyBabelLoader)(),
|
|
50
|
-
pipe(
|
|
51
|
-
createWebConfig,
|
|
52
|
-
applyStyleLoaders,
|
|
53
|
-
applyBabelLoader,
|
|
54
|
-
applyES5Transformation
|
|
55
|
-
)(),
|
|
56
|
-
pipe(
|
|
57
|
-
createWebConfig,
|
|
58
|
-
applyStyleLoaders,
|
|
59
|
-
applyBabelLoader,
|
|
60
|
-
applyES9Transformation
|
|
61
|
-
)(),
|
|
62
|
-
pipe(createNodeConfig, applyStyleLoaders, applyBabelLoader)(),
|
|
63
|
-
])
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
module.exports.applyBabelLoader = applyBabelLoader;
|