From fa49c11a74e50bb084a3d60772cc9f7aace9676c Mon Sep 17 00:00:00 2001 From: Denis Payase Date: Wed, 24 Aug 2016 17:13:12 +0300 Subject: [PATCH] fix(levels-to-bemdecl): should rebuild if levels was changed --- techs/levels-to-bemdecl.js | 67 +++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/techs/levels-to-bemdecl.js b/techs/levels-to-bemdecl.js index e444fa7..1953ed3 100644 --- a/techs/levels-to-bemdecl.js +++ b/techs/levels-to-bemdecl.js @@ -2,9 +2,7 @@ var inherit = require('inherit'), enb = require('enb'), vfs = enb.asyncFS || require('enb/lib/fs/async-fs'), BaseTech = enb.BaseTech || require('enb/lib/tech/base-tech'), - deps = require('../lib/deps/deps'), - asyncRequire = require('enb-async-require'), - clearRequire = require('clear-require'); + deps = require('../lib/deps/deps'); /** * @class LevelsToBemdeclTech @@ -58,50 +56,45 @@ module.exports = inherit(BaseTech, { cache = node.getNodeCache(target); return node.requireSources([this._source]).spread(function (levels) { - if (cache.needRebuildFile('bemdecl-file', bemdeclFilename)) { - var resDeps = [], - decl = [], - data, - str; - - levels.items.forEach(function (level) { - Object.keys(level.blocks).forEach(function (name) { - var block = level.blocks[name]; - - resDeps.push({ - block: name - }); - - processMods(resDeps, name, block.mods); - processElems(resDeps, name, block.elements); + var resDeps = [], + decl = [], + data, + str; + + levels.items.forEach(function (level) { + Object.keys(level.blocks).forEach(function (name) { + var block = level.blocks[name]; + + resDeps.push({ + block: name }); + + processMods(resDeps, name, block.mods); + processElems(resDeps, name, block.elements); }); + }); - if (bemdeclFormat === 'deps') { - decl = resDeps; - data = { deps: decl }; - str = 'exports.deps = ' + JSON.stringify(decl, null, 4) + ';\n'; - } else { - decl = deps.toBemdecl(resDeps); - data = { blocks: decl }; - str = 'exports.blocks = ' + JSON.stringify(decl, null, 4) + ';\n'; - } + if (bemdeclFormat === 'deps') { + decl = resDeps; + data = { deps: decl }; + str = 'exports.deps = ' + JSON.stringify(decl, null, 4) + ';\n'; + } else { + decl = deps.toBemdecl(resDeps); + data = { blocks: decl }; + str = 'exports.blocks = ' + JSON.stringify(decl, null, 4) + ';\n'; + } + if (cache.get('bemdecl') !== str || cache.needRebuildFile('bemdecl-file', bemdeclFilename)) { return vfs.write(bemdeclFilename, str, 'utf8') .then(function () { cache.cacheFileInfo('bemdecl-file', bemdeclFilename); + cache.set('bemdecl', str); node.resolveTarget(target, data); }); - } else { - node.isValidTarget(target); - clearRequire(bemdeclFilename); - - return asyncRequire(bemdeclFilename) - .then(function (result) { - node.resolveTarget(target, result); - return null; - }); } + + node.isValidTarget(target); + node.resolveTarget(target, data); }); } });