Comparing version 0.2.9 to 0.3.0
111
lib/index.js
@@ -38,2 +38,4 @@ /** | ||
cfg.suffix = cfg.suffix || '.combo'; | ||
cfg.sourceDir = path.dirname(cfg.target); | ||
@@ -110,3 +112,3 @@ | ||
fileContent = commentTpl.join('') + config.linefeed + fileContent; | ||
var cssFileExt = '.combo.css'; | ||
var cssFileExt = config.suffix + '.css'; | ||
if(config.compress){ | ||
@@ -122,3 +124,4 @@ utils.log('start compress file.', 'debug'); | ||
if(path.extname(config.output) !== '.css'){ | ||
comboFile = path.join(config.output, path.basename(config.target).replace(/(.source)?.css/, cssFileExt)); | ||
comboFile = path.resolve(config.output, path.basename(config.target).replace(/(\.source)?\.css/, cssFileExt)); | ||
utils.log('dest is dir, I guess the output file is: ' + comboFile, 'debug'); | ||
} | ||
@@ -145,2 +148,3 @@ | ||
var self = this; | ||
// utils.log('Analyzing ' + self.config.target, 'debug'); | ||
if(content){ | ||
@@ -154,11 +158,7 @@ var reg = /@import\s*(url)?\(?['"]([^'"]+)\.css['"]\)?[^;]*;/ig, | ||
self.getFileContent(filePath, function(data){ | ||
// if(content){ | ||
data = self.modifySubImportsPath(data,filePath); | ||
data = data.replace(/(['"]|\():/g,'$1'); | ||
data = data.replace(/(['"])%/g,'$1'); | ||
content = content.replace(result[0], '\n' + data + '\n'); | ||
content = self.analyzeImports(content, callback); | ||
// }else{ | ||
// utils.log('no content', 'debug'); | ||
// } | ||
data = self.modifySubImportsPath(data,filePath); | ||
data = data.replace(/(['"]|\():/g,'$1'); | ||
data = data.replace(/(['"])%/g,'$1'); | ||
content = content.replace(result[0], '\n' + data + '\n'); | ||
content = self.analyzeImports(content, callback); | ||
}); | ||
@@ -224,34 +224,66 @@ }else{ | ||
config.base = path.dirname(file); | ||
fs.readFile(file, '', function(err, data){ | ||
if(err){ | ||
utils.log(err, 'error'); | ||
throw self.error(err); | ||
} | ||
config.inputEncoding = config.inputEncoding ? config.inputEncoding : utils.detectCharset(data); | ||
var fileContent = iconv.decode(data, config.inputEncoding); | ||
// var fileContent = data; | ||
utils.log('file charset is: ' + config.inputEncoding, 'debug'); | ||
var data = fs.readFileSync(file); | ||
utils.log('Cur file is ' + self.config.target, 'debug'); | ||
utils.log('file read: ' + file, 'debug'); | ||
// preserve data url and comment. | ||
var preservedTokens = []; | ||
fileContent = compressor._extractDataUrls(fileContent, preservedTokens); | ||
fileContent = compressor._extractComments(fileContent, preservedTokens); | ||
config.inputEncoding = config.inputEncoding ? config.inputEncoding : utils.detectCharset(data); | ||
var fileContent = iconv.decode(data, config.inputEncoding); | ||
utils.log('file charset is: ' + config.inputEncoding, 'debug'); | ||
// start analyze file content | ||
self.analyzeImports(fileContent, function(data){ | ||
utils.log('analyze done.', 'debug'); | ||
// after combo, @charset position may be changed. since the output file encoding is specified, we should remove @charset. | ||
data = data.replace(/@charset\s+['|"](\S*)["|'];/g, ''); | ||
// restore all comments back. | ||
data = compressor._restoreComments(data, preservedTokens); | ||
self.generateOutput(data); | ||
report.imports = self.imports; | ||
report.target = self.config.target; | ||
report.output = self.config.output; | ||
report.content = data; | ||
callback && callback(null, report); | ||
}); | ||
// preserve data url and comment. | ||
var preservedTokens = []; | ||
fileContent = compressor._extractDataUrls(fileContent, preservedTokens); | ||
fileContent = compressor._extractComments(fileContent, preservedTokens); | ||
// start analyze file content | ||
self.analyzeImports(fileContent, function(data){ | ||
utils.log('analyze done.', 'debug'); | ||
// after combo, @charset position may be changed. since the output file encoding is specified, we should remove @charset. | ||
data = data.replace(/@charset\s+['|"](\S*)["|'];/g, ''); | ||
// restore all comments back. | ||
data = compressor._restoreComments(data, preservedTokens); | ||
self.generateOutput(data); | ||
report.imports = self.imports; | ||
report.target = self.config.target; | ||
report.output = self.config.output; | ||
report.content = data; | ||
callback && callback(null, report); | ||
}); | ||
// fs.readFile(file, '', function(err, data){ | ||
// if(err){ | ||
// utils.log(err, 'error'); | ||
// throw self.error(err); | ||
// } | ||
// utils.log('Cur file is ' + self.config.target, 'debug'); | ||
// utils.log('file read: ' + file, 'debug'); | ||
// | ||
// config.inputEncoding = config.inputEncoding ? config.inputEncoding : utils.detectCharset(data); | ||
// var fileContent = iconv.decode(data, config.inputEncoding); | ||
// utils.log('file charset is: ' + config.inputEncoding, 'debug'); | ||
// | ||
// // preserve data url and comment. | ||
// var preservedTokens = []; | ||
// fileContent = compressor._extractDataUrls(fileContent, preservedTokens); | ||
// fileContent = compressor._extractComments(fileContent, preservedTokens); | ||
// | ||
// // start analyze file content | ||
// self.analyzeImports(fileContent, function(data){ | ||
// utils.log('analyze done.', 'debug'); | ||
// // after combo, @charset position may be changed. since the output file encoding is specified, we should remove @charset. | ||
// data = data.replace(/@charset\s+['|"](\S*)["|'];/g, ''); | ||
// // restore all comments back. | ||
// data = compressor._restoreComments(data, preservedTokens); | ||
// self.generateOutput(data); | ||
// | ||
// report.imports = self.imports; | ||
// report.target = self.config.target; | ||
// report.output = self.config.output; | ||
// report.content = data; | ||
// callback && callback(null, report); | ||
// }); | ||
//// self.analyzeImports(); | ||
// }); | ||
} | ||
@@ -283,2 +315,3 @@ }; | ||
var funcs = []; | ||
_.forEach(files, function(file, index){ | ||
@@ -285,0 +318,0 @@ funcs.push(function(cb){ |
{ | ||
"name":"css-combo", | ||
"version":"0.2.9", | ||
"version":"0.3.0", | ||
"description":"css module combo tool", | ||
@@ -5,0 +5,0 @@ "author":"daxingplay <daxingplay@gmail.com>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
649523
29
2678
5