oc-template-elm-compiler 0.2.1 → 0.2.3
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
|
+
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
|
}
|
|
@@ -44,10 +31,12 @@ function elmEntry({ viewPath }) {
|
|
|
44
31
|
return app;
|
|
45
32
|
}
|
|
46
33
|
|
|
34
|
+
renderer.component = Elm["${extractName(viewPath)}"];
|
|
35
|
+
|
|
47
36
|
export default renderer;
|
|
48
37
|
`;
|
|
49
38
|
}
|
|
50
|
-
function jsEntry({ viewPath }) {
|
|
39
|
+
function jsEntry({ viewPath, providerFunctions }) {
|
|
51
40
|
return `
|
|
52
41
|
import config from '${removeJsExtension(viewPath)}';
|
|
53
42
|
const { js, program } = config;
|
|
@@ -55,28 +44,15 @@ function jsEntry({ viewPath }) {
|
|
|
55
44
|
if (!program) throw new Error('Missing program in config');
|
|
56
45
|
if (!program.init) throw new Error('Program does not look like an elm instance (missing init)');
|
|
57
46
|
|
|
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;
|
|
47
|
+
function renderer(props, node) {
|
|
48
|
+
const { _baseUrl, _componentName, _componentVersion, _staticPath, ...rest } = props;
|
|
75
49
|
const app = program.init({
|
|
76
50
|
node,
|
|
77
|
-
flags:
|
|
51
|
+
flags: rest
|
|
78
52
|
})
|
|
79
53
|
|
|
54
|
+
${providerFunctions}
|
|
55
|
+
|
|
80
56
|
if (app.ports && app.ports.getData) {
|
|
81
57
|
app.ports.getData.subscribe(parameters => {
|
|
82
58
|
getData({ _baseUrl, _componentName, _componentVersion }, parameters, (err, data) => {
|
|
@@ -95,13 +71,15 @@ function jsEntry({ viewPath }) {
|
|
|
95
71
|
return app;
|
|
96
72
|
}
|
|
97
73
|
|
|
74
|
+
renderer.component = program;
|
|
75
|
+
|
|
98
76
|
export default renderer;
|
|
99
77
|
`;
|
|
100
78
|
}
|
|
101
|
-
function elmOCProviderTemplate({ viewPath }) {
|
|
79
|
+
function elmOCProviderTemplate({ viewPath, providerFunctions }) {
|
|
102
80
|
if (viewPath.endsWith('.elm')) {
|
|
103
|
-
return elmEntry({ viewPath });
|
|
81
|
+
return elmEntry({ viewPath, providerFunctions });
|
|
104
82
|
}
|
|
105
|
-
return jsEntry({ viewPath });
|
|
83
|
+
return jsEntry({ viewPath, providerFunctions });
|
|
106
84
|
}
|
|
107
85
|
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.3",
|
|
4
4
|
"description": "Compiler for the Elm OC template",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"elm": "^0.19.1-6",
|
|
33
|
-
"oc-template-elm": "
|
|
34
|
-
"oc-vite-compiler": "^3.
|
|
33
|
+
"oc-template-elm": "0.1.1",
|
|
34
|
+
"oc-vite-compiler": "^3.4.0",
|
|
35
35
|
"vite-plugin-elm": "^2.8.0"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|