@decencia/ch-cli 1.0.0 → 1.1.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.
package/src/output.ts DELETED
@@ -1,186 +0,0 @@
1
- import chalk from 'chalk';
2
- import Table from 'cli-table3';
3
- import { getLastProjectContext } from './client';
4
-
5
- export interface OutputOptions {
6
- json?: boolean;
7
- table?: boolean;
8
- csv?: boolean;
9
- quiet?: boolean;
10
- }
11
-
12
- export function formatOutput(data: any, options: OutputOptions = {}): void {
13
- if (options.quiet) {
14
- // In quiet mode, only output raw JSON for piping
15
- console.log(JSON.stringify(data));
16
- return;
17
- }
18
-
19
- if (options.json) {
20
- console.log(JSON.stringify(data, null, 2));
21
- return;
22
- }
23
-
24
- if (options.csv) {
25
- printCsv(data);
26
- return;
27
- }
28
-
29
- // Default: table or pretty print
30
- if (Array.isArray(data)) {
31
- if (data.length === 0) {
32
- console.log(chalk.yellow('데이터가 없습니다.'));
33
- return;
34
- }
35
- printAutoTable(data);
36
- } else if (data && typeof data === 'object') {
37
- // Check if it's a paginated response
38
- if (data.data && Array.isArray(data.data)) {
39
- if (data.data.length === 0) {
40
- console.log(chalk.yellow('데이터가 없습니다.'));
41
- } else {
42
- printAutoTable(data.data);
43
- }
44
- if (data.pagination) {
45
- const p = data.pagination;
46
- console.log(
47
- chalk.gray(
48
- `\n페이지 ${p.page}/${p.totalPages} (총 ${p.total}건)`
49
- )
50
- );
51
- }
52
- } else {
53
- // Single object - print key-value pairs
54
- printKeyValue(data);
55
- }
56
- } else {
57
- console.log(data);
58
- }
59
- }
60
-
61
- function printAutoTable(rows: any[]): void {
62
- if (rows.length === 0) return;
63
-
64
- const keys = Object.keys(rows[0]);
65
- // Limit columns to avoid overly wide tables
66
- const displayKeys = keys.slice(0, 8);
67
-
68
- const table = new Table({
69
- head: displayKeys.map((k) => chalk.cyan(k)),
70
- style: { head: [], border: [] },
71
- wordWrap: true,
72
- });
73
-
74
- for (const row of rows) {
75
- table.push(
76
- displayKeys.map((k) => {
77
- const val = row[k];
78
- if (val === null || val === undefined) return '';
79
- if (typeof val === 'object') return JSON.stringify(val).substring(0, 50);
80
- const str = String(val);
81
- return str.length > 60 ? str.substring(0, 57) + '...' : str;
82
- })
83
- );
84
- }
85
-
86
- console.log(table.toString());
87
- }
88
-
89
- function printKeyValue(obj: any): void {
90
- const table = new Table({
91
- style: { head: [], border: [] },
92
- });
93
-
94
- for (const [key, value] of Object.entries(obj)) {
95
- let display: string;
96
- if (value === null || value === undefined) {
97
- display = chalk.gray('(없음)');
98
- } else if (Array.isArray(value)) {
99
- display = value.length > 0
100
- ? JSON.stringify(value, null, 2)
101
- : chalk.gray('(비어있음)');
102
- } else if (typeof value === 'object') {
103
- display = JSON.stringify(value, null, 2);
104
- } else {
105
- display = String(value);
106
- }
107
- table.push({ [chalk.cyan(key)]: display });
108
- }
109
-
110
- console.log(table.toString());
111
- }
112
-
113
- function printCsv(data: any): void {
114
- let rows: any[];
115
- if (Array.isArray(data)) {
116
- rows = data;
117
- } else if (data && data.data && Array.isArray(data.data)) {
118
- rows = data.data;
119
- } else {
120
- // Single object
121
- rows = [data];
122
- }
123
-
124
- if (rows.length === 0) return;
125
-
126
- const keys = Object.keys(rows[0]);
127
- // CSV header
128
- console.log(keys.map(escapeCsvField).join(','));
129
- // CSV rows
130
- for (const row of rows) {
131
- console.log(
132
- keys
133
- .map((k) => {
134
- const val = row[k];
135
- if (val === null || val === undefined) return '';
136
- if (typeof val === 'object') return escapeCsvField(JSON.stringify(val));
137
- return escapeCsvField(String(val));
138
- })
139
- .join(',')
140
- );
141
- }
142
- }
143
-
144
- function escapeCsvField(field: string): string {
145
- if (field.includes(',') || field.includes('"') || field.includes('\n')) {
146
- return `"${field.replace(/"/g, '""')}"`;
147
- }
148
- return field;
149
- }
150
-
151
- export function printTable(headers: string[], rows: string[][]): void {
152
- const table = new Table({
153
- head: headers.map((h) => chalk.cyan(h)),
154
- style: { head: [], border: [] },
155
- });
156
-
157
- for (const row of rows) {
158
- table.push(row);
159
- }
160
-
161
- console.log(table.toString());
162
- }
163
-
164
- export function printError(message: string): void {
165
- console.error(chalk.red(`오류: ${message}`));
166
- }
167
-
168
- function projectPrefix(): string {
169
- const ctx = getLastProjectContext();
170
- if (ctx?.projectName) {
171
- return chalk.cyan(`[${ctx.projectName}] `);
172
- }
173
- return '';
174
- }
175
-
176
- export function printSuccess(message: string): void {
177
- console.log(projectPrefix() + chalk.green(message));
178
- }
179
-
180
- export function printWarning(message: string): void {
181
- console.log(projectPrefix() + chalk.yellow(message));
182
- }
183
-
184
- export function printInfo(message: string): void {
185
- console.log(projectPrefix() + chalk.blue(message));
186
- }
package/src/utils.ts DELETED
@@ -1,3 +0,0 @@
1
- export function parseCommaSeparated(value: string): string[] {
2
- return value.split(',').map((v) => v.trim()).filter(Boolean);
3
- }
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "outDir": "dist",
6
- "rootDir": "src",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "skipLibCheck": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "resolveJsonModule": true,
12
- "declaration": true,
13
- "declarationMap": true,
14
- "sourceMap": true
15
- },
16
- "include": ["src/**/*"],
17
- "exclude": ["node_modules", "dist"]
18
- }