Skip to content

Commit 8988033

Browse files
authored
chore: Simplify CLI dependencies and update Renovate config (#2366)
1 parent 13b417b commit 8988033

6 files changed

Lines changed: 85 additions & 165 deletions

File tree

cli/package-lock.json

Lines changed: 3 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"protobufjs": "^8.7.0"
2424
},
2525
"dependencies": {
26-
"chalk": "^4.0.0",
2726
"escodegen": "^1.13.0",
2827
"espree": "^9.6.1",
2928
"estraverse": "^5.1.0",

cli/pbjs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
var path = require("path"),
33
fs = require("fs"),
44
minimist = require("minimist"),
5-
chalk = require("chalk"),
65
pkg = require("./package.json"),
76
util = require("./util"),
87
glob = require("glob"),
98
protobuf = require("protobufjs");
109

1110
var targets = util.requireAll("./targets");
11+
var color = util.color;
1212

1313
var lintDefault = "eslint-disable " + [
1414
"block-scoped-var",
@@ -234,7 +234,7 @@ exports.main = function main(args, callback) {
234234
process.stderr.write([
235235
"protobuf.js v" + pkg.version + " CLI for JavaScript",
236236
"",
237-
chalk.bold.white("Translates between file formats and generates static code."),
237+
color.bold + color.white + "Translates between file formats and generates static code." + color.reset,
238238
"",
239239
" -t, --target Specifies the target format. Also accepts a path to require a custom target.",
240240
"",
@@ -251,7 +251,7 @@ exports.main = function main(args, callback) {
251251
"",
252252
" --sparse Exports only those types referenced from a main file (experimental).",
253253
"",
254-
chalk.bold.gray(" Module targets only:"),
254+
color.bold + color.gray + " Module targets only:" + color.reset,
255255
"",
256256
" -w, --wrap Specifies the wrapper to use. Also accepts a path to require a custom wrapper.",
257257
"",
@@ -271,12 +271,12 @@ exports.main = function main(args, callback) {
271271
"",
272272
" --es6 Enables ES6 syntax (const/let instead of var)",
273273
"",
274-
chalk.bold.gray(" Proto sources only:"),
274+
color.bold + color.gray + " Proto sources only:" + color.reset,
275275
"",
276276
" --keep-case Keeps field casing instead of converting to camel case.",
277277
" --alt-comment Turns on an alternate comment parsing mode that preserves more comments.",
278278
"",
279-
chalk.bold.gray(" Static targets only:"),
279+
color.bold + color.gray + " Static targets only:" + color.reset,
280280
"",
281281
" --no-create Does not generate create functions used for reflection compatibility.",
282282
" --no-encode Does not generate encode functions.",
@@ -296,7 +296,7 @@ exports.main = function main(args, callback) {
296296
" --null-defaults Default value for optional fields is null instead of zero value.",
297297
" --null-semantics Make nullable fields match protobuf semantics (overrides --null-defaults).",
298298
"",
299-
"usage: " + chalk.bold.green("pbjs") + " [options] file1.proto file2.json ..." + chalk.gray(" (or pipe) ") + "other | " + chalk.bold.green("pbjs") + " [options] -",
299+
"usage: " + color.bold + color.green + "pbjs" + color.reset + " [options] file1.proto file2.json ..." + color.gray + " (or pipe) " + color.reset + "other | " + color.bold + color.green + "pbjs" + color.reset + " [options] -",
300300
""
301301
].join("\n"));
302302
return 1;

cli/pbts.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ var child_process = require("child_process"),
44
fs = require("fs"),
55
pkg = require("./package.json"),
66
minimist = require("minimist"),
7-
chalk = require("chalk"),
7+
util = require("./util"),
88
glob = require("glob"),
99
tmp = require("tmp");
1010

11+
var color = util.color;
12+
1113
/**
1214
* Runs pbts programmatically.
1315
* @param {string[]} args Command line arguments
@@ -72,7 +74,7 @@ function run(options) {
7274
process.stderr.write([
7375
"protobuf.js v" + pkg.version + " CLI for TypeScript",
7476
"",
75-
chalk.bold.white("Generates TypeScript definitions from annotated JavaScript files."),
77+
color.bold + color.white + "Generates TypeScript definitions from annotated JavaScript files." + color.reset,
7678
"",
7779
" -o, --out Saves to a file instead of writing to stdout.",
7880
"",
@@ -84,13 +86,13 @@ function run(options) {
8486
"",
8587
" --no-comments Does not output any JSDoc comments.",
8688
"",
87-
chalk.bold.gray(" Internal flags:"),
89+
color.bold + color.gray + " Internal flags:" + color.reset,
8890
"",
8991
" -n, --name Wraps everything in a module of the specified name.",
9092
"",
9193
" -m, --main Whether building a standalone file without any imports.",
9294
"",
93-
"usage: " + chalk.bold.green("pbts") + " [options] file1.js file2.js ..." + chalk.bold.gray(" (or) ") + "other | " + chalk.bold.green("pbts") + " [options] -",
95+
"usage: " + color.bold + color.green + "pbts" + color.reset + " [options] file1.js file2.js ..." + color.bold + color.gray + " (or) " + color.reset + "other | " + color.bold + color.green + "pbts" + color.reset + " [options] -",
9496
""
9597
].join("\n"));
9698
return 1;

cli/util.js

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,24 @@ exports.isEsmWrapper = function isEsmWrapper(wrap) {
6666
return wrap === "esm" || wrap === "es6";
6767
};
6868

69-
exports.inspect = function inspect(object, indent) {
70-
if (!object)
71-
return "";
72-
var chalk = require("chalk");
73-
var sb = [];
74-
if (!indent)
75-
indent = "";
76-
var ind = indent ? indent.substring(0, indent.length - 2) + "└ " : "";
77-
sb.push(
78-
ind + chalk.bold(object.toString()) + (object.visible ? " (visible)" : ""),
79-
indent + chalk.gray("parent: ") + object.parent
80-
);
81-
if (object instanceof protobuf.Field) {
82-
if (object.extend !== undefined)
83-
sb.push(indent + chalk.gray("extend: ") + object.extend);
84-
if (object.partOf)
85-
sb.push(indent + chalk.gray("oneof : ") + object.oneof);
86-
}
87-
sb.push("");
88-
if (object.fieldsArray)
89-
object.fieldsArray.forEach(function(field) {
90-
sb.push(inspect(field, indent + " "));
91-
});
92-
if (object.oneofsArray)
93-
object.oneofsArray.forEach(function(oneof) {
94-
sb.push(inspect(oneof, indent + " "));
95-
});
96-
if (object.methodsArray)
97-
object.methodsArray.forEach(function(service) {
98-
sb.push(inspect(service, indent + " "));
99-
});
100-
if (object.nestedArray)
101-
object.nestedArray.forEach(function(nested) {
102-
sb.push(inspect(nested, indent + " "));
103-
});
104-
return sb.join("\n");
69+
var env = process.env; // eslint-disable-line no-process-env
70+
var colorEnabled =
71+
env.NO_COLOR === undefined &&
72+
env.FORCE_COLOR !== "0" &&
73+
(env.FORCE_COLOR !== undefined || process.stderr && process.stderr.isTTY);
74+
75+
exports.color = colorEnabled ? {
76+
reset: "\x1b[0m",
77+
bold: "\x1b[1m",
78+
gray: "\x1b[90m",
79+
green: "\x1b[32m",
80+
white: "\x1b[37m"
81+
} : {
82+
reset: "",
83+
bold: "",
84+
gray: "",
85+
green: "",
86+
white: ""
10587
};
10688

10789
exports.wrap = function(OUTPUT, options) {

0 commit comments

Comments
 (0)