oc-template-elm-compiler 0.2.1 → 0.2.2
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.
|
@@ -2,35 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const extractName = (path) => path.match(/(\w+)\.elm$/)[1];
|
|
4
4
|
const removeJsExtension = (path) => path.replace(/\.(t|j)s?$/, '');
|
|
5
|
-
function elmEntry({ viewPath }) {
|
|
5
|
+
function elmEntry({ viewPath, providerFunctions }) {
|
|
6
6
|
return `
|
|
7
7
|
import { Elm } from '${viewPath}';
|
|
8
8
|
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
name: providerProps._componentName,
|
|
12
|
-
version: providerProps._componentVersion,
|
|
13
|
-
baseUrl: providerProps._baseUrl,
|
|
14
|
-
parameters
|
|
15
|
-
}, (err, data) => {
|
|
16
|
-
if (err) {
|
|
17
|
-
return cb(err);
|
|
18
|
-
}
|
|
19
|
-
const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = data.component.props;
|
|
20
|
-
cb(null, rest);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function renderer(model, node) {
|
|
25
|
-
const { _baseUrl, _componentName, _componentVersion, _staticPath, ...props } = model;
|
|
9
|
+
export default function renderer(props, node) {
|
|
10
|
+
const { _baseUrl, _componentName, _componentVersion, _staticPath, ...rest } = props;
|
|
26
11
|
const app = Elm["${extractName(viewPath)}"].init({
|
|
27
12
|
node,
|
|
28
|
-
flags:
|
|
13
|
+
flags: rest
|
|
29
14
|
})
|
|
30
15
|
|
|
16
|
+
${providerFunctions}
|
|
17
|
+
|
|
31
18
|
if (app.ports && app.ports.getData) {
|
|
32
19
|
app.ports.getData.subscribe(parameters => {
|
|
33
|
-
getData(
|
|
20
|
+
getData(parameters, (err, data) => {
|
|
34
21
|
if (err && process.env.NODE_ENV !== 'production') {
|
|
35
22
|
console.error('Error requesting OC Data', err);
|
|
36
23
|
}
|
|
@@ -43,11 +30,9 @@ function elmEntry({ viewPath }) {
|
|
|
43
30
|
|
|
44
31
|
return app;
|
|
45
32
|
}
|
|
46
|
-
|
|
47
|
-
export default renderer;
|
|
48
33
|
`;
|
|
49
34
|
}
|
|
50
|
-
function jsEntry({ viewPath }) {
|
|
35
|
+
function jsEntry({ viewPath, providerFunctions }) {
|
|
51
36
|
return `
|
|
52
37
|
import config from '${removeJsExtension(viewPath)}';
|
|
53
38
|
const { js, program } = config;
|
|
@@ -55,28 +40,15 @@ function jsEntry({ viewPath }) {
|
|
|
55
40
|
if (!program) throw new Error('Missing program in config');
|
|
56
41
|
if (!program.init) throw new Error('Program does not look like an elm instance (missing init)');
|
|
57
42
|
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
name: providerProps._componentName,
|
|
61
|
-
version: providerProps._componentVersion,
|
|
62
|
-
baseUrl: providerProps._baseUrl,
|
|
63
|
-
parameters
|
|
64
|
-
}, (err, data) => {
|
|
65
|
-
if (err) {
|
|
66
|
-
return cb(err);
|
|
67
|
-
}
|
|
68
|
-
const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = data.component.props;
|
|
69
|
-
cb(null, rest);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function renderer(model, node) {
|
|
74
|
-
const { _baseUrl, _componentName, _componentVersion, _staticPath, ...props } = model;
|
|
43
|
+
export default function renderer(props, node) {
|
|
44
|
+
const { _baseUrl, _componentName, _componentVersion, _staticPath, ...rest } = props;
|
|
75
45
|
const app = program.init({
|
|
76
46
|
node,
|
|
77
|
-
flags:
|
|
47
|
+
flags: rest
|
|
78
48
|
})
|
|
79
49
|
|
|
50
|
+
${providerFunctions}
|
|
51
|
+
|
|
80
52
|
if (app.ports && app.ports.getData) {
|
|
81
53
|
app.ports.getData.subscribe(parameters => {
|
|
82
54
|
getData({ _baseUrl, _componentName, _componentVersion }, parameters, (err, data) => {
|
|
@@ -94,14 +66,12 @@ function jsEntry({ viewPath }) {
|
|
|
94
66
|
|
|
95
67
|
return app;
|
|
96
68
|
}
|
|
97
|
-
|
|
98
|
-
export default renderer;
|
|
99
69
|
`;
|
|
100
70
|
}
|
|
101
|
-
function elmOCProviderTemplate({ viewPath }) {
|
|
71
|
+
function elmOCProviderTemplate({ viewPath, providerFunctions }) {
|
|
102
72
|
if (viewPath.endsWith('.elm')) {
|
|
103
|
-
return elmEntry({ viewPath });
|
|
73
|
+
return elmEntry({ viewPath, providerFunctions });
|
|
104
74
|
}
|
|
105
|
-
return jsEntry({ viewPath });
|
|
75
|
+
return jsEntry({ viewPath, providerFunctions });
|
|
106
76
|
}
|
|
107
77
|
exports.default = elmOCProviderTemplate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-template-elm-compiler",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Compiler for the Elm OC template",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"elm": "^0.19.1-6",
|
|
33
33
|
"oc-template-elm": "^0.1.0",
|
|
34
|
-
"oc-vite-compiler": "^3.
|
|
34
|
+
"oc-vite-compiler": "^3.3.0",
|
|
35
35
|
"vite-plugin-elm": "^2.8.0"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|