clean-css-cli
Advanced tools
Comparing version 5.2.2 to 5.3.0
@@ -0,1 +1,7 @@ | ||
[5.3.0 / 2021-04-28](https://github.com/jakubpawlowicz/clean-css-cli/compare/5.2...v5.3.0) | ||
================== | ||
* Fixed issue [#61](https://github.com/jakubpawlowicz/clean-css-cli/issues/61) - source maps, rebasing, and batch processing. | ||
* Fixed issue [#65](https://github.com/jakubpawlowicz/clean-css-cli/issues/65) - batch processing with output path. | ||
[5.2.2 / 2021-03-19](https://github.com/jakubpawlowicz/clean-css-cli/compare/v5.2.1...v5.2.2) | ||
@@ -2,0 +8,0 @@ ================== |
64
index.js
@@ -95,5 +95,3 @@ var fs = require('fs'); | ||
rebase: inputOptions.withRebase ? true : false, | ||
rebaseTo: inputOptions.withRebase && ('output' in inputOptions) && inputOptions.output.length > 0 ? | ||
path.dirname(path.resolve(inputOptions.output)) : | ||
(inputOptions.withRebase ? process.cwd() : undefined), | ||
rebaseTo: undefined, | ||
sourceMap: inputOptions.sourceMap, | ||
@@ -119,3 +117,3 @@ sourceMapInlineSources: inputOptions.sourceMapInlineSources | ||
if (options.sourceMap && !options.output) { | ||
if (options.sourceMap && !options.output && !options.batch) { | ||
outputFeedback(['Source maps will not be built because you have not specified an output file.'], true); | ||
@@ -125,2 +123,18 @@ options.sourceMap = false; | ||
if (options.output && options.batch) { | ||
fs.mkdirSync(options.output, {recursive: true}); | ||
} | ||
if (inputOptions.withRebase && ('output' in inputOptions) && inputOptions.output.length > 0) { | ||
if (isDirectory(path.resolve(inputOptions.output))) { | ||
options.rebaseTo = path.resolve(inputOptions.output); | ||
} else { | ||
options.rebaseTo = path.dirname(path.resolve(inputOptions.output)); | ||
} | ||
} else { | ||
if (inputOptions.withRebase) { | ||
options.rebaseTo = process.cwd(); | ||
} | ||
} | ||
var configurations = { | ||
@@ -150,2 +164,14 @@ batchSuffix: inputOptions.batchSuffix, | ||
function isDirectory(path) { | ||
try { | ||
return fs.statSync(path).isDirectory(); | ||
} catch (e) { | ||
if (e.code == 'ENOENT') { | ||
return false; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
function findArgumentTo(option, rawArgs, args) { | ||
@@ -186,3 +212,7 @@ var value = true; | ||
return globPatterns.reduce(function (accumulator, path) { | ||
return accumulator.concat(glob.sync(path, { ignore: ignoredGlobPatterns, nodir: true, nonull: true })); | ||
var expandedWithSource = | ||
glob.sync(path, { ignore: ignoredGlobPatterns, nodir: true, nonull: true }) | ||
.map(function (expandedPath) { return { expanded: expandedPath, source: path }; }); | ||
return accumulator.concat(expandedWithSource); | ||
}, []); | ||
@@ -193,11 +223,19 @@ } | ||
var cleanCss = new CleanCSS(options); | ||
var input = typeof(data) == 'string' ? | ||
data : | ||
data.map(function (o) { return o.expanded; }); | ||
applyNonBooleanCompatibilityFlags(cleanCss, options.compatibility); | ||
configurations.beforeMinifyCallback(cleanCss); | ||
cleanCss.minify(data, getSourceMapContent(configurations.inputSourceMap), function (errors, minified) { | ||
cleanCss.minify(input, getSourceMapContent(configurations.inputSourceMap), function (errors, minified) { | ||
var inputPath; | ||
var outputPath; | ||
if (options.batch && !('styles' in minified)) { | ||
for (inputPath in minified) { | ||
processMinified(process, configurations, minified[inputPath], inputPath, toOutputPath(inputPath, configurations.batchSuffix)); | ||
outputPath = options.batch && options.output ? | ||
toBatchOutputPath(inputPath, configurations.batchSuffix, options.output, data) : | ||
toSimpleOutputPath(inputPath, configurations.batchSuffix); | ||
processMinified(process, configurations, minified[inputPath], inputPath, outputPath); | ||
} | ||
@@ -210,3 +248,3 @@ } else { | ||
function toOutputPath(inputPath, batchSuffix) { | ||
function toSimpleOutputPath(inputPath, batchSuffix) { | ||
var extensionName = path.extname(inputPath); | ||
@@ -217,2 +255,12 @@ | ||
function toBatchOutputPath(inputPath, batchSuffix, output, expandedWithSource) { | ||
var extensionName = path.extname(inputPath); | ||
var inputSource = expandedWithSource.find(function (ic) { return ic.expanded == inputPath; }).source; | ||
var inputSourceRoot = inputSource.indexOf('*') > -1 ? | ||
inputSource.substring(0, inputSource.indexOf('*')) : | ||
path.dirname(inputSource); | ||
return path.join(output, inputPath.replace(inputSourceRoot, '').replace(new RegExp(extensionName + '$'), batchSuffix + extensionName)); | ||
} | ||
function processMinified(process, configurations, minified, inputPath, outputPath) { | ||
@@ -219,0 +267,0 @@ var mapOutputPath; |
{ | ||
"name": "clean-css-cli", | ||
"version": "5.2.2", | ||
"version": "5.3.0", | ||
"description": "A command-line interface to clean-css CSS optimization library", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -388,5 +388,11 @@ <h1 align="center"> | ||
```shell | ||
cleancss --batch --batch-suffix '.min' styles/*.css | ||
cleancss --batch --batch-suffix '.min' styles/*.css # output will have `.min` suffix before `.css`, e.g. styles.min.css | ||
``` | ||
or | ||
```shell | ||
cleancss --batch --batch-suffix '' styles/*.css # output files will OVERRIDE input files | ||
``` | ||
Remember you can use [glob matching](https://www.npmjs.com/package/glob#glob-primer) to match exactly the files you want. | ||
@@ -393,0 +399,0 @@ |
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
43044
304
474