@polylith/builder 0.0.33 → 0.0.36
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 +92 -46
- package/ConfigFeature.js +6 -5
- package/{loaderTemplate.js → loaderTemplate.txt} +3 -0
- package/package.json +2 -1
- package/plugin-jsconfig.js +3 -2
- package/plugin-loader.js +16 -17
- package/utils.js +20 -0
package/App.js
CHANGED
|
@@ -6,6 +6,7 @@ import { babel } from '@rollup/plugin-babel';
|
|
|
6
6
|
import * as resolve from '@rollup/plugin-node-resolve';
|
|
7
7
|
import commonjs from '@rollup/plugin-commonjs';
|
|
8
8
|
import html from 'rollup-plugin-html';
|
|
9
|
+
import livereload from 'rollup-plugin-livereload';
|
|
9
10
|
|
|
10
11
|
import loader from './plugin-loader.js';
|
|
11
12
|
import mainHTML from './plugin-main-html.js';
|
|
@@ -67,7 +68,9 @@ export default class App {
|
|
|
67
68
|
this.configs = {};
|
|
68
69
|
this.manualChunkType = 'function';
|
|
69
70
|
this.manualChunks = [];
|
|
70
|
-
this.files = new Files(this.sourcePath, this.destPath)
|
|
71
|
+
this.files = new Files(this.sourcePath, this.destPath);
|
|
72
|
+
this.cssFiles = [];
|
|
73
|
+
this.liveReload = true;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
static fileToPath(filename) {
|
|
@@ -106,6 +109,9 @@ export default class App {
|
|
|
106
109
|
return './' + path;
|
|
107
110
|
}
|
|
108
111
|
|
|
112
|
+
setLiveReload(on) {
|
|
113
|
+
this.liveReload = on;
|
|
114
|
+
}
|
|
109
115
|
setHtmlTemplate(source, destination) {
|
|
110
116
|
this.htmlTemplate = {source: source, destination: destination};
|
|
111
117
|
}
|
|
@@ -114,6 +120,25 @@ export default class App {
|
|
|
114
120
|
this.configs[root] = config;
|
|
115
121
|
}
|
|
116
122
|
|
|
123
|
+
async addMainCss(specs) {
|
|
124
|
+
var files = new Files(this.sourcePath, this.destPath)
|
|
125
|
+
|
|
126
|
+
// get the file paths
|
|
127
|
+
specs.forEach(function(spec) {
|
|
128
|
+
files.addCopySpec('', spec);
|
|
129
|
+
}, this)
|
|
130
|
+
|
|
131
|
+
var expanded = await files.findAllFiles();
|
|
132
|
+
var keys = Object.keys(expanded);
|
|
133
|
+
keys.forEach(function(key){
|
|
134
|
+
var file = expanded[key];
|
|
135
|
+
this.cssFiles.push(file.uri)
|
|
136
|
+
}, this);
|
|
137
|
+
|
|
138
|
+
// now add them to be copied
|
|
139
|
+
this.addResources('', specs);
|
|
140
|
+
}
|
|
141
|
+
|
|
117
142
|
/**
|
|
118
143
|
* Call this method to add a list of resources that will be moved to the
|
|
119
144
|
* destination path when the application is built. This will either be a
|
|
@@ -124,7 +149,7 @@ export default class App {
|
|
|
124
149
|
* @param {String} root the path to the origin of the caller. Paths in
|
|
125
150
|
* the spec are assumed to be relative to this.
|
|
126
151
|
*/
|
|
127
|
-
addResources(
|
|
152
|
+
addResources(root, resourceSpecs) {
|
|
128
153
|
resourceSpecs.forEach(function(spec) {
|
|
129
154
|
this.files.addCopySpec(root, spec);
|
|
130
155
|
}, this)
|
|
@@ -140,7 +165,7 @@ export default class App {
|
|
|
140
165
|
* If present that json will be loaded and used to build the feature.
|
|
141
166
|
*
|
|
142
167
|
* If that is not found it will look for an index.js file. and if found it
|
|
143
|
-
* will add that to the list
|
|
168
|
+
* will add that to the list of feature index files which will be
|
|
144
169
|
* automatically imported when the built code imports the @polylith/features
|
|
145
170
|
* module
|
|
146
171
|
*
|
|
@@ -326,23 +351,37 @@ export default class App {
|
|
|
326
351
|
* this loadable. When the loadable has been loaded, the start and
|
|
327
352
|
* ready methods will be called on all services starting with this
|
|
328
353
|
* prefix.
|
|
354
|
+
* @param {Array<CopySpec>} [css] if supplied it will be a copy spec of the
|
|
355
|
+
* css files that will included when the module is loaded
|
|
329
356
|
*/
|
|
330
|
-
async addLoadable(name, main, prefix, css) {
|
|
357
|
+
async addLoadable(root, name, main, prefix, css) {
|
|
331
358
|
// expand css specs
|
|
332
|
-
var
|
|
333
|
-
|
|
334
|
-
files.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
359
|
+
var cssUris = css ? [] : undefined;
|
|
360
|
+
if (css) {
|
|
361
|
+
var files = new Files(this.sourcePath, this.destPath)
|
|
362
|
+
css.forEach(function(spec) {
|
|
363
|
+
files.addCopySpec(root, spec);
|
|
364
|
+
}, this)
|
|
365
|
+
var expanded = await files.findAllFiles();
|
|
366
|
+
var keys = Object.keys(expanded);
|
|
367
|
+
keys.forEach(function(key){
|
|
368
|
+
var file = expanded[key];
|
|
369
|
+
cssUris.push(file.uri)
|
|
370
|
+
}, this)
|
|
371
|
+
}
|
|
343
372
|
|
|
344
373
|
var dest = path.posix.join(this.sourcePath, main);
|
|
345
|
-
this.loadables.push({name, path: dest, prefix});
|
|
374
|
+
this.loadables.push({name, path: dest, prefix, css: cssUris});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
buildMainCss() {
|
|
379
|
+
var cssTags = '';
|
|
380
|
+
this.cssFiles.forEach(function(uri) {
|
|
381
|
+
cssTags += ` <link rel="stylesheet" href="${uri}"></link>`
|
|
382
|
+
}, this);
|
|
383
|
+
|
|
384
|
+
return cssTags;
|
|
346
385
|
}
|
|
347
386
|
|
|
348
387
|
/**
|
|
@@ -354,8 +393,8 @@ export default class App {
|
|
|
354
393
|
|
|
355
394
|
buildConfiguration() {
|
|
356
395
|
var input = [this.fullIndexPath];
|
|
357
|
-
this.loadables.forEach(function(
|
|
358
|
-
input.push(
|
|
396
|
+
this.loadables.forEach(function(spec) {
|
|
397
|
+
input.push(spec.path);
|
|
359
398
|
});
|
|
360
399
|
|
|
361
400
|
this.variables = {
|
|
@@ -364,34 +403,42 @@ export default class App {
|
|
|
364
403
|
}
|
|
365
404
|
|
|
366
405
|
var manualChunks = this.getManualChunks();
|
|
406
|
+
var mainCss = this.buildMainCss();
|
|
407
|
+
var plugins = [
|
|
408
|
+
resolve.nodeResolve({
|
|
409
|
+
extensions: ['.js', '.jsx']
|
|
410
|
+
}),
|
|
411
|
+
commonjs(),
|
|
412
|
+
babel({
|
|
413
|
+
presets: ['@babel/preset-react'],
|
|
414
|
+
babelHelpers: 'bundled',
|
|
415
|
+
}),
|
|
416
|
+
loader(this.loadables),
|
|
417
|
+
features(this.featureIndexes),
|
|
418
|
+
jsconfig(this.root),
|
|
419
|
+
html({
|
|
420
|
+
include: path.join(this.sourcePath, "**/*.html"),
|
|
421
|
+
}),
|
|
422
|
+
styles(),
|
|
423
|
+
mainHTML({
|
|
424
|
+
root: this.root,
|
|
425
|
+
source: this.htmlTemplate.source,
|
|
426
|
+
destination: this.htmlTemplate.destination,
|
|
427
|
+
replaceVars: {mainCss: mainCss},
|
|
428
|
+
}),
|
|
429
|
+
resources(this.name, this.files)
|
|
430
|
+
];
|
|
431
|
+
|
|
432
|
+
if (this.liveReload) {
|
|
433
|
+
plugins.push(
|
|
434
|
+
liveReload(this.destPath)
|
|
435
|
+
)
|
|
436
|
+
}
|
|
367
437
|
|
|
368
438
|
var config = {
|
|
369
439
|
input : {
|
|
370
440
|
input: input,
|
|
371
|
-
plugins:
|
|
372
|
-
resolve.nodeResolve({
|
|
373
|
-
extensions: ['.js', '.jsx']
|
|
374
|
-
}),
|
|
375
|
-
commonjs(),
|
|
376
|
-
babel({
|
|
377
|
-
presets: ['@babel/preset-react'],
|
|
378
|
-
babelHelpers: 'bundled',
|
|
379
|
-
}),
|
|
380
|
-
loader(this.loadables),
|
|
381
|
-
features(this.featureIndexes),
|
|
382
|
-
jsconfig(this.root),
|
|
383
|
-
html({
|
|
384
|
-
include: path.join(this.sourcePath, "**/*.html"),
|
|
385
|
-
}),
|
|
386
|
-
styles(),
|
|
387
|
-
mainHTML({
|
|
388
|
-
root: this.root,
|
|
389
|
-
source: this.htmlTemplate.source,
|
|
390
|
-
destination: this.htmlTemplate.destination,
|
|
391
|
-
replaceVars: {},
|
|
392
|
-
}),
|
|
393
|
-
resources(this.name, this.files)
|
|
394
|
-
],
|
|
441
|
+
plugins: plugins,
|
|
395
442
|
},
|
|
396
443
|
output : {
|
|
397
444
|
output : {
|
|
@@ -458,14 +505,13 @@ export default class App {
|
|
|
458
505
|
}
|
|
459
506
|
|
|
460
507
|
if (event.code === 'BUNDLE_START') {
|
|
461
|
-
|
|
462
|
-
console.log(event);
|
|
508
|
+
// console.log(event);
|
|
463
509
|
}
|
|
464
510
|
|
|
465
511
|
if (event.code === 'BUNDLE_END') {
|
|
466
|
-
|
|
467
|
-
console.log(event);
|
|
512
|
+
// console.log(event);
|
|
468
513
|
}
|
|
469
514
|
}.bind(this));
|
|
470
515
|
}
|
|
516
|
+
|
|
471
517
|
}
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polylith/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"description": "The polylith builder",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"rollup": "^2.58.0",
|
|
24
24
|
"rollup-plugin-html": "^0.2.1",
|
|
25
25
|
"rollup-plugin-jsx": "^1.0.3",
|
|
26
|
+
"rollup-plugin-livereload": "^2.0.5",
|
|
26
27
|
"rollup-plugin-styles": "^4.0.0",
|
|
27
28
|
"sass": "^1.43.4"
|
|
28
29
|
}
|
package/plugin-jsconfig.js
CHANGED
|
@@ -83,7 +83,7 @@ async function findPathMatch(base, source, paths) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
export default function
|
|
86
|
+
export default function jsconfig(root) {
|
|
87
87
|
var jsConfig;
|
|
88
88
|
var basePath;
|
|
89
89
|
var paths;
|
|
@@ -111,7 +111,7 @@ export default function features(root) {
|
|
|
111
111
|
|
|
112
112
|
|
|
113
113
|
return {
|
|
114
|
-
name: '
|
|
114
|
+
name: 'jsconfig',
|
|
115
115
|
|
|
116
116
|
async resolveId (source, importer, options) {
|
|
117
117
|
source = fixPath(source);
|
|
@@ -125,6 +125,7 @@ export default function features(root) {
|
|
|
125
125
|
|
|
126
126
|
if (basePath) {
|
|
127
127
|
var tryName = path.join(root, basePath, source);
|
|
128
|
+
console.log('trying', tryName)
|
|
128
129
|
if (await fileExists(tryName)) {
|
|
129
130
|
previouslyMatched[source] = tryName;
|
|
130
131
|
return tryName;
|
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
|
+
}
|