@polylith/builder 0.0.33 → 0.0.34
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 +53 -18
- package/ConfigFeature.js +6 -5
- package/{loaderTemplate.js → loaderTemplate.txt} +3 -0
- package/package.json +1 -1
- package/plugin-loader.js +16 -17
- package/utils.js +20 -0
package/App.js
CHANGED
|
@@ -67,7 +67,8 @@ export default class App {
|
|
|
67
67
|
this.configs = {};
|
|
68
68
|
this.manualChunkType = 'function';
|
|
69
69
|
this.manualChunks = [];
|
|
70
|
-
this.files = new Files(this.sourcePath, this.destPath)
|
|
70
|
+
this.files = new Files(this.sourcePath, this.destPath);
|
|
71
|
+
this.cssFiles = [];
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
static fileToPath(filename) {
|
|
@@ -114,6 +115,25 @@ export default class App {
|
|
|
114
115
|
this.configs[root] = config;
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
async addMainCss(specs) {
|
|
119
|
+
var files = new Files(this.sourcePath, this.destPath)
|
|
120
|
+
|
|
121
|
+
// get the file paths
|
|
122
|
+
specs.forEach(function(spec) {
|
|
123
|
+
files.addCopySpec('', spec);
|
|
124
|
+
}, this)
|
|
125
|
+
|
|
126
|
+
var expanded = await files.findAllFiles();
|
|
127
|
+
var keys = Object.keys(expanded);
|
|
128
|
+
keys.forEach(function(key){
|
|
129
|
+
var file = expanded[key];
|
|
130
|
+
this.cssFiles.push(file.uri)
|
|
131
|
+
}, this);
|
|
132
|
+
|
|
133
|
+
// now add them to be copied
|
|
134
|
+
this.addResources('', specs);
|
|
135
|
+
}
|
|
136
|
+
|
|
117
137
|
/**
|
|
118
138
|
* Call this method to add a list of resources that will be moved to the
|
|
119
139
|
* destination path when the application is built. This will either be a
|
|
@@ -124,7 +144,7 @@ export default class App {
|
|
|
124
144
|
* @param {String} root the path to the origin of the caller. Paths in
|
|
125
145
|
* the spec are assumed to be relative to this.
|
|
126
146
|
*/
|
|
127
|
-
addResources(
|
|
147
|
+
addResources(root, resourceSpecs) {
|
|
128
148
|
resourceSpecs.forEach(function(spec) {
|
|
129
149
|
this.files.addCopySpec(root, spec);
|
|
130
150
|
}, this)
|
|
@@ -326,23 +346,37 @@ export default class App {
|
|
|
326
346
|
* this loadable. When the loadable has been loaded, the start and
|
|
327
347
|
* ready methods will be called on all services starting with this
|
|
328
348
|
* prefix.
|
|
349
|
+
* @param {Array<CopySpec>} [css] if supplied it will be a copy spec of the
|
|
350
|
+
* css files that will included when the module is loaded
|
|
329
351
|
*/
|
|
330
|
-
async addLoadable(name, main, prefix, css) {
|
|
352
|
+
async addLoadable(root, name, main, prefix, css) {
|
|
331
353
|
// expand css specs
|
|
332
|
-
var
|
|
333
|
-
|
|
334
|
-
files.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
354
|
+
var cssUris = css ? [] : undefined;
|
|
355
|
+
if (css) {
|
|
356
|
+
var files = new Files(this.sourcePath, this.destPath)
|
|
357
|
+
css.forEach(function(spec) {
|
|
358
|
+
files.addCopySpec(root, spec);
|
|
359
|
+
}, this)
|
|
360
|
+
var expanded = await files.findAllFiles();
|
|
361
|
+
var keys = Object.keys(expanded);
|
|
362
|
+
keys.forEach(function(key){
|
|
363
|
+
var file = expanded[key];
|
|
364
|
+
cssUris.push(file.uri)
|
|
365
|
+
}, this)
|
|
366
|
+
}
|
|
343
367
|
|
|
344
368
|
var dest = path.posix.join(this.sourcePath, main);
|
|
345
|
-
this.loadables.push({name, path: dest, prefix});
|
|
369
|
+
this.loadables.push({name, path: dest, prefix, css: cssUris});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
buildMainCss() {
|
|
374
|
+
var cssTags = '';
|
|
375
|
+
this.cssFiles.forEach(function(uri) {
|
|
376
|
+
cssTags += ` <link rel="stylesheet" href="${uri}"></link>`
|
|
377
|
+
}, this);
|
|
378
|
+
|
|
379
|
+
return cssTags;
|
|
346
380
|
}
|
|
347
381
|
|
|
348
382
|
/**
|
|
@@ -354,8 +388,8 @@ export default class App {
|
|
|
354
388
|
|
|
355
389
|
buildConfiguration() {
|
|
356
390
|
var input = [this.fullIndexPath];
|
|
357
|
-
this.loadables.forEach(function(
|
|
358
|
-
input.push(
|
|
391
|
+
this.loadables.forEach(function(spec) {
|
|
392
|
+
input.push(spec.path);
|
|
359
393
|
});
|
|
360
394
|
|
|
361
395
|
this.variables = {
|
|
@@ -364,6 +398,7 @@ export default class App {
|
|
|
364
398
|
}
|
|
365
399
|
|
|
366
400
|
var manualChunks = this.getManualChunks();
|
|
401
|
+
var mainCss = this.buildMainCss();
|
|
367
402
|
|
|
368
403
|
var config = {
|
|
369
404
|
input : {
|
|
@@ -388,7 +423,7 @@ export default class App {
|
|
|
388
423
|
root: this.root,
|
|
389
424
|
source: this.htmlTemplate.source,
|
|
390
425
|
destination: this.htmlTemplate.destination,
|
|
391
|
-
replaceVars: {},
|
|
426
|
+
replaceVars: {mainCss: mainCss},
|
|
392
427
|
}),
|
|
393
428
|
resources(this.name, this.files)
|
|
394
429
|
],
|
package/ConfigFeature.js
CHANGED
|
@@ -15,21 +15,22 @@ export default class ConfigFeature extends Feature {
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* The application calls the method to build the feature.
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* @param {App} app the application for the feature
|
|
19
20
|
*/
|
|
20
21
|
async build(app) {
|
|
21
22
|
var config = this.config;
|
|
22
23
|
|
|
23
24
|
if (config.loadables && Array.isArray(config.loadables)) {
|
|
24
|
-
config.loadables
|
|
25
|
+
for (let loadable of config.loadables){
|
|
25
26
|
if (loadable.name && loadable.index) {
|
|
26
|
-
app.addLoadable(loadable.name, path.join(this.root, loadable.index), loadable.prefix, loadable.css);
|
|
27
|
+
await app.addLoadable(this.root, loadable.name, path.join(this.root, loadable.index), loadable.prefix, loadable.css);
|
|
27
28
|
}
|
|
28
|
-
}
|
|
29
|
+
}
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
if (config.index) app.addFeatureIndex(path.join(this.root, config.index));
|
|
32
33
|
if (config.config) app.addConfig(config.config, this.root);
|
|
33
|
-
if (config.resources && Array.isArray(config.resources)) app.addResources(
|
|
34
|
+
if (config.resources && Array.isArray(config.resources)) app.addResources(this.root, config.resources);
|
|
34
35
|
}
|
|
35
36
|
}
|
package/package.json
CHANGED
package/plugin-loader.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import path from 'node:path/posix';
|
|
2
2
|
import {readFile, writeFile, stat} from 'node:fs/promises';
|
|
3
|
+
import {fixPath} from './utils.js';
|
|
3
4
|
var templateSource;
|
|
4
5
|
|
|
5
|
-
async function fileExists(path) {
|
|
6
|
-
try {
|
|
7
|
-
await stat(path)
|
|
8
|
-
return true;
|
|
9
|
-
} catch (e) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
6
|
function makeSource(loadables) {
|
|
15
7
|
var loadableSwitches = '';
|
|
16
8
|
|
|
17
|
-
function makeCss() {
|
|
9
|
+
function makeCss(loadable) {
|
|
18
10
|
if (!loadable.css) return '';
|
|
19
11
|
var jsonCss = JSON.stringify(loadable.css);
|
|
20
12
|
return (
|
|
@@ -23,7 +15,7 @@ function makeSource(loadables) {
|
|
|
23
15
|
|
|
24
16
|
}
|
|
25
17
|
|
|
26
|
-
function makeServices() {
|
|
18
|
+
function makeServices(loadable) {
|
|
27
19
|
if (!loadable.prefix) return '';
|
|
28
20
|
return (
|
|
29
21
|
` await registry.start('${loadable.prefix}');`
|
|
@@ -32,8 +24,8 @@ function makeSource(loadables) {
|
|
|
32
24
|
|
|
33
25
|
loadables.forEach(function(loadable) {
|
|
34
26
|
var prefixStr = ';';
|
|
35
|
-
var cssStr = makeCss();
|
|
36
|
-
var serviceStr = makeServices();
|
|
27
|
+
var cssStr = makeCss(loadable);
|
|
28
|
+
var serviceStr = makeServices(loadable);
|
|
37
29
|
|
|
38
30
|
if (loadable.prefix || loadable.css) {
|
|
39
31
|
prefixStr = `
|
|
@@ -44,8 +36,8 @@ ${serviceStr}
|
|
|
44
36
|
`
|
|
45
37
|
}
|
|
46
38
|
|
|
47
|
-
var switchStr =
|
|
48
|
-
case '${loadable.name}':
|
|
39
|
+
var switchStr =
|
|
40
|
+
` case '${loadable.name}':
|
|
49
41
|
promise = import('${loadable.path}')${prefixStr}
|
|
50
42
|
break;
|
|
51
43
|
`
|
|
@@ -54,10 +46,14 @@ ${serviceStr}
|
|
|
54
46
|
|
|
55
47
|
var source = templateSource;
|
|
56
48
|
var source = source.replace('{{SWITCHES}}', loadableSwitches);
|
|
49
|
+
var source = source.replace(/\t/g, ' ');
|
|
50
|
+
|
|
51
|
+
console.log(source);
|
|
57
52
|
|
|
58
53
|
return source;
|
|
59
54
|
}
|
|
60
55
|
|
|
56
|
+
|
|
61
57
|
export default function loader(loadables) {
|
|
62
58
|
return {
|
|
63
59
|
name: 'loader',
|
|
@@ -70,9 +66,12 @@ export default function loader(loadables) {
|
|
|
70
66
|
},
|
|
71
67
|
|
|
72
68
|
async load (id) {
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
var root = path.dirname(fixPath(import.meta.url));
|
|
70
|
+
if (!templateSource) {
|
|
71
|
+
templateSource = await readFile(path.join(root, 'loaderTemplate.txt'), 'utf-8');
|
|
72
|
+
console.log(templateSource);
|
|
75
73
|
}
|
|
74
|
+
|
|
76
75
|
if (id === '@polylith/loader') {
|
|
77
76
|
return makeSource(loadables);
|
|
78
77
|
}
|
package/utils.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path from 'node:path/posix';
|
|
2
|
+
import {readFile, writeFile, stat} from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
export function fixPath(src) {
|
|
5
|
+
src = src.replace('file:', '');
|
|
6
|
+
src = src.replace('///', '');
|
|
7
|
+
src = src.replace(/.:/, '');
|
|
8
|
+
src = src.replace(/\\/g, '/');
|
|
9
|
+
|
|
10
|
+
return src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function fileExists(path) {
|
|
14
|
+
try {
|
|
15
|
+
await stat(path)
|
|
16
|
+
return true;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|