@polylith/builder 0.1.17 → 0.1.19
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 +140 -18
- package/ConfigApp.js +3 -1
- package/ConfigFeature.js +7 -5
- package/package.json +2 -3
package/App.js
CHANGED
|
@@ -10,9 +10,7 @@ import svgr from '@svgr/rollup'
|
|
|
10
10
|
import html from 'rollup-plugin-html';
|
|
11
11
|
import livereload from 'rollup-plugin-livereload';
|
|
12
12
|
import styles from "rollup-plugin-styles";
|
|
13
|
-
import
|
|
14
|
-
import globals from 'rollup-plugin-node-globals';
|
|
15
|
-
|
|
13
|
+
import nodePolyfills from 'rollup-plugin-polyfill-node';
|
|
16
14
|
import loader from './plugin-loader.js';
|
|
17
15
|
import mainHTML from './plugin-main-html.js';
|
|
18
16
|
import features from './plugin-features.js';
|
|
@@ -32,14 +30,22 @@ export default class App {
|
|
|
32
30
|
* Construct the app object.
|
|
33
31
|
*
|
|
34
32
|
* @param {String} name a name for the app
|
|
35
|
-
* @param {
|
|
33
|
+
* @param {Object} config
|
|
34
|
+
* @property {String} root the full path to the root directory of the project.
|
|
36
35
|
* All other paths will be relative to this path.
|
|
37
|
-
* @
|
|
36
|
+
* @proprty {String} index the relative path to the main source file from the
|
|
38
37
|
* root. All source paths will be assumed to be relative to this path.
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
38
|
+
* @property {String} dest the relative path to the destination folder from
|
|
39
|
+
* the root for rolled up files
|
|
40
|
+
* @property {String} spec the relative path to the testing source file from
|
|
41
|
+
* the root. All source paths will be assumed to be relative to this
|
|
42
|
+
* path.
|
|
43
|
+
* @property {String} testDest the relative path to the testing destination
|
|
44
|
+
* folder from the root for rolled up files
|
|
41
45
|
*/
|
|
42
|
-
constructor(name,
|
|
46
|
+
constructor(name, config) {
|
|
47
|
+
var {root, index, dest, spec, testDest=''} = config;
|
|
48
|
+
|
|
43
49
|
root = forceToPosix(root);
|
|
44
50
|
this.root = root;
|
|
45
51
|
this.routerRoot = '/' + name;
|
|
@@ -47,10 +53,13 @@ export default class App {
|
|
|
47
53
|
var filename = path.posix.join(root, index);
|
|
48
54
|
this.sourcePath = path.posix.dirname(filename);
|
|
49
55
|
this.destPath = path.posix.join(root, dest);
|
|
56
|
+
this.testPath = path.posix.join(root, testDest);
|
|
50
57
|
|
|
51
58
|
this.name = name;
|
|
52
59
|
this.index = index;
|
|
60
|
+
this.spec = spec;
|
|
53
61
|
this.fullIndexPath = path.posix.join(root, index);
|
|
62
|
+
this.fullSpecPath = spec ? path.posix.join(root, spec) : undefined;
|
|
54
63
|
|
|
55
64
|
this.loadables = [];
|
|
56
65
|
this.features = [];
|
|
@@ -417,12 +426,13 @@ export default class App {
|
|
|
417
426
|
*
|
|
418
427
|
* @param {String} root path relative to the source directory for the
|
|
419
428
|
* feature to load.
|
|
429
|
+
* @param {Boolean} forTest true if building test features
|
|
420
430
|
*/
|
|
421
|
-
async loadFeature(root) {
|
|
431
|
+
async loadFeature(root, forTest) {
|
|
422
432
|
var featurePath = path.posix.join(this.sourcePath, root);
|
|
423
|
-
var indexPath = path.posix.join(featurePath, 'index.js')
|
|
424
|
-
var builderPath = path.posix.join(featurePath, 'build.js');
|
|
425
|
-
var jsonPath = path.posix.join(featurePath, 'build.json');
|
|
433
|
+
var indexPath = path.posix.join(featurePath, forTest ? 'spec.js' : 'index.js')
|
|
434
|
+
var builderPath = path.posix.join(featurePath, forTest ? 'test.js' : 'build.js');
|
|
435
|
+
var jsonPath = path.posix.join(featurePath, forTest ? 'test.json' : 'build.json');
|
|
426
436
|
|
|
427
437
|
var indexExists = await fileExists(indexPath);
|
|
428
438
|
var builderExists = await fileExists(builderPath);
|
|
@@ -445,7 +455,7 @@ export default class App {
|
|
|
445
455
|
let content = JSON.parse(await readFile(jsonPath));
|
|
446
456
|
|
|
447
457
|
let builder = new ConfigFeature(content, root);
|
|
448
|
-
await builder.build(this)
|
|
458
|
+
await builder.build(this, forTest)
|
|
449
459
|
} catch (e) {
|
|
450
460
|
console.error(e);
|
|
451
461
|
throw e;
|
|
@@ -463,6 +473,15 @@ export default class App {
|
|
|
463
473
|
}
|
|
464
474
|
}
|
|
465
475
|
|
|
476
|
+
async testFeatures() {
|
|
477
|
+
var features = this.features;
|
|
478
|
+
|
|
479
|
+
for (let feature of features) {
|
|
480
|
+
await(this.loadFeature(feature, true));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
|
|
466
485
|
/**
|
|
467
486
|
*
|
|
468
487
|
* @param {String} root the relative path from the source root to the
|
|
@@ -529,12 +548,94 @@ export default class App {
|
|
|
529
548
|
}
|
|
530
549
|
|
|
531
550
|
/**
|
|
532
|
-
*
|
|
551
|
+
* Call this method to create the configuration for testing the app
|
|
552
|
+
*
|
|
553
|
+
* @returns {Object} rollup configuration object
|
|
554
|
+
*/
|
|
555
|
+
|
|
556
|
+
async generateTestConfiguration() {
|
|
557
|
+
var input = [this.fullSpecPath];
|
|
558
|
+
|
|
559
|
+
// using a for loop because we are making an async call
|
|
560
|
+
for (let loadable of this.loadables) {
|
|
561
|
+
// find all the css files for the loadables
|
|
562
|
+
await this.findLoadableCss(loadable);
|
|
563
|
+
input.push(loadable.index);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
var manualChunks = this.getManualChunks();
|
|
567
|
+
|
|
568
|
+
var plugins = [
|
|
569
|
+
resolve.nodeResolve({
|
|
570
|
+
preferBuiltins: true,
|
|
571
|
+
browser: true,
|
|
572
|
+
extensions: ['.js', '.jsx']
|
|
573
|
+
}),
|
|
574
|
+
commonjs(),
|
|
575
|
+
nodePolyfills(),
|
|
576
|
+
rollupJson(),
|
|
577
|
+
jsconfig(this.root),
|
|
578
|
+
babel({
|
|
579
|
+
presets: ['@babel/preset-react'],
|
|
580
|
+
babelHelpers: 'bundled',
|
|
581
|
+
}),
|
|
582
|
+
svgr({svgo: false}),
|
|
583
|
+
loadConfigs(this.configs),
|
|
584
|
+
loader(this.loadables),
|
|
585
|
+
features(this.featureIndexes),
|
|
586
|
+
styles(),
|
|
587
|
+
resources(this.name, this.files)
|
|
588
|
+
];
|
|
589
|
+
|
|
590
|
+
var config = {
|
|
591
|
+
input : {
|
|
592
|
+
input: input,
|
|
593
|
+
plugins: plugins,
|
|
594
|
+
},
|
|
595
|
+
output : {
|
|
596
|
+
output : {
|
|
597
|
+
sourcemap: true,
|
|
598
|
+
dir : this.testPath,
|
|
599
|
+
format: 'es',
|
|
600
|
+
assetFileNames: function(chunkInfo) {
|
|
601
|
+
return '[name]-[hash][extname]';
|
|
602
|
+
},
|
|
603
|
+
entryFileNames: function(chunkInfo) {
|
|
604
|
+
var entry = forceToPosix(chunkInfo.facadeModuleId);
|
|
605
|
+
var found = this.loadables.find(function(loadable) {
|
|
606
|
+
return loadable.index === entry;
|
|
607
|
+
}, this);
|
|
608
|
+
var exists = Boolean(found);
|
|
609
|
+
|
|
610
|
+
if (exists) return (`${found.name}.js`);
|
|
611
|
+
if (entry === this.fullSpecPath) {
|
|
612
|
+
return `${this.name}.js`;
|
|
613
|
+
}
|
|
614
|
+
return '[name].js';
|
|
615
|
+
}.bind(this),
|
|
616
|
+
manualChunks: manualChunks,
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
watch : {
|
|
620
|
+
watch: {
|
|
621
|
+
buildDelay: 250,
|
|
622
|
+
exclude: 'node_modules/**',
|
|
623
|
+
clearScreen: true,
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
return config;
|
|
629
|
+
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Call this method to create the configuration for building the app
|
|
533
634
|
*
|
|
534
635
|
* @returns {Object} rollup configuration object
|
|
535
636
|
*/
|
|
536
637
|
|
|
537
|
-
async
|
|
638
|
+
async generateBuildConfiguration() {
|
|
538
639
|
var input = [this.fullIndexPath];
|
|
539
640
|
|
|
540
641
|
// using a for loop because we are making an async call
|
|
@@ -558,8 +659,7 @@ export default class App {
|
|
|
558
659
|
extensions: ['.js', '.jsx']
|
|
559
660
|
}),
|
|
560
661
|
commonjs(),
|
|
561
|
-
|
|
562
|
-
builtins(),
|
|
662
|
+
nodePolyfills(),
|
|
563
663
|
rollupJson(),
|
|
564
664
|
jsconfig(this.root),
|
|
565
665
|
babel({
|
|
@@ -630,14 +730,35 @@ export default class App {
|
|
|
630
730
|
return config;
|
|
631
731
|
}
|
|
632
732
|
|
|
733
|
+
async test() {
|
|
734
|
+
this.testing = true;
|
|
735
|
+
if (!this.testPath || !this.spec) {
|
|
736
|
+
console.error('Building tests is not properly configured.')
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
await this.testFeatures();
|
|
741
|
+
this.config = await this.generateTestConfiguration();
|
|
742
|
+
|
|
743
|
+
const bundle = await rollup.rollup(this.config.input);
|
|
744
|
+
await bundle.generate(this.config.output);
|
|
745
|
+
await bundle.write(this.config.output);
|
|
746
|
+
await bundle.close();
|
|
747
|
+
|
|
748
|
+
return true;
|
|
749
|
+
}
|
|
750
|
+
|
|
633
751
|
async build() {
|
|
752
|
+
this.testing = false;
|
|
634
753
|
await this.buildFeatures();
|
|
635
|
-
this.config = await this.
|
|
754
|
+
this.config = await this.generateBuildConfiguration();
|
|
636
755
|
|
|
637
756
|
const bundle = await rollup.rollup(this.config.input);
|
|
638
757
|
await bundle.generate(this.config.output);
|
|
639
758
|
await bundle.write(this.config.output);
|
|
640
759
|
await bundle.close();
|
|
760
|
+
|
|
761
|
+
return true;
|
|
641
762
|
}
|
|
642
763
|
|
|
643
764
|
watch() {
|
|
@@ -666,6 +787,7 @@ export default class App {
|
|
|
666
787
|
// console.log(event);
|
|
667
788
|
}
|
|
668
789
|
}.bind(this));
|
|
790
|
+
return true;
|
|
669
791
|
}
|
|
670
792
|
|
|
671
793
|
}
|
package/ConfigApp.js
CHANGED
|
@@ -11,8 +11,10 @@ export default class ConfigApp extends App {
|
|
|
11
11
|
var name = config.name || 'unnamed';
|
|
12
12
|
var index = config.index || 'src/index.js';
|
|
13
13
|
var dest = config.dest || 'dist';
|
|
14
|
+
var spec = config.spec;
|
|
15
|
+
var testDest = config.testDest;
|
|
14
16
|
|
|
15
|
-
super(name, root, index, dest);
|
|
17
|
+
super(name, {root, index, dest, spec, testDest});
|
|
16
18
|
this.config = config;
|
|
17
19
|
|
|
18
20
|
if (!config.template || !config.template.source) throw new Error('html source not defined in config file');
|
package/ConfigFeature.js
CHANGED
|
@@ -19,13 +19,15 @@ export default class ConfigFeature extends Feature {
|
|
|
19
19
|
*
|
|
20
20
|
* @param {App} app the application for the feature
|
|
21
21
|
*/
|
|
22
|
-
async build(app) {
|
|
22
|
+
async build(app, forTest) {
|
|
23
23
|
var config = this.config;
|
|
24
24
|
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if (!forTest) {
|
|
26
|
+
if (config.loadables && Array.isArray(config.loadables)) {
|
|
27
|
+
for (let loadable of config.loadables) {
|
|
28
|
+
if (loadable.name && loadable.index) {
|
|
29
|
+
await app.addLoadable(this.root, loadable.name, path.join(this.root, loadable.index), loadable.prefix, loadable.css);
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polylith/builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "The polylith builder",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
"rollup-plugin-html": "^0.2.1",
|
|
27
27
|
"rollup-plugin-jsx": "^1.0.3",
|
|
28
28
|
"rollup-plugin-livereload": "^2.0.5",
|
|
29
|
-
"rollup-plugin-node
|
|
30
|
-
"rollup-plugin-node-globals": "^1.4.0",
|
|
29
|
+
"rollup-plugin-polyfill-node": "^0.11.0",
|
|
31
30
|
"rollup-plugin-styles": "^4.0.0",
|
|
32
31
|
"sass": "^1.43.4"
|
|
33
32
|
}
|