Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP fileCache #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"autoprefixer": "6.3.4",
"csswring": "4.2.2",
"es6-promise": "3.1.2",
"lodash": "^4.7.0",
"nib": "1.1.0",
"postcss": "5.0.19",
"postcss-import": "7.1.3",
Expand Down
50 changes: 37 additions & 13 deletions techs/stylus.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Support node 0.10: `postcss` uses promises
require('es6-promise').polyfill();

var path = require('path'),
var _ = require('lodash'),
path = require('path'),
vow = require('vow'),
enb = require('enb'),
vfs = enb.asyncFS || require('enb/lib/fs/async-fs'),
Expand Down Expand Up @@ -119,18 +120,39 @@ module.exports = buildFlow.create()
.builder(function (sourceFiles) {
var node = this.node,
filename = node.resolvePath(path.basename(this._target)),
stylesImports = this._prepareImports(sourceFiles);

return this._processStylus(filename, stylesImports)
.spread(function (css, sourcemap) {
return this._processCss(filename, css, sourcemap);
}, this)
.then(function (result) {
return this._writeMap(filename + '.map', result.map)
.then(function () {
return result.css;
});
}, this);
fileCache = node.getSharedResources().fileCache;

return _(sourceFiles)
.map(function (sourceFile) {
var cacheKey = sourceFile.fullname + '.stylus.css';
return fileCache.get(cacheKey, sourceFile.mtime)
.then(function (content) {
if (content !== null) {
console.log('**** Using %s from cache', cacheKey);
return content;
}

var stylesImports = this._prepareImports([sourceFile]);
return this._processStylus(filename, stylesImports)
.spread(function (css, sourcemap) {
return this._processCss(filename, css, sourcemap);
}, this)
.then(function (result) {
return fileCache.put(cacheKey, result)
.then(function () {
return result;
});
});
}, this);
}.bind(this))
.thru(vow.all)
.value()
.then(function (results) {
// TODO: merge source maps
// TODO: save source maps
//return this._writeMap(filename + '.map', result.map)
return _.map(results, 'css').join(EOL);
});
})

.methods(/** @lends StylusTech.prototype */{
Expand Down Expand Up @@ -271,6 +293,7 @@ module.exports = buildFlow.create()

var stylus = require('stylus');

console.time('stylus init');
var renderer = stylus(stylesImports)
.set('prefix', this._prefix)
.set('filename', filename)
Expand Down Expand Up @@ -308,6 +331,7 @@ module.exports = buildFlow.create()
this._importPaths.forEach(function (importPath) {
renderer.import(importPath);
});
console.timeEnd('stylus init');

var defer = vow.defer();

Expand Down