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.4.2 to 1.5.0

.prettierrc.js

24

.eslintrc.js
module.exports = {
"extends": "google",
"parserOptions": {
"ecmaVersion": 2017
}
};
env: {
commonjs: true,
es6: true,
node: true,
},
extends: ['prettier', 'eslint:recommended'],
plugins: ['prettier'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
},
rules: {
'prettier/prettier': 'error',
'no-console': 0,
},
}
#!/usr/bin/env node
const zlib = require('zlib');
const fs = require('fs');
const path = require('path');
const distFolder = process.argv[2];
const logLevel = process.argv[3];
let logger = logLevel === '--log' ? loggerInit(true) : loggerInit(false);
const zlib = require('zlib')
const fs = require('fs')
const path = require('path')
const program = require('commander')
const version = require('./package.json').version
if (!distFolder) {
throw new Error('Path should be present.');
}
let outputDir
let globalFilesCount = 0;
let successGlobalFilesCount = 0;
const outputDir = path.resolve(process.cwd(), distFolder);
compileFolderRecursively(outputDir);
program
.version(version)
.usage('[options] <path>')
.action(folderPath => {
if (!folderPath) {
throw new Error(`Can't find a path.`)
}
outputDir = path.resolve(process.cwd(), folderPath)
})
.option('-v, --verbose', 'detailed level of logs')
.parse(process.argv)
let logger = program.verbose ? loggerInit(true) : loggerInit(false)
compileFolderRecursively(outputDir)
/**

@@ -24,28 +31,34 @@ * Compile files in folders recursively.

*/
function compileFolderRecursively(outputDir) {
const filesList = fs.readdirSync(outputDir);
function compileFolderRecursively(
outputDir,
globalCount = 0,
successGlobalCount = 0
) {
const filesList = fs.readdirSync(outputDir)
try {
filesList.forEach((file) => {
const fullFilePath = path.resolve(outputDir, file);
filesList.forEach(file => {
const filePath = path.resolve(outputDir, file)
if (fs.lstatSync(fullFilePath).isFile()
&& (path.extname(fullFilePath) === '.js'
|| path.extname(fullFilePath) === '.css')) {
++globalFilesCount;
if (
fs.lstatSync(filePath).isFile() &&
(path.extname(filePath) === '.js' || path.extname(filePath) === '.css')
) {
++globalCount
compressFile(file, outputDir, () => {
++successGlobalFilesCount;
logger(`File ${file} has been compiled.`);
++successGlobalCount
logger(`File ${file} has been compiled.`)
if (globalFilesCount === successGlobalFilesCount) {
logger(`${globalFilesCount} files have been compiled.`, true);
if (globalCount === successGlobalCount) {
logger(`${globalCount} files have been compiled.`, true)
}
});
} else if (fs.lstatSync(fullFilePath).isDirectory()) {
compileFolderRecursively(fullFilePath);
})
} else if (fs.lstatSync(filePath).isDirectory()) {
compileFolderRecursively(filePath, globalCount, successGlobalCount)
}
});
})
} catch (err) {
console.error(err);
console.error(err)
logger(`${globalCount} files have been compiled.`, true)
}

@@ -62,15 +75,14 @@ }

function compressFile(filename, outputDir, callback) {
let compress = zlib.createGzip();
let input = fs.createReadStream(path.join(outputDir, filename));
let output = fs.createWriteStream(path.join(outputDir, filename) + '.gz');
let compress = zlib.createGzip()
let input = fs.createReadStream(path.join(outputDir, filename))
let output = fs.createWriteStream(`${path.join(outputDir, filename)}.gz`)
input.pipe(compress).pipe(output);
input.pipe(compress).pipe(output)
if (callback) {
output.on('finish', callback);
output.on('error', (error) => console.error(error));
output.on('finish', callback)
output.on('error', error => console.error(error))
}
}
/**

@@ -83,3 +95,3 @@ * Custom logger.

function loggerInit(enable) {
return (message, force) => ((enable || force) && console.log(message));
return (message, force) => (enable || force) && console.log(message)
}
{
"name": "gzipper",
"version": "1.4.2",
"description": "Simple gzip script for your files.",
"version": "1.5.0",
"description": "CLI for gzipping js/css files, also perfectly works with Angular CLI.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prettier": "prettier --write \"**/*.js\"",
"eslint": "eslint \"**/*.js\"",
"check": "npm run prettier && npm run eslint"
},

@@ -15,5 +18,11 @@ "repository": {

"keywords": [
"tool",
"cli",
"zlib",
"zip",
"gzip",
"script",
"gzipper"
"gzipper",
"angular",
"compression"
],

@@ -27,8 +36,13 @@ "author": "Gios",

"devDependencies": {
"eslint": "^5.7.0",
"eslint-config-google": "^0.10.0"
"eslint": "^5.15.1",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"prettier": "^1.16.4"
},
"engines": {
"node": ">=8"
},
"dependencies": {
"commander": "^2.19.0"
}
}
# gzipper
Simple CLI for gzipping your js and css files.
CLI for gzipping js/css files.
## How to use:
### Install globally the package.
``` npm i gzipper -g ```
`npm i gzipper -g`
or locally to devDependencies
``` npm i gzipper ```
`npm i gzipper -D`
### Run script from global scope or from your package.json as a script;
Globally usage.
``` gzipper <path> args```
`gzipper <path> args`
Locally usage.
* add to scripts property in your package.json
- add to scripts property in your package.json
```

@@ -28,3 +32,4 @@ "scripts": {

* use gzipper with your build commands (e.g. Angular CLI)
- use gzipper with your build commands (e.g. Angular CLI)
```

@@ -36,9 +41,14 @@ "scripts": {

### Args
* ```--log``` - enable logging for each file
### Options:
- `-V, --version` output the version number
- `-v, --verbose` detailed level of logs
- `-h, --help` output usage information
### Contribution
I appreciate every contribution, just fork the repository and send the pull request with your changes.
### Requirments
* Node.js >= 8
### Requirements
- Node.js >= 8
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