Socket
Book a DemoInstallSign in
Socket

@unic/estatico-utils

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unic/estatico-utils

Utilities for logging etc.

latest
Source
npmnpm
Version
0.0.10
Version published
Maintainers
3
Created
Source

@unic/estatico-utils [WIP]

Utilities for logging etc.

Installation

$ npm install --save-dev @unic/estatico-utils

Usage

Logger

const parseArgs = require('minimist');
const { Logger } = require('@unic/estatico-utils');

const env = parseArgs(process.argv.slice(2));

// Create instance of logger for specific plugin
const logger = new Logger('estatico-bla');

// Log info
logger.info('Something is happening');

// Log debug info, only logged if "-LLLL" is set
logger.debug('Something is happening', /* Additional log info */);

// Log error, will exit process unless env.dev is true
logger.error(new Error('Something went wrong'), env.dev);

Plugin

const { Plugin } = require('@unic/estatico-utils');

// Set up details, schema and task
// …

module.exports = (options, env = {}) => new Plugin({
  defaults,
  schema,
  options,
  task,
  env,
});

Test

compareFiles(t, fileGlob)

Compares files resolved from fileGlob with current files in results/ directory.

const test = require('ava');
const utils = require('@unic/estatico-utils').test;

test.cb('default', (t) => {
  task(defaults)().on('end', () => utils.compareFiles(t, path.join(__dirname, 'expected/default/*')));
});

stripLogs(sinonSpy)

Join everything sinon.spy captured into string, strip ANSI characters and line-breaks.

const test = require('ava');
const sinon = require('sinon');
const utils = require('@unic/estatico-utils').test;

test.cb('error', (t) => {
  const spy = sinon.spy(console, 'log');

  task(defaults)().on('end', () => {
    spy.restore();

    const log = utils.stripLogs(spy);

    t.regex(log, /test\/fixtures\/error.hbs Parse error on line 2/);

    t.end();
  });
});

readFileSyncCached

Serve unchanged files from in-memory cache.

const { readFileSyncCached } = require('@unic/estatico-utils');

// First read will go to file system
console.log(readFileSyncCached('/path/to/my/file.ext'));

// Second request will be served from cache unless the file has changed in the meantime
// fs.statSync('/path/to/my/file.ext').mtime.getTime() is used as reference
console.log(readFileSyncCached('/path/to/my/file.ext'));

License

Apache 2.0.

FAQs

Package last updated on 08 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts