@polylith/builder 0.0.19 → 0.0.20
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/App.js +10 -2
- package/package.json +1 -1
- package/plugin-features.js +34 -0
package/App.js
CHANGED
|
@@ -47,6 +47,8 @@ export class App {
|
|
|
47
47
|
|
|
48
48
|
constructor(name, root, index , dest) {
|
|
49
49
|
root = fixPath(root);
|
|
50
|
+
this.root = root;
|
|
51
|
+
|
|
50
52
|
var filename = path.posix.join(root, index);
|
|
51
53
|
this.sourcePath = path.posix.dirname(filename);
|
|
52
54
|
this.destination = path.posix.join(root, dest);
|
|
@@ -54,7 +56,7 @@ export class App {
|
|
|
54
56
|
this.name = name;
|
|
55
57
|
this.index = index;
|
|
56
58
|
this.loadables = [];
|
|
57
|
-
this.
|
|
59
|
+
this.featureIndexes = [];
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
static fileToPath(filename) {
|
|
@@ -66,9 +68,14 @@ export class App {
|
|
|
66
68
|
* Call this method to generate a path relative to the src directory
|
|
67
69
|
*
|
|
68
70
|
* @param {String} path
|
|
71
|
+
* @returns the path relative to the source root.
|
|
69
72
|
*/
|
|
70
73
|
rootPath(path) {
|
|
74
|
+
var idx = path.indexOf(this.sourcePath);
|
|
75
|
+
if (idx === 0) path.splice(0, length(this.sourcePath));
|
|
76
|
+
if (path[0] === '/') path.splice(0, 1);
|
|
71
77
|
|
|
78
|
+
return './' + path;
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
setHtmlTemplate(template, target) {
|
|
@@ -98,7 +105,7 @@ export class App {
|
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
107
|
|
|
101
|
-
if (indexExists) this.featureIndexes.push(indexPath);
|
|
108
|
+
if (indexExists) this.featureIndexes.push(this.rootPath(indexPath));
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
async buildFeatures() {
|
|
@@ -146,6 +153,7 @@ export class App {
|
|
|
146
153
|
presets: ['@babel/preset-react'],
|
|
147
154
|
}),
|
|
148
155
|
loader(this.loadables),
|
|
156
|
+
features(this.featureIndexes),
|
|
149
157
|
html({
|
|
150
158
|
include: path.join(this.sourcePath, "**/*.html"),
|
|
151
159
|
}),
|
package/package.json
CHANGED
package/plugin-features.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function makeSource(features) {
|
|
2
|
+
|
|
3
|
+
var importStatements = '';
|
|
4
|
+
features.forEach(function(feature) {
|
|
5
|
+
importStatements += `import from '${feature}'\n`;
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
var source = `${importStatements}`
|
|
9
|
+
|
|
10
|
+
console.log(source);
|
|
11
|
+
return source;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export default function features(features) {
|
|
16
|
+
return {
|
|
17
|
+
name: 'features',
|
|
18
|
+
|
|
19
|
+
resolveId (source, _, third) {
|
|
20
|
+
if (source === '@polylith/features') {
|
|
21
|
+
return source;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
load (id) {
|
|
27
|
+
if (id === '@polylith/features') {
|
|
28
|
+
return makeSource(features);
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|