camunda-cli 0.2.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/README.md +167 -0
- package/bin/camunda.js +292 -0
- package/package.json +36 -0
- package/src/bpmn.js +387 -0
- package/src/client.js +400 -0
- package/src/commands/definitions.js +194 -0
- package/src/commands/deploy.js +82 -0
- package/src/commands/diagnose.js +257 -0
- package/src/commands/instances.js +205 -0
- package/src/commands/ops.js +127 -0
- package/src/commands/session.js +112 -0
- package/src/commands/tasks.js +129 -0
- package/src/config.js +33 -0
- package/src/errors.js +138 -0
- package/src/lint.js +244 -0
- package/src/output.js +135 -0
package/src/output.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Output layer. Two hard rules, both driven by the fact that the main consumer is an
|
|
2
|
+
// AI agent reading piped stdout, not a human staring at a terminal:
|
|
3
|
+
// 1. No box-drawing characters, ever. Columns are aligned with plain spaces.
|
|
4
|
+
// 2. No ANSI colour unless stdout is a TTY (and --no-color can still turn it off).
|
|
5
|
+
// Every command also honours --json, which prints the raw API payload and nothing else.
|
|
6
|
+
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
|
|
9
|
+
let jsonMode = false;
|
|
10
|
+
|
|
11
|
+
export function configureOutput({ json = false, color } = {}) {
|
|
12
|
+
jsonMode = json;
|
|
13
|
+
// chalk auto-detects TTY; only override when explicitly asked.
|
|
14
|
+
if (color === false) chalk.level = 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isJsonMode() {
|
|
18
|
+
return jsonMode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function json(data) {
|
|
22
|
+
console.log(JSON.stringify(data, null, 2));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function line(text = '') {
|
|
26
|
+
console.log(text);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function heading(text) {
|
|
30
|
+
console.log(chalk.bold(text));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function note(text) {
|
|
34
|
+
console.log(chalk.gray(text));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function warn(text) {
|
|
38
|
+
console.log(chalk.yellow(text));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function problem(text) {
|
|
42
|
+
console.log(chalk.red(text));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Key/value block, keys right-padded to align values.
|
|
46
|
+
export function kv(pairs, indent = ' ') {
|
|
47
|
+
const width = Math.max(0, ...pairs.map(([k]) => String(k).length));
|
|
48
|
+
for (const [k, v] of pairs) {
|
|
49
|
+
if (v === undefined || v === null || v === '') continue;
|
|
50
|
+
console.log(`${indent}${String(k).padEnd(width)} ${v}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Plain aligned table. `rows` are arrays of strings; `head` is optional.
|
|
55
|
+
// Column widths are computed on the visible (ANSI-stripped) length so colour
|
|
56
|
+
// never breaks alignment.
|
|
57
|
+
const ANSI = /\[[0-9;]*m/g;
|
|
58
|
+
const visibleLength = (s) => String(s ?? '').replace(ANSI, '').length;
|
|
59
|
+
|
|
60
|
+
export function table(head, rows, { indent = ' ' } = {}) {
|
|
61
|
+
if (rows.length === 0) return;
|
|
62
|
+
const cols = head ? head.length : Math.max(...rows.map((r) => r.length));
|
|
63
|
+
const widths = [];
|
|
64
|
+
for (let c = 0; c < cols; c++) {
|
|
65
|
+
widths[c] = Math.max(head ? visibleLength(head[c]) : 0, ...rows.map((r) => visibleLength(r[c])));
|
|
66
|
+
}
|
|
67
|
+
const render = (cells, styler) =>
|
|
68
|
+
cells
|
|
69
|
+
.map((cell, c) => {
|
|
70
|
+
const s = String(cell ?? '');
|
|
71
|
+
const pad = ' '.repeat(Math.max(0, widths[c] - visibleLength(s)));
|
|
72
|
+
// Don't pad the last column, avoids trailing whitespace.
|
|
73
|
+
return c === cols - 1 ? s : s + pad;
|
|
74
|
+
})
|
|
75
|
+
.join(' ')
|
|
76
|
+
.trimEnd();
|
|
77
|
+
|
|
78
|
+
if (head) console.log(indent + chalk.dim(render(head)));
|
|
79
|
+
for (const row of rows) console.log(indent + render(row));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Wraps prose at a word boundary. Long explanations are the point of several commands,
|
|
83
|
+
// and a 300-character single line is unreadable in a terminal and in a transcript alike.
|
|
84
|
+
export function wrap(text, width = 92) {
|
|
85
|
+
const words = String(text ?? '').split(/\s+/).filter(Boolean);
|
|
86
|
+
const lines = [];
|
|
87
|
+
let current = '';
|
|
88
|
+
for (const w of words) {
|
|
89
|
+
if (current && current.length + 1 + w.length > width) {
|
|
90
|
+
lines.push(current);
|
|
91
|
+
current = w;
|
|
92
|
+
} else {
|
|
93
|
+
current = current ? `${current} ${w}` : w;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (current) lines.push(current);
|
|
97
|
+
return lines;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function truncate(str, length) {
|
|
101
|
+
const s = String(str ?? '');
|
|
102
|
+
return s.length > length ? s.slice(0, length - 1) + '~' : s;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function formatDateTime(iso) {
|
|
106
|
+
if (!iso) return '';
|
|
107
|
+
return String(iso).replace('T', ' ').slice(0, 19);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function formatDuration(ms) {
|
|
111
|
+
if (ms === null || ms === undefined) return '';
|
|
112
|
+
if (ms < 1000) return `${ms}ms`;
|
|
113
|
+
const s = ms / 1000;
|
|
114
|
+
if (s < 60) return `${s.toFixed(1)}s`;
|
|
115
|
+
const m = Math.floor(s / 60);
|
|
116
|
+
if (m < 60) return `${m}m${String(Math.round(s % 60)).padStart(2, '0')}s`;
|
|
117
|
+
const h = Math.floor(m / 60);
|
|
118
|
+
return `${h}h${String(m % 60).padStart(2, '0')}m`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function stateLabel(state) {
|
|
122
|
+
switch (state) {
|
|
123
|
+
case 'ACTIVE':
|
|
124
|
+
return chalk.green(state);
|
|
125
|
+
case 'COMPLETED':
|
|
126
|
+
return chalk.blue(state);
|
|
127
|
+
case 'EXTERNALLY_TERMINATED':
|
|
128
|
+
case 'INTERNALLY_TERMINATED':
|
|
129
|
+
return chalk.yellow(state);
|
|
130
|
+
case 'SUSPENDED':
|
|
131
|
+
return chalk.gray(state);
|
|
132
|
+
default:
|
|
133
|
+
return state ?? '';
|
|
134
|
+
}
|
|
135
|
+
}
|