@graphql-codegen/cli 2.8.0-alpha-bd464a586.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,136 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorRenderer = exports.Renderer = void 0;
4
- const tslib_1 = require("tslib");
5
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const indentString_js_1 = require("./indentString.js");
7
- const log_symbols_1 = tslib_1.__importDefault(require("log-symbols"));
8
- const ansi_escapes_1 = tslib_1.__importDefault(require("ansi-escapes"));
9
- const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
10
- const common_tags_1 = require("common-tags");
11
- const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
12
- const debugging_js_1 = require("./debugging.js");
13
- const listr_update_renderer_1 = tslib_1.__importDefault(require("listr-update-renderer"));
14
- class Renderer {
15
- constructor(tasks, options) {
16
- this.updateRenderer = new listr_update_renderer_1.default(tasks, options);
17
- }
18
- render() {
19
- return this.updateRenderer.render();
20
- }
21
- end(err) {
22
- this.updateRenderer.end(err);
23
- if (typeof err === 'undefined') {
24
- logUpdate.clear();
25
- return;
26
- }
27
- // persist the output
28
- logUpdate.done();
29
- // show errors
30
- if (err) {
31
- const errorCount = err.errors ? err.errors.length : 0;
32
- if (errorCount > 0) {
33
- const count = (0, indentString_js_1.indentString)(chalk_1.default.red.bold(`Found ${errorCount} error${errorCount > 1 ? 's' : ''}`), 1);
34
- const details = err.errors
35
- .map(error => {
36
- (0, debugging_js_1.debugLog)(`[CLI] Exited with an error`, error);
37
- return { msg: (0, plugin_helpers_1.isDetailedError)(error) ? error.details : null, rawError: error };
38
- })
39
- .map(({ msg, rawError }, i) => {
40
- const source = err.errors[i].source;
41
- msg = msg ? chalk_1.default.gray((0, indentString_js_1.indentString)((0, common_tags_1.stripIndent)(`${msg}`), 4)) : null;
42
- const stack = rawError.stack ? chalk_1.default.gray((0, indentString_js_1.indentString)((0, common_tags_1.stripIndent)(rawError.stack), 4)) : null;
43
- if (source) {
44
- const sourceOfError = typeof source === 'string' ? source : source.name;
45
- const title = (0, indentString_js_1.indentString)(`${log_symbols_1.default.error} ${sourceOfError}`, 2);
46
- return [title, msg, stack, stack].filter(Boolean).join('\n');
47
- }
48
- return [msg, stack].filter(Boolean).join('\n');
49
- })
50
- .join('\n\n');
51
- logUpdate.emit(['', count, details, ''].join('\n\n'));
52
- }
53
- else {
54
- const details = err.details ? err.details : '';
55
- logUpdate.emit(`${chalk_1.default.red.bold(`${(0, indentString_js_1.indentString)(err.message, 2)}`)}\n${details}\n${chalk_1.default.grey(err.stack)}`);
56
- }
57
- }
58
- logUpdate.done();
59
- (0, debugging_js_1.printLogs)();
60
- }
61
- }
62
- exports.Renderer = Renderer;
63
- const render = tasks => {
64
- for (const task of tasks) {
65
- task.subscribe(event => {
66
- if (event.type === 'SUBTASKS') {
67
- render(task.subtasks);
68
- return;
69
- }
70
- if (event.type === 'DATA') {
71
- logUpdate.emit(chalk_1.default.dim(`${event.data}`));
72
- }
73
- logUpdate.done();
74
- }, err => {
75
- logUpdate.emit(err);
76
- logUpdate.done();
77
- });
78
- }
79
- };
80
- class ErrorRenderer {
81
- constructor(tasks, _options) {
82
- this.tasks = tasks;
83
- }
84
- render() {
85
- render(this.tasks);
86
- }
87
- static get nonTTY() {
88
- return true;
89
- }
90
- end() { }
91
- }
92
- exports.ErrorRenderer = ErrorRenderer;
93
- class LogUpdate {
94
- constructor() {
95
- this.stream = process.stdout;
96
- // state
97
- this.previousLineCount = 0;
98
- this.previousOutput = '';
99
- this.previousWidth = this.getWidth();
100
- }
101
- emit(...args) {
102
- let output = args.join(' ') + '\n';
103
- const width = this.getWidth();
104
- if (output === this.previousOutput && this.previousWidth === width) {
105
- return;
106
- }
107
- this.previousOutput = output;
108
- this.previousWidth = width;
109
- output = (0, wrap_ansi_1.default)(output, width, {
110
- trim: false,
111
- hard: true,
112
- wordWrap: false,
113
- });
114
- this.stream.write(ansi_escapes_1.default.eraseLines(this.previousLineCount) + output);
115
- this.previousLineCount = output.split('\n').length;
116
- }
117
- clear() {
118
- this.stream.write(ansi_escapes_1.default.eraseLines(this.previousLineCount));
119
- this.previousOutput = '';
120
- this.previousWidth = this.getWidth();
121
- this.previousLineCount = 0;
122
- }
123
- done() {
124
- this.previousOutput = '';
125
- this.previousWidth = this.getWidth();
126
- this.previousLineCount = 0;
127
- }
128
- getWidth() {
129
- const { columns } = this.stream;
130
- if (!columns) {
131
- return 80;
132
- }
133
- return columns;
134
- }
135
- }
136
- const logUpdate = new LogUpdate();
@@ -1,33 +0,0 @@
1
- /**
2
- Indent each line in a string.
3
- @param string - The string to indent.
4
- @param count - How many times you want `options.indent` repeated. Default: `1`.
5
- @example
6
- ```
7
- import indentString from 'indent-string';
8
- indentString('Unicorns\nRainbows', 4);
9
- //=> ' Unicorns\n Rainbows'
10
- indentString('Unicorns\nRainbows', 4, {indent: '♥'});
11
- //=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'
12
- ```
13
- */
14
- export function indentString(string, count = 1, options = {}) {
15
- const { indent = ' ', includeEmptyLines = false } = options;
16
- if (typeof string !== 'string') {
17
- throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof string}\``);
18
- }
19
- if (typeof count !== 'number') {
20
- throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``);
21
- }
22
- if (count < 0) {
23
- throw new RangeError(`Expected \`count\` to be at least 0, got \`${count}\``);
24
- }
25
- if (typeof indent !== 'string') {
26
- throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof indent}\``);
27
- }
28
- if (count === 0) {
29
- return string;
30
- }
31
- const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
32
- return string.replace(regex, indent.repeat(count));
33
- }
@@ -1,130 +0,0 @@
1
- import chalk from 'chalk';
2
- import { indentString } from './indentString.js';
3
- import logSymbol from 'log-symbols';
4
- import ansiEscapes from 'ansi-escapes';
5
- import wrapAnsi from 'wrap-ansi';
6
- import { stripIndent } from 'common-tags';
7
- import { isDetailedError } from '@graphql-codegen/plugin-helpers';
8
- import { debugLog, printLogs } from './debugging.js';
9
- import UpdateRenderer from 'listr-update-renderer';
10
- export class Renderer {
11
- constructor(tasks, options) {
12
- this.updateRenderer = new UpdateRenderer(tasks, options);
13
- }
14
- render() {
15
- return this.updateRenderer.render();
16
- }
17
- end(err) {
18
- this.updateRenderer.end(err);
19
- if (typeof err === 'undefined') {
20
- logUpdate.clear();
21
- return;
22
- }
23
- // persist the output
24
- logUpdate.done();
25
- // show errors
26
- if (err) {
27
- const errorCount = err.errors ? err.errors.length : 0;
28
- if (errorCount > 0) {
29
- const count = indentString(chalk.red.bold(`Found ${errorCount} error${errorCount > 1 ? 's' : ''}`), 1);
30
- const details = err.errors
31
- .map(error => {
32
- debugLog(`[CLI] Exited with an error`, error);
33
- return { msg: isDetailedError(error) ? error.details : null, rawError: error };
34
- })
35
- .map(({ msg, rawError }, i) => {
36
- const source = err.errors[i].source;
37
- msg = msg ? chalk.gray(indentString(stripIndent(`${msg}`), 4)) : null;
38
- const stack = rawError.stack ? chalk.gray(indentString(stripIndent(rawError.stack), 4)) : null;
39
- if (source) {
40
- const sourceOfError = typeof source === 'string' ? source : source.name;
41
- const title = indentString(`${logSymbol.error} ${sourceOfError}`, 2);
42
- return [title, msg, stack, stack].filter(Boolean).join('\n');
43
- }
44
- return [msg, stack].filter(Boolean).join('\n');
45
- })
46
- .join('\n\n');
47
- logUpdate.emit(['', count, details, ''].join('\n\n'));
48
- }
49
- else {
50
- const details = err.details ? err.details : '';
51
- logUpdate.emit(`${chalk.red.bold(`${indentString(err.message, 2)}`)}\n${details}\n${chalk.grey(err.stack)}`);
52
- }
53
- }
54
- logUpdate.done();
55
- printLogs();
56
- }
57
- }
58
- const render = tasks => {
59
- for (const task of tasks) {
60
- task.subscribe(event => {
61
- if (event.type === 'SUBTASKS') {
62
- render(task.subtasks);
63
- return;
64
- }
65
- if (event.type === 'DATA') {
66
- logUpdate.emit(chalk.dim(`${event.data}`));
67
- }
68
- logUpdate.done();
69
- }, err => {
70
- logUpdate.emit(err);
71
- logUpdate.done();
72
- });
73
- }
74
- };
75
- export class ErrorRenderer {
76
- constructor(tasks, _options) {
77
- this.tasks = tasks;
78
- }
79
- render() {
80
- render(this.tasks);
81
- }
82
- static get nonTTY() {
83
- return true;
84
- }
85
- end() { }
86
- }
87
- class LogUpdate {
88
- constructor() {
89
- this.stream = process.stdout;
90
- // state
91
- this.previousLineCount = 0;
92
- this.previousOutput = '';
93
- this.previousWidth = this.getWidth();
94
- }
95
- emit(...args) {
96
- let output = args.join(' ') + '\n';
97
- const width = this.getWidth();
98
- if (output === this.previousOutput && this.previousWidth === width) {
99
- return;
100
- }
101
- this.previousOutput = output;
102
- this.previousWidth = width;
103
- output = wrapAnsi(output, width, {
104
- trim: false,
105
- hard: true,
106
- wordWrap: false,
107
- });
108
- this.stream.write(ansiEscapes.eraseLines(this.previousLineCount) + output);
109
- this.previousLineCount = output.split('\n').length;
110
- }
111
- clear() {
112
- this.stream.write(ansiEscapes.eraseLines(this.previousLineCount));
113
- this.previousOutput = '';
114
- this.previousWidth = this.getWidth();
115
- this.previousLineCount = 0;
116
- }
117
- done() {
118
- this.previousOutput = '';
119
- this.previousWidth = this.getWidth();
120
- this.previousLineCount = 0;
121
- }
122
- getWidth() {
123
- const { columns } = this.stream;
124
- if (!columns) {
125
- return 80;
126
- }
127
- return columns;
128
- }
129
- }
130
- const logUpdate = new LogUpdate();
@@ -1,26 +0,0 @@
1
- export interface IndentStringOptions {
2
- /**
3
- The string to use for the indent.
4
- @default ' '
5
- */
6
- readonly indent?: string;
7
- /**
8
- Also indent empty lines.
9
- @default false
10
- */
11
- readonly includeEmptyLines?: boolean;
12
- }
13
- /**
14
- Indent each line in a string.
15
- @param string - The string to indent.
16
- @param count - How many times you want `options.indent` repeated. Default: `1`.
17
- @example
18
- ```
19
- import indentString from 'indent-string';
20
- indentString('Unicorns\nRainbows', 4);
21
- //=> ' Unicorns\n Rainbows'
22
- indentString('Unicorns\nRainbows', 4, {indent: '♥'});
23
- //=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'
24
- ```
25
- */
26
- export declare function indentString(string: string, count?: number, options?: IndentStringOptions): string;
@@ -1,18 +0,0 @@
1
- import { ListrTask } from 'listr';
2
- import { DetailedError } from '@graphql-codegen/plugin-helpers';
3
- export declare class Renderer {
4
- private updateRenderer;
5
- constructor(tasks: ListrTask, options: any);
6
- render(): any;
7
- end(err: Error & {
8
- errors?: (Error | DetailedError)[];
9
- details?: string;
10
- }): void;
11
- }
12
- export declare class ErrorRenderer {
13
- private tasks;
14
- constructor(tasks: any, _options: any);
15
- render(): void;
16
- static get nonTTY(): boolean;
17
- end(): void;
18
- }