Comparing version 0.1.4 to 0.1.5
@@ -8,3 +8,4 @@ { | ||
"/aaaaaa":"http://www.sogou.com" | ||
} | ||
}, | ||
"encoding": "utf-8" | ||
} |
@@ -5,3 +5,5 @@ var fs = require('fs'); | ||
var exec = require('child_process').exec; | ||
var crypto = require('crypto'); | ||
var yuicompressor = __dirname + '/../../3rd/yuicompressor.jar'; | ||
@@ -67,2 +69,55 @@ | ||
var getTimestamp = function(file){ | ||
var md5 = crypto.createHash('md5'); | ||
md5.update(fs.readFileSync(file )); | ||
var result = md5.digest('hex'); | ||
result = [result.slice(0,16) , result.slice(16)]; | ||
var f = ''; | ||
result.forEach(function(item){ | ||
var num = (parseInt( item , 16 ) % 997).toString(); | ||
while( num.length < 3 ){ | ||
num = '0' + num; | ||
} | ||
f += num; | ||
}); | ||
return f; | ||
}; | ||
var compileTimestamp = function(){ | ||
var cssMain = process.cwd() + '/build/static/css/main.css'; | ||
var cssToken = /url\(['"]?(.*?)['"]?\)/g , cr; | ||
var cssFile = fs.readFileSync( cssMain ).toString(); | ||
while( ( cr=cssToken.exec(cssFile) ) != null ){ | ||
var img = cr[1]; | ||
if( img.indexOf('http') == 0 ) continue;//online image will not compile | ||
img = process.cwd() + '/build/static/css/' + img; | ||
var tm = getTimestamp(img); | ||
cssFile = cssFile.replace( cr[1] , cr[1] +'?t='+tm ); | ||
} | ||
fs.writeFileSync( cssMain , cssFile ); | ||
var tplFolder = process.cwd() + '/tpl/'; | ||
try{ | ||
var tpls = fs.readdirSync(tplFolder); | ||
var token = /(?:href|src)=['"](.*)\?t=(\d+|@date@)['"]/g , result; | ||
tpls.forEach(function(tpl){ | ||
var file = fs.readFileSync(tplFolder + tpl); | ||
file = utils.decode(file); | ||
while( (result = token.exec(file)) != null ){ | ||
var target_file = process.cwd() + '/build/' + result[1]; | ||
var tm = getTimestamp(target_file); | ||
file = file.replace( '?t=' + result[2] , '?t=' + tm ); | ||
} | ||
fs.writeFileSync( tplFolder + tpl , utils.encode(file) ); | ||
}); | ||
utils.success('Add timestamp success.'); | ||
}catch(e){console.log(e)}; | ||
}; | ||
var publish = function(cb){ | ||
@@ -78,2 +133,4 @@ utils.log('try to publish now.'); | ||
utils.success('Publish success.'); | ||
cb && cb(); | ||
@@ -120,2 +177,3 @@ | ||
} | ||
compileTimestamp(); | ||
options.publish && publish(cb); | ||
@@ -126,2 +184,3 @@ }); | ||
}else{ | ||
compileTimestamp(); | ||
options.publish && publish(cb); | ||
@@ -128,0 +187,0 @@ } |
@@ -6,3 +6,8 @@ | ||
var util = require('util'); | ||
var Iconv = require('iconv').Iconv; | ||
var utf2gbk = new Iconv('UTF-8' , 'GBK'); | ||
var gbk2utf = new Iconv('GBK' , 'UTF-8'); | ||
var log = function(message){ | ||
@@ -145,2 +150,15 @@ console.log(message.cyan); | ||
exports.encode = function(file){ | ||
var conf = require('./conf').config; | ||
if( conf.encoding == 'gbk' ) file = utf2gbk.convert(file); | ||
return file; | ||
}; | ||
exports.decode = function(file){ | ||
var conf = require('./conf').config; | ||
if( conf.encoding == 'gbk' ) file = gbk2utf.convert(file); | ||
return file.toString(); | ||
}; | ||
exports.log = log; | ||
@@ -147,0 +165,0 @@ exports.warn = warn; |
{ | ||
"name": "ufo", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "UFO is a develope environment for front-end developer", | ||
@@ -5,0 +5,0 @@ "author": "UFO Team of Sogou-inc.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
1152828
4211