diff --git a/techs/borschik.js b/techs/borschik.js index a72c939..fc773ca 100644 --- a/techs/borschik.js +++ b/techs/borschik.js @@ -30,75 +30,44 @@ * ``` */ var vow = require('vow'), - inherit = require('inherit'), - BorschikPreprocessor = require('../lib/borschik-preprocessor'), - BorschikProcessorSibling = require('sibling').declare({ - process: function (sourcePath, targetPath, freeze, minify, tech, techOptions) { - return (new BorschikPreprocessor()) - .preprocessFile(sourcePath, targetPath, freeze, minify, tech, techOptions); + preprocessor = new (require('../lib/borschik-preprocessor'))(), + ProcessorSibling = require('sibling').declare({ + process: function () { + return preprocessor.preprocessFile.apply(preprocessor, arguments); } }); -/** - * @type {Tech} - */ -module.exports = inherit(require('enb/lib/tech/base-tech'), { - getName: function () { - return 'borschik'; - }, - - configure: function () { - this._source = this.getOption('sourceTarget'); - if (!this._source) { - this._source = this.getRequiredOption('source'); - } - this._target = this.getOption('destTarget'); - if (!this._target) { - this._target = this.getRequiredOption('target'); - } - this._freeze = this.getOption('freeze', false); - this._minify = this.getOption('minify', true); - this._noCache = this.getOption('noCache', false); - this._tech = this.getOption('tech', null); - this._techOptions = this.getOption('techOptions', null); - }, - - getTargets: function () { - return [this.node.unmaskTargetName(this._target)]; - }, +module.exports = require('enb/lib/build-flow').create() + .name('borschik') + .target('target') + .defineRequiredOption('source') + .optionAlias('target', 'destTarget') + .optionAlias('source', 'sourceTarget') + .defineOption('minify', true) + .defineOption('freeze', false) + .defineOption('noCache', false) + .defineOption('tech', null) + .defineOption('techOptions', null) + .saver(function () {}) + .builder(function () { + var node = this.node, + target = node.unmaskTargetName(this._target), + targetPath = node.resolvePath(target), + source = node.unmaskTargetName(this._source), + sourcePath = node.resolvePath(source), + borschikProcessor = ProcessorSibling.fork(); - build: function () { - var target = this.node.unmaskTargetName(this._target), - targetPath = this.node.resolvePath(target), - source = this.node.unmaskTargetName(this._source), - sourcePath = this.node.resolvePath(source), - _this = this, - cache = this.node.getNodeCache(target); - return this.node.requireSources([source]).then(function () { - if (_this._noCache || - cache.needRebuildFile('source-file', sourcePath) || - cache.needRebuildFile('target-file', targetPath) - ) { - var borschikProcessor = BorschikProcessorSibling.fork(); - return vow.when( - borschikProcessor.process( - sourcePath, - targetPath, - _this._freeze, - _this._minify, - _this._tech, - _this._techOptions) - ).then(function () { - cache.cacheFileInfo('source-file', sourcePath); - cache.cacheFileInfo('target-file', targetPath); - _this.node.resolveTarget(target); - borschikProcessor.dispose(); - }); - } else { - _this.node.isValidTarget(target); - _this.node.resolveTarget(target); - return null; - } - }); - } -}); + return vow + .when(borschikProcessor.process( + sourcePath, + targetPath, + this._freeze, + this._minify, + this._tech, + this._techOptions + )) + .then(function () { + borschikProcessor.dispose(); + }); + }) + .createTech(); diff --git a/test/techs/borschik.test.js b/test/techs/borschik.test.js index e3a9bbd..2adb9f0 100644 --- a/test/techs/borschik.test.js +++ b/test/techs/borschik.test.js @@ -19,8 +19,16 @@ describe('borschik', function () { }); describe('required options', function () { + it('must throw error if sourceTarget and destTarget properties are missed', function () { + var bundle = new MockNode('bundle'); + + (function () { + return bundle.runTechAndGetContent(Tech); + }).must.throw('Option "target" is required for technology "borschik".'); + }); + it('must throw error if sourceTarget property is missed', function () { - var options = {}, + var options = { destTarget: '_?.css' }, bundle = new MockNode('bundle'); (function () {