@polylith/builder 0.0.34 → 0.0.37
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 +40 -29
- package/Files.js +4 -0
- package/package.json +2 -1
- package/plugin-copy-resources.js +10 -1
- package/plugin-jsconfig.js +2 -6
- package/plugin-loader.js +0 -3
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';
|
|
@@ -69,6 +70,7 @@ export default class App {
|
|
|
69
70
|
this.manualChunks = [];
|
|
70
71
|
this.files = new Files(this.sourcePath, this.destPath);
|
|
71
72
|
this.cssFiles = [];
|
|
73
|
+
this.liveReload = true;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
static fileToPath(filename) {
|
|
@@ -107,6 +109,9 @@ export default class App {
|
|
|
107
109
|
return './' + path;
|
|
108
110
|
}
|
|
109
111
|
|
|
112
|
+
setLiveReload(on) {
|
|
113
|
+
this.liveReload = on;
|
|
114
|
+
}
|
|
110
115
|
setHtmlTemplate(source, destination) {
|
|
111
116
|
this.htmlTemplate = {source: source, destination: destination};
|
|
112
117
|
}
|
|
@@ -160,7 +165,7 @@ export default class App {
|
|
|
160
165
|
* If present that json will be loaded and used to build the feature.
|
|
161
166
|
*
|
|
162
167
|
* If that is not found it will look for an index.js file. and if found it
|
|
163
|
-
* will add that to the list
|
|
168
|
+
* will add that to the list of feature index files which will be
|
|
164
169
|
* automatically imported when the built code imports the @polylith/features
|
|
165
170
|
* module
|
|
166
171
|
*
|
|
@@ -399,34 +404,41 @@ export default class App {
|
|
|
399
404
|
|
|
400
405
|
var manualChunks = this.getManualChunks();
|
|
401
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
|
+
}
|
|
402
437
|
|
|
403
438
|
var config = {
|
|
404
439
|
input : {
|
|
405
440
|
input: input,
|
|
406
|
-
plugins:
|
|
407
|
-
resolve.nodeResolve({
|
|
408
|
-
extensions: ['.js', '.jsx']
|
|
409
|
-
}),
|
|
410
|
-
commonjs(),
|
|
411
|
-
babel({
|
|
412
|
-
presets: ['@babel/preset-react'],
|
|
413
|
-
babelHelpers: 'bundled',
|
|
414
|
-
}),
|
|
415
|
-
loader(this.loadables),
|
|
416
|
-
features(this.featureIndexes),
|
|
417
|
-
jsconfig(this.root),
|
|
418
|
-
html({
|
|
419
|
-
include: path.join(this.sourcePath, "**/*.html"),
|
|
420
|
-
}),
|
|
421
|
-
styles(),
|
|
422
|
-
mainHTML({
|
|
423
|
-
root: this.root,
|
|
424
|
-
source: this.htmlTemplate.source,
|
|
425
|
-
destination: this.htmlTemplate.destination,
|
|
426
|
-
replaceVars: {mainCss: mainCss},
|
|
427
|
-
}),
|
|
428
|
-
resources(this.name, this.files)
|
|
429
|
-
],
|
|
441
|
+
plugins: plugins,
|
|
430
442
|
},
|
|
431
443
|
output : {
|
|
432
444
|
output : {
|
|
@@ -493,14 +505,13 @@ export default class App {
|
|
|
493
505
|
}
|
|
494
506
|
|
|
495
507
|
if (event.code === 'BUNDLE_START') {
|
|
496
|
-
|
|
497
|
-
console.log(event);
|
|
508
|
+
// console.log(event);
|
|
498
509
|
}
|
|
499
510
|
|
|
500
511
|
if (event.code === 'BUNDLE_END') {
|
|
501
|
-
|
|
502
|
-
console.log(event);
|
|
512
|
+
// console.log(event);
|
|
503
513
|
}
|
|
504
514
|
}.bind(this));
|
|
505
515
|
}
|
|
516
|
+
|
|
506
517
|
}
|
package/Files.js
CHANGED
|
@@ -142,12 +142,16 @@ export default class Files {
|
|
|
142
142
|
* stored in the object variable this.files
|
|
143
143
|
*/
|
|
144
144
|
async findAllFiles() {
|
|
145
|
+
if (this.filesFound) return this.files;
|
|
146
|
+
|
|
145
147
|
// using a for loop here because we are making async calls
|
|
146
148
|
for (let idx = 0; idx < this.specs.length; idx++) {
|
|
147
149
|
let spec = this.specs[idx];
|
|
148
150
|
await this.findFiles(spec);
|
|
149
151
|
}
|
|
150
152
|
|
|
153
|
+
this.filesFound = true;
|
|
154
|
+
|
|
151
155
|
return this.files;
|
|
152
156
|
}
|
|
153
157
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polylith/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
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-copy-resources.js
CHANGED
|
@@ -8,7 +8,16 @@ var copied= {}
|
|
|
8
8
|
*/
|
|
9
9
|
export default function(name, files) {
|
|
10
10
|
return {
|
|
11
|
-
name: "
|
|
11
|
+
name: "copy-resources",
|
|
12
|
+
|
|
13
|
+
async buildStart(){
|
|
14
|
+
var foundFiles = files.findAllFiles();
|
|
15
|
+
var filenames = Object.keys(foundFiles);
|
|
16
|
+
filenames.forEach(function(name) {
|
|
17
|
+
var destFilename = foundFiles[name].destFilename;
|
|
18
|
+
this.addWatchFile(destFilename);
|
|
19
|
+
});
|
|
20
|
+
},
|
|
12
21
|
|
|
13
22
|
async generateBundle(outputOptions, bundleInfo) {
|
|
14
23
|
// assets are not watched, never copy more than once
|
package/plugin-jsconfig.js
CHANGED
|
@@ -63,7 +63,6 @@ async function findPathMatch(base, source, paths) {
|
|
|
63
63
|
if (source.indexOf(base) === 0) return
|
|
64
64
|
// source = source.slice(base.length);
|
|
65
65
|
|
|
66
|
-
console.log('>>>', source)
|
|
67
66
|
for(let patternIdx = 0; patternIdx < patterns.length; patternIdx++) {
|
|
68
67
|
let pattern = patterns[patternIdx];
|
|
69
68
|
let searches = paths[pattern];
|
|
@@ -73,7 +72,6 @@ async function findPathMatch(base, source, paths) {
|
|
|
73
72
|
if (!Array.isArray(searches)) continue;
|
|
74
73
|
for (let searchIdx = 0; searchIdx < searches.length; searchIdx++) {
|
|
75
74
|
var tryName = path.join(base, searches[searchIdx].replace('*', capture));
|
|
76
|
-
console.log('\t..', searches[searchIdx], tryName);
|
|
77
75
|
|
|
78
76
|
if (await fileExists(tryName)) {
|
|
79
77
|
return tryName;
|
|
@@ -83,13 +81,12 @@ async function findPathMatch(base, source, paths) {
|
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
|
|
86
|
-
export default function
|
|
84
|
+
export default function jsconfig(root) {
|
|
87
85
|
var jsConfig;
|
|
88
86
|
var basePath;
|
|
89
87
|
var paths;
|
|
90
88
|
var previouslyMatched = {};
|
|
91
89
|
|
|
92
|
-
console.log('====root', root);
|
|
93
90
|
async function readJsConfig() {
|
|
94
91
|
var jsConfigPath = path.join(root, 'jsconfig.json');
|
|
95
92
|
var exists = await fileExists(jsConfigPath);
|
|
@@ -111,12 +108,11 @@ export default function features(root) {
|
|
|
111
108
|
|
|
112
109
|
|
|
113
110
|
return {
|
|
114
|
-
name: '
|
|
111
|
+
name: 'jsconfig',
|
|
115
112
|
|
|
116
113
|
async resolveId (source, importer, options) {
|
|
117
114
|
source = fixPath(source);
|
|
118
115
|
|
|
119
|
-
// console.log('---', source);
|
|
120
116
|
if (previouslyMatched[source] !== undefined) return previouslyMatched[source];
|
|
121
117
|
previouslyMatched[source] === null;
|
|
122
118
|
|
package/plugin-loader.js
CHANGED
|
@@ -48,8 +48,6 @@ ${serviceStr}
|
|
|
48
48
|
var source = source.replace('{{SWITCHES}}', loadableSwitches);
|
|
49
49
|
var source = source.replace(/\t/g, ' ');
|
|
50
50
|
|
|
51
|
-
console.log(source);
|
|
52
|
-
|
|
53
51
|
return source;
|
|
54
52
|
}
|
|
55
53
|
|
|
@@ -69,7 +67,6 @@ export default function loader(loadables) {
|
|
|
69
67
|
var root = path.dirname(fixPath(import.meta.url));
|
|
70
68
|
if (!templateSource) {
|
|
71
69
|
templateSource = await readFile(path.join(root, 'loaderTemplate.txt'), 'utf-8');
|
|
72
|
-
console.log(templateSource);
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
if (id === '@polylith/loader') {
|