Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jadiagaurang committed Apr 18, 2022
2 parents c3c022b + 1926338 commit 6ece011
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 80 deletions.
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

[![NPM Downloads](https://img.shields.io/npm/dw/minify-all-cli)](https://www.npmjs.com/package/minify-all-cli)

Minify All JS, CSS and HTML files in a folder by using UglifyJS, CSSNano and HTMLMinifier with an option to gzip all the files as well. Package also supports processCount to set maximum degree of parallelism.
Minify All JS, CSS and HTML files in a folder by using UglifyJS, CSSNano and HTMLMinifier with an option to gzip all the files as well.

Package also supports processCount to set maximum degree of parallelism.

## Installation

Expand All @@ -24,34 +26,35 @@ minify-all-cli -s [source folder] -d [destination folder] [options]
Usage: -s <source> -d <destination>

Options:
--help Show help [boolean]
--version Show version number [boolean]
-j, --skipJS Should minify JS the file or skip it? [boolean]
-c, --skipCSS Should minify CSS the file or skip it? [boolean]
-h, --skipHTML Should minify HTML the file or skip it? [boolean]
-g, --doGzip Should gzip the file or skip it? [boolean]
-m, --skipFileMasks Partial Filder Path to skip it over [string]
-i, --ignoreFileMasks Partial Filder Path to ignore it over [string]
-f, --configFile Specifies a json configuration file for the
UglifyJS, CSSNano and HTML Minifier module [string]
-l, --logLevel Set log level to print warn, log, error,
fatal messages [string]
-p, --processCount Specifies process count to set maximum degree
of parallelism [number]
--help Show help [boolean]
--version Show version number [boolean]
-j, --skipJS Should minify JS the file or skip it? [boolean]
-c, --skipCSS Should minify CSS the file or skip it? [boolean]
-h, --skipHTML Should minify HTML the file or skip it? [boolean]
-g, --doGzip Should gzip the file or skip it? [boolean]
-m, --skipFileMasks Partial Filder Path to skip it over [string]
-e, --skipFileExtensions File Extensions to skip it over [array]
-i, --ignoreFileMasks Partial Filder Path to ignore it over [string]
-f, --configFile Specifies a json configuration file for the
UglifyJS, CSSNano and HTML Minifier module [string]
-l, --logLevel Set log level to print warn, log, error,
fatal messages [string]
-p, --processCount Specifies process count to set maximum degree
of parallelism [number]
```

## CLI Example

### Prod

```bash
npx minify-all-cli -s "/home/ubuntu/source" -d "/home/ubuntu/compressed" --logLevel=info
npx minify-all-cli -s "/home/ubuntu/source" -d "/home/ubuntu/compressed" --skipFileExtensions=.mp3,.mp4 --logLevel=info
```

### Local

```bash
node . -s "/home/ubuntu/source" -d "/home/ubuntu/compressed" --logLevel=info
node . -s "/home/ubuntu/source" -d "/home/ubuntu/compressed" --skipFileExtensions=.mp3,.mp4 --logLevel=info
```

## License
Expand Down
2 changes: 2 additions & 0 deletions bin/minify-all-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const cliOptions = yargs
.option("h", { alias: "skipHTML", describe: "Should minify HTML the file or skip it?", type: "boolean", demandOption: false })
.option("g", { alias: "doGzip", describe: "Should gzip the file or skip it?", type: "boolean", demandOption: false })
.option("m", { alias: "skipFileMasks", describe: "Partial Filder Path to skip it over", type: "string", demandOption: false })
.option("e", { alias: "skipFileExtensions", describe: "File Extensions to skip it over", type: "array", demandOption: false })
.option("i", { alias: "ignoreFileMasks", describe: "Partial Filder Path to ignore it over", type: "string", demandOption: false })
.option("f", { alias: "configFile", describe: "Specifies a json configuration file for the UglifyJS, CSSNano and HTML Minifier module", type: "string", demandOption: false })
.option("l", { alias: "logLevel", describe: "Set log level to print warn, log, error, fatal messages", type: "string", demandOption: false })
Expand All @@ -24,6 +25,7 @@ const cliOptions = yargs
skipHTML: cliOptions.skipHTML || cliOptions.h || false,
doGzip: cliOptions.doGzip || cliOptions.g || false,
skipFileMasks: cliOptions.skipFileMasks || cliOptions.m || "",
skipFileExtensions: cliOptions.skipFileExtensions || cliOptions.e || [],
ignoreFileMasks: cliOptions.ignoreFileMasks || cliOptions.i || "",
configFile: cliOptions.configFile || cliOptions.f || null,
logLevel: cliOptions.logLevel || cliOptions.l || "info",
Expand Down
6 changes: 4 additions & 2 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = class MinifyAllCLI {
skipHTML: false,
doGzip: false,
skipFileMasks: "",
skipFileExtensions: [".mp3", ".mp4"],
ignoreFileMasks: "",
configFile: null,
logLevel: "info",
Expand Down Expand Up @@ -192,10 +193,11 @@ module.exports = class MinifyAllCLI {
var strPartialFilePath = path.relative(me.SourceDirectory, strFilePath);
var strDestinationFile = path.join(me.DestinationDirectory, path.sep, strPartialFilePath);
var strFileDirectory = path.dirname(strDestinationFile);

var strFileExtension = path.extname(strFilePath);

fs.mkdirSync(strFileDirectory, { recursive: true });

if (me.options.doGzip) {
if (me.options.doGzip && !_.contains(me.options.skipFileExtensions, strFileExtension)) {
AppUtil.doGzip(strFilePath, strDestinationFile).then(function () {
me.logger.info("Gzip. Source: " + strFilePath + "; Destination: " + strDestinationFile);
resolve();
Expand Down
120 changes: 60 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minify-all-cli",
"version": "1.0.7",
"version": "1.0.8",
"description": "Minify All JS, CSS and HTML files in a folder by using UglifyJS, CSSNano and HTMLMinifier with an option to gzip all the files as well.",
"main": "bin/minify-all-cli.js",
"bin": {
Expand Down

0 comments on commit 6ece011

Please sign in to comment.