Skip to content

Commit

Permalink
Merge pull request #4 from pakhuta/add-brotli-comression
Browse files Browse the repository at this point in the history
Add brotli comression
  • Loading branch information
pahuta committed Jan 23, 2020
2 parents 0f9a463 + 8394702 commit d56eb63
Show file tree
Hide file tree
Showing 27 changed files with 3,788 additions and 388 deletions.
19 changes: 14 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
root = true

[*]
end_of_line = lf
indent_style = space
indent_size = 4
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.json]
indent_size = 2
[*.md]
max_line_length = off
trim_trailing_whitespace = false

[*.ts]
ij_typescript_spaces_within_imports = true
ij_typescript_use_double_quotes = false
ij_typescript_force_quote_style = true
ij_typescript_import_sort_members = true
ij_typescript_import_sort_module_name = true
ij_typescript_spaces_within_object_literal_braces = true
55 changes: 55 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"env": {
"es6": true,
"node": true,
"browser": false,
"jest": true
},
"extends": [
"standard"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"semi": [
"error",
"always"
],
"space-before-function-paren": [
"error",
{
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}
],
"quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"quote-props": ["error", "consistent-as-needed"],
"import/no-duplicates": "off",
"no-useless-escape": "off",
"no-return-assign": "off",
"no-prototype-builtins": "off",
"prefer-promise-reject-errors": "off",
"@typescript-eslint/interface-name-prefix": ["error", { "prefixWithI": "always" }],
"no-unused-vars": "off",
"generator-star-spacing": ["error", {"before": false, "after": true}],
"yield-star-spacing": ["error", {"before": false, "after": true}]
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
/coverage
/inputDir
/outputDir

.tsbuildinfo
/gzip-cli-*.tgz
/dist
5 changes: 2 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/.idea
.editorconfig
.npmignore
/dist/!(index).d.ts
/!(package.json)
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Siarhei Pakhuta
Copyright (c) 2020 Siarhei Pakhuta

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
80 changes: 65 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,98 @@


# gzip-cli
Provide possibility to gzip files from npm script section. Also you can use it in your code as imported module.
`gzip-cli` provides CLI for compressing files by using compress algorithms such as Gzip and Brotli.

### Install

```bash
npm i gzip-cli
```
### Command Line

## CLI usage
```bash
Usage: gzip [glob patterns]

Options:
-o, --output output directory
-e, --extension output file extension (default=gz)
-e, --extension output file extension (default=gz). Also supported a few extensions in one command
```

#### CLI example
```bash
gzip dist/**/*.js
```
Will gzip all `*.js` files in folder `dist` and output them to the same folder, e.g.
All `*.js` files in folder `dist` and its sub-folders will be compressed by Gzip algorithm and put them to the same folder, e.g.

`dist/public/main.js` -> `dist/public/main.js.gz`
```bash
gzip dist/**/*.js --extension=gz --extension=br
```
All `*.js` files in folder `dist` and its sub-folders will be compressed by Gzip and Brotli algorithm and put them to the same folder, e.g.
```bash
dist/public/main.js` -> `dist/public/main.js.gz
dist/public/main.js` -> `dist/public/main.js.br
```

```bash
gzip source/**/*.js --output=dist
```
Will gzip all `*.js` files in folder `source` and output them to the `dist` folder with saving file paths relative to glob base, e.g.
All `*.js` files in folder `source` and its sub-folders will be compressed by Gzip algorithm and put them to the `dist` folder with saving file paths relative to a glob pattern base, e.g.

`source/utils/fileUtils.js` -> `dist/utils/fileUtils.js.gz`

## gzip(patterns, [outputDir])
#### CLI example of using in a "scripts" section of your package.json
Compress all `*.js` files in folder `dist`:
```bash
"scripts": {
"gzip": "gzip dist/**/*.js"
}
```

Build Angular application and compress all `*.js` files in folder `dist`:
```bash
"scripts": {
"build": "ng build && gzip dist/**/*.js"
}
```

* `patterns` `{Array<String>}` Patterns to be matched
* `outputDir` `{String}` Output dir
Build React application and compress all `*.js` files in folder `build` by Gzip and Brotli algorithm:
```bash
"scripts": {
"build": "react-scripts build && gzip build/**/*.js --extension=gz --extension=br"
}
```

## Module usage
### gzip(options)

* `options.patterns` `{String[]}` Array of patterns to be matched
* `outputDir` `{String} <optional>` Output dir
* `outputExtensions` `{String[]} <optional>` Array of output file extension. `br` - for Brotli algorithm, `gz` or others - for Gzip algorithm.

### Module example
`gzip-cli` can be used like a regular module:

### Code example
```javascript
const gzib = require('gzib');
gzip(['source/**/*.js'], 'dist');
const gzip = require('gzip-cli').gzip;
gzip({patterns: ['dist/public/**/*.{html,css,js}'], outputExtensions: ['gz', 'br']});
```
All `*.html`, `*.css` and `*.js` files in folder `dist/public` and its sub-folders will be compressed by Gzip and Brotli algorithm and put them to the same folder, e.g.

```bash
dist/public/main.js` -> `dist/public/main.js.gz
dist/public/main.js` -> `dist/public/main.js.br
```
Will gzip all `*.js` files in folder `source` and its sub-folders and output them to the `dist` folder with saving file paths relative to glob base, e.g.

`source/public/main.js` -> `dist/public/main.js.gz`
`gzip({...})` returns a promise which will be resolved when all resources will be compressed.

#### Module example of using in a Gulp task
```javascript
const gzip = require('gzip-cli').gzip;
gulp.task('compress-static-files', () => {
return gzip({patterns: ['dist/public/**/*.{html,css,js}'], outputExtensions: ['gz', 'br']});
});
```
All `*.html`, `*.css` and `*.js` files in folder `dist/public` and its sub-folders will be compressed by Gzip and Brotli algorithm and put them to the same folder.

### Requirements

Node.js >= 12
19 changes: 14 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const {defaults} = require('jest-config');

module.exports = {
coveragePathIgnorePatterns : [
...defaults.coveragePathIgnorePatterns,
'/test/utils/',
'/test/config.js'
]
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],

globals: {
'ts-jest': {
tsConfig: 'tsconfig.spec.json'
}
},
coveragePathIgnorePatterns: [
...defaults.coveragePathIgnorePatterns,
'/test/utils/',
'/test/config.js'
]
};

0 comments on commit d56eb63

Please sign in to comment.