Skip to content

Commit e6cf3b1

Browse files
committed
WIP deferred engine load!
part of #610 part of the merge of #608 most unit tests working, only a few left - due to me hanging a property off the engine that @geoffp was not doing. still need to see how it behaves during actual builds
1 parent 457ed48 commit e6cf3b1

31 files changed

+516
-441
lines changed

.eslintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
"space-infix-ops": 1,
8484
"valid-typeof": 2,
8585
"vars-on-top": 0,
86-
"wrap-iife": [2, "inside"]
86+
"wrap-iife": [2, "inside"],
87+
"prefer-const": ["error", {
88+
"destructuring": "any",
89+
"ignoreReadBeforeAssign": false
90+
}]
8791
}
8892
}

core/lib/annotation_exporter.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
"use strict";
1+
'use strict';
2+
const path = require('path');
3+
const glob = require('glob');
4+
const fs = require('fs-extra');
5+
const JSON5 = require('json5');
6+
const _ = require('lodash');
7+
const mp = require('./markdown_parser');
28

3-
var path = require('path'),
4-
glob = require('glob'),
5-
fs = require('fs-extra'),
6-
JSON5 = require('json5'),
7-
_ = require('lodash'),
8-
mp = require('./markdown_parser');
9+
const annotations_exporter = function (pl) {
910

10-
var annotations_exporter = function (pl) {
11-
12-
var paths = pl.config.paths;
11+
const paths = pl.config.paths;
12+
let oldAnnotations;
1313

1414
/*
1515
Returns the array of comments that used to be wrapped in raw JS.
1616
*/
1717
function parseAnnotationsJS() {
1818
//attempt to read the file
1919
try {
20-
var oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8');
20+
oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8');
2121
} catch (ex) {
2222
if (pl.config.debug) {
2323
console.log('annotations.js file missing from ' + paths.source.annotations + '. This may be expected.');
@@ -40,8 +40,8 @@ var annotations_exporter = function (pl) {
4040
}
4141

4242
function buildAnnotationMD(annotationsYAML, markdown_parser) {
43-
var annotation = {};
44-
var markdownObj = markdown_parser.parse(annotationsYAML);
43+
const annotation = {};
44+
const markdownObj = markdown_parser.parse(annotationsYAML);
4545

4646
annotation.el = markdownObj.el || markdownObj.selector;
4747
annotation.title = markdownObj.title;
@@ -50,16 +50,16 @@ var annotations_exporter = function (pl) {
5050
}
5151

5252
function parseMDFile(annotations, parser) {
53-
var annotations = annotations;
54-
var markdown_parser = parser;
53+
//let annotations = annotations;
54+
const markdown_parser = parser;
5555

5656
return function (filePath) {
57-
var annotationsMD = fs.readFileSync(path.resolve(filePath), 'utf8');
57+
const annotationsMD = fs.readFileSync(path.resolve(filePath), 'utf8');
5858

5959
//take the annotation snippets and split them on our custom delimiter
60-
var annotationsYAML = annotationsMD.split('~*~');
61-
for (var i = 0; i < annotationsYAML.length; i++) {
62-
var annotation = buildAnnotationMD(annotationsYAML[i], markdown_parser);
60+
const annotationsYAML = annotationsMD.split('~*~');
61+
for (let i = 0; i < annotationsYAML.length; i++) {
62+
const annotation = buildAnnotationMD(annotationsYAML[i], markdown_parser);
6363
annotations.push(annotation);
6464
}
6565
return false;
@@ -70,17 +70,17 @@ var annotations_exporter = function (pl) {
7070
Converts the *.md file yaml list into an array of annotations
7171
*/
7272
function parseAnnotationsMD() {
73-
var markdown_parser = new mp();
74-
var annotations = [];
75-
var mdFiles = glob.sync(paths.source.annotations + '/*.md');
73+
const markdown_parser = new mp();
74+
const annotations = [];
75+
const mdFiles = glob.sync(paths.source.annotations + '/*.md');
7676

7777
mdFiles.forEach(parseMDFile(annotations, markdown_parser));
7878
return annotations;
7979
}
8080

8181
function gatherAnnotations() {
82-
var annotationsJS = parseAnnotationsJS();
83-
var annotationsMD = parseAnnotationsMD();
82+
const annotationsJS = parseAnnotationsJS();
83+
const annotationsMD = parseAnnotationsMD();
8484
return _.unionBy(annotationsJS, annotationsMD, 'el');
8585
}
8686

core/lib/changes_hunter.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
"use strict";
2-
const fs = require("fs-extra"),
3-
CompileState = require('./object_factory').CompileState;
1+
'use strict';
2+
const fs = require("fs-extra");
3+
const CompileState = require('./object_factory').CompileState;
44

55
/**
66
* For detecting changed patterns.
77
* @constructor
88
*/
9-
let ChangesHunter = function () {
9+
const ChangesHunter = function () {
1010
};
1111

1212
ChangesHunter.prototype = {
@@ -24,11 +24,11 @@ ChangesHunter.prototype = {
2424
checkBuildState: function (pattern, patternlab) {
2525

2626
//write the compiled template to the public patterns directory
27-
let renderedTemplatePath =
27+
const renderedTemplatePath =
2828
patternlab.config.paths.public.patterns + pattern.getPatternLink(patternlab, 'rendered');
2929

3030
//write the compiled template to the public patterns directory
31-
let markupOnlyPath =
31+
const markupOnlyPath =
3232
patternlab.config.paths.public.patterns + pattern.getPatternLink(patternlab, 'markupOnly');
3333

3434
if (!pattern.compileState) {
@@ -45,7 +45,7 @@ ChangesHunter.prototype = {
4545
// Prevent error message if file does not exist
4646
fs.accessSync(renderedFile, fs.F_OK)
4747
);
48-
let outputLastModified = fs.statSync(renderedTemplatePath).mtime.getTime();
48+
const outputLastModified = fs.statSync(renderedTemplatePath).mtime.getTime();
4949

5050
if (pattern.lastModified && outputLastModified > pattern.lastModified) {
5151
pattern.compileState = CompileState.CLEAN;
@@ -55,7 +55,7 @@ ChangesHunter.prototype = {
5555
pattern.compileState = CompileState.NEEDS_REBUILD;
5656
}
5757

58-
let node = patternlab.graph.node(pattern);
58+
const node = patternlab.graph.node(pattern);
5959

6060
// Make the pattern known to the PatternGraph and remember its compileState
6161
if (!node) {
@@ -78,7 +78,7 @@ ChangesHunter.prototype = {
7878
checkLastModified: function (currentPattern, file) {
7979
if (file) {
8080
try {
81-
let stat = fs.statSync(file);
81+
const stat = fs.statSync(file);
8282

8383
// Needs recompile whenever one of the patterns files (template, json, pseudopatterns) changed
8484
currentPattern.lastModified =

core/lib/lineage_hunter.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
"use strict";
1+
'use strict';
2+
const extend = require("util")._extend;
23

3-
var extend = require("util")._extend;
4+
const lineage_hunter = function () {
45

5-
var lineage_hunter = function () {
6+
function findlineage(pattern, patternlab) {
67

7-
var pa = require('./pattern_assembler');
8+
const pa = require('./pattern_assembler');
9+
const pattern_assembler = new pa();
810

9-
function findlineage(pattern, patternlab) {
1011
// As we are adding edges from pattern to ancestor patterns, ensure it is known to the graph
1112
patternlab.graph.add(pattern);
1213

13-
var pattern_assembler = new pa();
1414

1515
//find the {{> template-name }} within patterns
16-
var matches = pattern.findPartials();
16+
const matches = pattern.findPartials();
1717
if (matches !== null) {
1818
matches.forEach(function (match) {
1919
//get the ancestorPattern
20-
var ancestorPattern = pattern_assembler.getPartial(pattern.findPartial(match), patternlab);
20+
const ancestorPattern = pattern_assembler.getPartial(pattern.findPartial(match), patternlab);
2121

2222
if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.patternPartial) === -1) {
2323
//add it since it didnt exist
2424
pattern.lineageIndex.push(ancestorPattern.patternPartial);
2525

2626
//create the more complex patternLineage object too
27-
var l = {
27+
const l = {
2828
"lineagePattern": ancestorPattern.patternPartial,
2929
"lineagePath": "../../patterns/" + ancestorPattern.patternLink
3030
};
@@ -44,7 +44,7 @@ var lineage_hunter = function () {
4444
ancestorPattern.lineageRIndex.push(pattern.patternPartial);
4545

4646
//create the more complex patternLineage object in reverse
47-
var lr = {
47+
const lr = {
4848
"lineagePattern": pattern.patternPartial,
4949
"lineagePath": "../../patterns/" + pattern.patternLink
5050
};
@@ -69,15 +69,15 @@ var lineage_hunter = function () {
6969
* @param graph {PatternGraph}
7070
*/
7171
function setPatternState(direction, pattern, targetPattern, graph) {
72-
var index = null;
72+
let index = null;
7373
if (direction === 'fromPast') {
7474
index = graph.lineage(pattern);
7575
} else {
7676
index = graph.lineageR(pattern);
7777
}
7878

7979
// if the request came from the past, apply target pattern state to current pattern lineage
80-
for (var i = 0; i < index.length; i++) {
80+
for (let i = 0; i < index.length; i++) {
8181
if (index[i].patternPartial === targetPattern.patternPartial) {
8282
index[i].lineageState = targetPattern.patternState;
8383
}
@@ -87,36 +87,36 @@ var lineage_hunter = function () {
8787

8888
function cascadePatternStates(patternlab) {
8989

90-
for (var i = 0; i < patternlab.patterns.length; i++) {
91-
var pattern = patternlab.patterns[i];
90+
for (let i = 0; i < patternlab.patterns.length; i++) {
91+
const pattern = patternlab.patterns[i];
9292

9393
//for each pattern with a defined state
9494
if (pattern.patternState) {
95-
var lineage = patternlab.graph.lineage(pattern);
95+
const lineage = patternlab.graph.lineage(pattern);
9696

9797
if (lineage && lineage.length > 0) {
9898

9999
//find all lineage - patterns being consumed by this one
100-
for (var h = 0; h < lineage.length; h++) {
100+
for (let h = 0; h < lineage.length; h++) {
101101
// Not needed, the graph already knows the concrete pattern
102-
// var lineagePattern = pattern_assembler.getPartial(lineageIndex[h], patternlab);
102+
// let lineagePattern = pattern_assembler.getPartial(lineageIndex[h], patternlab);
103103
setPatternState('fromFuture', lineage[h], pattern, patternlab.graph);
104104
}
105105
}
106-
var lineageR = patternlab.graph.lineageR(pattern);
106+
const lineageR = patternlab.graph.lineageR(pattern);
107107
if (lineageR && lineageR.length > 0) {
108108

109109
//find all reverse lineage - that is, patterns consuming this one
110-
for (var j = 0; j < lineageR.length; j++) {
110+
for (let j = 0; j < lineageR.length; j++) {
111111

112-
var lineageRPattern = lineageR[j];
112+
const lineageRPattern = lineageR[j];
113113

114114
//only set patternState if pattern.patternState "is less than" the lineageRPattern.patternstate
115115
//or if lineageRPattern.patternstate (the consuming pattern) does not have a state
116116
//this makes patternlab apply the lowest common ancestor denominator
117-
let patternStateCascade = patternlab.config.patternStateCascade;
118-
let patternStateIndex = patternStateCascade.indexOf(pattern.patternState);
119-
let patternReverseStateIndex = patternStateCascade.indexOf(lineageRPattern.patternState);
117+
const patternStateCascade = patternlab.config.patternStateCascade;
118+
const patternStateIndex = patternStateCascade.indexOf(pattern.patternState);
119+
const patternReverseStateIndex = patternStateCascade.indexOf(lineageRPattern.patternState);
120120
if (lineageRPattern.patternState === '' || (patternStateIndex < patternReverseStateIndex)) {
121121

122122
if (patternlab.config.debug) {

0 commit comments

Comments
 (0)