@sanjay5114/cdx 1.0.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/bin/cdx.js +27 -0
- package/commands/auth.js +197 -0
- package/commands/config.js +165 -0
- package/commands/create.js +474 -0
- package/index.js +530 -0
- package/lib/ai.js +249 -0
- package/lib/auth.js +120 -0
- package/lib/fetch.js +46 -0
- package/lib/scanner.js +351 -0
- package/lib/store.js +83 -0
- package/lib/ui.js +477 -0
- package/package.json +35 -0
package/lib/ui.js
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const chalk = require("chalk");
|
|
4
|
+
|
|
5
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
6
|
+
// DESIGN TOKENS
|
|
7
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
8
|
+
const C = {
|
|
9
|
+
brand : "#0EA5E9",
|
|
10
|
+
brandDark : "#0369A1",
|
|
11
|
+
brandLight : "#38BDF8",
|
|
12
|
+
violet : "#8B5CF6",
|
|
13
|
+
emerald : "#10B981",
|
|
14
|
+
amber : "#F59E0B",
|
|
15
|
+
rose : "#F43F5E",
|
|
16
|
+
white : "#F8FAFC",
|
|
17
|
+
muted : "#94A3B8",
|
|
18
|
+
dim : "#475569",
|
|
19
|
+
ghost : "#1E293B",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const T = {
|
|
23
|
+
brand : chalk.hex(C.brand),
|
|
24
|
+
brandBold : chalk.hex(C.brand).bold,
|
|
25
|
+
brandDim : chalk.hex(C.brandDark),
|
|
26
|
+
accent : chalk.hex(C.brandLight),
|
|
27
|
+
violet : chalk.hex(C.violet),
|
|
28
|
+
success : chalk.hex(C.emerald),
|
|
29
|
+
warn : chalk.hex(C.amber),
|
|
30
|
+
error : chalk.hex(C.rose),
|
|
31
|
+
white : chalk.hex(C.white),
|
|
32
|
+
whiteBold : chalk.hex(C.white).bold,
|
|
33
|
+
muted : chalk.hex(C.muted),
|
|
34
|
+
dim : chalk.hex(C.dim),
|
|
35
|
+
bgBrand : chalk.bgHex(C.brand).hex("#000"),
|
|
36
|
+
bgSuccess : chalk.bgHex(C.emerald).hex("#000"),
|
|
37
|
+
bgWarn : chalk.bgHex(C.amber).hex("#000"),
|
|
38
|
+
bgError : chalk.bgHex(C.rose).hex("#fff"),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const W = Math.min(process.stdout.columns || 80, 110);
|
|
42
|
+
|
|
43
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
44
|
+
// PRIMITIVES
|
|
45
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
46
|
+
function stripAnsi(s) { return s.replace(/\x1B\[[0-9;]*m/g, ""); }
|
|
47
|
+
|
|
48
|
+
function pad(text, len) {
|
|
49
|
+
const raw = stripAnsi(text);
|
|
50
|
+
const n = Math.max(0, len - raw.length);
|
|
51
|
+
return text + " ".repeat(n);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function center(text, width) {
|
|
55
|
+
width = width || W;
|
|
56
|
+
const len = stripAnsi(text).length;
|
|
57
|
+
const p = Math.max(0, Math.floor((width - len) / 2));
|
|
58
|
+
return " ".repeat(p) + text;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function rule(char, color) {
|
|
62
|
+
char = char || "─";
|
|
63
|
+
color = color || T.dim;
|
|
64
|
+
return color(char.repeat(W));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
68
|
+
// BANNER
|
|
69
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
70
|
+
function printBanner() {
|
|
71
|
+
const L = [
|
|
72
|
+
" ██████╗██████╗ ██╗ ██╗ ██╗ ██╗",
|
|
73
|
+
" ██╔════╝██╔══██╗╚██╗██╔╝ ╚██╗██╔╝",
|
|
74
|
+
" ██║ ██║ ██║ ╚███╔╝ ╚███╔╝ ",
|
|
75
|
+
" ██║ ██║ ██║ ██╔██╗ ██╔██╗ ",
|
|
76
|
+
" ╚██████╗██████╔╝██╔╝ ██╗ ██╔╝ ██╗",
|
|
77
|
+
" ╚═════╝╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝",
|
|
78
|
+
];
|
|
79
|
+
const GRAD = ["#0EA5E9","#14B8A6","#22D3EE","#38BDF8","#7DD3FC","#BAE6FD"];
|
|
80
|
+
console.log();
|
|
81
|
+
L.forEach(function(row, i) { console.log(center(chalk.hex(GRAD[i]).bold(row))); });
|
|
82
|
+
console.log();
|
|
83
|
+
console.log(center(T.muted("─".repeat(38))));
|
|
84
|
+
console.log(center(
|
|
85
|
+
T.accent(" Code Documentation eXpert") +
|
|
86
|
+
T.dim(" · ") + T.muted("v3.0.0") +
|
|
87
|
+
T.dim(" · ") + T.violet("Enterprise Edition")
|
|
88
|
+
));
|
|
89
|
+
console.log(center(T.dim("Powered by Gemini AI · Firebase Auth · GitHub Integration")));
|
|
90
|
+
console.log();
|
|
91
|
+
console.log(rule("═", T.brandDim));
|
|
92
|
+
console.log();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
96
|
+
// DEX — Animated CLI Mascot
|
|
97
|
+
// A friendly robot assistant with mood-based expressions
|
|
98
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
const DEX_FRAMES = {
|
|
101
|
+
idle: [
|
|
102
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ── │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
103
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ∪∪ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
104
|
+
[" ╭──────╮ ", " │ ─ ─ │ ", " │ ── │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
105
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ── │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
106
|
+
],
|
|
107
|
+
think: [
|
|
108
|
+
[" ╭──────╮ ", " │ ◔ ◔ │ ", " │ · │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
109
|
+
[" ╭──────╮ ", " │ ◔ ◑ │ ", " │ ·· │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
110
|
+
[" ╭──────╮ ", " │ ◑ ◔ │ ", " │ · │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
111
|
+
[" ╭──────╮ ", " │ ○ ◔ │ ", " │ ·· │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
112
|
+
],
|
|
113
|
+
happy: [
|
|
114
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ╰──╯ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
115
|
+
[" ╭──────╮ ", " │ ^ ^ │ ", " │ ╰──╯ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
116
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ∪∪ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
117
|
+
[" ╭──────╮ ", " │ ^ ^ │ ", " │ ╰──╯ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
118
|
+
],
|
|
119
|
+
error: [
|
|
120
|
+
[" ╭──────╮ ", " │ × × │ ", " │ ── │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
121
|
+
[" ╭──────╮ ", " │ × × │ ", " │ ∩∩ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
122
|
+
],
|
|
123
|
+
greet: [
|
|
124
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ∪∪ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
125
|
+
[" ╭──────╮ ", " │ ^ ^ │ ", " │ ╰──╯ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
126
|
+
[" ╭──────╮ ", " │ ◠ ◠ │ ", " │ ╰──╯ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
127
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ∪∪ │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
128
|
+
],
|
|
129
|
+
wait: [
|
|
130
|
+
[" ╭──────╮ ", " │ ─ ─ │ ", " │ ·· │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
131
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ·· │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
132
|
+
[" ╭──────╮ ", " │ ─ ─ │ ", " │ ── │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
133
|
+
[" ╭──────╮ ", " │ ◉ ◉ │ ", " │ ── │ ", " ╰──────╯ ", " ╰────╯ "],
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const DEX_COLOR = {
|
|
138
|
+
idle : "#38BDF8",
|
|
139
|
+
think : "#A78BFA",
|
|
140
|
+
happy : "#10B981",
|
|
141
|
+
error : "#F43F5E",
|
|
142
|
+
greet : "#34D399",
|
|
143
|
+
wait : "#94A3B8",
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const SPIN_CHARS = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Print Dex with a speech bubble — static, no animation.
|
|
150
|
+
*/
|
|
151
|
+
function dex(message, mood) {
|
|
152
|
+
mood = mood || "idle";
|
|
153
|
+
var face = (DEX_FRAMES[mood] || DEX_FRAMES.idle)[0];
|
|
154
|
+
var color = chalk.hex(DEX_COLOR[mood] || DEX_COLOR.idle);
|
|
155
|
+
|
|
156
|
+
// Wrap message at 38 chars
|
|
157
|
+
var words = String(message).split(" ");
|
|
158
|
+
var lines = [];
|
|
159
|
+
var current = "";
|
|
160
|
+
for (var i = 0; i < words.length; i++) {
|
|
161
|
+
var w = words[i];
|
|
162
|
+
var candidate = current ? current + " " + w : w;
|
|
163
|
+
if (candidate.length > 38) { lines.push(current); current = w; }
|
|
164
|
+
else current = candidate;
|
|
165
|
+
}
|
|
166
|
+
if (current) lines.push(current);
|
|
167
|
+
|
|
168
|
+
var bw = 0;
|
|
169
|
+
for (var j = 0; j < lines.length; j++) if (lines[j].length > bw) bw = lines[j].length;
|
|
170
|
+
bw = Math.max(bw + 2, 12);
|
|
171
|
+
|
|
172
|
+
var d = T.dim;
|
|
173
|
+
var w2 = T.white;
|
|
174
|
+
|
|
175
|
+
var bubble = [];
|
|
176
|
+
bubble.push(d("╭" + "─".repeat(bw) + "╮"));
|
|
177
|
+
for (var k = 0; k < lines.length; k++) {
|
|
178
|
+
bubble.push(d("│ ") + w2(lines[k] + " ".repeat(bw - 2 - lines[k].length)) + d(" │"));
|
|
179
|
+
}
|
|
180
|
+
bubble.push(d("╰" + "─".repeat(bw) + "╯"));
|
|
181
|
+
bubble.push(d(" ╲"));
|
|
182
|
+
|
|
183
|
+
var faceH = face.length;
|
|
184
|
+
var bubbleH = bubble.length;
|
|
185
|
+
var maxH = Math.max(faceH + 1, bubbleH);
|
|
186
|
+
|
|
187
|
+
console.log();
|
|
188
|
+
for (var n = 0; n < maxH; n++) {
|
|
189
|
+
var fl = n < faceH ? color(face[n]) : " ";
|
|
190
|
+
var bl = n < bubbleH ? " " + bubble[n] : "";
|
|
191
|
+
console.log(" " + fl + " " + bl);
|
|
192
|
+
}
|
|
193
|
+
console.log();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Animate Dex with cycling frames while work is happening.
|
|
198
|
+
* Returns { stop(finalMsg, finalMood) }
|
|
199
|
+
*/
|
|
200
|
+
function dexAnimate(message, mood) {
|
|
201
|
+
mood = mood || "think";
|
|
202
|
+
var frames = DEX_FRAMES[mood] || DEX_FRAMES.think;
|
|
203
|
+
var color = chalk.hex(DEX_COLOR[mood] || DEX_COLOR.think);
|
|
204
|
+
var isTTY = process.stdout.isTTY;
|
|
205
|
+
var fi = 0;
|
|
206
|
+
|
|
207
|
+
var FACE_H = frames[0].length; // 5 lines
|
|
208
|
+
var STATUS = 1; // 1 status line above face
|
|
209
|
+
var TOTAL = FACE_H + STATUS + 1; // +1 blank line
|
|
210
|
+
|
|
211
|
+
if (!isTTY) {
|
|
212
|
+
process.stdout.write(" " + chalk.hex("#38BDF8")(message) + "\n");
|
|
213
|
+
return { stop: function(m, md) { if (m) console.log(" " + chalk.hex("#10B981")("✔ " + m)); } };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Print initial block
|
|
217
|
+
function printBlock(face, statusMsg, statusColor) {
|
|
218
|
+
var spin = SPIN_CHARS[fi % SPIN_CHARS.length];
|
|
219
|
+
process.stdout.write((statusColor || chalk.hex("#38BDF8"))(" " + spin + " " + statusMsg + " ".repeat(Math.max(0, 60 - statusMsg.length))) + "\n");
|
|
220
|
+
face.forEach(function(row) { process.stdout.write(" " + color(row) + "\n"); });
|
|
221
|
+
process.stdout.write("\n");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
printBlock(frames[0], message);
|
|
225
|
+
|
|
226
|
+
var iv = setInterval(function() {
|
|
227
|
+
fi++;
|
|
228
|
+
// Move cursor up TOTAL lines
|
|
229
|
+
process.stdout.write("\x1B[" + TOTAL + "A");
|
|
230
|
+
process.stdout.clearLine && process.stdout.clearLine(0);
|
|
231
|
+
printBlock(frames[fi % frames.length], message);
|
|
232
|
+
}, 180);
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
stop: function(finalMsg, finalMood) {
|
|
236
|
+
clearInterval(iv);
|
|
237
|
+
finalMood = finalMood || "happy";
|
|
238
|
+
var finalFrames = DEX_FRAMES[finalMood] || DEX_FRAMES.happy;
|
|
239
|
+
var finalColor = chalk.hex(DEX_COLOR[finalMood] || DEX_COLOR.happy);
|
|
240
|
+
var faceToShow = finalFrames[0];
|
|
241
|
+
|
|
242
|
+
// Overwrite
|
|
243
|
+
process.stdout.write("\x1B[" + TOTAL + "A");
|
|
244
|
+
process.stdout.write(chalk.hex("#10B981")(" ✔ " + (finalMsg || message) + " ".repeat(Math.max(0, 60 - (finalMsg || message).length))) + "\n");
|
|
245
|
+
faceToShow.forEach(function(row) { process.stdout.write(" " + finalColor(row) + "\n"); });
|
|
246
|
+
process.stdout.write("\n");
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Dex types out a greeting character-by-character next to his face.
|
|
253
|
+
*/
|
|
254
|
+
async function dexGreet(name) {
|
|
255
|
+
var face = DEX_FRAMES.greet;
|
|
256
|
+
var color = chalk.hex(DEX_COLOR.greet);
|
|
257
|
+
var isTTY = process.stdout.isTTY;
|
|
258
|
+
|
|
259
|
+
if (!isTTY) {
|
|
260
|
+
if (name) console.log(chalk.hex("#34D399")(" Welcome back, " + name + "!"));
|
|
261
|
+
else console.log(chalk.hex("#38BDF8")(" Hello! Please sign in to continue."));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Print face first
|
|
266
|
+
console.log();
|
|
267
|
+
var frame = face[0];
|
|
268
|
+
frame.forEach(function(row) { console.log(" " + color(row)); });
|
|
269
|
+
console.log();
|
|
270
|
+
|
|
271
|
+
var msg = name ? "Hey " + name + "! Great to have you back. \u2019" : "Hi there! Please sign in to get started. \u2019";
|
|
272
|
+
var bubble = " \u276f\u276f ";
|
|
273
|
+
|
|
274
|
+
process.stdout.write(chalk.hex("#34D399")(bubble));
|
|
275
|
+
|
|
276
|
+
// Typewrite the message
|
|
277
|
+
await new Promise(function(resolve) {
|
|
278
|
+
var i = 0;
|
|
279
|
+
var iv = setInterval(function() {
|
|
280
|
+
process.stdout.write(chalk.hex("#F8FAFC")(msg[i]));
|
|
281
|
+
i++;
|
|
282
|
+
if (i >= msg.length) { clearInterval(iv); resolve(); }
|
|
283
|
+
}, 28);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
console.log();
|
|
287
|
+
console.log();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
291
|
+
// SECTION HEADER
|
|
292
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
293
|
+
function section(title, subtitle) {
|
|
294
|
+
var inner = subtitle ? title + " \u203a " + subtitle : title;
|
|
295
|
+
var rawLen = stripAnsi(inner).length + 4;
|
|
296
|
+
var width = Math.max(rawLen, 40);
|
|
297
|
+
console.log();
|
|
298
|
+
console.log(" " + T.brandDim("┌" + "─".repeat(width) + "┐"));
|
|
299
|
+
console.log(" " + T.brandDim("│") + " " + T.whiteBold(title) + (subtitle ? T.dim(" › ") + T.muted(subtitle) : "") + " " + T.brandDim("│"));
|
|
300
|
+
console.log(" " + T.brandDim("└" + "─".repeat(width) + "┘"));
|
|
301
|
+
console.log();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
305
|
+
// STATUS LINES
|
|
306
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
307
|
+
var ICONS = {
|
|
308
|
+
arrow : "›",
|
|
309
|
+
bullet : "◆",
|
|
310
|
+
check : "✔",
|
|
311
|
+
cross : "✖",
|
|
312
|
+
warn : "⚠",
|
|
313
|
+
info : "ℹ",
|
|
314
|
+
rocket : "◈",
|
|
315
|
+
lock : "◉",
|
|
316
|
+
star : "★",
|
|
317
|
+
dot : "•",
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
function step(icon, label, value) {
|
|
321
|
+
value = value || "";
|
|
322
|
+
console.log(" " + T.brand(icon) + " " + T.white(label) + (value ? " " + T.dim(value) : ""));
|
|
323
|
+
}
|
|
324
|
+
function ok(msg) { console.log(" " + T.success(ICONS.check) + " " + T.success(msg)); }
|
|
325
|
+
function warn(msg) { console.log(" " + T.warn(ICONS.warn) + " " + T.warn(msg)); }
|
|
326
|
+
function err(msg) { console.log(" " + T.error(ICONS.cross) + " " + T.error(msg)); }
|
|
327
|
+
function info(msg) { console.log(" " + T.accent(ICONS.info) + " " + T.accent(msg)); }
|
|
328
|
+
function note(msg) { console.log(" " + T.dim(ICONS.dot) + " " + T.muted(msg)); }
|
|
329
|
+
|
|
330
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
331
|
+
// SPINNER
|
|
332
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
333
|
+
function spinner(text) {
|
|
334
|
+
var i = 0, iv, _t = text;
|
|
335
|
+
var isTTY = process.stdout.isTTY;
|
|
336
|
+
var s = {
|
|
337
|
+
start: function() {
|
|
338
|
+
if (isTTY) process.stdout.write("\x1B[?25l");
|
|
339
|
+
iv = setInterval(function() {
|
|
340
|
+
if (!isTTY) return;
|
|
341
|
+
process.stdout.clearLine(0);
|
|
342
|
+
process.stdout.cursorTo(0);
|
|
343
|
+
process.stdout.write(" " + T.brand(SPIN_CHARS[i++ % SPIN_CHARS.length]) + " " + T.accent(_t));
|
|
344
|
+
}, 70);
|
|
345
|
+
return s;
|
|
346
|
+
},
|
|
347
|
+
update: function(msg) { _t = msg; },
|
|
348
|
+
done: function(msg, type) {
|
|
349
|
+
clearInterval(iv);
|
|
350
|
+
if (isTTY) {
|
|
351
|
+
process.stdout.clearLine(0);
|
|
352
|
+
process.stdout.cursorTo(0);
|
|
353
|
+
process.stdout.write("\x1B[?25h");
|
|
354
|
+
}
|
|
355
|
+
type = type || "ok";
|
|
356
|
+
var icon = type === "ok" ? T.success(ICONS.check) : type === "warn" ? T.warn(ICONS.warn) : T.error(ICONS.cross);
|
|
357
|
+
var color = type === "ok" ? T.white : type === "warn" ? T.warn : T.error;
|
|
358
|
+
console.log(" " + icon + " " + color(msg || _t));
|
|
359
|
+
},
|
|
360
|
+
ok: function(msg) { s.done(msg, "ok"); },
|
|
361
|
+
fail: function(msg) { s.done(msg, "fail"); },
|
|
362
|
+
warn: function(msg) { s.done(msg, "warn"); },
|
|
363
|
+
};
|
|
364
|
+
return s;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
368
|
+
// PROGRESS BAR
|
|
369
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
370
|
+
function progressBar(label, pct, width) {
|
|
371
|
+
width = width || 28;
|
|
372
|
+
var f = Math.round((pct / 100) * width);
|
|
373
|
+
var bar = T.brand("█".repeat(f)) + T.dim("░".repeat(width - f));
|
|
374
|
+
var pctStr = String(pct).padStart(3);
|
|
375
|
+
if (process.stdout.isTTY) {
|
|
376
|
+
process.stdout.clearLine(0);
|
|
377
|
+
process.stdout.cursorTo(0);
|
|
378
|
+
process.stdout.write(" " + T.muted(label) + " " + bar + " " + T.accent(pctStr + "%"));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function animateProgress(label, ms) {
|
|
383
|
+
ms = ms || 1600;
|
|
384
|
+
return new Promise(function(resolve) {
|
|
385
|
+
var pct = 0;
|
|
386
|
+
var iv = setInterval(function() {
|
|
387
|
+
pct = Math.min(pct + 2, 100);
|
|
388
|
+
progressBar(label, pct);
|
|
389
|
+
if (pct >= 100) { clearInterval(iv); if (process.stdout.isTTY) process.stdout.write("\n"); resolve(); }
|
|
390
|
+
}, ms / 50);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
395
|
+
// TABLE
|
|
396
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
397
|
+
function table(rows, opts) {
|
|
398
|
+
opts = opts || {};
|
|
399
|
+
var colW = opts.colW || Math.floor((W - 12) / 2);
|
|
400
|
+
var line = function(l, m, r) { return " " + T.dim(l + "─".repeat(colW) + m + "─".repeat(colW) + r); };
|
|
401
|
+
console.log(line("┌", "┬", "┐"));
|
|
402
|
+
rows.forEach(function(row, i) {
|
|
403
|
+
var k = row[0], v = row[1];
|
|
404
|
+
var kp = pad(k, colW - 2);
|
|
405
|
+
var vp = pad(v, colW - 2);
|
|
406
|
+
console.log(" " + T.dim("│") + " " + T.muted(kp) + " " + T.dim("│") + " " + T.white(vp) + " " + T.dim("│"));
|
|
407
|
+
if (i < rows.length - 1) console.log(line("├", "┼", "┤"));
|
|
408
|
+
});
|
|
409
|
+
console.log(line("└", "┴", "┘"));
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
413
|
+
// BADGE & PANEL
|
|
414
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
415
|
+
function badge(text, type) {
|
|
416
|
+
type = type || "default";
|
|
417
|
+
var styles = {
|
|
418
|
+
success : chalk.bgHex(C.emerald).hex("#000"),
|
|
419
|
+
warn : chalk.bgHex(C.amber).hex("#000"),
|
|
420
|
+
error : chalk.bgHex(C.rose).hex("#fff"),
|
|
421
|
+
info : chalk.bgHex(C.brand).hex("#000"),
|
|
422
|
+
purple : chalk.bgHex(C.violet).hex("#fff"),
|
|
423
|
+
default : chalk.bgHex(C.dim).hex(C.white),
|
|
424
|
+
};
|
|
425
|
+
return (styles[type] || styles.default)(" " + text + " ");
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function panel(lines, title) {
|
|
429
|
+
var maxRaw = 0;
|
|
430
|
+
lines.forEach(function(l) { var n = stripAnsi(l).length; if (n > maxRaw) maxRaw = n; });
|
|
431
|
+
if (title) { var tn = stripAnsi(title).length; if (tn > maxRaw) maxRaw = tn; }
|
|
432
|
+
var inner = Math.min(maxRaw + 4, W - 6);
|
|
433
|
+
var h = function(l, m, r) { return " " + T.dim(l + m.repeat(inner) + r); };
|
|
434
|
+
console.log();
|
|
435
|
+
if (title) {
|
|
436
|
+
console.log(h("┌", "─", "┐"));
|
|
437
|
+
console.log(" " + T.dim("│") + " " + T.whiteBold(pad(title, inner - 2)) + " " + T.dim("│"));
|
|
438
|
+
console.log(h("├", "─", "┤"));
|
|
439
|
+
} else { console.log(h("┌", "─", "┐")); }
|
|
440
|
+
lines.forEach(function(l) { console.log(" " + T.dim("│") + " " + pad(l, inner - 2) + " " + T.dim("│")); });
|
|
441
|
+
console.log(h("└", "─", "┘"));
|
|
442
|
+
console.log();
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
446
|
+
// FOOTER
|
|
447
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
448
|
+
function footer() {
|
|
449
|
+
console.log();
|
|
450
|
+
console.log(rule("─", T.dim));
|
|
451
|
+
console.log(center(T.dim("CDX Enterprise · " + new Date().toLocaleDateString("en-US", {weekday:"short",year:"numeric",month:"short",day:"numeric"}) + " · " + new Date().toLocaleTimeString())));
|
|
452
|
+
console.log();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
456
|
+
// TYPEWRITER
|
|
457
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
458
|
+
function typewrite(text, delay) {
|
|
459
|
+
delay = delay || 16;
|
|
460
|
+
return new Promise(function(resolve) {
|
|
461
|
+
var i = 0;
|
|
462
|
+
var iv = setInterval(function() {
|
|
463
|
+
process.stdout.write(text[i]);
|
|
464
|
+
i++;
|
|
465
|
+
if (i >= text.length) { clearInterval(iv); process.stdout.write("\n"); resolve(); }
|
|
466
|
+
}, delay);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
module.exports = {
|
|
471
|
+
T, C, W, rule, center, stripAnsi, pad,
|
|
472
|
+
printBanner, section, footer,
|
|
473
|
+
step, ok, warn, err, info, note,
|
|
474
|
+
spinner, progressBar, animateProgress,
|
|
475
|
+
table, badge, panel, typewrite, ICONS,
|
|
476
|
+
dex, dexAnimate, dexGreet,
|
|
477
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sanjay5114/cdx",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightning-fast extensible CLI for developer productivity with modular commands, AI integrations, and automation.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"developer-tools",
|
|
8
|
+
"automation",
|
|
9
|
+
"ai",
|
|
10
|
+
"scaffolding"
|
|
11
|
+
],
|
|
12
|
+
"author": "Sanjay",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "index.js",
|
|
15
|
+
"bin": {
|
|
16
|
+
"cdx": "bin/cdx.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/",
|
|
20
|
+
"lib/",
|
|
21
|
+
"commands/",
|
|
22
|
+
"index.js"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"chalk": "^4.1.2",
|
|
29
|
+
"commander": "^11.1.0",
|
|
30
|
+
"inquirer": "^8.2.6",
|
|
31
|
+
"jsonwebtoken": "^9.0.2",
|
|
32
|
+
"node-fetch": "2.7.0",
|
|
33
|
+
"ora": "^5.4.1"
|
|
34
|
+
}
|
|
35
|
+
}
|