Skip to content

Commit bf6b79f

Browse files
committed
first commit: apply a thin coating of Promises to start the process of an end-to-end async
build process
1 parent 1f5af94 commit bf6b79f

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

core/lib/patternlab.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,13 @@ const patternlab_engine = function (config) {
280280
return value;
281281
}
282282

283+
// GTP: this commented out now on the advice of Brian, because we think nobody looks at it,
284+
// and it causes problems.
283285
//debug file can be written by setting flag on patternlab-config.json
284-
if (patternlab.config.debug) {
285-
console.log('writing patternlab debug file to ./patternlab.json');
286-
fs.outputFileSync('./patternlab.json', JSON.stringify(patternlab, propertyStringReplacer, 3));
287-
}
286+
// if (patternlab.config.debug) {
287+
// console.log('writing patternlab debug file to ./patternlab.json');
288+
// fs.outputFileSync('./patternlab.json', JSON.stringify(patternlab, propertyStringReplacer, 3));
289+
// }
288290
}
289291

290292
function setCacheBust() {
@@ -382,7 +384,7 @@ const patternlab_engine = function (config) {
382384
function renderSinglePattern(pattern, head) {
383385
// Pattern does not need to be built and recompiled more than once
384386
if (!pattern.isPattern || pattern.compileState === CompileState.CLEAN) {
385-
return false;
387+
return Promise.resolve(false);
386388
}
387389

388390
// Allows serializing the compile state
@@ -478,7 +480,8 @@ const patternlab_engine = function (config) {
478480
// Allows serializing the compile state
479481
patternlab.graph.node(pattern).compileState = pattern.compileState = CompileState.CLEAN;
480482
plutils.log.info("Built pattern: " + pattern.patternPartial);
481-
return true;
483+
484+
return Promise.resolve(true);
482485
}
483486

484487
/**
@@ -630,17 +633,21 @@ const patternlab_engine = function (config) {
630633
}
631634

632635
//render all patterns last, so lineageR works
633-
patternsToBuild.forEach(pattern => renderSinglePattern(pattern, head));
634-
635-
// Saves the pattern graph when all files have been compiled
636-
PatternGraph.storeToFile(patternlab);
637-
if (patternlab.config.exportToGraphViz) {
638-
PatternGraph.exportToDot(patternlab, "dependencyGraph.dot");
639-
plutils.log.info(`Exported pattern graph to ${path.join(config.paths.public.root, "dependencyGraph.dot")}`);
640-
}
641-
642-
//export patterns if necessary
643-
pattern_exporter.export_patterns(patternlab);
636+
return patternsToBuild
637+
.reduce((previousPromise, pattern) => {
638+
return previousPromise.then(() => renderSinglePattern(pattern, head));
639+
}, Promise.resolve())
640+
.then(() => {
641+
// Saves the pattern graph when all files have been compiled
642+
PatternGraph.storeToFile(patternlab);
643+
if (patternlab.config.exportToGraphViz) {
644+
PatternGraph.exportToDot(patternlab, "dependencyGraph.dot");
645+
plutils.log.info(`Exported pattern graph to ${path.join(config.paths.public.root, "dependencyGraph.dot")}`);
646+
}
647+
648+
//export patterns if necessary
649+
pattern_exporter.export_patterns(patternlab);
650+
});
644651
}).catch((err) => {
645652
console.log('Error in buildPatterns():', err);
646653
});

0 commit comments

Comments
 (0)