Skip to content

Commit

Permalink
#20 Rewrite borschik technology with build-flow module usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tormozz48 committed Jun 26, 2015
1 parent dcecd32 commit db08632
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 69 deletions.
105 changes: 37 additions & 68 deletions techs/borschik.js
Expand Up @@ -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();
10 changes: 9 additions & 1 deletion test/techs/borschik.test.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit db08632

Please sign in to comment.