Comparing version 2.7.0 to 2.8.0
@@ -10,2 +10,3 @@ #!/usr/bin/env node | ||
GZIPPER_EXCLUDE, | ||
GZIPPER_INCLUDE, | ||
GZIPPER_GZIP_LEVEL, | ||
@@ -26,2 +27,3 @@ GZIPPER_GZIP_MEMORY_LEVEL, | ||
.option('-e, --exclude [exclude]', 'exclude file extensions from compression') | ||
.option('-i, --include [include]', 'include file extensions for compression') | ||
.option( | ||
@@ -71,2 +73,3 @@ '-gl, --gzip-level [level]', | ||
exclude: GZIPPER_EXCLUDE || program.exclude, | ||
include: GZIPPER_INCLUDE || program.include, | ||
gzipLevel: +GZIPPER_GZIP_LEVEL || +program.gzipLevel, | ||
@@ -73,0 +76,0 @@ gzipMemoryLevel: +GZIPPER_GZIP_MEMORY_LEVEL || +program.gzipMemoryLevel, |
{ | ||
"name": "gzipper", | ||
"version": "2.7.0", | ||
"version": "2.8.0", | ||
"description": "CLI for compressing files.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -60,2 +60,3 @@ # Gzipper | ||
| `-e, --exclude` | `GZIPPER_EXCLUDE` | exclude file extensions from compression | | ||
| `-i, --include` | `GZIPPER_INCLUDE` | include file extensions for compression | | ||
| `-gl, --gzip-level [level]` | `GZIPPER_GZIP_LEVEL` | gzip compression level -1 (default), 0 (no compression) - 9 (best compression) | | ||
@@ -62,0 +63,0 @@ | `-gm, --gzip-memory-level [memoryLevel]` | `GZIPPER_GZIP_MEMORY_LEVEL` | amount of memory which will be allocated for compression 8 (default), 1 (minimum memory) - 9 (maximum memory) | |
@@ -302,2 +302,13 @@ const fs = require('fs') | ||
} | ||
const includeExtensions = | ||
this.options.include && | ||
this.options.include.split(',').map(item => `.${item.trim()}`) | ||
if (includeExtensions) { | ||
return VALID_EXTENSIONS.filter(extension => | ||
includeExtensions.includes(extension) | ||
) | ||
} | ||
return VALID_EXTENSIONS | ||
@@ -304,0 +315,0 @@ } |
@@ -339,2 +339,31 @@ const assert = require('assert') | ||
it('should include only specific file extensions for compression', async () => { | ||
const options = { | ||
include: 'js,css,html', | ||
verbose: true, | ||
} | ||
const INCLUDED_FILES_COUNT = 9 | ||
const gzipper = new Gzipper(COMPRESS_PATH, null, options) | ||
const loggerSuccessSpy = sinon.spy(gzipper.logger, 'success') | ||
const loggerInfoSpy = sinon.spy(gzipper.logger, 'info') | ||
await gzipper.compress() | ||
const files = await getFiles(COMPRESS_PATH, ['.gz']) | ||
assert.ok( | ||
loggerSuccessSpy.calledOnceWithExactly( | ||
`${files.length} files have been compressed.`, | ||
true | ||
) | ||
) | ||
assert.strictEqual(loggerInfoSpy.callCount, INCLUDED_FILES_COUNT + 1) | ||
assert.ok(gzipper.createCompression() instanceof zlib.Gzip) | ||
assert.strictEqual(gzipper.compressionInstance.ext, 'gz') | ||
assert.strictEqual( | ||
Object.keys(gzipper.compressionInstance.compressionOptions).length, | ||
0 | ||
) | ||
assert.strictEqual(Object.keys(gzipper.options).length, 2) | ||
}) | ||
it('should exclude file extensions from compression jpeg,jpg', async () => { | ||
@@ -341,0 +370,0 @@ const options = { |
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
514629
1449
78