Skip to content

Commit 9a3f027

Browse files
author
Tobias Brennecke
committed
#540 JSLint and documentation, enable ES6 in .eslintrc
1 parent 1e57ccd commit 9a3f027

11 files changed

+372
-243
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"env": {
33
"node": true,
4-
"builtin": true
4+
"builtin": true,
5+
"es6": true
56
},
67
"parserOptions": {
78
"ecmaVersion": 6,

core/lib/changes_hunter.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@
22
const fs = require("fs-extra"),
33
CompileState = require('./object_factory').CompileState;
44

5-
6-
7-
let changesHunter = function() {
5+
/**
6+
* For detecting changed patterns.
7+
* @constructor
8+
*/
9+
let ChangesHunter = function () {
810
};
911

10-
changesHunter.prototype = {
12+
ChangesHunter.prototype = {
13+
14+
/**
15+
* Checks the build state of a pattern by comparing the modification date of the rendered output
16+
* file with the {@link Pattern.lastModified}. If the pattern was modified after the last
17+
* time it has been rendered, it is flagged for rebuilding via {@link CompileState.NEEDS_REBUILD}.
18+
*
19+
* @param {Pattern} pattern
20+
* @param patternlab
21+
*
22+
* @see {@link CompileState}
23+
*/
1124
checkBuildState: function (pattern, patternlab) {
25+
1226
//write the compiled template to the public patterns directory
13-
var renderedTemplatePath =
27+
let renderedTemplatePath =
1428
patternlab.config.paths.public.patterns + pattern.getPatternLink(patternlab, 'rendered');
1529

1630
if (!pattern.compileState) {
@@ -20,7 +34,7 @@ changesHunter.prototype = {
2034
try {
2135
// Prevent error message if file does not exist
2236
fs.accessSync(renderedTemplatePath, fs.F_OK);
23-
var outputLastModified = fs.statSync(renderedTemplatePath).mtime.getTime();
37+
let outputLastModified = fs.statSync(renderedTemplatePath).mtime.getTime();
2438

2539
if (pattern.lastModified && outputLastModified > pattern.lastModified) {
2640
pattern.compileState = CompileState.CLEAN;
@@ -45,13 +59,15 @@ changesHunter.prototype = {
4559
/**
4660
* Updates {Pattern#lastModified} to the files modification date if the file was modified
4761
* after {Pattern#lastModified}.
62+
*
4863
* @param {Pattern} currentPattern
4964
* @param {string} file
5065
*/
5166
checkLastModified: function (currentPattern, file) {
5267
if (file) {
5368
try {
5469
let stat = fs.statSync(file);
70+
5571
// Needs recompile whenever one of the patterns files (template, json, pseudopatterns) changed
5672
currentPattern.lastModified =
5773
Math.max(stat.mtime.getTime(), currentPattern.lastModified || 0);
@@ -62,4 +78,4 @@ changesHunter.prototype = {
6278
}
6379
};
6480

65-
module.exports = changesHunter;
81+
module.exports = ChangesHunter;

core/lib/lineage_hunter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var lineage_hunter = function () {
3333
}
3434

3535
patternlab.graph.add(ancestorPattern);
36+
3637
// Confusing: pattern includes "ancestorPattern", not the other way round
3738
patternlab.graph.link(pattern, ancestorPattern);
3839

@@ -70,10 +71,11 @@ var lineage_hunter = function () {
7071
function setPatternState(direction, pattern, targetPattern, graph) {
7172
var index = null;
7273
if (direction === 'fromPast') {
73-
index = graph.lineage(pattern);
74+
index = graph.lineage(pattern);
7475
} else {
7576
index = graph.lineageR(pattern);
7677
}
78+
7779
// if the request came from the past, apply target pattern state to current pattern lineage
7880
for (var i = 0; i < index.length; i++) {
7981
if (index[i].patternPartial === targetPattern.patternPartial) {

core/lib/object_factory.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,19 @@ var Pattern = function (relPath, data, patternlab) {
7373
this.isPseudoPattern = false;
7474
this.order = Number.MAX_SAFE_INTEGER;
7575
this.engine = patternEngines.getEngineForPattern(this);
76-
// For completeness
76+
77+
/**
78+
* Determines if this pattern needs to be recompiled.
79+
*
80+
* @ee {@link CompileState}*/
7781
this.compileState = null;
78-
// The unix timestamp when the pattern was last modified
82+
83+
/**
84+
* Timestamp in milliseconds when the pattern template or auxilary file (e.g. json) were modified.
85+
* If multiple files are affected, this is the timestamp of the most recent change.
86+
*
87+
* @see {@link pattern}
88+
*/
7989
this.lastModified = null;
8090

8191
};

core/lib/pattern_assembler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ var pattern_assembler = function () {
369369
currentPattern.parameteredPartials = currentPattern.findPartialsWithPatternParameters();
370370

371371
[templatePath, jsonFilename, listJsonFileName].forEach(file => {
372-
changes_hunter.checkLastModified(currentPattern, file)
372+
changes_hunter.checkLastModified(currentPattern, file);
373373
});
374374

375375
changes_hunter.checkBuildState(currentPattern, patternlab);
@@ -405,7 +405,7 @@ var pattern_assembler = function () {
405405
}
406406

407407
function findModifiedPatterns(lastModified, patternlab) {
408-
return patternlab.patterns.filter( p => {
408+
return patternlab.patterns.filter(p => {
409409
if (p.compileState !== CompileState.CLEAN || ! p.lastModified) {
410410
return true;
411411
}
@@ -527,7 +527,7 @@ var pattern_assembler = function () {
527527

528528
return {
529529
find_modified_patterns: function (lastModified, patternlab) {
530-
return findModifiedPatterns(lastModified, patternlab)
530+
return findModifiedPatterns(lastModified, patternlab);
531531
},
532532
find_pattern_partials: function (pattern) {
533533
return pattern.findPartials();

0 commit comments

Comments
 (0)