clean-css-cli
Advanced tools
Comparing version 4.2.1 to 4.3.0
@@ -1,6 +0,7 @@ | ||
[4.2.1 / 2018-08-07](https://github.com/jakubpawlowicz/clean-css-cli/compare/v4.2.0...v4.2.1) | ||
[4.3.0 / 2019-04-06](https://github.com/jakubpawlowicz/clean-css-cli/compare/4.2...v4.3.0) | ||
================== | ||
* Bumps clean-css dependency to 4.2.1. | ||
* Derives line break before source map comment from `breakWith` option. | ||
* Fixed issue [#21](https://github.com/jakubpawlowicz/clean-css-cli/issues/21) - sanity check for printing out help. | ||
* Fixed issue [#27](https://github.com/jakubpawlowicz/clean-css-cli/issues/27) - way to provide input source map. | ||
@@ -7,0 +8,0 @@ [4.2.0 / 2018-08-02](https://github.com/jakubpawlowicz/clean-css-cli/compare/4.1...v4.2.0) |
57
index.js
@@ -9,3 +9,3 @@ var fs = require('fs'); | ||
var COMPATIBILITY_PATTERN = /([\w\.]+)=(\w+)/g; | ||
var systemLineBreak = require('os').EOL; | ||
var lineBreak = require('os').EOL; | ||
@@ -38,3 +38,4 @@ function cli(process, beforeMinifyCallback) { | ||
.option('--source-map', 'Enables building input\'s source map') | ||
.option('--source-map-inline-sources', 'Enables inlining sources inside source maps'); | ||
.option('--source-map-inline-sources', 'Enables inlining sources inside source maps') | ||
.option('--input-source-map [file]', 'Specifies the path of the input source map file'); | ||
@@ -136,6 +137,8 @@ commands.on('--help', function () { | ||
// If no sensible data passed in just print help and exit | ||
fromStdin = !process.env.__DIRECT__ && !process.stdin.isTTY; | ||
if (!fromStdin && commands.args.length === 0) { | ||
commands.outputHelp(); | ||
return 0; | ||
if (commands.args.length === 0) { | ||
fromStdin = !process.env.__DIRECT__ && !process.stdin.isTTY; | ||
if (!fromStdin) { | ||
commands.outputHelp(); | ||
return 0; | ||
} | ||
} | ||
@@ -162,2 +165,6 @@ | ||
if (commands.inputSourceMap && !options.sourceMap) { | ||
options.sourceMap = true; | ||
} | ||
if (options.sourceMap && !options.output) { | ||
@@ -168,5 +175,12 @@ outputFeedback(['Source maps will not be built because you have not specified an output file.'], true); | ||
var configurations = { | ||
beforeMinifyCallback: beforeMinifyCallback, | ||
debugMode: debugMode, | ||
removeInlinedFiles: removeInlinedFiles, | ||
inputSourceMap: commands.inputSourceMap | ||
}; | ||
// ... and do the magic! | ||
if (commands.args.length > 0) { | ||
minify(process, beforeMinifyCallback, options, debugMode, removeInlinedFiles, expandGlobs(commands.args)); | ||
minify(process, options, configurations, expandGlobs(commands.args)); | ||
} else { | ||
@@ -180,3 +194,3 @@ stdin = process.openStdin(); | ||
stdin.on('end', function () { | ||
minify(process, beforeMinifyCallback, options, debugMode, removeInlinedFiles, data); | ||
minify(process, options, configurations, data); | ||
}); | ||
@@ -220,12 +234,11 @@ } | ||
function minify(process, beforeMinifyCallback, options, debugMode, removeInlinedFiles, data) { | ||
function minify(process, options, configurations, data) { | ||
var cleanCss = new CleanCSS(options); | ||
applyNonBooleanCompatibilityFlags(cleanCss, options.compatibility); | ||
beforeMinifyCallback(cleanCss); | ||
cleanCss.minify(data, function (errors, minified) { | ||
configurations.beforeMinifyCallback(cleanCss); | ||
cleanCss.minify(data, getSourceMapContent(configurations.inputSourceMap), function (errors, minified) { | ||
var mapFilename; | ||
var lineBreak; | ||
if (debugMode) { | ||
if (configurations.debugMode) { | ||
console.error('Original: %d bytes', minified.stats.originalSize); | ||
@@ -251,3 +264,3 @@ console.error('Minified: %d bytes', minified.stats.minifiedSize); | ||
if (removeInlinedFiles) { | ||
if (configurations.removeInlinedFiles) { | ||
minified.inlinedStylesheets.forEach(fs.unlinkSync); | ||
@@ -258,3 +271,2 @@ } | ||
mapFilename = path.basename(options.output) + '.map'; | ||
lineBreak = cleanCss.options.format ? cleanCss.options.format.breakWith : systemLineBreak; | ||
output(process, options, minified.styles + lineBreak + '/*# sourceMappingURL=' + mapFilename + ' */'); | ||
@@ -303,2 +315,17 @@ outputMap(options, minified.sourceMap, mapFilename); | ||
function getSourceMapContent(sourceMapPath) { | ||
if (!sourceMapPath || !fs.existsSync(sourceMapPath)) { | ||
return null; | ||
} | ||
var content = null; | ||
try { | ||
content = fs.readFileSync(sourceMapPath).toString(); | ||
} catch (e) { | ||
console.error('Failed to read the input source map file.'); | ||
} | ||
return content; | ||
} | ||
function output(process, options, minified) { | ||
@@ -305,0 +332,0 @@ if (options.output) { |
{ | ||
"name": "clean-css-cli", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "A command-line interface to clean-css CSS optimization library", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -105,2 +105,3 @@ <h1 align="center"> | ||
--source-map-inline-sources Enables inlining sources inside source maps | ||
--input-source-map [file] Specifies the path of the input source map file | ||
``` | ||
@@ -174,2 +175,3 @@ | ||
# `betweenSelectors` controls if a line break comes between selectors; defaults to `off` | ||
# `breakWith` controls the new line character, can be `windows` or `unix` (aliased via `crlf` and `lf`); defaults to system one, so former on Windows and latter on Unix | ||
# `indentBy` controls number of characters to indent with; defaults to `0` | ||
@@ -176,0 +178,0 @@ # `indentWith` controls a character to indent with, can be `space` or `tab`; defaults to `space` |
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
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
41246
287
399