remove chalk dependency

This commit is contained in:
silverwind 2018-11-28 00:41:13 +01:00
parent ae5b4ef32e
commit 402c6ed7ba
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
2 changed files with 10 additions and 6 deletions

@ -27,7 +27,6 @@
"updates.js"
],
"dependencies": {
"chalk": "2.4.1",
"escape-string-regexp": "1.0.5",
"find-up": "3.0.0",
"hosted-git-info": "^2.7.1",

@ -80,8 +80,14 @@ if (args.version) {
process.exit(0);
}
if (args["color"]) process.env.FORCE_COLOR = "1";
if (args["no-color"]) process.env.FORCE_COLOR = "0";
let useColor = Boolean(process.stdout.isTTY);
if (args["color"]) useColor = true;
if (args["no-color"]) useColor = false;
const colors = {
green: str => useColor ? `\x1b[0;32m${str}\x1b[0m` : str,
red: str => useColor ? `\x1b[0;31m${str}\x1b[0m` : str,
};
const greatest = parseMixedArg(args.greatest);
const prerelease = parseMixedArg(args.prerelease);
@ -167,7 +173,6 @@ if (!Object.keys(deps).length) {
const fetch = require("make-fetch-happen");
const esc = require("escape-string-regexp");
const chalk = require("chalk");
const hostedGitInfo = require("hosted-git-info");
const get = async name => {
@ -224,7 +229,7 @@ Promise.all(Object.keys(deps).map(name => get(name))).then(dati => {
package.json updated
`;
finish(chalk.green(msg.substring(1)));
finish(colors.green(msg.substring(1)));
}).catch(finish);
function finish(obj, opts) {
@ -262,7 +267,7 @@ function finish(obj, opts) {
function highlightDiff(a, b, added) {
const aParts = a.split(/\./);
const bParts = b.split(/\./);
const color = chalk[added ? "green" : "red"];
const color = colors[added ? "green" : "red"];
const versionPartRe = /^[0-9a-zA-Z-.]+$/;
let res = "";