Skip to content

Commit

Permalink
chore: add color to output
Browse files Browse the repository at this point in the history
  • Loading branch information
sixmen committed Feb 27, 2024
1 parent 4288199 commit 9d2062e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/graphql/lib/cli/check-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function check(schema_file, query_list_file) {
const is_field_deprecated = isDeprecated(field.astNode?.directives);
if (is_field_deprecated) {
has_deprecated = true;
console.log(`${type.name}.${field.name} is deprecated`);
console.log(`${common_1.COLORS.RED}${type.name}.${field.name} is deprecated${common_1.COLORS.RESET}`);
}
if (node.arguments) {
for (const argument of node.arguments) {
Expand All @@ -47,7 +47,7 @@ async function check(schema_file, query_list_file) {
const is_arg_deprecated = isDeprecated(field_arg.astNode?.directives);
if (is_arg_deprecated) {
has_deprecated = true;
console.log(`${type.name}.${field.name}(${field_arg.name}) is deprecated`);
console.log(`${common_1.COLORS.RED}${type.name}.${field.name}(${field_arg.name}) is deprecated${common_1.COLORS.RESET}`);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/graphql/lib/cli/common.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export declare function extractQueryList(text: string): string[];
export declare const COLORS: {
RED: string;
GREEN: string;
BLUE: string;
RESET: string;
};
8 changes: 7 additions & 1 deletion packages/graphql/lib/cli/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractQueryList = void 0;
exports.COLORS = exports.extractQueryList = void 0;
function extractQueryList(text) {
return text
.split('\n')
Expand All @@ -17,3 +17,9 @@ function extractQueryList(text) {
.split('\n');
}
exports.extractQueryList = extractQueryList;
exports.COLORS = {
RED: '\x1b[31m',
GREEN: '\x1b[32m',
BLUE: '\x1b[34m',
RESET: '\x1b[0m',
};
8 changes: 5 additions & 3 deletions packages/graphql/src/cli/check-deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs/promises';
import { ASTVisitor, buildSchema, ConstDirectiveNode, Kind, parse, TypeInfo, visit, visitWithTypeInfo } from 'graphql';
import { extractQueryList } from './common';
import { COLORS, extractQueryList } from './common';

function isDeprecated(directives: readonly ConstDirectiveNode[] | undefined) {
for (const directive of directives || []) {
Expand Down Expand Up @@ -36,7 +36,7 @@ async function check(schema_file: string, query_list_file: string) {
const is_field_deprecated = isDeprecated(field.astNode?.directives);
if (is_field_deprecated) {
has_deprecated = true;
console.log(`${type.name}.${field.name} is deprecated`);
console.log(`${COLORS.RED}${type.name}.${field.name} is deprecated${COLORS.RESET}`);
}
if (node.arguments) {
for (const argument of node.arguments) {
Expand All @@ -45,7 +45,9 @@ async function check(schema_file: string, query_list_file: string) {
const is_arg_deprecated = isDeprecated(field_arg.astNode?.directives);
if (is_arg_deprecated) {
has_deprecated = true;
console.log(`${type.name}.${field.name}(${field_arg.name}) is deprecated`);
console.log(
`${COLORS.RED}${type.name}.${field.name}(${field_arg.name}) is deprecated${COLORS.RESET}`,
);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/graphql/src/cli/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ export function extractQueryList(text: string) {
.trim()
.split('\n');
}

export const COLORS = {
RED: '\x1b[31m',
GREEN: '\x1b[32m',
BLUE: '\x1b[34m',
RESET: '\x1b[0m',
};

0 comments on commit 9d2062e

Please sign in to comment.