Skip to content

Instantly share code, notes, and snippets.

const fs = require('fs');
const { promisify } = require('util');
const compareImages = promisify(require('looks-same'));
const createDiffImage = promisify(require('looks-same').createDiff);
const resembleCompareImages = require('resemblejs/compareImages');
const sharp = require('sharp');
@kisenka
kisenka / transformer.js
Created April 19, 2018 19:29
TypeScript transformer to rename imports (like babel-plugin-import-rename)
const ts = require('typescript');
const IMPORT_RE = /(.*)\.pcss$/;
const REPLACE_TO = '$1.css';
module.exports = function () {
return function (context) {
function visitor(node) {
const isImport = ts.isImportDeclaration(node);
const moduleName = isImport && node.moduleSpecifier ? node.moduleSpecifier.text : null;
const spriteSize = {
width: 610.6,
height: 248.5
};
const symbolSize = {
width: 610.6,
height: 108.5
};
module.exports = (wallaby) => {
const config = {
files: [
{ pattern: 'lib/*.js' },
{ pattern: 'lib/**/*.js' },
{ pattern: 'test/tests-*.js', instrument: false }
],
tests: [
{ pattern: 'test/*.test.js' }
@kisenka
kisenka / server.js
Created April 6, 2017 12:00
JSON server mock
const express = require('express');
const data = require('./server-data.json');
const server = express();
const responseHeaders = {
'Content-Type': 'application/javascript',
'Access-Control-Allow-Origin': '*'
};
server.get('/products/releases', (req, res) => {
@kisenka
kisenka / app.js
Last active February 16, 2017 16:37
HotModuleReplacementPlugin doesn't generate hot update assets if it applies in child compilation
require('./styles.css');
@kisenka
kisenka / plugin.js
Created October 12, 2016 22:05
Prevent Webpack to emit asset in compilation.assets
compiler.plugin('compilation', function(compilation) {
compilation.plugin('chunk-asset', function (chunk, filename) {
// chunk.name can be useful, usually it's name of entrypoint
delete this.assets[filename];
});
});
@kisenka
kisenka / webpack.config.js
Created July 6, 2016 21:24
Webpack dev server build info show only errors
devServer: {
// It suppress error shown in console, so it has to be set to false.
quiet: false,
// It suppress everything except error, so it has to be set to false as well
// to see success build.
noInfo: false,
stats: {
// Config for minimal console.log mess.
assets: false,
@kisenka
kisenka / parseYAMLFrontMatter.js
Last active May 6, 2016 22:54
Parse YAML front matter
/**
* @param {string} src Markdown source.
* @param {string} [delimiter='---'] Front matter delimiter. --- by default.
* @returns {{meta: Object, body: string}}
*/
function parseYAMLFrontMatter(src, delimiter) {
var delimiter = delimiter || '---';
var meta = null;
var body = src;
@kisenka
kisenka / getAdditionalAssets.js
Created April 21, 2016 16:09
getAdditionalAssets
function getAdditionalAssets(compilation) {
var stats = compilation.getStats().toJson();
var modules = stats.modules;
var chunks = {};
modules.forEach(function (module) {
var moduleChunks = module.chunks;
var isNormalModule = module.chunks.length > 0 && module.assets.length == 0;
if (isNormalModule)
return;