Skip to content

Commit

Permalink
Merge pull request #9 from enb-bem/issue-8
Browse files Browse the repository at this point in the history
Used cache for inline examples
  • Loading branch information
Andrew Abramov committed Nov 28, 2014
2 parents a6c6447 + 8defe64 commit 44d81f4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/plugins/inline-bemjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ module.exports = function (helper) {

_buildTargets: function (options) {
var channel = helper.getEventChannel(),
root = helper.getRootPath();
root = helper.getRootPath(),
task = helper._projectConfig._tasks[helper._taskName];

helper.prebuild(function (magic, logger) {
var cache = task._makePlatform._cacheStorage;

return getMdFiles(options.levels)
.then(function (filenames) {
return getExamplesFromMdFiles(root, options.destPath, filenames);
Expand All @@ -58,8 +61,13 @@ module.exports = function (helper) {
return vow.all(examples.map(function (example) {
var dirname = path.join(root, example.path),
target = path.join(example.path, example.name + '.bemjson.js'),
bemjsonFilename = path.join(root, target),
bemjson = buildBemjson(example, bemjsonFilename, options.processInlineBemjson, logger);
bemjsonFilename = path.join(root, target);

if (cache.get('inline-example', bemjsonFilename)) {
return;
}

var bemjson = buildBemjson(example, bemjsonFilename, options.processInlineBemjson, logger);

if (!bemjson) {
return;
Expand All @@ -71,6 +79,8 @@ module.exports = function (helper) {
return vfs.write(bemjsonFilename, bemjson, 'utf-8');
})
.then(function () {
cache.set('inline-example', bemjsonFilename, true);

magic.registerNode(example.path);

return example;
Expand Down

0 comments on commit 44d81f4

Please sign in to comment.