Skip to content

Commit

Permalink
Use only *.styl file if an entity has multiple files (close enb#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Alaev committed May 27, 2015
1 parent c68cf7f commit 55b14d1
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions techs/css-stylus.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,30 @@ module.exports = require('enb/lib/build-flow').create()
var node = this.node,
filename = node.resolvePath(path.basename(this._target)),
defer = vow.defer(),
styl = {},
css, renderer;

css = sourceFiles.map(function (file) {
var url = node.relativePath(file.fullname);

if (file.name.indexOf('.styl') !== -1) {
return '/* ' + url + ':begin */\n' +
'@import "' + url + '";\n' +
'/* ' + url + ':end */\n';
} else {
return '@import "' + url + '";';
sourceFiles.forEach(function (file) {
if (isStylFile(file.name)) {
styl[file.name] = true;
}
}).join('\n');
});

css = sourceFiles
.filter(function (file) {
return isStylFile(file.name) || !styl[file.name.slice(0, -3) + 'styl'];
})
.map(function (file) {
var url = node.relativePath(file.fullname);

if (isStylFile(file.name)) {
return '/* ' + url + ':begin */\n' +
'@import "' + url + '";\n' +
'/* ' + url + ':end */\n';
} else {
return '@import "' + url + '";';
}
}).join('\n');

renderer = stylus(css, {
compress: this._compress,
Expand Down Expand Up @@ -98,3 +109,7 @@ module.exports = require('enb/lib/build-flow').create()
}
})
.createTech();

function isStylFile (name) {
return name.substr(-5) === '.styl';
}

0 comments on commit 55b14d1

Please sign in to comment.