Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import supportsColor from 'supports-color';
if (supportsColor) {
console.log('Terminal supports color');
if (supportsColor.hasBasic) {
const level: number = supportsColor.level;
console.log('Terminal has basic color support', level);
}
if (supportsColor.has256) {
console.log('Terminal supports 256 colors');
}
if (supportsColor.has16m) {
console.log('Terminal supports 16 million colors (truecolor)');
}
// $ExpectError
supportsColor.nope;
// $ExpectError
(supportsColor.level: string);
console.log('Terminal has basic color support', level);
}
if (supportsColor.has256) {
console.log('Terminal supports 256 colors');
}
if (supportsColor.has16m) {
console.log('Terminal supports 16 million colors (truecolor)');
}
// $ExpectError
supportsColor.nope;
// $ExpectError
(supportsColor.level: string);
}
// Resolve from LOG4_* env vars
logger.predefinedLevels.forEach(function (level) {
var varName = "LOG_" + level.toUpperCase();
if (process.env[varName]) conf[level] = process.env[varName].split(",");
});
// Eventually support as fallback DEBUG env var
if (!conf.debug && process.env.DEBUG) conf.debug = process.env.DEBUG.split(",");
// Do not show debug level logs by default
if (!conf.debug) conf.debug = [];
conf.debug.unshift("-*");
setupVisibility(conf);
// Resolve eventual colors setup (as in debug lib)
if (supportsColor && process.env.LOG4_COLORS !== "no") {
var colors;
if (supportsColor.level >= 2) {
colors = [
20,
21,
26,
27,
32,
33,
38,
39,
40,
41,
42,
43,
44,
45,
56,
execute() {
if (!this.initCommand) return;
const env = Object.assign({}, process.env);
const pathVariableName = getPathVariableName();
// Using process.cwd until a better solution is found for (#5)
env[pathVariableName] +=
(isWin() ? ';' : ':') + process.cwd() + '/node_modules/.bin';
this.proc = cp.spawn(this.initCommand, [], {
env: Object.assign({ FORCE_COLOR: supportsColor.level }, env),
shell: true
});
this.proc.stdout.setEncoding('utf8');
this.proc.stderr.setEncoding('utf8');
// this.proc && this.proc.stdin.setEncoding('utf-8');
this.executing = true;
this.setupEvents();
this.pid = this.proc.pid;
}
}
exports.init = init;
exports.log = log;
exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
/**
* Colors.
*/
exports.colors = [ 6, 2, 3, 4, 5, 1 ];
try {
var supportsColor = require('supports-color');
if (supportsColor && supportsColor.level >= 2) {
exports.colors = [
20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68,
69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134,
135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 214, 215, 220, 221
];
}
} catch (err) {
// swallow - we only care if `supports-color` is available; it doesn't have to be.
}
/**
* Build up the default `inspectOpts` object from the environment variables.
*
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
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;
}
exports.init = init;
exports.log = log;
exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
/**
* Colors.
*/
exports.colors = [ 6, 2, 3, 4, 5, 1 ];
try {
var supportsColor = require('supports-color');
if (supportsColor && supportsColor.level >= 2) {
exports.colors = [
20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68,
69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134,
135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 214, 215, 220, 221
];
}
} catch (err) {
// swallow - we only care if `supports-color` is available; it doesn't have to be.
}
/**
* Build up the default `inspectOpts` object from the environment variables.
*
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
const supportsColor = require('supports-color');
console.log(`check if support colors in current process? ${JSON.stringify(supportsColor)}`);
serverless.supportColorLevel = supportsColor.level;
if (supportsColor.level > 0) {
console.log('Support colors in current process');
} else {
console.error('FAILED: DO NOT SUPPORT colors');
}
new Promise((resolve, reject) => {
if (watcher.isInterrupted()) {
throw new CancelRun();
}
const env = Object.assign({}, process.env, {
FORCE_COLOR: supportsColor.level
});
onStart(test)
.then(() =>
spawn(
electron,
[path.join(__dirname, "electron-transport.js")],
{ stdio: ["ipc"], env }
)
)
.then(electron => {
process.on("exit", code => {
electron.kill();
});
electron.on("message", message => {
const uuid = require('uuid');
const osName = require('os-name');
const isCi = require('is-ci');
const _ = require('lodash');
const debug = require('debug')('release-it:metrics');
const pkg = require('../package.json');
const noop = Promise.resolve();
const cast = value => (value ? 1 : 0);
const cid = uuid.v4();
const dimensions = windowSize ? windowSize.get() : { width: 0, height: 0 };
const vp = `${dimensions.width}x${dimensions.height}`;
const depths = ['1-bit', '4-bit', '8-bit', '24-bits'];
const sd = depths[supportsColor.level || 0];
const payload = config => ({
v: 1,
tid: 'UA-108828841-1',
cid,
vp,
sd,
cd1: pkg.version,
cd2: process.version,
cd3: osName(),
cd4: cast(!config.isCI),
cd5: cast(config.isDryRun),
cd6: cast(config.isVerbose),
cd7: cast(config.isDebug),
cd8: null,
cd9: config.preReleaseId,