Socket
Socket
Sign inDemoInstall

gobem-proc-sqwish

Package Overview
Dependencies
36
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.6 to 0.0.7

38

index.js
'use strict';
var sqwish = require('sqwish'),
redis = require('redis');
var path = require('path'),
fs = require('fs'),
sqwish = require('sqwish'),
xxhash = require('xxhash');

@@ -9,35 +11,25 @@ module.exports = function (options) {

let client = options.redisClient,
key = options.redisKey || 'gobem-proc-sqwish';
return {
before: function (next) {
client = client || redis.createClient(options.redisOptions);
client.expire(key, 86400);
next();
},
process: function (next, input, output, config, rawContent, rawPath) {
if (!rawContent) return next();
process: function (next, input, output, config, content, path) {
if (!content) return next();
client.hget(key, content, function (error, reply) {
if (reply === null) {
let key = xxhash.hash(new Buffer(rawContent), 0xCAFEBABE) + '',
filePath = path.join(options.cacheDir + '', 'gobem-proc-sqwish^' + key);
fs.readFile(filePath, 'utf8', (error, fileContent) => {
if (error) {
try {
output.set(path, sqwish.minify(content));
client.hset(key, content, output.get(path), next);
output.set(rawPath, sqwish.minify(rawContent));
fs.writeFile(filePath, output.get(rawPath), next);
} catch (error) {
output.set(path, content);
output.set(rawPath, rawContent);
next(options.ignoreErrors ? null : error);
}
} else {
output.set(path, reply);
output.set(rawPath, fileContent);
next();
}
});
},
clear: function (next) {
!options.redisClient && client.end();
next();
}
};
};
{
"name": "gobem-proc-sqwish",
"version": "0.0.6",
"version": "0.0.7",
"description": "Processor to minify CSS files for gobem builder.",

@@ -8,3 +8,3 @@ "main": "index.js",

"sqwish": "*",
"redis": "*"
"xxhash": "*"
},

@@ -11,0 +11,0 @@ "peerDependencies": {

# gobem-proc-sqwish
This processor for [gobem](https://github.com/Enet/gobem) minifies CSS files using **sqwish**. All options are passed as a single object. **gobem-proc-sqwish** requires redis database to cache results of the work.
This processor for [gobem](https://github.com/Enet/gobem) minifies CSS files using **sqwish**. All options are passed as a single object. **gobem-proc-sqwish** requires directory to cache results of the work.
The following options are supported:
* `ignoreErrors`<br>
* `ignoreErrors`\
If this flag is `true` and error occured, raw file's content will be written instead minified one.
* `redisKey`<br>
The key in the redis database to store cache. Default value is `gobem-proc-sqwish`.
* `redisClient`<br>
Already created redis-client. [This](https://github.com/NodeRedis/node_redis) module is used.
* `redisOptions`<br>
Options for a new redis-client. This field is ignored, if `redisClient` is passed.
* `cacheDir`\
Full path to a readable and writable directory to cache files.

@@ -21,5 +17,3 @@ ### Example for **build.js**

ignoreErrors: true,
redisOptions: {
port: 6370
}
cacheDir: '/var/www/gobem/cache'
}],

@@ -26,0 +20,0 @@ ['write', 1]

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc