Skip to content
Closed
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
21 changes: 14 additions & 7 deletions bin/blessc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ args = args.filter(function (arg) {
console.log('Usage: blessc [options] [ source | - ] [destination]');
console.log('');
console.log('Options :');
console.log(' -v, --version print version');
console.log(' -h, --help print this help');
console.log(' -f, --force overwrite input file');
console.log(' -x, --compress "minify" @import');
console.log(' --no-cleanup don\'t remove old css file before overwriting');
console.log(' --no-imports disable @import on stylesheets');
console.log(' --no-cache-buster turn off the cache buster');
console.log(' -v, --version print version');
console.log(' -h, --help print this help');
console.log(' -f, --force overwrite input file');
console.log(' -x, --compress "minify" @import');
console.log(' --no-cleanup don\'t remove old css file before overwriting');
console.log(' --no-imports disable @import on stylesheets');
console.log(' --no-cache-buster turn off the cache buster');
console.log(' --cache-buster=MODE specify cache buster mode: timestamp (default), checksum');
console.log('');
console.log('Full documentation can be found at http://blesscss.com/');
process.exit(0);
Expand All @@ -60,6 +61,12 @@ args = args.filter(function (arg) {
break;
case 'no-cache-buster':
options.cacheBuster = false;
break;
case 'cache-buster':
// Only honor if cacheBuster has not yet been disabled.
if (options.cacheBuster === true) {
options.cacheBuster = match[2] || true;
}
}
});

Expand Down
22 changes: 15 additions & 7 deletions lib/bless/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var path = require('path'),
fs = require('fs'),
bless = exports,
cacheBuster = '?z=' + new Date().getTime();
crypto = require('crypto'),
timestamp = new Date().getTime();

bless.Parser = function Parser(env) {
this.env = env = env || {};
Expand Down Expand Up @@ -38,7 +39,17 @@ bless.Parser = function Parser(env) {
var ext = path.extname(output),
filename = path.basename(output, ext),
offset = 0,
selectorCount = 0;
selectorCount = 0,
cacheBuster = '';

if (options.cacheBuster) {
cacheBuster = '?z=';
if (options.cacheBuster == 'checksum') {
cacheBuster += crypto.createHash('md5').update(str).digest('hex');
} else {
cacheBuster += timestamp;
}
}

for (var i = 0, length = rules.length; i < length; i++) {
var matchCount,
Expand Down Expand Up @@ -91,10 +102,7 @@ bless.Parser = function Parser(env) {

if (filesLength > 0 && options.imports) {
for(var k=1; k<=filesLength; k++) {
var outputFilename = filename + '-blessed' + k + ext;
if (options.cacheBuster) {
outputFilename += cacheBuster;
}
var outputFilename = filename + '-blessed' + k + ext + cacheBuster;
var importStr = '@import url(\'' + outputFilename + '\');';
importStr = options.compress ? importStr : importStr + '\n';
rules.unshift(importStr);
Expand Down Expand Up @@ -122,7 +130,7 @@ bless.Parser.cleanup = function (options, output, callback) {
fileRegex = filename + '-blessed' + '(\\d+)' + ext;

if (options.cacheBuster) {
fileRegex += cacheBuster;
fileRegex += '\?[^\']*';
}

var importRegex = '@import url\\(\'(' + fileRegex + '\')\\);';
Expand Down
2 changes: 1 addition & 1 deletion test/output/above-limit-with-comment.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('above-limit-with-comment-blessed1.css');
@import url('above-limit-with-comment-blessed1.css?z=54a6d19615cdadba8e7e7c3cd85e28d0');

#test,
#test,
Expand Down
4 changes: 2 additions & 2 deletions test/output/above-limit.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('above-limit-blessed2.css');
@import url('above-limit-blessed1.css');
@import url('above-limit-blessed2.css?z=c75b09cdde4a378204235a0c5c6e21d1');
@import url('above-limit-blessed1.css?z=c75b09cdde4a378204235a0c5c6e21d1');

#test { background-color: blue; }
2 changes: 1 addition & 1 deletion test/output/media-query-one.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('media-query-one-blessed1.css');
@import url('media-query-one-blessed1.css?z=17bd598459bcea0918342caf7cb34645');

@media print {
#test { color: #090; }
Expand Down
2 changes: 1 addition & 1 deletion test/output/media-query-three.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('media-query-three-blessed1.css');
@import url('media-query-three-blessed1.css?z=9e44e23e31ba3a8216a62fc276131100');

@media screen and (max-device-width: 480px) {
#test,
Expand Down
2 changes: 1 addition & 1 deletion test/output/media-query-two.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('media-query-two-blessed1.css');
@import url('media-query-two-blessed1.css?z=d600730222ade09d92e438ed9334a616');

@media print {
#test { color: #090; }
Expand Down
3 changes: 2 additions & 1 deletion test/parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var parser = {
options: {
cleanup: true,
compress: false,
imports: true
imports: true,
cacheBuster: 'checksum'
}
}).parse(fs.readFileSync(path.join(__dirname, 'input', file), 'utf-8'), callback);
}
Expand Down