@graphql-hive/cli
Version:
A CLI util to manage and control your GraphQL Hive
96 lines • 3.95 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Texture = exports.createBuilder = exports.warning = exports.info = exports.failure = exports.success = exports.inspect = exports.prefixedInspect = exports.boldQuotedWords = exports.trimEnd = exports.plural = exports.header = exports.newline = exports.indent = exports.space = exports.colors = void 0;
const tslib_1 = require("tslib");
const node_util_1 = require("node:util");
const colors_1 = tslib_1.__importDefault(require("colors"));
exports.colors = colors_1.default;
tslib_1.__exportStar(require("./table"), exports);
exports.space = ' ';
exports.indent = exports.space.repeat(3);
exports.newline = '\n';
const header = (value) => colors_1.default.dim('=== ') + colors_1.default.bold(value);
exports.header = header;
const plural = (value) => (value.length > 1 ? 's' : '');
exports.plural = plural;
const trimEnd = (value) => value.replace(/\s+$/g, '');
exports.trimEnd = trimEnd;
/**
* Convert quoted text to bolded text. Quotes are stripped.
*/
const boldQuotedWords = (value) => {
const singleQuotedTextRegex = /'([^']+)'/gim;
const doubleQuotedTextRegex = /"([^"]+)"/gim;
return value
.replace(singleQuotedTextRegex, (_, capturedValue) => colors_1.default.bold(capturedValue))
.replace(doubleQuotedTextRegex, (_, capturedValue) => colors_1.default.bold(capturedValue));
};
exports.boldQuotedWords = boldQuotedWords;
const prefixedInspect = (prefix) => (...values) => {
const body = values.map(exports.inspect).join(' ');
return [prefix, body].join(' ');
};
exports.prefixedInspect = prefixedInspect;
const inspect = (value) => {
if (typeof value === 'string') {
return value;
}
return (0, node_util_1.inspect)(value);
};
exports.inspect = inspect;
const success = (...values) => (0, exports.prefixedInspect)(colors_1.default.green('✔'))(...values);
exports.success = success;
const failure = (...values) => (0, exports.prefixedInspect)(colors_1.default.red('✖'))(...values);
exports.failure = failure;
const info = (...values) => (0, exports.prefixedInspect)(colors_1.default.yellow('ℹ'))(...values);
exports.info = info;
const warning = (...values) => (0, exports.prefixedInspect)(colors_1.default.yellow('⚠'))(...values);
exports.warning = warning;
const createBuilder = () => {
const state = {
value: '',
};
const builder = {
line: value => {
if (value === undefined) {
state.value = state.value + exports.newline;
}
else if (typeof value === 'string') {
state.value = state.value + value + exports.newline;
}
else {
state.value = state.value + value.state.value;
}
return builder;
},
header: value => {
state.value = state.value + (0, exports.header)(value) + exports.newline;
return builder;
},
indent: value => {
state.value = state.value + exports.indent + value + exports.newline;
return builder;
},
success: (...values) => {
state.value = state.value + (0, exports.success)(...values) + exports.newline;
return builder;
},
failure: (...values) => {
state.value = state.value + (0, exports.failure)(...values) + exports.newline;
return builder;
},
info: (...values) => {
state.value = state.value + (0, exports.info)(...values) + exports.newline;
return builder;
},
warning: (...values) => {
state.value = state.value + (0, exports.warning)(...values) + exports.newline;
return builder;
},
state,
};
return builder;
};
exports.createBuilder = createBuilder;
exports.Texture = tslib_1.__importStar(require("./texture"));
//# sourceMappingURL=texture.js.map
;