Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gzipper

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gzipper - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

.eslintrc.js

67

index.js

@@ -6,2 +6,4 @@ #!/usr/bin/env node

const distFolder = process.argv[2];
const logLevel = process.argv[3];
let logger = logLevel === '--log' ? loggerInit(true) : loggerInit(false);

@@ -12,6 +14,47 @@ if (!distFolder) {

let globalFilesCount = 0;
let successGlobalFilesCount = 0;
const outputDir = path.resolve(__dirname, distFolder);
const filesList = fs.readdirSync(outputDir).filter(file => path.extname(file) === '.js');
getNext(filesList, outputDir, () => console.log('Done!'));
compileFolderRecursively(outputDir);
/**
* Compile files in folders recursively
* @param {string} outputDir
* @param {number} fileCounter
*/
function compileFolderRecursively(outputDir) {
const filesList = fs.readdirSync(outputDir);
try {
filesList.forEach((file) => {
const fullFilePath = path.resolve(outputDir, file);
if (fs.lstatSync(fullFilePath).isFile()
&& path.extname(fullFilePath) === '.js') {
++globalFilesCount;
compressFile(file, outputDir, () => {
++successGlobalFilesCount;
logger(`File ${file} has been compiled.`);
if (globalFilesCount === successGlobalFilesCount) {
logger(`${globalFilesCount} files have been compiled.`, true);
}
});
} else if (fs.lstatSync(fullFilePath).isDirectory()) {
compileFolderRecursively(fullFilePath);
}
});
} catch (err) {
console.error(err);
}
}
/**
* File compression func
*
* @param {string} filename
* @param {string} outputDir
* @param {any} callback
*/
function compressFile(filename, outputDir, callback) {

@@ -30,12 +73,10 @@ let compress = zlib.createGzip();

function getNext(filesList, outputDir, callback) {
if (filesList.length) {
const file = filesList.shift();
compressFile(file, outputDir, () => {
console.log(`File ${file} has been compiled.`);
getNext(filesList, outputDir, callback);
});
} else if (callback) {
callback();
}
}
/**
* Custom logger
* @param {boolean} enable
* @return {Function} logger function
*/
function loggerInit(enable) {
return (message, force) => ((enable || force) && console.log(message));
}
{
"name": "gzipper",
"version": "1.0.3",
"version": "1.1.0",
"description": "Simple gzip script for your files.",

@@ -23,3 +23,10 @@ "main": "index.js",

},
"homepage": "https://github.com/gios/gzipper#readme"
"homepage": "https://github.com/gios/gzipper#readme",
"devDependencies": {
"eslint": "^4.10.0",
"eslint-config-google": "^0.9.1"
},
"engines": {
"node": ">=6 <8"
}
}
# gzipper
Simple script for gzipping your js files.
Simple CLI for gzipping your js files.
## How to use:
### Install globally the package.
``` npm i gzipper -g ```
or locally to devDependencies
``` npm i gzipper -D ```
### Run script from global scope or from your package.json as a script;
Globally usage.
``` gzipper <path> args```
Locally usage.
* add to scripts property in your package.json
```
"scripts": {
...
"gzipper": "gzipper"
}
```
* use gzipper with your build commands (ex. Angular CLI)
```
"scripts": {
"build": "ng build && gzipper './dist'"
}
```
### Args
* ```--log``` - enable logging
### Roadmap
- [x] First work version
- [ ] Unit tests
- [ ] Additional arguments for CLI
- [ ] Your porposal for improvement
### Contribution
I appreciate every contribution, just fork the repository and send the pull request with your changes.
### Requirments
* Node.js 6 or 8
dist/nested/test.js
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc