3966 lines
94 KiB
JavaScript
3966 lines
94 KiB
JavaScript
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
|
|
var fs = require('fs');
|
|
var fs__default = _interopDefault(fs);
|
|
var path = require('path');
|
|
var path__default = _interopDefault(path);
|
|
var module$1 = _interopDefault(require('module'));
|
|
var os = _interopDefault(require('os'));
|
|
var rollup = require('../dist/rollup.js');
|
|
var assert = _interopDefault(require('assert'));
|
|
var events = _interopDefault(require('events'));
|
|
|
|
var minimist = function (args, opts) {
|
|
if (!opts) { opts = {}; }
|
|
|
|
var flags = { bools : {}, strings : {}, unknownFn: null };
|
|
|
|
if (typeof opts['unknown'] === 'function') {
|
|
flags.unknownFn = opts['unknown'];
|
|
}
|
|
|
|
if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
|
|
flags.allBools = true;
|
|
} else {
|
|
[].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
|
|
flags.bools[key] = true;
|
|
});
|
|
}
|
|
|
|
var aliases = {};
|
|
Object.keys(opts.alias || {}).forEach(function (key) {
|
|
aliases[key] = [].concat(opts.alias[key]);
|
|
aliases[key].forEach(function (x) {
|
|
aliases[x] = [key].concat(aliases[key].filter(function (y) {
|
|
return x !== y;
|
|
}));
|
|
});
|
|
});
|
|
|
|
[].concat(opts.string).filter(Boolean).forEach(function (key) {
|
|
flags.strings[key] = true;
|
|
if (aliases[key]) {
|
|
flags.strings[aliases[key]] = true;
|
|
}
|
|
});
|
|
|
|
var defaults = opts['default'] || {};
|
|
|
|
var argv = { _ : [] };
|
|
Object.keys(flags.bools).forEach(function (key) {
|
|
setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
|
});
|
|
|
|
var notFlags = [];
|
|
|
|
if (args.indexOf('--') !== -1) {
|
|
notFlags = args.slice(args.indexOf('--')+1);
|
|
args = args.slice(0, args.indexOf('--'));
|
|
}
|
|
|
|
function argDefined(key, arg) {
|
|
return (flags.allBools && /^--[^=]+$/.test(arg)) ||
|
|
flags.strings[key] || flags.bools[key] || aliases[key];
|
|
}
|
|
|
|
function setArg (key, val, arg) {
|
|
if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
|
if (flags.unknownFn(arg) === false) { return; }
|
|
}
|
|
|
|
var value = !flags.strings[key] && isNumber(val)
|
|
? Number(val) : val;
|
|
setKey(argv, key.split('.'), value);
|
|
|
|
(aliases[key] || []).forEach(function (x) {
|
|
setKey(argv, x.split('.'), value);
|
|
});
|
|
}
|
|
|
|
function setKey (obj, keys, value) {
|
|
var o = obj;
|
|
keys.slice(0,-1).forEach(function (key) {
|
|
if (o[key] === undefined) { o[key] = {}; }
|
|
o = o[key];
|
|
});
|
|
|
|
var key = keys[keys.length - 1];
|
|
if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
|
|
o[key] = value;
|
|
}
|
|
else if (Array.isArray(o[key])) {
|
|
o[key].push(value);
|
|
}
|
|
else {
|
|
o[key] = [ o[key], value ];
|
|
}
|
|
}
|
|
|
|
function aliasIsBoolean(key) {
|
|
return aliases[key].some(function (x) {
|
|
return flags.bools[x];
|
|
});
|
|
}
|
|
|
|
for (var i = 0; i < args.length; i++) {
|
|
var arg = args[i];
|
|
|
|
if (/^--.+=/.test(arg)) {
|
|
// Using [\s\S] instead of . because js doesn't support the
|
|
// 'dotall' regex modifier. See:
|
|
// http://stackoverflow.com/a/1068308/13216
|
|
var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
|
|
var key = m[1];
|
|
var value = m[2];
|
|
if (flags.bools[key]) {
|
|
value = value !== 'false';
|
|
}
|
|
setArg(key, value, arg);
|
|
}
|
|
else if (/^--no-.+/.test(arg)) {
|
|
var key = arg.match(/^--no-(.+)/)[1];
|
|
setArg(key, false, arg);
|
|
}
|
|
else if (/^--.+/.test(arg)) {
|
|
var key = arg.match(/^--(.+)/)[1];
|
|
var next = args[i + 1];
|
|
if (next !== undefined && !/^-/.test(next)
|
|
&& !flags.bools[key]
|
|
&& !flags.allBools
|
|
&& (aliases[key] ? !aliasIsBoolean(key) : true)) {
|
|
setArg(key, next, arg);
|
|
i++;
|
|
}
|
|
else if (/^(true|false)$/.test(next)) {
|
|
setArg(key, next === 'true', arg);
|
|
i++;
|
|
}
|
|
else {
|
|
setArg(key, flags.strings[key] ? '' : true, arg);
|
|
}
|
|
}
|
|
else if (/^-[^-]+/.test(arg)) {
|
|
var letters = arg.slice(1,-1).split('');
|
|
|
|
var broken = false;
|
|
for (var j = 0; j < letters.length; j++) {
|
|
var next = arg.slice(j+2);
|
|
|
|
if (next === '-') {
|
|
setArg(letters[j], next, arg);
|
|
continue;
|
|
}
|
|
|
|
if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
|
|
setArg(letters[j], next.split('=')[1], arg);
|
|
broken = true;
|
|
break;
|
|
}
|
|
|
|
if (/[A-Za-z]/.test(letters[j])
|
|
&& /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
|
|
setArg(letters[j], next, arg);
|
|
broken = true;
|
|
break;
|
|
}
|
|
|
|
if (letters[j+1] && letters[j+1].match(/\W/)) {
|
|
setArg(letters[j], arg.slice(j+2), arg);
|
|
broken = true;
|
|
break;
|
|
}
|
|
else {
|
|
setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
|
|
}
|
|
}
|
|
|
|
var key = arg.slice(-1)[0];
|
|
if (!broken && key !== '-') {
|
|
if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
|
|
&& !flags.bools[key]
|
|
&& (aliases[key] ? !aliasIsBoolean(key) : true)) {
|
|
setArg(key, args[i+1], arg);
|
|
i++;
|
|
}
|
|
else if (args[i+1] && /true|false/.test(args[i+1])) {
|
|
setArg(key, args[i+1] === 'true', arg);
|
|
i++;
|
|
}
|
|
else {
|
|
setArg(key, flags.strings[key] ? '' : true, arg);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
|
|
argv._.push(
|
|
flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)
|
|
);
|
|
}
|
|
if (opts.stopEarly) {
|
|
argv._.push.apply(argv._, args.slice(i + 1));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Object.keys(defaults).forEach(function (key) {
|
|
if (!hasKey(argv, key.split('.'))) {
|
|
setKey(argv, key.split('.'), defaults[key]);
|
|
|
|
(aliases[key] || []).forEach(function (x) {
|
|
setKey(argv, x.split('.'), defaults[key]);
|
|
});
|
|
}
|
|
});
|
|
|
|
if (opts['--']) {
|
|
argv['--'] = new Array();
|
|
notFlags.forEach(function(key) {
|
|
argv['--'].push(key);
|
|
});
|
|
}
|
|
else {
|
|
notFlags.forEach(function(key) {
|
|
argv._.push(key);
|
|
});
|
|
}
|
|
|
|
return argv;
|
|
};
|
|
|
|
function hasKey (obj, keys) {
|
|
var o = obj;
|
|
keys.slice(0,-1).forEach(function (key) {
|
|
o = (o[key] || {});
|
|
});
|
|
|
|
var key = keys[keys.length - 1];
|
|
return key in o;
|
|
}
|
|
|
|
function isNumber (x) {
|
|
if (typeof x === 'number') { return true; }
|
|
if (/^0x[0-9a-f]+$/i.test(x)) { return true; }
|
|
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
|
|
}
|
|
|
|
var help = "rollup version __VERSION__\n=====================================\n\nUsage: rollup [options] <entry file>\n\nBasic options:\n\n-v, --version Show version number\n-h, --help Show this help message\n-c, --config Use this config file (if argument is used but value\n is unspecified, defaults to rollup.config.js)\n-w, --watch Watch files in bundle and rebuild on changes\n-i, --input Input (alternative to <entry file>)\n-o, --output.file <output> Output (if absent, prints to stdout)\n-f, --output.format [es] Type of output (amd, cjs, es, iife, umd)\n-e, --external Comma-separate list of module IDs to exclude\n-g, --globals Comma-separate list of `module ID:Global` pairs\n Any module IDs defined here are added to external\n-n, --name Name for UMD export\n-m, --sourcemap Generate sourcemap (`-m inline` for inline map)\n--amd.id ID for AMD module (default is anonymous)\n--amd.define Function to use in place of `define`\n--no-strict Don't emit a `\"use strict\";` in the generated modules.\n--no-indent Don't indent result\n--environment <values> Settings passed to config file (see example)\n--no-conflict Generate a noConflict method for UMD globals\n--silent Don't print warnings\n--intro Content to insert at top of bundle (inside wrapper)\n--outro Content to insert at end of bundle (inside wrapper)\n--banner Content to insert at top of bundle (outside wrapper)\n--footer Content to insert at end of bundle (outside wrapper)\n--interop Include interop block (true by default)\n\nExamples:\n\n# use settings in config file\nrollup -c\n\n# in config file, process.env.INCLUDE_DEPS === 'true'\n# and process.env.BUILD === 'production'\nrollup -c --environment INCLUDE_DEPS,BUILD:production\n\n# create CommonJS bundle.js from src/main.js\nrollup --format=cjs --output=bundle.js -- src/main.js\n\n# create self-executing IIFE using `window.jQuery`\n# and `window._` as external globals\nrollup -f iife --globals jquery:jQuery,lodash:_ \\\n -i src/app.js -o build/app.js -m build/app.js.map\n\nNotes:\n\n* When piping to stdout, only inline sourcemaps are permitted\n\nFor more information visit https://github.com/rollup/rollup/wiki\n";
|
|
|
|
var version = "0.50.1";
|
|
|
|
var modules = {};
|
|
|
|
var getModule = function(dir) {
|
|
var rootPath = dir ? path__default.resolve(dir) : process.cwd();
|
|
var rootName = path__default.join(rootPath, '@root');
|
|
var root = modules[rootName];
|
|
if (!root) {
|
|
root = new module$1(rootName);
|
|
root.filename = rootName;
|
|
root.paths = module$1._nodeModulePaths(rootPath);
|
|
modules[rootName] = root;
|
|
}
|
|
return root;
|
|
};
|
|
|
|
var requireRelative = function(requested, relativeTo) {
|
|
var root = getModule(relativeTo);
|
|
return root.require(requested);
|
|
};
|
|
|
|
requireRelative.resolve = function(requested, relativeTo) {
|
|
var root = getModule(relativeTo);
|
|
return module$1._resolveFilename(requested, root);
|
|
};
|
|
|
|
var requireRelative_1 = requireRelative;
|
|
|
|
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
|
|
|
|
var escapeStringRegexp = function (str) {
|
|
if (typeof str !== 'string') {
|
|
throw new TypeError('Expected a string');
|
|
}
|
|
|
|
return str.replace(matchOperatorsRe, '\\$&');
|
|
};
|
|
|
|
function createCommonjsModule(fn, module) {
|
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
}
|
|
|
|
var colorName = {
|
|
"aliceblue": [240, 248, 255],
|
|
"antiquewhite": [250, 235, 215],
|
|
"aqua": [0, 255, 255],
|
|
"aquamarine": [127, 255, 212],
|
|
"azure": [240, 255, 255],
|
|
"beige": [245, 245, 220],
|
|
"bisque": [255, 228, 196],
|
|
"black": [0, 0, 0],
|
|
"blanchedalmond": [255, 235, 205],
|
|
"blue": [0, 0, 255],
|
|
"blueviolet": [138, 43, 226],
|
|
"brown": [165, 42, 42],
|
|
"burlywood": [222, 184, 135],
|
|
"cadetblue": [95, 158, 160],
|
|
"chartreuse": [127, 255, 0],
|
|
"chocolate": [210, 105, 30],
|
|
"coral": [255, 127, 80],
|
|
"cornflowerblue": [100, 149, 237],
|
|
"cornsilk": [255, 248, 220],
|
|
"crimson": [220, 20, 60],
|
|
"cyan": [0, 255, 255],
|
|
"darkblue": [0, 0, 139],
|
|
"darkcyan": [0, 139, 139],
|
|
"darkgoldenrod": [184, 134, 11],
|
|
"darkgray": [169, 169, 169],
|
|
"darkgreen": [0, 100, 0],
|
|
"darkgrey": [169, 169, 169],
|
|
"darkkhaki": [189, 183, 107],
|
|
"darkmagenta": [139, 0, 139],
|
|
"darkolivegreen": [85, 107, 47],
|
|
"darkorange": [255, 140, 0],
|
|
"darkorchid": [153, 50, 204],
|
|
"darkred": [139, 0, 0],
|
|
"darksalmon": [233, 150, 122],
|
|
"darkseagreen": [143, 188, 143],
|
|
"darkslateblue": [72, 61, 139],
|
|
"darkslategray": [47, 79, 79],
|
|
"darkslategrey": [47, 79, 79],
|
|
"darkturquoise": [0, 206, 209],
|
|
"darkviolet": [148, 0, 211],
|
|
"deeppink": [255, 20, 147],
|
|
"deepskyblue": [0, 191, 255],
|
|
"dimgray": [105, 105, 105],
|
|
"dimgrey": [105, 105, 105],
|
|
"dodgerblue": [30, 144, 255],
|
|
"firebrick": [178, 34, 34],
|
|
"floralwhite": [255, 250, 240],
|
|
"forestgreen": [34, 139, 34],
|
|
"fuchsia": [255, 0, 255],
|
|
"gainsboro": [220, 220, 220],
|
|
"ghostwhite": [248, 248, 255],
|
|
"gold": [255, 215, 0],
|
|
"goldenrod": [218, 165, 32],
|
|
"gray": [128, 128, 128],
|
|
"green": [0, 128, 0],
|
|
"greenyellow": [173, 255, 47],
|
|
"grey": [128, 128, 128],
|
|
"honeydew": [240, 255, 240],
|
|
"hotpink": [255, 105, 180],
|
|
"indianred": [205, 92, 92],
|
|
"indigo": [75, 0, 130],
|
|
"ivory": [255, 255, 240],
|
|
"khaki": [240, 230, 140],
|
|
"lavender": [230, 230, 250],
|
|
"lavenderblush": [255, 240, 245],
|
|
"lawngreen": [124, 252, 0],
|
|
"lemonchiffon": [255, 250, 205],
|
|
"lightblue": [173, 216, 230],
|
|
"lightcoral": [240, 128, 128],
|
|
"lightcyan": [224, 255, 255],
|
|
"lightgoldenrodyellow": [250, 250, 210],
|
|
"lightgray": [211, 211, 211],
|
|
"lightgreen": [144, 238, 144],
|
|
"lightgrey": [211, 211, 211],
|
|
"lightpink": [255, 182, 193],
|
|
"lightsalmon": [255, 160, 122],
|
|
"lightseagreen": [32, 178, 170],
|
|
"lightskyblue": [135, 206, 250],
|
|
"lightslategray": [119, 136, 153],
|
|
"lightslategrey": [119, 136, 153],
|
|
"lightsteelblue": [176, 196, 222],
|
|
"lightyellow": [255, 255, 224],
|
|
"lime": [0, 255, 0],
|
|
"limegreen": [50, 205, 50],
|
|
"linen": [250, 240, 230],
|
|
"magenta": [255, 0, 255],
|
|
"maroon": [128, 0, 0],
|
|
"mediumaquamarine": [102, 205, 170],
|
|
"mediumblue": [0, 0, 205],
|
|
"mediumorchid": [186, 85, 211],
|
|
"mediumpurple": [147, 112, 219],
|
|
"mediumseagreen": [60, 179, 113],
|
|
"mediumslateblue": [123, 104, 238],
|
|
"mediumspringgreen": [0, 250, 154],
|
|
"mediumturquoise": [72, 209, 204],
|
|
"mediumvioletred": [199, 21, 133],
|
|
"midnightblue": [25, 25, 112],
|
|
"mintcream": [245, 255, 250],
|
|
"mistyrose": [255, 228, 225],
|
|
"moccasin": [255, 228, 181],
|
|
"navajowhite": [255, 222, 173],
|
|
"navy": [0, 0, 128],
|
|
"oldlace": [253, 245, 230],
|
|
"olive": [128, 128, 0],
|
|
"olivedrab": [107, 142, 35],
|
|
"orange": [255, 165, 0],
|
|
"orangered": [255, 69, 0],
|
|
"orchid": [218, 112, 214],
|
|
"palegoldenrod": [238, 232, 170],
|
|
"palegreen": [152, 251, 152],
|
|
"paleturquoise": [175, 238, 238],
|
|
"palevioletred": [219, 112, 147],
|
|
"papayawhip": [255, 239, 213],
|
|
"peachpuff": [255, 218, 185],
|
|
"peru": [205, 133, 63],
|
|
"pink": [255, 192, 203],
|
|
"plum": [221, 160, 221],
|
|
"powderblue": [176, 224, 230],
|
|
"purple": [128, 0, 128],
|
|
"rebeccapurple": [102, 51, 153],
|
|
"red": [255, 0, 0],
|
|
"rosybrown": [188, 143, 143],
|
|
"royalblue": [65, 105, 225],
|
|
"saddlebrown": [139, 69, 19],
|
|
"salmon": [250, 128, 114],
|
|
"sandybrown": [244, 164, 96],
|
|
"seagreen": [46, 139, 87],
|
|
"seashell": [255, 245, 238],
|
|
"sienna": [160, 82, 45],
|
|
"silver": [192, 192, 192],
|
|
"skyblue": [135, 206, 235],
|
|
"slateblue": [106, 90, 205],
|
|
"slategray": [112, 128, 144],
|
|
"slategrey": [112, 128, 144],
|
|
"snow": [255, 250, 250],
|
|
"springgreen": [0, 255, 127],
|
|
"steelblue": [70, 130, 180],
|
|
"tan": [210, 180, 140],
|
|
"teal": [0, 128, 128],
|
|
"thistle": [216, 191, 216],
|
|
"tomato": [255, 99, 71],
|
|
"turquoise": [64, 224, 208],
|
|
"violet": [238, 130, 238],
|
|
"wheat": [245, 222, 179],
|
|
"white": [255, 255, 255],
|
|
"whitesmoke": [245, 245, 245],
|
|
"yellow": [255, 255, 0],
|
|
"yellowgreen": [154, 205, 50]
|
|
};
|
|
|
|
var conversions = createCommonjsModule(function (module) {
|
|
/* MIT license */
|
|
|
|
|
|
// NOTE: conversions should only return primitive values (i.e. arrays, or
|
|
// values that give correct `typeof` results).
|
|
// do not use box values types (i.e. Number(), String(), etc.)
|
|
|
|
var reverseKeywords = {};
|
|
for (var key in colorName) {
|
|
if (colorName.hasOwnProperty(key)) {
|
|
reverseKeywords[colorName[key]] = key;
|
|
}
|
|
}
|
|
|
|
var convert = module.exports = {
|
|
rgb: {channels: 3, labels: 'rgb'},
|
|
hsl: {channels: 3, labels: 'hsl'},
|
|
hsv: {channels: 3, labels: 'hsv'},
|
|
hwb: {channels: 3, labels: 'hwb'},
|
|
cmyk: {channels: 4, labels: 'cmyk'},
|
|
xyz: {channels: 3, labels: 'xyz'},
|
|
lab: {channels: 3, labels: 'lab'},
|
|
lch: {channels: 3, labels: 'lch'},
|
|
hex: {channels: 1, labels: ['hex']},
|
|
keyword: {channels: 1, labels: ['keyword']},
|
|
ansi16: {channels: 1, labels: ['ansi16']},
|
|
ansi256: {channels: 1, labels: ['ansi256']},
|
|
hcg: {channels: 3, labels: ['h', 'c', 'g']},
|
|
apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
|
|
gray: {channels: 1, labels: ['gray']}
|
|
};
|
|
|
|
// hide .channels and .labels properties
|
|
for (var model in convert) {
|
|
if (convert.hasOwnProperty(model)) {
|
|
if (!('channels' in convert[model])) {
|
|
throw new Error('missing channels property: ' + model);
|
|
}
|
|
|
|
if (!('labels' in convert[model])) {
|
|
throw new Error('missing channel labels property: ' + model);
|
|
}
|
|
|
|
if (convert[model].labels.length !== convert[model].channels) {
|
|
throw new Error('channel and label counts mismatch: ' + model);
|
|
}
|
|
|
|
var channels = convert[model].channels;
|
|
var labels = convert[model].labels;
|
|
delete convert[model].channels;
|
|
delete convert[model].labels;
|
|
Object.defineProperty(convert[model], 'channels', {value: channels});
|
|
Object.defineProperty(convert[model], 'labels', {value: labels});
|
|
}
|
|
}
|
|
|
|
convert.rgb.hsl = function (rgb) {
|
|
var r = rgb[0] / 255;
|
|
var g = rgb[1] / 255;
|
|
var b = rgb[2] / 255;
|
|
var min = Math.min(r, g, b);
|
|
var max = Math.max(r, g, b);
|
|
var delta = max - min;
|
|
var h;
|
|
var s;
|
|
var l;
|
|
|
|
if (max === min) {
|
|
h = 0;
|
|
} else if (r === max) {
|
|
h = (g - b) / delta;
|
|
} else if (g === max) {
|
|
h = 2 + (b - r) / delta;
|
|
} else if (b === max) {
|
|
h = 4 + (r - g) / delta;
|
|
}
|
|
|
|
h = Math.min(h * 60, 360);
|
|
|
|
if (h < 0) {
|
|
h += 360;
|
|
}
|
|
|
|
l = (min + max) / 2;
|
|
|
|
if (max === min) {
|
|
s = 0;
|
|
} else if (l <= 0.5) {
|
|
s = delta / (max + min);
|
|
} else {
|
|
s = delta / (2 - max - min);
|
|
}
|
|
|
|
return [h, s * 100, l * 100];
|
|
};
|
|
|
|
convert.rgb.hsv = function (rgb) {
|
|
var r = rgb[0];
|
|
var g = rgb[1];
|
|
var b = rgb[2];
|
|
var min = Math.min(r, g, b);
|
|
var max = Math.max(r, g, b);
|
|
var delta = max - min;
|
|
var h;
|
|
var s;
|
|
var v;
|
|
|
|
if (max === 0) {
|
|
s = 0;
|
|
} else {
|
|
s = (delta / max * 1000) / 10;
|
|
}
|
|
|
|
if (max === min) {
|
|
h = 0;
|
|
} else if (r === max) {
|
|
h = (g - b) / delta;
|
|
} else if (g === max) {
|
|
h = 2 + (b - r) / delta;
|
|
} else if (b === max) {
|
|
h = 4 + (r - g) / delta;
|
|
}
|
|
|
|
h = Math.min(h * 60, 360);
|
|
|
|
if (h < 0) {
|
|
h += 360;
|
|
}
|
|
|
|
v = ((max / 255) * 1000) / 10;
|
|
|
|
return [h, s, v];
|
|
};
|
|
|
|
convert.rgb.hwb = function (rgb) {
|
|
var r = rgb[0];
|
|
var g = rgb[1];
|
|
var b = rgb[2];
|
|
var h = convert.rgb.hsl(rgb)[0];
|
|
var w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
|
|
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
|
|
return [h, w * 100, b * 100];
|
|
};
|
|
|
|
convert.rgb.cmyk = function (rgb) {
|
|
var r = rgb[0] / 255;
|
|
var g = rgb[1] / 255;
|
|
var b = rgb[2] / 255;
|
|
var c;
|
|
var m;
|
|
var y;
|
|
var k;
|
|
|
|
k = Math.min(1 - r, 1 - g, 1 - b);
|
|
c = (1 - r - k) / (1 - k) || 0;
|
|
m = (1 - g - k) / (1 - k) || 0;
|
|
y = (1 - b - k) / (1 - k) || 0;
|
|
|
|
return [c * 100, m * 100, y * 100, k * 100];
|
|
};
|
|
|
|
/**
|
|
* See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
|
* */
|
|
function comparativeDistance(x, y) {
|
|
return (
|
|
Math.pow(x[0] - y[0], 2) +
|
|
Math.pow(x[1] - y[1], 2) +
|
|
Math.pow(x[2] - y[2], 2)
|
|
);
|
|
}
|
|
|
|
convert.rgb.keyword = function (rgb) {
|
|
var reversed = reverseKeywords[rgb];
|
|
if (reversed) {
|
|
return reversed;
|
|
}
|
|
|
|
var currentClosestDistance = Infinity;
|
|
var currentClosestKeyword;
|
|
|
|
for (var keyword in colorName) {
|
|
if (colorName.hasOwnProperty(keyword)) {
|
|
var value = colorName[keyword];
|
|
|
|
// Compute comparative distance
|
|
var distance = comparativeDistance(rgb, value);
|
|
|
|
// Check if its less, if so set as closest
|
|
if (distance < currentClosestDistance) {
|
|
currentClosestDistance = distance;
|
|
currentClosestKeyword = keyword;
|
|
}
|
|
}
|
|
}
|
|
|
|
return currentClosestKeyword;
|
|
};
|
|
|
|
convert.keyword.rgb = function (keyword) {
|
|
return colorName[keyword];
|
|
};
|
|
|
|
convert.rgb.xyz = function (rgb) {
|
|
var r = rgb[0] / 255;
|
|
var g = rgb[1] / 255;
|
|
var b = rgb[2] / 255;
|
|
|
|
// assume sRGB
|
|
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
|
|
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
|
|
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
|
|
|
|
var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
|
|
var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
|
|
var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
|
|
|
|
return [x * 100, y * 100, z * 100];
|
|
};
|
|
|
|
convert.rgb.lab = function (rgb) {
|
|
var xyz = convert.rgb.xyz(rgb);
|
|
var x = xyz[0];
|
|
var y = xyz[1];
|
|
var z = xyz[2];
|
|
var l;
|
|
var a;
|
|
var b;
|
|
|
|
x /= 95.047;
|
|
y /= 100;
|
|
z /= 108.883;
|
|
|
|
x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
|
|
y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
|
|
z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
|
|
|
|
l = (116 * y) - 16;
|
|
a = 500 * (x - y);
|
|
b = 200 * (y - z);
|
|
|
|
return [l, a, b];
|
|
};
|
|
|
|
convert.hsl.rgb = function (hsl) {
|
|
var h = hsl[0] / 360;
|
|
var s = hsl[1] / 100;
|
|
var l = hsl[2] / 100;
|
|
var t1;
|
|
var t2;
|
|
var t3;
|
|
var rgb;
|
|
var val;
|
|
|
|
if (s === 0) {
|
|
val = l * 255;
|
|
return [val, val, val];
|
|
}
|
|
|
|
if (l < 0.5) {
|
|
t2 = l * (1 + s);
|
|
} else {
|
|
t2 = l + s - l * s;
|
|
}
|
|
|
|
t1 = 2 * l - t2;
|
|
|
|
rgb = [0, 0, 0];
|
|
for (var i = 0; i < 3; i++) {
|
|
t3 = h + 1 / 3 * -(i - 1);
|
|
if (t3 < 0) {
|
|
t3++;
|
|
}
|
|
if (t3 > 1) {
|
|
t3--;
|
|
}
|
|
|
|
if (6 * t3 < 1) {
|
|
val = t1 + (t2 - t1) * 6 * t3;
|
|
} else if (2 * t3 < 1) {
|
|
val = t2;
|
|
} else if (3 * t3 < 2) {
|
|
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
} else {
|
|
val = t1;
|
|
}
|
|
|
|
rgb[i] = val * 255;
|
|
}
|
|
|
|
return rgb;
|
|
};
|
|
|
|
convert.hsl.hsv = function (hsl) {
|
|
var h = hsl[0];
|
|
var s = hsl[1] / 100;
|
|
var l = hsl[2] / 100;
|
|
var smin = s;
|
|
var lmin = Math.max(l, 0.01);
|
|
var sv;
|
|
var v;
|
|
|
|
l *= 2;
|
|
s *= (l <= 1) ? l : 2 - l;
|
|
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
v = (l + s) / 2;
|
|
sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
|
|
|
|
return [h, sv * 100, v * 100];
|
|
};
|
|
|
|
convert.hsv.rgb = function (hsv) {
|
|
var h = hsv[0] / 60;
|
|
var s = hsv[1] / 100;
|
|
var v = hsv[2] / 100;
|
|
var hi = Math.floor(h) % 6;
|
|
|
|
var f = h - Math.floor(h);
|
|
var p = 255 * v * (1 - s);
|
|
var q = 255 * v * (1 - (s * f));
|
|
var t = 255 * v * (1 - (s * (1 - f)));
|
|
v *= 255;
|
|
|
|
switch (hi) {
|
|
case 0:
|
|
return [v, t, p];
|
|
case 1:
|
|
return [q, v, p];
|
|
case 2:
|
|
return [p, v, t];
|
|
case 3:
|
|
return [p, q, v];
|
|
case 4:
|
|
return [t, p, v];
|
|
case 5:
|
|
return [v, p, q];
|
|
}
|
|
};
|
|
|
|
convert.hsv.hsl = function (hsv) {
|
|
var h = hsv[0];
|
|
var s = hsv[1] / 100;
|
|
var v = hsv[2] / 100;
|
|
var vmin = Math.max(v, 0.01);
|
|
var lmin;
|
|
var sl;
|
|
var l;
|
|
|
|
l = (2 - s) * v;
|
|
lmin = (2 - s) * vmin;
|
|
sl = s * vmin;
|
|
sl /= (lmin <= 1) ? lmin : 2 - lmin;
|
|
sl = sl || 0;
|
|
l /= 2;
|
|
|
|
return [h, sl * 100, l * 100];
|
|
};
|
|
|
|
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
|
convert.hwb.rgb = function (hwb) {
|
|
var h = hwb[0] / 360;
|
|
var wh = hwb[1] / 100;
|
|
var bl = hwb[2] / 100;
|
|
var ratio = wh + bl;
|
|
var i;
|
|
var v;
|
|
var f;
|
|
var n;
|
|
|
|
// wh + bl cant be > 1
|
|
if (ratio > 1) {
|
|
wh /= ratio;
|
|
bl /= ratio;
|
|
}
|
|
|
|
i = Math.floor(6 * h);
|
|
v = 1 - bl;
|
|
f = 6 * h - i;
|
|
|
|
if ((i & 0x01) !== 0) {
|
|
f = 1 - f;
|
|
}
|
|
|
|
n = wh + f * (v - wh); // linear interpolation
|
|
|
|
var r;
|
|
var g;
|
|
var b;
|
|
switch (i) {
|
|
default:
|
|
case 6:
|
|
case 0: r = v; g = n; b = wh; break;
|
|
case 1: r = n; g = v; b = wh; break;
|
|
case 2: r = wh; g = v; b = n; break;
|
|
case 3: r = wh; g = n; b = v; break;
|
|
case 4: r = n; g = wh; b = v; break;
|
|
case 5: r = v; g = wh; b = n; break;
|
|
}
|
|
|
|
return [r * 255, g * 255, b * 255];
|
|
};
|
|
|
|
convert.cmyk.rgb = function (cmyk) {
|
|
var c = cmyk[0] / 100;
|
|
var m = cmyk[1] / 100;
|
|
var y = cmyk[2] / 100;
|
|
var k = cmyk[3] / 100;
|
|
var r;
|
|
var g;
|
|
var b;
|
|
|
|
r = 1 - Math.min(1, c * (1 - k) + k);
|
|
g = 1 - Math.min(1, m * (1 - k) + k);
|
|
b = 1 - Math.min(1, y * (1 - k) + k);
|
|
|
|
return [r * 255, g * 255, b * 255];
|
|
};
|
|
|
|
convert.xyz.rgb = function (xyz) {
|
|
var x = xyz[0] / 100;
|
|
var y = xyz[1] / 100;
|
|
var z = xyz[2] / 100;
|
|
var r;
|
|
var g;
|
|
var b;
|
|
|
|
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
|
|
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
|
|
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
|
|
|
|
// assume sRGB
|
|
r = r > 0.0031308
|
|
? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
|
|
: r * 12.92;
|
|
|
|
g = g > 0.0031308
|
|
? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
|
|
: g * 12.92;
|
|
|
|
b = b > 0.0031308
|
|
? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
|
|
: b * 12.92;
|
|
|
|
r = Math.min(Math.max(0, r), 1);
|
|
g = Math.min(Math.max(0, g), 1);
|
|
b = Math.min(Math.max(0, b), 1);
|
|
|
|
return [r * 255, g * 255, b * 255];
|
|
};
|
|
|
|
convert.xyz.lab = function (xyz) {
|
|
var x = xyz[0];
|
|
var y = xyz[1];
|
|
var z = xyz[2];
|
|
var l;
|
|
var a;
|
|
var b;
|
|
|
|
x /= 95.047;
|
|
y /= 100;
|
|
z /= 108.883;
|
|
|
|
x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
|
|
y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
|
|
z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
|
|
|
|
l = (116 * y) - 16;
|
|
a = 500 * (x - y);
|
|
b = 200 * (y - z);
|
|
|
|
return [l, a, b];
|
|
};
|
|
|
|
convert.lab.xyz = function (lab) {
|
|
var l = lab[0];
|
|
var a = lab[1];
|
|
var b = lab[2];
|
|
var x;
|
|
var y;
|
|
var z;
|
|
|
|
y = (l + 16) / 116;
|
|
x = a / 500 + y;
|
|
z = y - b / 200;
|
|
|
|
var y2 = Math.pow(y, 3);
|
|
var x2 = Math.pow(x, 3);
|
|
var z2 = Math.pow(z, 3);
|
|
y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
|
|
x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
|
|
z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
|
|
|
|
x *= 95.047;
|
|
y *= 100;
|
|
z *= 108.883;
|
|
|
|
return [x, y, z];
|
|
};
|
|
|
|
convert.lab.lch = function (lab) {
|
|
var l = lab[0];
|
|
var a = lab[1];
|
|
var b = lab[2];
|
|
var hr;
|
|
var h;
|
|
var c;
|
|
|
|
hr = Math.atan2(b, a);
|
|
h = hr * 360 / 2 / Math.PI;
|
|
|
|
if (h < 0) {
|
|
h += 360;
|
|
}
|
|
|
|
c = Math.sqrt(a * a + b * b);
|
|
|
|
return [l, c, h];
|
|
};
|
|
|
|
convert.lch.lab = function (lch) {
|
|
var l = lch[0];
|
|
var c = lch[1];
|
|
var h = lch[2];
|
|
var a;
|
|
var b;
|
|
var hr;
|
|
|
|
hr = h / 360 * 2 * Math.PI;
|
|
a = c * Math.cos(hr);
|
|
b = c * Math.sin(hr);
|
|
|
|
return [l, a, b];
|
|
};
|
|
|
|
convert.rgb.ansi16 = function (args) {
|
|
var r = args[0];
|
|
var g = args[1];
|
|
var b = args[2];
|
|
var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
|
|
|
|
value = Math.round(value / 50);
|
|
|
|
if (value === 0) {
|
|
return 30;
|
|
}
|
|
|
|
var ansi = 30
|
|
+ ((Math.round(b / 255) << 2)
|
|
| (Math.round(g / 255) << 1)
|
|
| Math.round(r / 255));
|
|
|
|
if (value === 2) {
|
|
ansi += 60;
|
|
}
|
|
|
|
return ansi;
|
|
};
|
|
|
|
convert.hsv.ansi16 = function (args) {
|
|
// optimization here; we already know the value and don't need to get
|
|
// it converted for us.
|
|
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
};
|
|
|
|
convert.rgb.ansi256 = function (args) {
|
|
var r = args[0];
|
|
var g = args[1];
|
|
var b = args[2];
|
|
|
|
// we use the extended greyscale palette here, with the exception of
|
|
// black and white. normal palette only has 4 greyscale shades.
|
|
if (r === g && g === b) {
|
|
if (r < 8) {
|
|
return 16;
|
|
}
|
|
|
|
if (r > 248) {
|
|
return 231;
|
|
}
|
|
|
|
return Math.round(((r - 8) / 247) * 24) + 232;
|
|
}
|
|
|
|
var ansi = 16
|
|
+ (36 * Math.round(r / 255 * 5))
|
|
+ (6 * Math.round(g / 255 * 5))
|
|
+ Math.round(b / 255 * 5);
|
|
|
|
return ansi;
|
|
};
|
|
|
|
convert.ansi16.rgb = function (args) {
|
|
var color = args % 10;
|
|
|
|
// handle greyscale
|
|
if (color === 0 || color === 7) {
|
|
if (args > 50) {
|
|
color += 3.5;
|
|
}
|
|
|
|
color = color / 10.5 * 255;
|
|
|
|
return [color, color, color];
|
|
}
|
|
|
|
var mult = (~~(args > 50) + 1) * 0.5;
|
|
var r = ((color & 1) * mult) * 255;
|
|
var g = (((color >> 1) & 1) * mult) * 255;
|
|
var b = (((color >> 2) & 1) * mult) * 255;
|
|
|
|
return [r, g, b];
|
|
};
|
|
|
|
convert.ansi256.rgb = function (args) {
|
|
// handle greyscale
|
|
if (args >= 232) {
|
|
var c = (args - 232) * 10 + 8;
|
|
return [c, c, c];
|
|
}
|
|
|
|
args -= 16;
|
|
|
|
var rem;
|
|
var r = Math.floor(args / 36) / 5 * 255;
|
|
var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
var b = (rem % 6) / 5 * 255;
|
|
|
|
return [r, g, b];
|
|
};
|
|
|
|
convert.rgb.hex = function (args) {
|
|
var integer = ((Math.round(args[0]) & 0xFF) << 16)
|
|
+ ((Math.round(args[1]) & 0xFF) << 8)
|
|
+ (Math.round(args[2]) & 0xFF);
|
|
|
|
var string = integer.toString(16).toUpperCase();
|
|
return '000000'.substring(string.length) + string;
|
|
};
|
|
|
|
convert.hex.rgb = function (args) {
|
|
var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
if (!match) {
|
|
return [0, 0, 0];
|
|
}
|
|
|
|
var colorString = match[0];
|
|
|
|
if (match[0].length === 3) {
|
|
colorString = colorString.split('').map(function (char) {
|
|
return char + char;
|
|
}).join('');
|
|
}
|
|
|
|
var integer = parseInt(colorString, 16);
|
|
var r = (integer >> 16) & 0xFF;
|
|
var g = (integer >> 8) & 0xFF;
|
|
var b = integer & 0xFF;
|
|
|
|
return [r, g, b];
|
|
};
|
|
|
|
convert.rgb.hcg = function (rgb) {
|
|
var r = rgb[0] / 255;
|
|
var g = rgb[1] / 255;
|
|
var b = rgb[2] / 255;
|
|
var max = Math.max(Math.max(r, g), b);
|
|
var min = Math.min(Math.min(r, g), b);
|
|
var chroma = (max - min);
|
|
var grayscale;
|
|
var hue;
|
|
|
|
if (chroma < 1) {
|
|
grayscale = min / (1 - chroma);
|
|
} else {
|
|
grayscale = 0;
|
|
}
|
|
|
|
if (chroma <= 0) {
|
|
hue = 0;
|
|
} else
|
|
if (max === r) {
|
|
hue = ((g - b) / chroma) % 6;
|
|
} else
|
|
if (max === g) {
|
|
hue = 2 + (b - r) / chroma;
|
|
} else {
|
|
hue = 4 + (r - g) / chroma + 4;
|
|
}
|
|
|
|
hue /= 6;
|
|
hue %= 1;
|
|
|
|
return [hue * 360, chroma * 100, grayscale * 100];
|
|
};
|
|
|
|
convert.hsl.hcg = function (hsl) {
|
|
var s = hsl[1] / 100;
|
|
var l = hsl[2] / 100;
|
|
var c = 1;
|
|
var f = 0;
|
|
|
|
if (l < 0.5) {
|
|
c = 2.0 * s * l;
|
|
} else {
|
|
c = 2.0 * s * (1.0 - l);
|
|
}
|
|
|
|
if (c < 1.0) {
|
|
f = (l - 0.5 * c) / (1.0 - c);
|
|
}
|
|
|
|
return [hsl[0], c * 100, f * 100];
|
|
};
|
|
|
|
convert.hsv.hcg = function (hsv) {
|
|
var s = hsv[1] / 100;
|
|
var v = hsv[2] / 100;
|
|
|
|
var c = s * v;
|
|
var f = 0;
|
|
|
|
if (c < 1.0) {
|
|
f = (v - c) / (1 - c);
|
|
}
|
|
|
|
return [hsv[0], c * 100, f * 100];
|
|
};
|
|
|
|
convert.hcg.rgb = function (hcg) {
|
|
var h = hcg[0] / 360;
|
|
var c = hcg[1] / 100;
|
|
var g = hcg[2] / 100;
|
|
|
|
if (c === 0.0) {
|
|
return [g * 255, g * 255, g * 255];
|
|
}
|
|
|
|
var pure = [0, 0, 0];
|
|
var hi = (h % 1) * 6;
|
|
var v = hi % 1;
|
|
var w = 1 - v;
|
|
var mg = 0;
|
|
|
|
switch (Math.floor(hi)) {
|
|
case 0:
|
|
pure[0] = 1; pure[1] = v; pure[2] = 0; break;
|
|
case 1:
|
|
pure[0] = w; pure[1] = 1; pure[2] = 0; break;
|
|
case 2:
|
|
pure[0] = 0; pure[1] = 1; pure[2] = v; break;
|
|
case 3:
|
|
pure[0] = 0; pure[1] = w; pure[2] = 1; break;
|
|
case 4:
|
|
pure[0] = v; pure[1] = 0; pure[2] = 1; break;
|
|
default:
|
|
pure[0] = 1; pure[1] = 0; pure[2] = w;
|
|
}
|
|
|
|
mg = (1.0 - c) * g;
|
|
|
|
return [
|
|
(c * pure[0] + mg) * 255,
|
|
(c * pure[1] + mg) * 255,
|
|
(c * pure[2] + mg) * 255
|
|
];
|
|
};
|
|
|
|
convert.hcg.hsv = function (hcg) {
|
|
var c = hcg[1] / 100;
|
|
var g = hcg[2] / 100;
|
|
|
|
var v = c + g * (1.0 - c);
|
|
var f = 0;
|
|
|
|
if (v > 0.0) {
|
|
f = c / v;
|
|
}
|
|
|
|
return [hcg[0], f * 100, v * 100];
|
|
};
|
|
|
|
convert.hcg.hsl = function (hcg) {
|
|
var c = hcg[1] / 100;
|
|
var g = hcg[2] / 100;
|
|
|
|
var l = g * (1.0 - c) + 0.5 * c;
|
|
var s = 0;
|
|
|
|
if (l > 0.0 && l < 0.5) {
|
|
s = c / (2 * l);
|
|
} else
|
|
if (l >= 0.5 && l < 1.0) {
|
|
s = c / (2 * (1 - l));
|
|
}
|
|
|
|
return [hcg[0], s * 100, l * 100];
|
|
};
|
|
|
|
convert.hcg.hwb = function (hcg) {
|
|
var c = hcg[1] / 100;
|
|
var g = hcg[2] / 100;
|
|
var v = c + g * (1.0 - c);
|
|
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
};
|
|
|
|
convert.hwb.hcg = function (hwb) {
|
|
var w = hwb[1] / 100;
|
|
var b = hwb[2] / 100;
|
|
var v = 1 - b;
|
|
var c = v - w;
|
|
var g = 0;
|
|
|
|
if (c < 1) {
|
|
g = (v - c) / (1 - c);
|
|
}
|
|
|
|
return [hwb[0], c * 100, g * 100];
|
|
};
|
|
|
|
convert.apple.rgb = function (apple) {
|
|
return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
|
|
};
|
|
|
|
convert.rgb.apple = function (rgb) {
|
|
return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
|
|
};
|
|
|
|
convert.gray.rgb = function (args) {
|
|
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
};
|
|
|
|
convert.gray.hsl = convert.gray.hsv = function (args) {
|
|
return [0, 0, args[0]];
|
|
};
|
|
|
|
convert.gray.hwb = function (gray) {
|
|
return [0, 100, gray[0]];
|
|
};
|
|
|
|
convert.gray.cmyk = function (gray) {
|
|
return [0, 0, 0, gray[0]];
|
|
};
|
|
|
|
convert.gray.lab = function (gray) {
|
|
return [gray[0], 0, 0];
|
|
};
|
|
|
|
convert.gray.hex = function (gray) {
|
|
var val = Math.round(gray[0] / 100 * 255) & 0xFF;
|
|
var integer = (val << 16) + (val << 8) + val;
|
|
|
|
var string = integer.toString(16).toUpperCase();
|
|
return '000000'.substring(string.length) + string;
|
|
};
|
|
|
|
convert.rgb.gray = function (rgb) {
|
|
var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
return [val / 255 * 100];
|
|
};
|
|
});
|
|
|
|
/*
|
|
this function routes a model to all other models.
|
|
|
|
all functions that are routed have a property `.conversion` attached
|
|
to the returned synthetic function. This property is an array
|
|
of strings, each with the steps in between the 'from' and 'to'
|
|
color models (inclusive).
|
|
|
|
conversions that are not possible simply are not included.
|
|
*/
|
|
|
|
// https://jsperf.com/object-keys-vs-for-in-with-closure/3
|
|
var models$1 = Object.keys(conversions);
|
|
|
|
function buildGraph() {
|
|
var graph = {};
|
|
|
|
for (var len = models$1.length, i = 0; i < len; i++) {
|
|
graph[models$1[i]] = {
|
|
// http://jsperf.com/1-vs-infinity
|
|
// micro-opt, but this is simple.
|
|
distance: -1,
|
|
parent: null
|
|
};
|
|
}
|
|
|
|
return graph;
|
|
}
|
|
|
|
// https://en.wikipedia.org/wiki/Breadth-first_search
|
|
function deriveBFS(fromModel) {
|
|
var graph = buildGraph();
|
|
var queue = [fromModel]; // unshift -> queue -> pop
|
|
|
|
graph[fromModel].distance = 0;
|
|
|
|
while (queue.length) {
|
|
var current = queue.pop();
|
|
var adjacents = Object.keys(conversions[current]);
|
|
|
|
for (var len = adjacents.length, i = 0; i < len; i++) {
|
|
var adjacent = adjacents[i];
|
|
var node = graph[adjacent];
|
|
|
|
if (node.distance === -1) {
|
|
node.distance = graph[current].distance + 1;
|
|
node.parent = current;
|
|
queue.unshift(adjacent);
|
|
}
|
|
}
|
|
}
|
|
|
|
return graph;
|
|
}
|
|
|
|
function link(from, to) {
|
|
return function (args) {
|
|
return to(from(args));
|
|
};
|
|
}
|
|
|
|
function wrapConversion(toModel, graph) {
|
|
var path$$1 = [graph[toModel].parent, toModel];
|
|
var fn = conversions[graph[toModel].parent][toModel];
|
|
|
|
var cur = graph[toModel].parent;
|
|
while (graph[cur].parent) {
|
|
path$$1.unshift(graph[cur].parent);
|
|
fn = link(conversions[graph[cur].parent][cur], fn);
|
|
cur = graph[cur].parent;
|
|
}
|
|
|
|
fn.conversion = path$$1;
|
|
return fn;
|
|
}
|
|
|
|
var route = function (fromModel) {
|
|
var graph = deriveBFS(fromModel);
|
|
var conversion = {};
|
|
|
|
var models = Object.keys(graph);
|
|
for (var len = models.length, i = 0; i < len; i++) {
|
|
var toModel = models[i];
|
|
var node = graph[toModel];
|
|
|
|
if (node.parent === null) {
|
|
// no possible conversion, or this node is the source model.
|
|
continue;
|
|
}
|
|
|
|
conversion[toModel] = wrapConversion(toModel, graph);
|
|
}
|
|
|
|
return conversion;
|
|
};
|
|
|
|
var convert = {};
|
|
|
|
var models = Object.keys(conversions);
|
|
|
|
function wrapRaw(fn) {
|
|
var wrappedFn = function (args) {
|
|
if (args === undefined || args === null) {
|
|
return args;
|
|
}
|
|
|
|
if (arguments.length > 1) {
|
|
args = Array.prototype.slice.call(arguments);
|
|
}
|
|
|
|
return fn(args);
|
|
};
|
|
|
|
// preserve .conversion property if there is one
|
|
if ('conversion' in fn) {
|
|
wrappedFn.conversion = fn.conversion;
|
|
}
|
|
|
|
return wrappedFn;
|
|
}
|
|
|
|
function wrapRounded(fn) {
|
|
var wrappedFn = function (args) {
|
|
if (args === undefined || args === null) {
|
|
return args;
|
|
}
|
|
|
|
if (arguments.length > 1) {
|
|
args = Array.prototype.slice.call(arguments);
|
|
}
|
|
|
|
var result = fn(args);
|
|
|
|
// we're assuming the result is an array here.
|
|
// see notice in conversions.js; don't use box types
|
|
// in conversion functions.
|
|
if (typeof result === 'object') {
|
|
for (var len = result.length, i = 0; i < len; i++) {
|
|
result[i] = Math.round(result[i]);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
};
|
|
|
|
// preserve .conversion property if there is one
|
|
if ('conversion' in fn) {
|
|
wrappedFn.conversion = fn.conversion;
|
|
}
|
|
|
|
return wrappedFn;
|
|
}
|
|
|
|
models.forEach(function (fromModel) {
|
|
convert[fromModel] = {};
|
|
|
|
Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels});
|
|
Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels});
|
|
|
|
var routes = route(fromModel);
|
|
var routeModels = Object.keys(routes);
|
|
|
|
routeModels.forEach(function (toModel) {
|
|
var fn = routes[toModel];
|
|
|
|
convert[fromModel][toModel] = wrapRounded(fn);
|
|
convert[fromModel][toModel].raw = wrapRaw(fn);
|
|
});
|
|
});
|
|
|
|
var colorConvert = convert;
|
|
|
|
var ansiStyles = createCommonjsModule(function (module) {
|
|
'use strict';
|
|
|
|
|
|
const wrapAnsi16 = (fn, offset) => function () {
|
|
const code = fn.apply(colorConvert, arguments);
|
|
return `\u001B[${code + offset}m`;
|
|
};
|
|
|
|
const wrapAnsi256 = (fn, offset) => function () {
|
|
const code = fn.apply(colorConvert, arguments);
|
|
return `\u001B[${38 + offset};5;${code}m`;
|
|
};
|
|
|
|
const wrapAnsi16m = (fn, offset) => function () {
|
|
const rgb = fn.apply(colorConvert, arguments);
|
|
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
|
};
|
|
|
|
function assembleStyles() {
|
|
const codes = new Map();
|
|
const styles = {
|
|
modifier: {
|
|
reset: [0, 0],
|
|
// 21 isn't widely supported and 22 does the same thing
|
|
bold: [1, 22],
|
|
dim: [2, 22],
|
|
italic: [3, 23],
|
|
underline: [4, 24],
|
|
inverse: [7, 27],
|
|
hidden: [8, 28],
|
|
strikethrough: [9, 29]
|
|
},
|
|
color: {
|
|
black: [30, 39],
|
|
red: [31, 39],
|
|
green: [32, 39],
|
|
yellow: [33, 39],
|
|
blue: [34, 39],
|
|
magenta: [35, 39],
|
|
cyan: [36, 39],
|
|
white: [37, 39],
|
|
gray: [90, 39],
|
|
|
|
// Bright color
|
|
redBright: [91, 39],
|
|
greenBright: [92, 39],
|
|
yellowBright: [93, 39],
|
|
blueBright: [94, 39],
|
|
magentaBright: [95, 39],
|
|
cyanBright: [96, 39],
|
|
whiteBright: [97, 39]
|
|
},
|
|
bgColor: {
|
|
bgBlack: [40, 49],
|
|
bgRed: [41, 49],
|
|
bgGreen: [42, 49],
|
|
bgYellow: [43, 49],
|
|
bgBlue: [44, 49],
|
|
bgMagenta: [45, 49],
|
|
bgCyan: [46, 49],
|
|
bgWhite: [47, 49],
|
|
|
|
// Bright color
|
|
bgBlackBright: [100, 49],
|
|
bgRedBright: [101, 49],
|
|
bgGreenBright: [102, 49],
|
|
bgYellowBright: [103, 49],
|
|
bgBlueBright: [104, 49],
|
|
bgMagentaBright: [105, 49],
|
|
bgCyanBright: [106, 49],
|
|
bgWhiteBright: [107, 49]
|
|
}
|
|
};
|
|
|
|
// Fix humans
|
|
styles.color.grey = styles.color.gray;
|
|
|
|
for (const groupName of Object.keys(styles)) {
|
|
const group = styles[groupName];
|
|
|
|
for (const styleName of Object.keys(group)) {
|
|
const style = group[styleName];
|
|
|
|
styles[styleName] = {
|
|
open: `\u001B[${style[0]}m`,
|
|
close: `\u001B[${style[1]}m`
|
|
};
|
|
|
|
group[styleName] = styles[styleName];
|
|
|
|
codes.set(style[0], style[1]);
|
|
}
|
|
|
|
Object.defineProperty(styles, groupName, {
|
|
value: group,
|
|
enumerable: false
|
|
});
|
|
|
|
Object.defineProperty(styles, 'codes', {
|
|
value: codes,
|
|
enumerable: false
|
|
});
|
|
}
|
|
|
|
const rgb2rgb = (r, g, b) => [r, g, b];
|
|
|
|
styles.color.close = '\u001B[39m';
|
|
styles.bgColor.close = '\u001B[49m';
|
|
|
|
styles.color.ansi = {};
|
|
styles.color.ansi256 = {};
|
|
styles.color.ansi16m = {
|
|
rgb: wrapAnsi16m(rgb2rgb, 0)
|
|
};
|
|
|
|
styles.bgColor.ansi = {};
|
|
styles.bgColor.ansi256 = {};
|
|
styles.bgColor.ansi16m = {
|
|
rgb: wrapAnsi16m(rgb2rgb, 10)
|
|
};
|
|
|
|
for (const key of Object.keys(colorConvert)) {
|
|
if (typeof colorConvert[key] !== 'object') {
|
|
continue;
|
|
}
|
|
|
|
const suite = colorConvert[key];
|
|
|
|
if ('ansi16' in suite) {
|
|
styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
|
|
styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
|
|
}
|
|
|
|
if ('ansi256' in suite) {
|
|
styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
|
|
styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
|
|
}
|
|
|
|
if ('rgb' in suite) {
|
|
styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
|
|
styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
|
|
}
|
|
}
|
|
|
|
return styles;
|
|
}
|
|
|
|
// Make the export immutable
|
|
Object.defineProperty(module, 'exports', {
|
|
enumerable: true,
|
|
get: assembleStyles
|
|
});
|
|
});
|
|
|
|
var hasFlag = function (flag, argv) {
|
|
argv = argv || process.argv;
|
|
|
|
var terminatorPos = argv.indexOf('--');
|
|
var prefix = /^-{1,2}/.test(flag) ? '' : '--';
|
|
var pos = argv.indexOf(prefix + flag);
|
|
|
|
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
|
|
};
|
|
|
|
var supportsColor = createCommonjsModule(function (module) {
|
|
'use strict';
|
|
|
|
|
|
|
|
const env = process.env;
|
|
|
|
const support = level => {
|
|
if (level === 0) {
|
|
return false;
|
|
}
|
|
|
|
return {
|
|
level,
|
|
hasBasic: true,
|
|
has256: level >= 2,
|
|
has16m: level >= 3
|
|
};
|
|
};
|
|
|
|
let supportLevel = (() => {
|
|
if (hasFlag('no-color') ||
|
|
hasFlag('no-colors') ||
|
|
hasFlag('color=false')) {
|
|
return 0;
|
|
}
|
|
|
|
if (hasFlag('color=16m') ||
|
|
hasFlag('color=full') ||
|
|
hasFlag('color=truecolor')) {
|
|
return 3;
|
|
}
|
|
|
|
if (hasFlag('color=256')) {
|
|
return 2;
|
|
}
|
|
|
|
if (hasFlag('color') ||
|
|
hasFlag('colors') ||
|
|
hasFlag('color=true') ||
|
|
hasFlag('color=always')) {
|
|
return 1;
|
|
}
|
|
|
|
if (process.stdout && !process.stdout.isTTY) {
|
|
return 0;
|
|
}
|
|
|
|
if (process.platform === 'win32') {
|
|
// Node.js 7.5.0 is the first version of Node.js to include a patch to
|
|
// libuv that enables 256 color output on Windows. Anything earlier and it
|
|
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
|
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
|
|
// release that supports 256 colors.
|
|
const osRelease = os.release().split('.');
|
|
if (
|
|
Number(process.versions.node.split('.')[0]) >= 8 &&
|
|
Number(osRelease[0]) >= 10 &&
|
|
Number(osRelease[2]) >= 10586
|
|
) {
|
|
return 2;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
if ('CI' in env) {
|
|
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
if ('TEAMCITY_VERSION' in env) {
|
|
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
}
|
|
|
|
if ('TERM_PROGRAM' in env) {
|
|
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
|
|
switch (env.TERM_PROGRAM) {
|
|
case 'iTerm.app':
|
|
return version >= 3 ? 3 : 2;
|
|
case 'Hyper':
|
|
return 3;
|
|
case 'Apple_Terminal':
|
|
return 2;
|
|
// No default
|
|
}
|
|
}
|
|
|
|
if (/-256(color)?$/i.test(env.TERM)) {
|
|
return 2;
|
|
}
|
|
|
|
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
return 1;
|
|
}
|
|
|
|
if ('COLORTERM' in env) {
|
|
return 1;
|
|
}
|
|
|
|
if (env.TERM === 'dumb') {
|
|
return 0;
|
|
}
|
|
|
|
return 0;
|
|
})();
|
|
|
|
if ('FORCE_COLOR' in env) {
|
|
supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1);
|
|
}
|
|
|
|
module.exports = process && support(supportLevel);
|
|
});
|
|
|
|
var templates = createCommonjsModule(function (module) {
|
|
'use strict';
|
|
const TEMPLATE_REGEX = /(?:\\(u[a-f0-9]{4}|x[a-f0-9]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
|
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
const ESCAPE_REGEX = /\\(u[0-9a-f]{4}|x[0-9a-f]{2}|.)|([^\\])/gi;
|
|
|
|
const ESCAPES = {
|
|
n: '\n',
|
|
r: '\r',
|
|
t: '\t',
|
|
b: '\b',
|
|
f: '\f',
|
|
v: '\v',
|
|
0: '\0',
|
|
'\\': '\\',
|
|
e: '\u001b',
|
|
a: '\u0007'
|
|
};
|
|
|
|
function unescape(c) {
|
|
if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
|
|
return String.fromCharCode(parseInt(c.slice(1), 16));
|
|
}
|
|
|
|
return ESCAPES[c] || c;
|
|
}
|
|
|
|
function parseArguments(name, args) {
|
|
const results = [];
|
|
const chunks = args.trim().split(/\s*,\s*/g);
|
|
let matches;
|
|
|
|
for (const chunk of chunks) {
|
|
if (!isNaN(chunk)) {
|
|
results.push(Number(chunk));
|
|
} else if ((matches = chunk.match(STRING_REGEX))) {
|
|
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
|
|
} else {
|
|
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
function parseStyle(style) {
|
|
STYLE_REGEX.lastIndex = 0;
|
|
|
|
const results = [];
|
|
let matches;
|
|
|
|
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
|
const name = matches[1];
|
|
|
|
if (matches[2]) {
|
|
const args = parseArguments(name, matches[2]);
|
|
results.push([name].concat(args));
|
|
} else {
|
|
results.push([name]);
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
function buildStyle(chalk, styles) {
|
|
const enabled = {};
|
|
|
|
for (const layer of styles) {
|
|
for (const style of layer.styles) {
|
|
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
|
}
|
|
}
|
|
|
|
let current = chalk;
|
|
for (const styleName of Object.keys(enabled)) {
|
|
if (Array.isArray(enabled[styleName])) {
|
|
if (!(styleName in current)) {
|
|
throw new Error(`Unknown Chalk style: ${styleName}`);
|
|
}
|
|
|
|
if (enabled[styleName].length > 0) {
|
|
current = current[styleName].apply(current, enabled[styleName]);
|
|
} else {
|
|
current = current[styleName];
|
|
}
|
|
}
|
|
}
|
|
|
|
return current;
|
|
}
|
|
|
|
module.exports = (chalk, tmp) => {
|
|
const styles = [];
|
|
const chunks = [];
|
|
let chunk = [];
|
|
|
|
// eslint-disable-next-line max-params
|
|
tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
|
|
if (escapeChar) {
|
|
chunk.push(unescape(escapeChar));
|
|
} else if (style) {
|
|
const str = chunk.join('');
|
|
chunk = [];
|
|
chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
|
|
styles.push({inverse, styles: parseStyle(style)});
|
|
} else if (close) {
|
|
if (styles.length === 0) {
|
|
throw new Error('Found extraneous } in Chalk template literal');
|
|
}
|
|
|
|
chunks.push(buildStyle(chalk, styles)(chunk.join('')));
|
|
chunk = [];
|
|
styles.pop();
|
|
} else {
|
|
chunk.push(chr);
|
|
}
|
|
});
|
|
|
|
chunks.push(chunk.join(''));
|
|
|
|
if (styles.length > 0) {
|
|
const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
|
|
throw new Error(errMsg);
|
|
}
|
|
|
|
return chunks.join('');
|
|
};
|
|
});
|
|
|
|
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
|
|
|
|
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
|
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
|
|
|
|
// `color-convert` models to exclude from the Chalk API due to conflicts and such
|
|
const skipModels = new Set(['gray']);
|
|
|
|
const styles = Object.create(null);
|
|
|
|
function applyOptions(obj, options) {
|
|
options = options || {};
|
|
|
|
// Detect level if not set manually
|
|
const scLevel = supportsColor ? supportsColor.level : 0;
|
|
obj.level = options.level === undefined ? scLevel : options.level;
|
|
obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
|
|
}
|
|
|
|
function Chalk(options) {
|
|
// We check for this.template here since calling `chalk.constructor()`
|
|
// by itself will have a `this` of a previously constructed chalk object
|
|
if (!this || !(this instanceof Chalk) || this.template) {
|
|
const chalk = {};
|
|
applyOptions(chalk, options);
|
|
|
|
chalk.template = function () {
|
|
const args = [].slice.call(arguments);
|
|
return chalkTag.apply(null, [chalk.template].concat(args));
|
|
};
|
|
|
|
Object.setPrototypeOf(chalk, Chalk.prototype);
|
|
Object.setPrototypeOf(chalk.template, chalk);
|
|
|
|
chalk.template.constructor = Chalk;
|
|
|
|
return chalk.template;
|
|
}
|
|
|
|
applyOptions(this, options);
|
|
}
|
|
|
|
// Use bright blue on Windows as the normal blue color is illegible
|
|
if (isSimpleWindowsTerm) {
|
|
ansiStyles.blue.open = '\u001B[94m';
|
|
}
|
|
|
|
for (const key of Object.keys(ansiStyles)) {
|
|
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
|
|
|
|
styles[key] = {
|
|
get() {
|
|
const codes = ansiStyles[key];
|
|
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], key);
|
|
}
|
|
};
|
|
}
|
|
|
|
ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
|
|
for (const model of Object.keys(ansiStyles.color.ansi)) {
|
|
if (skipModels.has(model)) {
|
|
continue;
|
|
}
|
|
|
|
styles[model] = {
|
|
get() {
|
|
const level = this.level;
|
|
return function () {
|
|
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
|
|
const codes = {
|
|
open,
|
|
close: ansiStyles.color.close,
|
|
closeRe: ansiStyles.color.closeRe
|
|
};
|
|
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
|
|
};
|
|
}
|
|
};
|
|
}
|
|
|
|
ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
|
|
for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
|
|
if (skipModels.has(model)) {
|
|
continue;
|
|
}
|
|
|
|
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
|
styles[bgModel] = {
|
|
get() {
|
|
const level = this.level;
|
|
return function () {
|
|
const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
|
|
const codes = {
|
|
open,
|
|
close: ansiStyles.bgColor.close,
|
|
closeRe: ansiStyles.bgColor.closeRe
|
|
};
|
|
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
|
|
};
|
|
}
|
|
};
|
|
}
|
|
|
|
const proto = Object.defineProperties(() => {}, styles);
|
|
|
|
function build(_styles, key) {
|
|
const builder = function () {
|
|
return applyStyle.apply(builder, arguments);
|
|
};
|
|
|
|
builder._styles = _styles;
|
|
|
|
const self = this;
|
|
|
|
Object.defineProperty(builder, 'level', {
|
|
enumerable: true,
|
|
get() {
|
|
return self.level;
|
|
},
|
|
set(level) {
|
|
self.level = level;
|
|
}
|
|
});
|
|
|
|
Object.defineProperty(builder, 'enabled', {
|
|
enumerable: true,
|
|
get() {
|
|
return self.enabled;
|
|
},
|
|
set(enabled) {
|
|
self.enabled = enabled;
|
|
}
|
|
});
|
|
|
|
// See below for fix regarding invisible grey/dim combination on Windows
|
|
builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
|
|
|
|
// `__proto__` is used because we must return a function, but there is
|
|
// no way to create a function with a different prototype
|
|
builder.__proto__ = proto; // eslint-disable-line no-proto
|
|
|
|
return builder;
|
|
}
|
|
|
|
function applyStyle() {
|
|
// Support varags, but simply cast to string in case there's only one arg
|
|
const args = arguments;
|
|
const argsLen = args.length;
|
|
let str = String(arguments[0]);
|
|
|
|
if (argsLen === 0) {
|
|
return '';
|
|
}
|
|
|
|
if (argsLen > 1) {
|
|
// Don't slice `arguments`, it prevents V8 optimizations
|
|
for (let a = 1; a < argsLen; a++) {
|
|
str += ' ' + args[a];
|
|
}
|
|
}
|
|
|
|
if (!this.enabled || this.level <= 0 || !str) {
|
|
return str;
|
|
}
|
|
|
|
// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
|
|
// see https://github.com/chalk/chalk/issues/58
|
|
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
|
|
const originalDim = ansiStyles.dim.open;
|
|
if (isSimpleWindowsTerm && this.hasGrey) {
|
|
ansiStyles.dim.open = '';
|
|
}
|
|
|
|
for (const code of this._styles.slice().reverse()) {
|
|
// Replace any instances already present with a re-opening code
|
|
// otherwise only the part of the string until said closing code
|
|
// will be colored, and the rest will simply be 'plain'.
|
|
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
|
|
|
// Close the styling before a linebreak and reopen
|
|
// after next line to fix a bleed issue on macOS
|
|
// https://github.com/chalk/chalk/pull/92
|
|
str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
|
|
}
|
|
|
|
// Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
|
|
ansiStyles.dim.open = originalDim;
|
|
|
|
return str;
|
|
}
|
|
|
|
function chalkTag(chalk, strings) {
|
|
if (!Array.isArray(strings)) {
|
|
// If chalk() was called by itself or with a string,
|
|
// return the string itself as a string.
|
|
return [].slice.call(arguments, 1).join(' ');
|
|
}
|
|
|
|
const args = [].slice.call(arguments, 2);
|
|
const parts = [strings.raw[0]];
|
|
|
|
for (let i = 1; i < strings.length; i++) {
|
|
parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
|
|
parts.push(String(strings.raw[i]));
|
|
}
|
|
|
|
return templates(chalk, parts.join(''));
|
|
}
|
|
|
|
Object.defineProperties(Chalk.prototype, styles);
|
|
|
|
var chalk = Chalk(); // eslint-disable-line new-cap
|
|
var supportsColor_1 = supportsColor;
|
|
|
|
chalk.supportsColor = supportsColor_1;
|
|
|
|
const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;
|
|
|
|
|
|
function isAbsolute ( path$$1 ) {
|
|
return absolutePath.test( path$$1 );
|
|
}
|
|
|
|
function relativeId ( id ) {
|
|
if ( typeof process === 'undefined' || !isAbsolute( id ) ) { return id; }
|
|
return path.relative( process.cwd(), id );
|
|
}
|
|
|
|
if ( !process.stderr.isTTY ) { chalk.enabled = false; }
|
|
|
|
// log to stderr to keep `rollup main.js > bundle.js` from breaking
|
|
const stderr = console.error.bind( console ); // eslint-disable-line no-console
|
|
|
|
function handleError ( err, recover ) {
|
|
let description = err.message || err;
|
|
if (err.name) { description = `${err.name}: ${description}`; }
|
|
const message = (err.plugin ? `(${err.plugin} plugin) ${description}` : description) || err;
|
|
|
|
stderr( chalk.bold.red( `[!] ${chalk.bold( message )}` ) );
|
|
|
|
// TODO should this be "err.url || (err.file && err.loc.file) || err.id"?
|
|
if ( err.url ) {
|
|
stderr( chalk.cyan( err.url ) );
|
|
}
|
|
|
|
if ( err.loc ) {
|
|
stderr( `${relativeId( err.loc.file || err.id )} (${err.loc.line}:${err.loc.column})` );
|
|
} else if ( err.id ) {
|
|
stderr( relativeId( err.id ) );
|
|
}
|
|
|
|
if ( err.frame ) {
|
|
stderr( chalk.dim( err.frame ) );
|
|
} else if ( err.stack ) {
|
|
stderr( chalk.dim( err.stack ) );
|
|
}
|
|
|
|
stderr( '' );
|
|
|
|
if ( !recover ) { process.exit( 1 ); }
|
|
}
|
|
|
|
function ensureArray ( thing ) {
|
|
if ( Array.isArray( thing ) ) { return thing; }
|
|
if ( thing == undefined ) { return []; }
|
|
return [ thing ];
|
|
}
|
|
|
|
function deprecateOptions(options) {
|
|
const deprecations = [];
|
|
|
|
if ( options.entry ) {
|
|
deprecations.push({ old: 'options.entry', new: 'options.input' });
|
|
options.input = options.entry; // don't delete, as plugins sometimes depend on this...
|
|
}
|
|
|
|
if ( options.moduleName ) {
|
|
deprecations.push({ old: 'options.moduleName', new: 'options.name' });
|
|
options.name = options.moduleName;
|
|
delete options.moduleName;
|
|
}
|
|
|
|
if ( options.sourceMap ) {
|
|
deprecations.push({ old: 'options.sourceMap', new: 'options.sourcemap' });
|
|
options.sourcemap = options.sourceMap;
|
|
delete options.sourceMap;
|
|
}
|
|
|
|
if ( options.sourceMapFile ) {
|
|
deprecations.push({ old: 'options.sourceMapFile', new: 'options.sourcemapFile' });
|
|
options.sourcemapFile = options.sourceMapFile;
|
|
delete options.sourceMapFile;
|
|
}
|
|
|
|
if ( options.useStrict ) {
|
|
deprecations.push({ old: 'options.useStrict', new: 'options.strict' });
|
|
options.strict = options.useStrict;
|
|
delete options.useStrict;
|
|
}
|
|
|
|
if ( options.targets ) {
|
|
deprecations.push({ old: 'options.targets', new: 'options.output' });
|
|
options.output = options.targets;
|
|
delete options.targets;
|
|
|
|
let deprecatedDest = false;
|
|
options.output.forEach(output => {
|
|
if (output.dest) {
|
|
if (!deprecatedDest) {
|
|
deprecations.push({ old: 'output.dest', new: 'output.file' });
|
|
deprecatedDest = true;
|
|
}
|
|
output.file = output.dest;
|
|
delete output.dest;
|
|
}
|
|
});
|
|
} else if ( options.dest ) {
|
|
deprecations.push({ old: 'options.dest', new: 'options.output.file' });
|
|
options.output = {
|
|
file: options.dest,
|
|
format: options.format
|
|
};
|
|
delete options.dest;
|
|
}
|
|
|
|
if ( options.format ) {
|
|
if ( !options.output ) { options.output = { format: options.format }; }
|
|
deprecations.push({ old: 'options.format', new: 'options.output.format' });
|
|
delete options.format;
|
|
}
|
|
|
|
return deprecations;
|
|
}
|
|
|
|
function mergeOptions ( config, command ) {
|
|
// deprecations... TODO
|
|
const deprecations = deprecate( config, command );
|
|
|
|
function getOption(name) {
|
|
return command[name] !== undefined ? command[name] : config[name];
|
|
}
|
|
|
|
const inputOptions = {
|
|
input: getOption('input'),
|
|
legacy: getOption('legacy'),
|
|
treeshake: getOption('treeshake'),
|
|
acorn: config.acorn,
|
|
context: config.context,
|
|
moduleContext: config.moduleContext,
|
|
plugins: config.plugins,
|
|
onwarn: config.onwarn,
|
|
watch: config.watch
|
|
};
|
|
|
|
// legacy, to ensure e.g. commonjs plugin still works
|
|
inputOptions.entry = inputOptions.input;
|
|
|
|
const commandExternal = ( command.external || '' ).split( ',' );
|
|
const configExternal = config.external;
|
|
|
|
if ( command.globals ) {
|
|
const globals = Object.create( null );
|
|
|
|
command.globals.split( ',' ).forEach( str => {
|
|
const names = str.split( ':' );
|
|
globals[ names[0] ] = names[1];
|
|
|
|
// Add missing Module IDs to external.
|
|
if ( commandExternal.indexOf( names[0] ) === -1 ) {
|
|
commandExternal.push( names[0] );
|
|
}
|
|
});
|
|
|
|
command.globals = globals;
|
|
}
|
|
|
|
if ( typeof configExternal === 'function' ) {
|
|
inputOptions.external = id => {
|
|
return configExternal( id ) || ~commandExternal.indexOf( id );
|
|
};
|
|
} else {
|
|
inputOptions.external = ( configExternal || [] ).concat( commandExternal );
|
|
}
|
|
|
|
if (command.silent) {
|
|
inputOptions.onwarn = () => {};
|
|
}
|
|
|
|
const baseOutputOptions = {
|
|
extend: command.extend !== undefined ? command.extend : config.extend,
|
|
amd: Object.assign({}, config.amd, command.amd),
|
|
|
|
banner: getOption('banner'),
|
|
footer: getOption('footer'),
|
|
intro: getOption('intro'),
|
|
outro: getOption('outro'),
|
|
sourcemap: getOption('sourcemap'),
|
|
name: getOption('name'),
|
|
globals: getOption('globals'),
|
|
interop: getOption('interop'),
|
|
legacy: getOption('legacy'),
|
|
indent: getOption('indent'),
|
|
strict: getOption('strict'),
|
|
noConflict: getOption('noConflict'),
|
|
paths: getOption('paths')
|
|
};
|
|
|
|
let mergedOutputOptions;
|
|
if (Array.isArray(config.output)) {
|
|
mergedOutputOptions = config.output.map((output) => Object.assign({}, output, command.output));
|
|
} else if (config.output && command.output) {
|
|
mergedOutputOptions = [Object.assign({}, config.output, command.output)];
|
|
} else {
|
|
mergedOutputOptions = (command.output || config.output) ?
|
|
ensureArray(command.output || config.output) :
|
|
[{
|
|
file: command.output ? command.output.file : null,
|
|
format: command.output ? command.output.format : null
|
|
}];
|
|
}
|
|
|
|
const outputOptions = mergedOutputOptions.map(output => {
|
|
return Object.assign({}, baseOutputOptions, output);
|
|
});
|
|
|
|
return { inputOptions, outputOptions, deprecations };
|
|
}
|
|
|
|
function deprecate( config, command ) {
|
|
const deprecations = [];
|
|
|
|
// CLI
|
|
if ( command.id ) {
|
|
deprecations.push({
|
|
old: '-u/--id',
|
|
new: '--amd.id'
|
|
});
|
|
(command.amd || (command.amd = {})).id = command.id;
|
|
}
|
|
|
|
if ( typeof command.output === 'string' ) {
|
|
deprecations.push({
|
|
old: '--output',
|
|
new: '--output.file'
|
|
});
|
|
command.output = { file: command.output };
|
|
}
|
|
|
|
if ( command.format ) {
|
|
deprecations.push({
|
|
old: '--format',
|
|
new: '--output.format'
|
|
});
|
|
(command.output || (command.output = {})).format = command.format;
|
|
}
|
|
|
|
// config file
|
|
deprecations.push.apply(deprecations, deprecateOptions(config));
|
|
return deprecations;
|
|
}
|
|
|
|
function batchWarnings () {
|
|
let allWarnings = new Map();
|
|
let count = 0;
|
|
|
|
return {
|
|
get count() {
|
|
return count;
|
|
},
|
|
|
|
add: warning => {
|
|
if ( typeof warning === 'string' ) {
|
|
warning = { code: 'UNKNOWN', message: warning };
|
|
}
|
|
|
|
if ( warning.code in immediateHandlers ) {
|
|
immediateHandlers[ warning.code ]( warning );
|
|
return;
|
|
}
|
|
|
|
if ( !allWarnings.has( warning.code ) ) { allWarnings.set( warning.code, [] ); }
|
|
allWarnings.get( warning.code ).push( warning );
|
|
|
|
count += 1;
|
|
},
|
|
|
|
flush: () => {
|
|
if ( count === 0 ) { return; }
|
|
|
|
const codes = Array.from( allWarnings.keys() )
|
|
.sort( ( a, b ) => {
|
|
if ( deferredHandlers[a] && deferredHandlers[b] ) {
|
|
return deferredHandlers[a].priority - deferredHandlers[b].priority;
|
|
}
|
|
|
|
if ( deferredHandlers[a] ) { return -1; }
|
|
if ( deferredHandlers[b] ) { return 1; }
|
|
return allWarnings.get( b ).length - allWarnings.get( a ).length;
|
|
});
|
|
|
|
codes.forEach( code => {
|
|
const handler = deferredHandlers[ code ];
|
|
const warnings = allWarnings.get( code );
|
|
|
|
if ( handler ) {
|
|
handler.fn( warnings );
|
|
} else {
|
|
warnings.forEach( warning => {
|
|
stderr( `${chalk.bold.yellow('(!)')} ${chalk.bold.yellow( warning.message )}` );
|
|
|
|
if ( warning.url ) { info( warning.url ); }
|
|
|
|
const id = warning.loc && warning.loc.file || warning.id;
|
|
if ( id ) {
|
|
const loc = warning.loc ?
|
|
`${relativeId( id )}: (${warning.loc.line}:${warning.loc.column})` :
|
|
relativeId( id );
|
|
|
|
stderr( chalk.bold( relativeId( loc ) ) );
|
|
}
|
|
|
|
if ( warning.frame ) { info( warning.frame ); }
|
|
});
|
|
}
|
|
});
|
|
|
|
allWarnings = new Map();
|
|
count = 0;
|
|
}
|
|
};
|
|
}
|
|
|
|
const immediateHandlers = {
|
|
DEPRECATED_OPTIONS: warning => {
|
|
title( `Some options have been renamed` );
|
|
info( `https://gist.github.com/Rich-Harris/d472c50732dab03efeb37472b08a3f32` );
|
|
warning.deprecations.forEach(option => {
|
|
stderr( `${chalk.bold(option.old)} is now ${option.new}` );
|
|
});
|
|
},
|
|
|
|
MISSING_NODE_BUILTINS: warning => {
|
|
title( `Missing shims for Node.js built-ins` );
|
|
|
|
const detail = warning.modules.length === 1 ?
|
|
`'${warning.modules[0]}'` :
|
|
`${warning.modules.slice( 0, -1 ).map( name => `'${name}'` ).join( ', ' )} and '${warning.modules.slice( -1 )}'`;
|
|
stderr( `Creating a browser bundle that depends on ${detail}. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins` );
|
|
},
|
|
|
|
MIXED_EXPORTS: () => {
|
|
title( 'Mixing named and default exports' );
|
|
stderr( `Consumers of your bundle will have to use bundle['default'] to access the default export, which may not be what you want. Use \`exports: 'named'\` to disable this warning` );
|
|
},
|
|
|
|
EMPTY_BUNDLE: () => {
|
|
title( `Generated an empty bundle` );
|
|
}
|
|
};
|
|
|
|
// TODO select sensible priorities
|
|
const deferredHandlers = {
|
|
UNUSED_EXTERNAL_IMPORT: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( 'Unused external imports' );
|
|
warnings.forEach( warning => {
|
|
stderr( `${warning.names} imported from external module '${warning.source}' but never used` );
|
|
});
|
|
}
|
|
},
|
|
|
|
UNRESOLVED_IMPORT: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( 'Unresolved dependencies' );
|
|
info( 'https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency' );
|
|
|
|
const dependencies = new Map();
|
|
warnings.forEach( warning => {
|
|
if ( !dependencies.has( warning.source ) ) { dependencies.set( warning.source, [] ); }
|
|
dependencies.get( warning.source ).push( warning.importer );
|
|
});
|
|
|
|
Array.from( dependencies.keys() ).forEach( dependency => {
|
|
const importers = dependencies.get( dependency );
|
|
stderr( `${chalk.bold( dependency )} (imported by ${importers.join( ', ' )})` );
|
|
});
|
|
}
|
|
},
|
|
|
|
MISSING_EXPORT: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( 'Missing exports' );
|
|
info( 'https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module' );
|
|
|
|
warnings.forEach( warning => {
|
|
stderr( chalk.bold( warning.importer ) );
|
|
stderr( `${warning.missing} is not exported by ${warning.exporter}` );
|
|
stderr( chalk.grey( warning.frame ) );
|
|
});
|
|
}
|
|
},
|
|
|
|
THIS_IS_UNDEFINED: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( '`this` has been rewritten to `undefined`' );
|
|
info( 'https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined' );
|
|
showTruncatedWarnings(warnings);
|
|
}
|
|
},
|
|
|
|
EVAL: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( 'Use of eval is strongly discouraged' );
|
|
info( 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval' );
|
|
showTruncatedWarnings(warnings);
|
|
}
|
|
},
|
|
|
|
NON_EXISTENT_EXPORT: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( `Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}` );
|
|
showTruncatedWarnings(warnings);
|
|
}
|
|
},
|
|
|
|
NAMESPACE_CONFLICT: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( `Conflicting re-exports` );
|
|
warnings.forEach(warning => {
|
|
stderr( `${chalk.bold(relativeId(warning.reexporter))} re-exports '${warning.name}' from both ${relativeId(warning.sources[0])} and ${relativeId(warning.sources[1])} (will be ignored)` );
|
|
});
|
|
}
|
|
},
|
|
|
|
MISSING_GLOBAL_NAME: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( `Missing global variable ${warnings.length > 1 ? 'names' : 'name'}` );
|
|
stderr( `Use options.globals to specify browser global variable names corresponding to external modules` );
|
|
warnings.forEach(warning => {
|
|
stderr(`${chalk.bold(warning.source)} (guessing '${warning.guess}')`);
|
|
});
|
|
}
|
|
},
|
|
|
|
SOURCEMAP_BROKEN: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
title( `Broken sourcemap` );
|
|
info( 'https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect' );
|
|
|
|
const plugins = Array.from( new Set( warnings.map( w => w.plugin ).filter( Boolean ) ) );
|
|
const detail = plugins.length === 0 ? '' : plugins.length > 1 ?
|
|
` (such as ${plugins.slice(0, -1).map(p => `'${p}'`).join(', ')} and '${plugins.slice(-1)}')` :
|
|
` (such as '${plugins[0]}')`;
|
|
|
|
stderr( `Plugins that transform code${detail} should generate accompanying sourcemaps` );
|
|
}
|
|
},
|
|
|
|
PLUGIN_WARNING: {
|
|
priority: 1,
|
|
fn: warnings => {
|
|
const nestedByPlugin = nest(warnings, 'plugin');
|
|
|
|
nestedByPlugin.forEach((ref) => {
|
|
var plugin = ref.key;
|
|
var items = ref.items;
|
|
|
|
const nestedByMessage = nest(items, 'message');
|
|
|
|
let lastUrl;
|
|
|
|
nestedByMessage.forEach((ref) => {
|
|
var message = ref.key;
|
|
var items = ref.items;
|
|
|
|
title( `${plugin} plugin: ${message}` );
|
|
items.forEach(warning => {
|
|
if ( warning.url !== lastUrl ) { info( lastUrl = warning.url ); }
|
|
|
|
const loc = warning.loc ?
|
|
`${relativeId( warning.id )}: (${warning.loc.line}:${warning.loc.column})` :
|
|
relativeId( warning.id );
|
|
|
|
stderr( chalk.bold( relativeId( loc ) ) );
|
|
if ( warning.frame ) { info( warning.frame ); }
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
|
|
function title ( str ) {
|
|
stderr( `${chalk.bold.yellow('(!)')} ${chalk.bold.yellow( str )}` );
|
|
}
|
|
|
|
function info ( url ) {
|
|
stderr( chalk.grey( url ) );
|
|
}
|
|
|
|
function nest(array, prop) {
|
|
const nested = [];
|
|
const lookup = new Map();
|
|
|
|
array.forEach(item => {
|
|
const key = item[prop];
|
|
if (!lookup.has(key)) {
|
|
lookup.set(key, {
|
|
key,
|
|
items: []
|
|
});
|
|
|
|
nested.push(lookup.get(key));
|
|
}
|
|
|
|
lookup.get(key).items.push(item);
|
|
});
|
|
|
|
return nested;
|
|
}
|
|
|
|
function showTruncatedWarnings(warnings) {
|
|
const nestedByModule = nest(warnings, 'id');
|
|
|
|
const sliced = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule;
|
|
sliced.forEach((ref) => {
|
|
var id = ref.key;
|
|
var items = ref.items;
|
|
|
|
stderr( chalk.bold( relativeId( id ) ) );
|
|
stderr( chalk.grey( items[0].frame ) );
|
|
|
|
if ( items.length > 1 ) {
|
|
stderr( `...and ${items.length - 1} other ${items.length > 2 ? 'occurrences' : 'occurrence'}` );
|
|
}
|
|
});
|
|
|
|
if ( nestedByModule.length > sliced.length ) {
|
|
stderr( `\n...and ${nestedByModule.length - sliced.length} other files` );
|
|
}
|
|
}
|
|
|
|
function loadConfigFile (configFile, silent) {
|
|
const warnings = batchWarnings();
|
|
|
|
return rollup.rollup({
|
|
input: configFile,
|
|
external: id => {
|
|
return (id[0] !== '.' && !path__default.isAbsolute(id)) || id.slice(-5,id.length) === '.json';
|
|
},
|
|
onwarn: warnings.add
|
|
})
|
|
.then( bundle => {
|
|
if ( !silent && warnings.count > 0 ) {
|
|
stderr( chalk.bold( `loaded ${relativeId( configFile )} with warnings` ) );
|
|
warnings.flush();
|
|
}
|
|
|
|
return bundle.generate({
|
|
format: 'cjs'
|
|
});
|
|
})
|
|
.then( (ref) => {
|
|
var code = ref.code;
|
|
|
|
// temporarily override require
|
|
const defaultLoader = require.extensions[ '.js' ];
|
|
require.extensions[ '.js' ] = ( m, filename ) => {
|
|
if ( filename === configFile ) {
|
|
m._compile( code, filename );
|
|
} else {
|
|
defaultLoader( m, filename );
|
|
}
|
|
};
|
|
|
|
delete require.cache[configFile];
|
|
const configs = require( configFile );
|
|
if ( Object.keys( configs ).length === 0 ) {
|
|
handleError({
|
|
code: 'MISSING_CONFIG',
|
|
message: 'Config file must export an options object, or an array of options objects',
|
|
url: 'https://github.com/rollup/rollup/wiki/Command-Line-Interface#using-a-config-file'
|
|
});
|
|
}
|
|
|
|
require.extensions[ '.js' ] = defaultLoader;
|
|
|
|
return Array.isArray( configs ) ? configs : [configs];
|
|
});
|
|
}
|
|
|
|
function sequence ( array, fn ) {
|
|
const results = [];
|
|
let promise = Promise.resolve();
|
|
|
|
function next ( member, i ) {
|
|
return fn( member ).then( value => results[i] = value );
|
|
}
|
|
|
|
for ( let i = 0; i < array.length; i += 1 ) {
|
|
promise = promise.then( () => next( array[i], i ) );
|
|
}
|
|
|
|
return promise.then( () => results );
|
|
}
|
|
|
|
var parseMs = function (ms) {
|
|
if (typeof ms !== 'number') {
|
|
throw new TypeError('Expected a number');
|
|
}
|
|
|
|
var roundTowardZero = ms > 0 ? Math.floor : Math.ceil;
|
|
|
|
return {
|
|
days: roundTowardZero(ms / 86400000),
|
|
hours: roundTowardZero(ms / 3600000) % 24,
|
|
minutes: roundTowardZero(ms / 60000) % 60,
|
|
seconds: roundTowardZero(ms / 1000) % 60,
|
|
milliseconds: roundTowardZero(ms) % 1000
|
|
};
|
|
};
|
|
|
|
var addendum = "addenda";
|
|
var aircraft = "aircraft";
|
|
var alga = "algae";
|
|
var alumna = "alumnae";
|
|
var alumnus = "alumni";
|
|
var amoeba = "amoebae";
|
|
var analysis = "analyses";
|
|
var antenna = "antennae";
|
|
var antithesis = "antitheses";
|
|
var apex = "apices";
|
|
var appendix = "appendices";
|
|
var automaton = "automata";
|
|
var axis = "axes";
|
|
var bacillus = "bacilli";
|
|
var bacterium = "bacteria";
|
|
var barracks = "barracks";
|
|
var basis = "bases";
|
|
var beau = "beaux";
|
|
var bison = "bison";
|
|
var buffalo = "buffalo";
|
|
var bureau = "bureaus";
|
|
var cactus = "cacti";
|
|
var calf = "calves";
|
|
var carp = "carp";
|
|
var census = "censuses";
|
|
var chassis = "chassis";
|
|
var cherub = "cherubim";
|
|
var child = "children";
|
|
var cod = "cod";
|
|
var codex = "codices";
|
|
var concerto = "concerti";
|
|
var corpus = "corpora";
|
|
var crisis = "crises";
|
|
var criterion = "criteria";
|
|
var curriculum = "curricula";
|
|
var datum = "data";
|
|
var deer = "deer";
|
|
var diagnosis = "diagnoses";
|
|
var die = "dice";
|
|
var dwarf = "dwarfs";
|
|
var echo = "echoes";
|
|
var elf = "elves";
|
|
var elk = "elk";
|
|
var ellipsis = "ellipses";
|
|
var embargo = "embargoes";
|
|
var emphasis = "emphases";
|
|
var erratum = "errata";
|
|
var fez = "fezes";
|
|
var firmware = "firmware";
|
|
var fish = "fish";
|
|
var focus = "foci";
|
|
var foot = "feet";
|
|
var formula = "formulae";
|
|
var fungus = "fungi";
|
|
var gallows = "gallows";
|
|
var genus = "genera";
|
|
var goose = "geese";
|
|
var graffito = "graffiti";
|
|
var grouse = "grouse";
|
|
var half = "halves";
|
|
var hero = "heroes";
|
|
var hoof = "hooves";
|
|
var hovercraft = "hovercraft";
|
|
var hypothesis = "hypotheses";
|
|
var index = "indices";
|
|
var kakapo = "kakapo";
|
|
var knife = "knives";
|
|
var larva = "larvae";
|
|
var leaf = "leaves";
|
|
var libretto = "libretti";
|
|
var life = "lives";
|
|
var loaf = "loaves";
|
|
var locus = "loci";
|
|
var louse = "lice";
|
|
var man = "men";
|
|
var matrix = "matrices";
|
|
var means = "means";
|
|
var medium = "media";
|
|
var memorandum = "memoranda";
|
|
var millennium = "millennia";
|
|
var minutia = "minutiae";
|
|
var moose = "moose";
|
|
var mouse = "mice";
|
|
var nebula = "nebulae";
|
|
var nemesis = "nemeses";
|
|
var neurosis = "neuroses";
|
|
var news = "news";
|
|
var nucleus = "nuclei";
|
|
var oasis = "oases";
|
|
var offspring = "offspring";
|
|
var opus = "opera";
|
|
var ovum = "ova";
|
|
var ox = "oxen";
|
|
var paralysis = "paralyses";
|
|
var parenthesis = "parentheses";
|
|
var person = "people";
|
|
var phenomenon = "phenomena";
|
|
var phylum = "phyla";
|
|
var pike = "pike";
|
|
var polyhedron = "polyhedra";
|
|
var potato = "potatoes";
|
|
var prognosis = "prognoses";
|
|
var quiz = "quizzes";
|
|
var radius = "radii";
|
|
var referendum = "referenda";
|
|
var salmon = "salmon";
|
|
var scarf = "scarves";
|
|
var self$1 = "selves";
|
|
var series = "series";
|
|
var sheep = "sheep";
|
|
var shelf = "shelves";
|
|
var shrimp = "shrimp";
|
|
var spacecraft = "spacecraft";
|
|
var species = "species";
|
|
var spectrum = "spectra";
|
|
var squid = "squid";
|
|
var stimulus = "stimuli";
|
|
var stratum = "strata";
|
|
var swine = "swine";
|
|
var syllabus = "syllabi";
|
|
var symposium = "symposia";
|
|
var synopsis = "synopses";
|
|
var synthesis = "syntheses";
|
|
var tableau = "tableaus";
|
|
var that = "those";
|
|
var thesis = "theses";
|
|
var thief = "thieves";
|
|
var tomato = "tomatoes";
|
|
var tooth = "teeth";
|
|
var trout = "trout";
|
|
var tuna = "tuna";
|
|
var vertebra = "vertebrae";
|
|
var vertex = "vertices";
|
|
var veto = "vetoes";
|
|
var vita = "vitae";
|
|
var vortex = "vortices";
|
|
var watercraft = "watercraft";
|
|
var wharf = "wharves";
|
|
var wife = "wives";
|
|
var wolf = "wolves";
|
|
var woman = "women";
|
|
var irregularPlurals = {
|
|
addendum: addendum,
|
|
aircraft: aircraft,
|
|
alga: alga,
|
|
alumna: alumna,
|
|
alumnus: alumnus,
|
|
amoeba: amoeba,
|
|
analysis: analysis,
|
|
antenna: antenna,
|
|
antithesis: antithesis,
|
|
apex: apex,
|
|
appendix: appendix,
|
|
automaton: automaton,
|
|
axis: axis,
|
|
bacillus: bacillus,
|
|
bacterium: bacterium,
|
|
barracks: barracks,
|
|
basis: basis,
|
|
beau: beau,
|
|
bison: bison,
|
|
buffalo: buffalo,
|
|
bureau: bureau,
|
|
cactus: cactus,
|
|
calf: calf,
|
|
carp: carp,
|
|
census: census,
|
|
chassis: chassis,
|
|
cherub: cherub,
|
|
child: child,
|
|
cod: cod,
|
|
codex: codex,
|
|
concerto: concerto,
|
|
corpus: corpus,
|
|
crisis: crisis,
|
|
criterion: criterion,
|
|
curriculum: curriculum,
|
|
datum: datum,
|
|
deer: deer,
|
|
diagnosis: diagnosis,
|
|
die: die,
|
|
dwarf: dwarf,
|
|
echo: echo,
|
|
elf: elf,
|
|
elk: elk,
|
|
ellipsis: ellipsis,
|
|
embargo: embargo,
|
|
emphasis: emphasis,
|
|
erratum: erratum,
|
|
fez: fez,
|
|
firmware: firmware,
|
|
fish: fish,
|
|
focus: focus,
|
|
foot: foot,
|
|
formula: formula,
|
|
fungus: fungus,
|
|
gallows: gallows,
|
|
genus: genus,
|
|
goose: goose,
|
|
graffito: graffito,
|
|
grouse: grouse,
|
|
half: half,
|
|
hero: hero,
|
|
hoof: hoof,
|
|
hovercraft: hovercraft,
|
|
hypothesis: hypothesis,
|
|
index: index,
|
|
kakapo: kakapo,
|
|
knife: knife,
|
|
larva: larva,
|
|
leaf: leaf,
|
|
libretto: libretto,
|
|
life: life,
|
|
loaf: loaf,
|
|
locus: locus,
|
|
louse: louse,
|
|
man: man,
|
|
matrix: matrix,
|
|
means: means,
|
|
medium: medium,
|
|
memorandum: memorandum,
|
|
millennium: millennium,
|
|
minutia: minutia,
|
|
moose: moose,
|
|
mouse: mouse,
|
|
nebula: nebula,
|
|
nemesis: nemesis,
|
|
neurosis: neurosis,
|
|
news: news,
|
|
nucleus: nucleus,
|
|
oasis: oasis,
|
|
offspring: offspring,
|
|
opus: opus,
|
|
ovum: ovum,
|
|
ox: ox,
|
|
paralysis: paralysis,
|
|
parenthesis: parenthesis,
|
|
person: person,
|
|
phenomenon: phenomenon,
|
|
phylum: phylum,
|
|
pike: pike,
|
|
polyhedron: polyhedron,
|
|
potato: potato,
|
|
prognosis: prognosis,
|
|
quiz: quiz,
|
|
radius: radius,
|
|
referendum: referendum,
|
|
salmon: salmon,
|
|
scarf: scarf,
|
|
self: self$1,
|
|
series: series,
|
|
sheep: sheep,
|
|
shelf: shelf,
|
|
shrimp: shrimp,
|
|
spacecraft: spacecraft,
|
|
species: species,
|
|
spectrum: spectrum,
|
|
squid: squid,
|
|
stimulus: stimulus,
|
|
stratum: stratum,
|
|
swine: swine,
|
|
syllabus: syllabus,
|
|
symposium: symposium,
|
|
synopsis: synopsis,
|
|
synthesis: synthesis,
|
|
tableau: tableau,
|
|
that: that,
|
|
thesis: thesis,
|
|
thief: thief,
|
|
tomato: tomato,
|
|
tooth: tooth,
|
|
trout: trout,
|
|
tuna: tuna,
|
|
vertebra: vertebra,
|
|
vertex: vertex,
|
|
veto: veto,
|
|
vita: vita,
|
|
vortex: vortex,
|
|
watercraft: watercraft,
|
|
wharf: wharf,
|
|
wife: wife,
|
|
wolf: wolf,
|
|
woman: woman,
|
|
"château": "châteaus",
|
|
"faux pas": "faux pas"
|
|
};
|
|
|
|
var irregularPlurals$1 = Object.freeze({
|
|
addendum: addendum,
|
|
aircraft: aircraft,
|
|
alga: alga,
|
|
alumna: alumna,
|
|
alumnus: alumnus,
|
|
amoeba: amoeba,
|
|
analysis: analysis,
|
|
antenna: antenna,
|
|
antithesis: antithesis,
|
|
apex: apex,
|
|
appendix: appendix,
|
|
automaton: automaton,
|
|
axis: axis,
|
|
bacillus: bacillus,
|
|
bacterium: bacterium,
|
|
barracks: barracks,
|
|
basis: basis,
|
|
beau: beau,
|
|
bison: bison,
|
|
buffalo: buffalo,
|
|
bureau: bureau,
|
|
cactus: cactus,
|
|
calf: calf,
|
|
carp: carp,
|
|
census: census,
|
|
chassis: chassis,
|
|
cherub: cherub,
|
|
child: child,
|
|
cod: cod,
|
|
codex: codex,
|
|
concerto: concerto,
|
|
corpus: corpus,
|
|
crisis: crisis,
|
|
criterion: criterion,
|
|
curriculum: curriculum,
|
|
datum: datum,
|
|
deer: deer,
|
|
diagnosis: diagnosis,
|
|
die: die,
|
|
dwarf: dwarf,
|
|
echo: echo,
|
|
elf: elf,
|
|
elk: elk,
|
|
ellipsis: ellipsis,
|
|
embargo: embargo,
|
|
emphasis: emphasis,
|
|
erratum: erratum,
|
|
fez: fez,
|
|
firmware: firmware,
|
|
fish: fish,
|
|
focus: focus,
|
|
foot: foot,
|
|
formula: formula,
|
|
fungus: fungus,
|
|
gallows: gallows,
|
|
genus: genus,
|
|
goose: goose,
|
|
graffito: graffito,
|
|
grouse: grouse,
|
|
half: half,
|
|
hero: hero,
|
|
hoof: hoof,
|
|
hovercraft: hovercraft,
|
|
hypothesis: hypothesis,
|
|
index: index,
|
|
kakapo: kakapo,
|
|
knife: knife,
|
|
larva: larva,
|
|
leaf: leaf,
|
|
libretto: libretto,
|
|
life: life,
|
|
loaf: loaf,
|
|
locus: locus,
|
|
louse: louse,
|
|
man: man,
|
|
matrix: matrix,
|
|
means: means,
|
|
medium: medium,
|
|
memorandum: memorandum,
|
|
millennium: millennium,
|
|
minutia: minutia,
|
|
moose: moose,
|
|
mouse: mouse,
|
|
nebula: nebula,
|
|
nemesis: nemesis,
|
|
neurosis: neurosis,
|
|
news: news,
|
|
nucleus: nucleus,
|
|
oasis: oasis,
|
|
offspring: offspring,
|
|
opus: opus,
|
|
ovum: ovum,
|
|
ox: ox,
|
|
paralysis: paralysis,
|
|
parenthesis: parenthesis,
|
|
person: person,
|
|
phenomenon: phenomenon,
|
|
phylum: phylum,
|
|
pike: pike,
|
|
polyhedron: polyhedron,
|
|
potato: potato,
|
|
prognosis: prognosis,
|
|
quiz: quiz,
|
|
radius: radius,
|
|
referendum: referendum,
|
|
salmon: salmon,
|
|
scarf: scarf,
|
|
self: self$1,
|
|
series: series,
|
|
sheep: sheep,
|
|
shelf: shelf,
|
|
shrimp: shrimp,
|
|
spacecraft: spacecraft,
|
|
species: species,
|
|
spectrum: spectrum,
|
|
squid: squid,
|
|
stimulus: stimulus,
|
|
stratum: stratum,
|
|
swine: swine,
|
|
syllabus: syllabus,
|
|
symposium: symposium,
|
|
synopsis: synopsis,
|
|
synthesis: synthesis,
|
|
tableau: tableau,
|
|
that: that,
|
|
thesis: thesis,
|
|
thief: thief,
|
|
tomato: tomato,
|
|
tooth: tooth,
|
|
trout: trout,
|
|
tuna: tuna,
|
|
vertebra: vertebra,
|
|
vertex: vertex,
|
|
veto: veto,
|
|
vita: vita,
|
|
vortex: vortex,
|
|
watercraft: watercraft,
|
|
wharf: wharf,
|
|
wife: wife,
|
|
wolf: wolf,
|
|
woman: woman,
|
|
default: irregularPlurals
|
|
});
|
|
|
|
var irregularPlurals$2 = ( irregularPlurals$1 && irregularPlurals ) || irregularPlurals$1;
|
|
|
|
var plur = function (str, plural, count) {
|
|
if (typeof plural === 'number') {
|
|
count = plural;
|
|
}
|
|
|
|
if (str in irregularPlurals$2) {
|
|
plural = irregularPlurals$2[str];
|
|
} else if (typeof plural !== 'string') {
|
|
plural = (str.replace(/(?:s|x|z|ch|sh)$/i, '$&e').replace(/([^aeiou])y$/i, '$1ie') + 's')
|
|
.replace(/i?e?s$/i, function (m) {
|
|
var isTailLowerCase = str.slice(-1) === str.slice(-1).toLowerCase();
|
|
return isTailLowerCase ? m.toLowerCase() : m.toUpperCase();
|
|
});
|
|
}
|
|
|
|
return count === 1 ? str : plural;
|
|
};
|
|
|
|
var prettyMs = createCommonjsModule(function (module) {
|
|
'use strict';
|
|
|
|
|
|
|
|
module.exports = (ms, opts) => {
|
|
if (!Number.isFinite(ms)) {
|
|
throw new TypeError('Expected a finite number');
|
|
}
|
|
|
|
opts = opts || {};
|
|
|
|
if (ms < 1000) {
|
|
const msDecimalDigits = typeof opts.msDecimalDigits === 'number' ? opts.msDecimalDigits : 0;
|
|
return (msDecimalDigits ? ms.toFixed(msDecimalDigits) : Math.ceil(ms)) + (opts.verbose ? ' ' + plur('millisecond', Math.ceil(ms)) : 'ms');
|
|
}
|
|
|
|
const ret = [];
|
|
|
|
const add = (val, long, short, valStr) => {
|
|
if (val === 0) {
|
|
return;
|
|
}
|
|
|
|
const postfix = opts.verbose ? ' ' + plur(long, val) : short;
|
|
|
|
ret.push((valStr || val) + postfix);
|
|
};
|
|
|
|
const parsed = parseMs(ms);
|
|
|
|
add(Math.trunc(parsed.days / 365), 'year', 'y');
|
|
add(parsed.days % 365, 'day', 'd');
|
|
add(parsed.hours, 'hour', 'h');
|
|
add(parsed.minutes, 'minute', 'm');
|
|
|
|
if (opts.compact) {
|
|
add(parsed.seconds, 'second', 's');
|
|
return '~' + ret[0];
|
|
}
|
|
|
|
const sec = ms / 1000 % 60;
|
|
const secDecimalDigits = typeof opts.secDecimalDigits === 'number' ? opts.secDecimalDigits : 1;
|
|
const secStr = sec.toFixed(secDecimalDigits).replace(/\.0$/, '');
|
|
add(sec, 'second', 's', secStr);
|
|
|
|
return ret.join(' ');
|
|
};
|
|
});
|
|
|
|
function mapSequence ( array, fn ) {
|
|
const results = [];
|
|
let promise = Promise.resolve();
|
|
|
|
function next ( member, i ) {
|
|
return Promise.resolve( fn( member ) ).then( value => results[i] = value );
|
|
}
|
|
|
|
for ( let i = 0; i < array.length; i += 1 ) {
|
|
promise = promise.then( () => next( array[i], i ) );
|
|
}
|
|
|
|
return promise.then( () => results );
|
|
}
|
|
|
|
let SOURCEMAPPING_URL = 'sourceMa';
|
|
SOURCEMAPPING_URL += 'ppingURL';
|
|
|
|
var SOURCEMAPPING_URL$1 = SOURCEMAPPING_URL;
|
|
|
|
function build$1 ( inputOptions, outputOptions, warnings, silent ) {
|
|
const useStdout = outputOptions.length === 1 && !outputOptions[0].file;
|
|
|
|
const start = Date.now();
|
|
const files = useStdout ? [ 'stdout' ] : outputOptions.map( t => relativeId( t.file ) );
|
|
if ( !silent ) { stderr( chalk.cyan( `\n${chalk.bold( inputOptions.input )} → ${chalk.bold( files.join( ', ' ) )}...` ) ); }
|
|
|
|
return rollup.rollup( inputOptions )
|
|
.then( bundle => {
|
|
if ( useStdout ) {
|
|
const output = outputOptions[0];
|
|
if ( output.sourcemap && output.sourcemap !== 'inline' ) {
|
|
handleError({
|
|
code: 'MISSING_OUTPUT_OPTION',
|
|
message: 'You must specify an --output (-o) option when creating a file with a sourcemap'
|
|
});
|
|
}
|
|
|
|
return bundle.generate(output).then( (ref) => {
|
|
var code = ref.code;
|
|
var map = ref.map;
|
|
|
|
if ( output.sourcemap === 'inline' ) {
|
|
code += `\n//# ${SOURCEMAPPING_URL$1}=${map.toUrl()}\n`;
|
|
}
|
|
|
|
process.stdout.write( code );
|
|
});
|
|
}
|
|
|
|
return mapSequence( outputOptions, output => {
|
|
return bundle.write( output );
|
|
});
|
|
})
|
|
.then( () => {
|
|
warnings.flush();
|
|
if ( !silent ) { stderr( chalk.green( `created ${chalk.bold( files.join( ', ' ) )} in ${chalk.bold(prettyMs( Date.now() - start))}` ) ); }
|
|
})
|
|
.catch( handleError );
|
|
}
|
|
|
|
var signals$1 = createCommonjsModule(function (module) {
|
|
// This is not the set of all possible signals.
|
|
//
|
|
// It IS, however, the set of all signals that trigger
|
|
// an exit on either Linux or BSD systems. Linux is a
|
|
// superset of the signal names supported on BSD, and
|
|
// the unknown signals just fail to register, so we can
|
|
// catch that easily enough.
|
|
//
|
|
// Don't bother with SIGKILL. It's uncatchable, which
|
|
// means that we can't fire any callbacks anyway.
|
|
//
|
|
// If a user does happen to register a handler on a non-
|
|
// fatal signal like SIGWINCH or something, and then
|
|
// exit, it'll end up firing `process.emit('exit')`, so
|
|
// the handler will be fired anyway.
|
|
//
|
|
// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
|
|
// artificially, inherently leave the process in a
|
|
// state from which it is not safe to try and enter JS
|
|
// listeners.
|
|
module.exports = [
|
|
'SIGABRT',
|
|
'SIGALRM',
|
|
'SIGHUP',
|
|
'SIGINT',
|
|
'SIGTERM'
|
|
];
|
|
|
|
if (process.platform !== 'win32') {
|
|
module.exports.push(
|
|
'SIGVTALRM',
|
|
'SIGXCPU',
|
|
'SIGXFSZ',
|
|
'SIGUSR2',
|
|
'SIGTRAP',
|
|
'SIGSYS',
|
|
'SIGQUIT',
|
|
'SIGIOT'
|
|
// should detect profiler and enable/disable accordingly.
|
|
// see #21
|
|
// 'SIGPROF'
|
|
);
|
|
}
|
|
|
|
if (process.platform === 'linux') {
|
|
module.exports.push(
|
|
'SIGIO',
|
|
'SIGPOLL',
|
|
'SIGPWR',
|
|
'SIGSTKFLT',
|
|
'SIGUNUSED'
|
|
);
|
|
}
|
|
});
|
|
|
|
// Note: since nyc uses this module to output coverage, any lines
|
|
// that are in the direct sync flow of nyc's outputCoverage are
|
|
// ignored, since we can never get coverage for them.
|
|
|
|
var signals = signals$1;
|
|
|
|
var EE = events;
|
|
/* istanbul ignore if */
|
|
if (typeof EE !== 'function') {
|
|
EE = EE.EventEmitter;
|
|
}
|
|
|
|
var emitter;
|
|
if (process.__signal_exit_emitter__) {
|
|
emitter = process.__signal_exit_emitter__;
|
|
} else {
|
|
emitter = process.__signal_exit_emitter__ = new EE();
|
|
emitter.count = 0;
|
|
emitter.emitted = {};
|
|
}
|
|
|
|
// Because this emitter is a global, we have to check to see if a
|
|
// previous version of this library failed to enable infinite listeners.
|
|
// I know what you're about to say. But literally everything about
|
|
// signal-exit is a compromise with evil. Get used to it.
|
|
if (!emitter.infinite) {
|
|
emitter.setMaxListeners(Infinity);
|
|
emitter.infinite = true;
|
|
}
|
|
|
|
var signalExit = function (cb, opts) {
|
|
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
|
|
|
|
if (loaded === false) {
|
|
load();
|
|
}
|
|
|
|
var ev = 'exit';
|
|
if (opts && opts.alwaysLast) {
|
|
ev = 'afterexit';
|
|
}
|
|
|
|
var remove = function () {
|
|
emitter.removeListener(ev, cb);
|
|
if (emitter.listeners('exit').length === 0 &&
|
|
emitter.listeners('afterexit').length === 0) {
|
|
unload();
|
|
}
|
|
};
|
|
emitter.on(ev, cb);
|
|
|
|
return remove
|
|
};
|
|
|
|
var unload_1 = unload;
|
|
function unload () {
|
|
if (!loaded) {
|
|
return
|
|
}
|
|
loaded = false;
|
|
|
|
signals.forEach(function (sig) {
|
|
try {
|
|
process.removeListener(sig, sigListeners[sig]);
|
|
} catch (er) {}
|
|
});
|
|
process.emit = originalProcessEmit;
|
|
process.reallyExit = originalProcessReallyExit;
|
|
emitter.count -= 1;
|
|
}
|
|
|
|
function emit (event, code, signal) {
|
|
if (emitter.emitted[event]) {
|
|
return
|
|
}
|
|
emitter.emitted[event] = true;
|
|
emitter.emit(event, code, signal);
|
|
}
|
|
|
|
// { <signal>: <listener fn>, ... }
|
|
var sigListeners = {};
|
|
signals.forEach(function (sig) {
|
|
sigListeners[sig] = function listener () {
|
|
// If there are no other listeners, an exit is coming!
|
|
// Simplest way: remove us and then re-send the signal.
|
|
// We know that this will kill the process, so we can
|
|
// safely emit now.
|
|
var listeners = process.listeners(sig);
|
|
if (listeners.length === emitter.count) {
|
|
unload();
|
|
emit('exit', null, sig);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', null, sig);
|
|
/* istanbul ignore next */
|
|
process.kill(process.pid, sig);
|
|
}
|
|
};
|
|
});
|
|
|
|
var signals_1 = function () {
|
|
return signals
|
|
};
|
|
|
|
var load_1 = load;
|
|
|
|
var loaded = false;
|
|
|
|
function load () {
|
|
if (loaded) {
|
|
return
|
|
}
|
|
loaded = true;
|
|
|
|
// This is the number of onSignalExit's that are in play.
|
|
// It's important so that we can count the correct number of
|
|
// listeners on signals, and don't wait for the other one to
|
|
// handle it instead of us.
|
|
emitter.count += 1;
|
|
|
|
signals = signals.filter(function (sig) {
|
|
try {
|
|
process.on(sig, sigListeners[sig]);
|
|
return true
|
|
} catch (er) {
|
|
return false
|
|
}
|
|
});
|
|
|
|
process.emit = processEmit;
|
|
process.reallyExit = processReallyExit;
|
|
}
|
|
|
|
var originalProcessReallyExit = process.reallyExit;
|
|
function processReallyExit (code) {
|
|
process.exitCode = code || 0;
|
|
emit('exit', process.exitCode, null);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', process.exitCode, null);
|
|
/* istanbul ignore next */
|
|
originalProcessReallyExit.call(process, process.exitCode);
|
|
}
|
|
|
|
var originalProcessEmit = process.emit;
|
|
function processEmit (ev, arg) {
|
|
if (ev === 'exit') {
|
|
if (arg !== undefined) {
|
|
process.exitCode = arg;
|
|
}
|
|
var ret = originalProcessEmit.apply(this, arguments);
|
|
emit('exit', process.exitCode, null);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', process.exitCode, null);
|
|
return ret
|
|
} else {
|
|
return originalProcessEmit.apply(this, arguments)
|
|
}
|
|
}
|
|
|
|
signalExit.unload = unload_1;
|
|
signalExit.signals = signals_1;
|
|
signalExit.load = load_1;
|
|
|
|
var timeZone = createCommonjsModule(function (module) {
|
|
'use strict';
|
|
module.exports = date => {
|
|
const offset = (date || new Date()).getTimezoneOffset();
|
|
const absOffset = Math.abs(offset);
|
|
const hours = Math.floor(absOffset / 60);
|
|
const minutes = absOffset % 60;
|
|
const minutesOut = minutes > 0 ? ':' + ('0' + minutes).slice(-2) : '';
|
|
|
|
return (offset < 0 ? '+' : '-') + hours + minutesOut;
|
|
};
|
|
});
|
|
|
|
var dateTime = createCommonjsModule(function (module) {
|
|
'use strict';
|
|
|
|
|
|
module.exports = options => {
|
|
options = Object.assign({
|
|
date: new Date(),
|
|
local: true,
|
|
showTimeZone: false,
|
|
showMilliseconds: false
|
|
}, options);
|
|
|
|
let date = options.date;
|
|
|
|
if (options.local) {
|
|
// Offset the date so it will return the correct value when getting the ISO string
|
|
date = new Date(date.getTime() - (date.getTimezoneOffset() * 60000));
|
|
}
|
|
|
|
let end = '';
|
|
|
|
if (options.showTimeZone) {
|
|
end = ' UTC' + (options.local ? timeZone(date) : '');
|
|
}
|
|
|
|
if (options.showMilliseconds && date.getUTCMilliseconds() > 0) {
|
|
end = ` ${date.getUTCMilliseconds()}ms${end}`;
|
|
}
|
|
|
|
return date
|
|
.toISOString()
|
|
.replace(/T/, ' ')
|
|
.replace(/\..+/, end);
|
|
};
|
|
});
|
|
|
|
var ansiEscapes = createCommonjsModule(function (module) {
|
|
'use strict';
|
|
const x = module.exports;
|
|
const ESC = '\u001B[';
|
|
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
|
|
x.cursorTo = function (x, y) {
|
|
if (arguments.length === 0) {
|
|
return ESC + 'H';
|
|
}
|
|
|
|
if (arguments.length === 1) {
|
|
return ESC + (x + 1) + 'G';
|
|
}
|
|
|
|
return ESC + (y + 1) + ';' + (x + 1) + 'H';
|
|
};
|
|
|
|
x.cursorMove = (x, y) => {
|
|
let ret = '';
|
|
|
|
if (x < 0) {
|
|
ret += ESC + (-x) + 'D';
|
|
} else if (x > 0) {
|
|
ret += ESC + x + 'C';
|
|
}
|
|
|
|
if (y < 0) {
|
|
ret += ESC + (-y) + 'A';
|
|
} else if (y > 0) {
|
|
ret += ESC + y + 'B';
|
|
}
|
|
|
|
return ret;
|
|
};
|
|
|
|
x.cursorUp = count => ESC + (typeof count === 'number' ? count : 1) + 'A';
|
|
x.cursorDown = count => ESC + (typeof count === 'number' ? count : 1) + 'B';
|
|
x.cursorForward = count => ESC + (typeof count === 'number' ? count : 1) + 'C';
|
|
x.cursorBackward = count => ESC + (typeof count === 'number' ? count : 1) + 'D';
|
|
|
|
x.cursorLeft = ESC + 'G';
|
|
x.cursorSavePosition = ESC + (isTerminalApp ? '7' : 's');
|
|
x.cursorRestorePosition = ESC + (isTerminalApp ? '8' : 'u');
|
|
x.cursorGetPosition = ESC + '6n';
|
|
x.cursorNextLine = ESC + 'E';
|
|
x.cursorPrevLine = ESC + 'F';
|
|
x.cursorHide = ESC + '?25l';
|
|
x.cursorShow = ESC + '?25h';
|
|
|
|
x.eraseLines = count => {
|
|
let clear = '';
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
clear += x.eraseLine + (i < count - 1 ? x.cursorUp() : '');
|
|
}
|
|
|
|
if (count) {
|
|
clear += x.cursorLeft;
|
|
}
|
|
|
|
return clear;
|
|
};
|
|
|
|
x.eraseEndLine = ESC + 'K';
|
|
x.eraseStartLine = ESC + '1K';
|
|
x.eraseLine = ESC + '2K';
|
|
x.eraseDown = ESC + 'J';
|
|
x.eraseUp = ESC + '1J';
|
|
x.eraseScreen = ESC + '2J';
|
|
x.scrollUp = ESC + 'S';
|
|
x.scrollDown = ESC + 'T';
|
|
|
|
x.clearScreen = '\u001Bc';
|
|
x.beep = '\u0007';
|
|
|
|
x.image = (buf, opts) => {
|
|
opts = opts || {};
|
|
|
|
let ret = '\u001B]1337;File=inline=1';
|
|
|
|
if (opts.width) {
|
|
ret += `;width=${opts.width}`;
|
|
}
|
|
|
|
if (opts.height) {
|
|
ret += `;height=${opts.height}`;
|
|
}
|
|
|
|
if (opts.preserveAspectRatio === false) {
|
|
ret += ';preserveAspectRatio=0';
|
|
}
|
|
|
|
return ret + ':' + buf.toString('base64') + '\u0007';
|
|
};
|
|
|
|
x.iTerm = {};
|
|
|
|
x.iTerm.setCwd = cwd => '\u001B]50;CurrentDir=' + (cwd || process.cwd()) + '\u0007';
|
|
});
|
|
|
|
const SHOW_ALTERNATE_SCREEN = '\u001B[?1049h';
|
|
const HIDE_ALTERNATE_SCREEN = '\u001B[?1049l';
|
|
|
|
function alternateScreen ( enabled ) {
|
|
if (!enabled) {
|
|
let needAnnounce = true;
|
|
return {
|
|
open() {},
|
|
close() {},
|
|
reset( heading ) {
|
|
if ( needAnnounce ) {
|
|
stderr( heading );
|
|
needAnnounce = false;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
return {
|
|
open() {
|
|
process.stderr.write(SHOW_ALTERNATE_SCREEN);
|
|
},
|
|
close() {
|
|
process.stderr.write(HIDE_ALTERNATE_SCREEN);
|
|
},
|
|
reset( heading ) {
|
|
stderr( `${ansiEscapes.eraseScreen}${ansiEscapes.cursorTo(0, 0)}${heading}` );
|
|
}
|
|
};
|
|
}
|
|
|
|
function watch$1(configFile, configs, command, silent) {
|
|
const isTTY = Boolean(process.stderr.isTTY);
|
|
|
|
const screen = alternateScreen(isTTY);
|
|
screen.open();
|
|
|
|
const warnings = batchWarnings();
|
|
|
|
let watcher;
|
|
let configWatcher;
|
|
|
|
function start(configs) {
|
|
screen.reset( chalk.underline( `rollup v${rollup.VERSION}` ) );
|
|
|
|
configs = configs.map(options => {
|
|
const merged = mergeOptions(options, command);
|
|
const onwarn = merged.inputOptions.onwarn;
|
|
if ( onwarn ) {
|
|
merged.inputOptions.onwarn = warning => {
|
|
onwarn( warning, warnings.add );
|
|
};
|
|
} else {
|
|
merged.inputOptions.onwarn = warnings.add;
|
|
}
|
|
|
|
const result = Object.assign({}, merged.inputOptions, {
|
|
output: merged.outputOptions
|
|
});
|
|
|
|
if (merged.deprecations.length) {
|
|
if (!result.watch) { result.watch = {}; }
|
|
result.watch._deprecations = merged.deprecations;
|
|
}
|
|
|
|
return result;
|
|
});
|
|
|
|
watcher = rollup.watch(configs);
|
|
|
|
watcher.on('event', event => {
|
|
switch (event.code) {
|
|
case 'FATAL':
|
|
screen.close();
|
|
handleError(event.error, true);
|
|
process.exit(1);
|
|
break;
|
|
|
|
case 'ERROR':
|
|
warnings.flush();
|
|
handleError(event.error, true);
|
|
break;
|
|
|
|
case 'START':
|
|
screen.reset( chalk.underline( `rollup v${rollup.VERSION}` ) );
|
|
break;
|
|
|
|
case 'BUNDLE_START':
|
|
if ( !silent ) { stderr( chalk.cyan( `bundles ${chalk.bold( event.input )} → ${chalk.bold( event.output.map( relativeId ).join( ', ' ) )}...` ) ); }
|
|
break;
|
|
|
|
case 'BUNDLE_END':
|
|
warnings.flush();
|
|
if ( !silent ) { stderr( chalk.green( `created ${chalk.bold( event.output.map( relativeId ).join( ', ' ) )} in ${chalk.bold(prettyMs(event.duration))}` ) ); }
|
|
break;
|
|
|
|
case 'END':
|
|
if ( !silent && isTTY ) {
|
|
stderr( `\n[${dateTime()}] waiting for changes...` );
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// catch ctrl+c, kill, and uncaught errors
|
|
const removeOnExit = signalExit(close);
|
|
process.on('uncaughtException', close);
|
|
|
|
// only listen to stdin if it is a pipe
|
|
if (!process.stdin.isTTY) {
|
|
process.stdin.on('end', close); // in case we ever support stdin!
|
|
}
|
|
|
|
function close() {
|
|
removeOnExit();
|
|
process.removeListener('uncaughtException', close);
|
|
// removing a non-existent listener is a no-op
|
|
process.stdin.removeListener('end', close);
|
|
|
|
screen.close();
|
|
watcher.close();
|
|
|
|
if (configWatcher) { configWatcher.close(); }
|
|
}
|
|
|
|
start(configs);
|
|
|
|
if (configFile && !configFile.startsWith('node:')) {
|
|
let restarting = false;
|
|
let aborted = false;
|
|
let configFileData = fs__default.readFileSync(configFile, 'utf-8');
|
|
|
|
const restart = () => {
|
|
const newConfigFileData = fs__default.readFileSync(configFile, 'utf-8');
|
|
if (newConfigFileData === configFileData) { return; }
|
|
configFileData = newConfigFileData;
|
|
|
|
if (restarting) {
|
|
aborted = true;
|
|
return;
|
|
}
|
|
|
|
restarting = true;
|
|
|
|
loadConfigFile(configFile, silent)
|
|
.then(configs => {
|
|
restarting = false;
|
|
|
|
if (aborted) {
|
|
aborted = false;
|
|
restart();
|
|
} else {
|
|
watcher.close();
|
|
start(configs);
|
|
}
|
|
})
|
|
.catch(err => {
|
|
handleError(err, true);
|
|
});
|
|
};
|
|
|
|
configWatcher = fs__default.watch(configFile, event => {
|
|
if (event === 'change') { restart(); }
|
|
});
|
|
}
|
|
}
|
|
|
|
function runRollup ( command ) {
|
|
if ( command._.length > 1 ) {
|
|
handleError({
|
|
code: 'ONE_AT_A_TIME',
|
|
message: 'rollup can only bundle one file at a time'
|
|
});
|
|
}
|
|
|
|
if ( command._.length === 1 ) {
|
|
if ( command.input ) {
|
|
handleError({
|
|
code: 'DUPLICATE_IMPORT_OPTIONS',
|
|
message: 'use --input, or pass input path as argument'
|
|
});
|
|
}
|
|
|
|
command.input = command._[0];
|
|
}
|
|
|
|
if ( command.environment ) {
|
|
command.environment.split( ',' ).forEach( pair => {
|
|
const index = pair.indexOf( ':' );
|
|
if ( ~index ) {
|
|
process.env[ pair.slice( 0, index ) ] = pair.slice( index + 1 );
|
|
} else {
|
|
process.env[ pair ] = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
let configFile = command.config === true ? 'rollup.config.js' : command.config;
|
|
|
|
if ( configFile ) {
|
|
if ( configFile.slice( 0, 5 ) === 'node:' ) {
|
|
const pkgName = configFile.slice( 5 );
|
|
try {
|
|
configFile = requireRelative_1.resolve( `rollup-config-${pkgName}`, process.cwd() );
|
|
} catch ( err ) {
|
|
try {
|
|
configFile = requireRelative_1.resolve( pkgName, process.cwd() );
|
|
} catch ( err ) {
|
|
if ( err.code === 'MODULE_NOT_FOUND' ) {
|
|
handleError({
|
|
code: 'MISSING_EXTERNAL_CONFIG',
|
|
message: `Could not resolve config file ${configFile}`
|
|
});
|
|
}
|
|
|
|
throw err;
|
|
}
|
|
}
|
|
} else {
|
|
// find real path of config so it matches what Node provides to callbacks in require.extensions
|
|
configFile = fs.realpathSync( configFile );
|
|
}
|
|
|
|
if (command.watch) { process.env.ROLLUP_WATCH = 'true'; }
|
|
|
|
loadConfigFile(configFile, command.silent)
|
|
.then(normalized => execute( configFile, normalized, command ))
|
|
.catch(handleError);
|
|
} else {
|
|
return execute( configFile, [{}], command );
|
|
}
|
|
}
|
|
|
|
function execute ( configFile, configs, command ) {
|
|
if ( command.watch ) {
|
|
watch$1( configFile, configs, command, command.silent );
|
|
} else {
|
|
return sequence( configs, config => {
|
|
var ref = mergeOptions( config, command );
|
|
var inputOptions = ref.inputOptions;
|
|
var outputOptions = ref.outputOptions;
|
|
var deprecations = ref.deprecations;
|
|
|
|
const warnings = batchWarnings();
|
|
|
|
const onwarn = inputOptions.onwarn;
|
|
if ( onwarn ) {
|
|
inputOptions.onwarn = warning => {
|
|
onwarn( warning, warnings.add );
|
|
};
|
|
} else {
|
|
inputOptions.onwarn = warnings.add;
|
|
}
|
|
|
|
if (deprecations.length) {
|
|
inputOptions.onwarn({
|
|
code: 'DEPRECATED_OPTIONS',
|
|
message: `The following options have been renamed — please update your config: ${deprecations.map(option => `${option.old} -> ${option.new}`).join(', ')}`,
|
|
deprecations
|
|
});
|
|
}
|
|
|
|
return build$1( inputOptions, outputOptions, warnings, command.silent );
|
|
});
|
|
}
|
|
}
|
|
|
|
const command = minimist( process.argv.slice( 2 ), {
|
|
alias: {
|
|
// Aliases
|
|
strict: 'useStrict',
|
|
|
|
// Short options
|
|
c: 'config',
|
|
d: 'indent',
|
|
e: 'external',
|
|
f: 'output.format',
|
|
g: 'globals',
|
|
h: 'help',
|
|
i: 'input',
|
|
l: 'legacy',
|
|
m: 'sourcemap',
|
|
n: 'name',
|
|
o: 'output.file',
|
|
u: 'id',
|
|
v: 'version',
|
|
w: 'watch'
|
|
}
|
|
});
|
|
|
|
if ( command.help || ( process.argv.length <= 2 && process.stdin.isTTY ) ) {
|
|
console.log( `\n${help.replace('__VERSION__', version)}\n` ); // eslint-disable-line no-console
|
|
}
|
|
|
|
else if ( command.version ) {
|
|
console.log( `rollup version ${version}` ); // eslint-disable-line no-console
|
|
}
|
|
|
|
else {
|
|
try {
|
|
require('source-map-support').install();
|
|
} catch (err) {
|
|
// do nothing
|
|
}
|
|
|
|
runRollup( command );
|
|
}
|