create-ilorb 0.0.0-stage → 0.3.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 +304 -2
- package/assets/dev-local.mjs +205 -0
- package/dist/args.js +39 -0
- package/dist/cli.js +7 -0
- package/dist/cloudflare/provider.js +48 -0
- package/dist/cloudflare/real.js +211 -0
- package/dist/cloudflare/simulated.js +213 -0
- package/dist/core-admin.js +85 -0
- package/dist/engine.js +52 -0
- package/dist/errors.js +23 -0
- package/dist/exec.js +49 -0
- package/dist/fsutil.js +130 -0
- package/dist/generate.js +260 -0
- package/dist/i18n/en.js +422 -0
- package/dist/i18n/es.js +414 -0
- package/dist/i18n/index.js +23 -0
- package/dist/i18n/pt.js +414 -0
- package/dist/license/activate.js +71 -0
- package/dist/license/keys.js +14 -0
- package/dist/license/verify.js +56 -0
- package/dist/local/ports.js +33 -0
- package/dist/main.js +642 -0
- package/dist/products.js +1528 -0
- package/dist/readme.js +228 -0
- package/dist/state.js +58 -0
- package/dist/steps.js +875 -0
- package/dist/templates.js +31 -0
- package/dist/theme/preview.js +67 -0
- package/dist/theme/vendor/color.js +133 -0
- package/dist/theme/vendor/tokens.js +314 -0
- package/dist/theme/vendor/validate.js +219 -0
- package/dist/ui/prompt.js +108 -0
- package/dist/ui/term.js +92 -0
- package/dist/update.js +348 -0
- package/package.json +49 -4
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Buyer theme validation — the SAME on the server (rejects with 422 invalid_theme) and in the panel (contrast table,
|
|
2
|
+
// "Fix" button). Two families of problems:
|
|
3
|
+
// 1. format: unknown key, color that is not hex, size outside 14–18, bad URL… → error
|
|
4
|
+
// 2. legibility of what the BUYER chose: text/background below 4.5, background outside the mode's range → error
|
|
5
|
+
// (DERIVED colors are not checked here: the engine always fixes them — see buildTheme)
|
|
6
|
+
// + warnings (non-blocking): the engine will show the color with a different lightness, a button that vanishes into the background.
|
|
7
|
+
// Every problem carries the pair, the measured ratio, the minimum and a SUGGESTION (the field value that fixes it).
|
|
8
|
+
import { contrast, ensureContrast } from "./color.js";
|
|
9
|
+
import { BACKGROUND_RANGE, DENSITY_IDS, FONT_IDS, FONT_SIZE, HEADING_WEIGHT_IDS, MODE_IDS, PRESETS, RADIUS_IDS, TEXT_MIN, chosenSurface, clampBackground, defaultBackground, defaultText, isHex, resolveConfig, solidWithOn, } from "./tokens.js";
|
|
10
|
+
/** all the keys the theme accepts (v1 format) */
|
|
11
|
+
export const THEME_FIELDS = [
|
|
12
|
+
'preset', 'mode', 'primary', 'secondary', 'accent', 'background', 'text', 'backgroundDark', 'textDark', 'success', 'danger',
|
|
13
|
+
'radius', 'font', 'fontSize', 'headingWeight', 'density', 'logo', 'logoDark', 'favicon',
|
|
14
|
+
];
|
|
15
|
+
export const COLOR_FIELDS = ['primary', 'secondary', 'accent', 'background', 'text', 'backgroundDark', 'textDark', 'success', 'danger'];
|
|
16
|
+
export const URL_FIELDS = ['logo', 'logoDark', 'favicon'];
|
|
17
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
18
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
19
|
+
/** URL accepted for logo/favicon: https (or http on localhost/127.0.0.1, for local mode), up to 500 characters */
|
|
20
|
+
export function isAssetUrl(v) {
|
|
21
|
+
if (typeof v !== 'string' || v.length > 500 || /\s/.test(v))
|
|
22
|
+
return false;
|
|
23
|
+
try {
|
|
24
|
+
const u = new URL(v);
|
|
25
|
+
if (u.protocol === 'https:')
|
|
26
|
+
return true;
|
|
27
|
+
return u.protocol === 'http:' && (u.hostname === 'localhost' || u.hostname === '127.0.0.1');
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** format only (serves the general theme and a product's "only what changes"). `null` in a field = remove it. */
|
|
34
|
+
export function checkThemeShape(input, opts = {}) {
|
|
35
|
+
const issues = [];
|
|
36
|
+
if (!isObj(input))
|
|
37
|
+
return [{ code: 'invalid_value', severity: 'error', field: '', message: 'o tema precisa ser um objeto' }];
|
|
38
|
+
const bad = (field, message, suggestion) => issues.push({ code: 'invalid_value', severity: 'error', field, message, ...(suggestion !== undefined ? { suggestion } : {}) });
|
|
39
|
+
for (const [k, v] of Object.entries(input)) {
|
|
40
|
+
if (!THEME_FIELDS.includes(k)) {
|
|
41
|
+
issues.push({ code: 'unknown_field', severity: 'error', field: k, suggestion: null, message: `campo desconhecido: ${k}` });
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (v === null || v === undefined) {
|
|
45
|
+
if (k === 'preset' && !opts.partial)
|
|
46
|
+
bad(k, 'preset é obrigatório', 'clean');
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
switch (k) {
|
|
50
|
+
case 'preset':
|
|
51
|
+
if (typeof v !== 'string' || !(v in PRESETS))
|
|
52
|
+
bad(k, 'preset: clean|bold|soft|night', 'clean');
|
|
53
|
+
break;
|
|
54
|
+
case 'mode':
|
|
55
|
+
if (!MODE_IDS.includes(v))
|
|
56
|
+
bad(k, 'mode: system|light|dark', 'system');
|
|
57
|
+
break;
|
|
58
|
+
case 'radius':
|
|
59
|
+
if (!RADIUS_IDS.includes(v))
|
|
60
|
+
bad(k, 'radius: sharp|soft|round', 'soft');
|
|
61
|
+
break;
|
|
62
|
+
case 'font':
|
|
63
|
+
if (!FONT_IDS.includes(v))
|
|
64
|
+
bad(k, 'font: system|inter|jakarta|nunito', 'inter');
|
|
65
|
+
break;
|
|
66
|
+
case 'density':
|
|
67
|
+
if (!DENSITY_IDS.includes(v))
|
|
68
|
+
bad(k, 'density: compact|regular|comfortable', 'regular');
|
|
69
|
+
break;
|
|
70
|
+
case 'headingWeight':
|
|
71
|
+
if (!HEADING_WEIGHT_IDS.includes(v))
|
|
72
|
+
bad(k, 'headingWeight: semibold|bold|extrabold', 'bold');
|
|
73
|
+
break;
|
|
74
|
+
case 'fontSize':
|
|
75
|
+
if (typeof v !== 'number' || !Number.isInteger(v) || v < FONT_SIZE.min || v > FONT_SIZE.max) {
|
|
76
|
+
const n = typeof v === 'number' && Number.isFinite(v) ? Math.min(FONT_SIZE.max, Math.max(FONT_SIZE.min, Math.round(v))) : FONT_SIZE.default;
|
|
77
|
+
bad(k, `fontSize: inteiro de ${FONT_SIZE.min} a ${FONT_SIZE.max}`, n);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case 'logo':
|
|
81
|
+
case 'logoDark':
|
|
82
|
+
case 'favicon':
|
|
83
|
+
if (!isAssetUrl(v))
|
|
84
|
+
bad(k, `${k}: URL https (até 500 caracteres)`, null);
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
if (!isHex(v))
|
|
88
|
+
bad(k, `${k}: cor em hex (#RRGGBB)`, null);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!opts.partial && !('preset' in input))
|
|
92
|
+
bad('preset', 'preset é obrigatório', 'clean');
|
|
93
|
+
return issues;
|
|
94
|
+
}
|
|
95
|
+
/** Merges the general theme with the product's "only what changes" (field by field; `null` in the product = inherit). */
|
|
96
|
+
export function mergeTheme(general, override) {
|
|
97
|
+
const out = { ...general };
|
|
98
|
+
if (override)
|
|
99
|
+
for (const [k, v] of Object.entries(override))
|
|
100
|
+
if (v !== null && v !== undefined)
|
|
101
|
+
out[k] = v;
|
|
102
|
+
// `secondary` is the new name of `accent`: whoever changes one in the product changes the color of both
|
|
103
|
+
if (override && (override.secondary || override.accent)) {
|
|
104
|
+
out.secondary = override.secondary ?? override.accent;
|
|
105
|
+
delete out.accent;
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
/** the keys the product inherits from the general theme (the ones it does not change) */
|
|
110
|
+
export function inheritedFields(override) {
|
|
111
|
+
const own = new Set(Object.entries(override ?? {}).filter(([, v]) => v !== null && v !== undefined).map(([k]) => k));
|
|
112
|
+
if (own.has('accent'))
|
|
113
|
+
own.add('secondary');
|
|
114
|
+
if (own.has('secondary'))
|
|
115
|
+
own.add('accent');
|
|
116
|
+
return THEME_FIELDS.filter((f) => !own.has(f));
|
|
117
|
+
}
|
|
118
|
+
/** Legibility of what the buyer chose (the config already has a valid format). */
|
|
119
|
+
function checkLegibility(cfg) {
|
|
120
|
+
const issues = [];
|
|
121
|
+
for (const scheme of ['light', 'dark']) {
|
|
122
|
+
const chosen = chosenSurface(cfg, scheme);
|
|
123
|
+
const bgField = scheme === 'light' ? 'background' : 'backgroundDark';
|
|
124
|
+
const textField = scheme === 'light' ? 'text' : 'textDark';
|
|
125
|
+
let bg = chosen.bg ?? defaultBackground(cfg, scheme);
|
|
126
|
+
// 1. background within the mode's range (only what the buyer GAVE: the derived one is born inside it)
|
|
127
|
+
if (chosen.bgFrom === bgField) {
|
|
128
|
+
const r = BACKGROUND_RANGE[scheme];
|
|
129
|
+
const ratio = contrast(bg, r.against);
|
|
130
|
+
if (ratio < r.min) {
|
|
131
|
+
const fixed = clampBackground(bg, scheme);
|
|
132
|
+
issues.push({
|
|
133
|
+
code: 'background_range', severity: 'error', field: bgField, scheme, pair: [bgField, scheme === 'light' ? '#000000' : '#FFFFFF'],
|
|
134
|
+
colors: [bg, r.against], ratio: round2(ratio), min: r.min, suggestion: ensureContrast(bg, r.against, r.min + 0.2),
|
|
135
|
+
message: scheme === 'light'
|
|
136
|
+
? `fundo do modo claro escuro demais (${round2(ratio)}:1 com o preto; mínimo ${r.min}:1)`
|
|
137
|
+
: `fundo do modo escuro claro demais (${round2(ratio)}:1 com o branco; mínimo ${r.min}:1)`,
|
|
138
|
+
});
|
|
139
|
+
bg = fixed;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// 2. text over the background (when either of the two is the buyer's choice)
|
|
143
|
+
const givenText = chosen.textFrom === textField;
|
|
144
|
+
const givenBg = chosen.bgFrom === bgField;
|
|
145
|
+
if (givenText || givenBg) {
|
|
146
|
+
const text = chosen.text ?? defaultText(cfg, scheme);
|
|
147
|
+
const ratio = contrast(text, bg);
|
|
148
|
+
if (ratio < TEXT_MIN) {
|
|
149
|
+
// fixes the text if it was the one the buyer gave; otherwise the background (which is the one they gave)
|
|
150
|
+
const field = givenText ? textField : bgField;
|
|
151
|
+
const suggestion = givenText ? ensureContrast(text, bg, TEXT_MIN + 0.1) : clampBackground(ensureContrast(bg, text, TEXT_MIN + 0.1), scheme);
|
|
152
|
+
issues.push({
|
|
153
|
+
code: 'low_contrast', severity: 'error', field, scheme, pair: [textField, bgField], colors: [text, bg],
|
|
154
|
+
ratio: round2(ratio), min: TEXT_MIN, suggestion,
|
|
155
|
+
message: `texto sobre o fundo (${scheme === 'light' ? 'claro' : 'escuro'}) = ${round2(ratio)}:1; mínimo ${TEXT_MIN}:1`,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// warnings: the solid color the engine will show in light mode differs from the chosen one (button, success, error)
|
|
161
|
+
const lightBg = clampBackground(cfg.background ?? '#FFFFFF', 'light');
|
|
162
|
+
for (const field of ['primary', 'success', 'danger']) {
|
|
163
|
+
const chosenColor = cfg[field];
|
|
164
|
+
// the style's default color raises no warning (Bold is born with the red adjusted on purpose)
|
|
165
|
+
if (!chosenColor || (field === 'primary' && normalizeHex(chosenColor) === PRESETS[cfg.preset].primary))
|
|
166
|
+
continue;
|
|
167
|
+
const { solid, on } = solidWithOn(chosenColor);
|
|
168
|
+
if (solid.toUpperCase() !== normalizeHex(chosenColor)) {
|
|
169
|
+
issues.push({
|
|
170
|
+
code: 'adjusted', severity: 'warning', field, scheme: 'light', pair: [field, 'on'], colors: [chosenColor, on],
|
|
171
|
+
ratio: round2(contrast(chosenColor, on)), min: 4.5, suggestion: solid,
|
|
172
|
+
message: `${field}: o texto em cima não passa 4.5; o app mostra ${solid}`,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (cfg.background) {
|
|
177
|
+
const { solid } = solidWithOn(cfg.primary);
|
|
178
|
+
const ratio = contrast(solid, lightBg);
|
|
179
|
+
if (ratio < 3) {
|
|
180
|
+
issues.push({
|
|
181
|
+
code: 'low_visibility', severity: 'warning', field: 'primary', scheme: 'light', pair: ['primary', 'background'],
|
|
182
|
+
colors: [solid, lightBg], ratio: round2(ratio), min: 3, suggestion: ensureContrast(solid, lightBg, 3.1),
|
|
183
|
+
message: `botão principal quase some no fundo (${round2(ratio)}:1; recomendado 3:1)`,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return issues;
|
|
188
|
+
}
|
|
189
|
+
/** #abc / #AbCdEf → #AABBCC */
|
|
190
|
+
export function normalizeHex(hex) {
|
|
191
|
+
let h = hex.trim().replace(/^#/, '');
|
|
192
|
+
if (h.length === 3)
|
|
193
|
+
h = h.split('').map((c) => c + c).join('');
|
|
194
|
+
return `#${h.toUpperCase()}`;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The theme's problems (format + legibility). `ok` = no ERROR (warnings do not block).
|
|
198
|
+
* The server saves only if `ok`; the panel shows everything and "Fix" applies `suggestion` to `field`.
|
|
199
|
+
*/
|
|
200
|
+
export function validateTheme(input) {
|
|
201
|
+
const shape = checkThemeShape(input);
|
|
202
|
+
if (shape.length)
|
|
203
|
+
return { ok: false, issues: shape };
|
|
204
|
+
const issues = checkLegibility(resolveConfig(input));
|
|
205
|
+
return { ok: !issues.some((i) => i.severity === 'error'), issues };
|
|
206
|
+
}
|
|
207
|
+
/** Applies the suggestions (from "Fix all" or from a single problem). `null` removes the field. */
|
|
208
|
+
export function applySuggestions(config, issues) {
|
|
209
|
+
const out = { ...config };
|
|
210
|
+
for (const i of issues) {
|
|
211
|
+
if (i.suggestion === undefined || !i.field)
|
|
212
|
+
continue;
|
|
213
|
+
if (i.suggestion === null)
|
|
214
|
+
delete out[i.field];
|
|
215
|
+
else
|
|
216
|
+
out[i.field] = i.suggestion;
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Terminal questions with no dependency (Node's readline). Choose by number; Enter accepts the default.
|
|
2
|
+
// Secret: hidden typing. Tests swap in scriptedPrompter (ready-made answers).
|
|
3
|
+
import { createInterface } from 'node:readline';
|
|
4
|
+
export function ttyPrompter(out, words) {
|
|
5
|
+
let rl = null;
|
|
6
|
+
let muted = false;
|
|
7
|
+
const get = () => {
|
|
8
|
+
if (!rl) {
|
|
9
|
+
rl = createInterface({ input: process.stdin, output: process.stdout, terminal: !!process.stdin.isTTY });
|
|
10
|
+
const w = rl;
|
|
11
|
+
const orig = w._writeToOutput?.bind(rl);
|
|
12
|
+
w._writeToOutput = (s) => {
|
|
13
|
+
if (muted && !/\r?\n/.test(s))
|
|
14
|
+
return orig?.(s.replace(/[^\r\n]/g, '•'));
|
|
15
|
+
orig?.(s);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return rl;
|
|
19
|
+
};
|
|
20
|
+
const ask = (q, mute = false) => new Promise((resolve, reject) => {
|
|
21
|
+
const r = get();
|
|
22
|
+
const onClose = () => reject(Object.assign(new Error('aborted'), { aborted: true }));
|
|
23
|
+
r.once('close', onClose);
|
|
24
|
+
r.question(q, (a) => {
|
|
25
|
+
r.off('close', onClose);
|
|
26
|
+
out.log(`${q}${muted ? '••••' : a}`);
|
|
27
|
+
muted = false;
|
|
28
|
+
resolve(a);
|
|
29
|
+
});
|
|
30
|
+
// the question has already been written: from here on what is typed shows as •
|
|
31
|
+
muted = mute;
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
async text(q, o = {}) {
|
|
35
|
+
for (;;) {
|
|
36
|
+
const a = (await ask(` ${out.cyan('?')} ${out.bold(q)}${o.default ? out.dim(` (${o.default})`) : ''} `)).trim() || o.default || '';
|
|
37
|
+
const err = o.validate?.(a) ?? null;
|
|
38
|
+
if (!err)
|
|
39
|
+
return a;
|
|
40
|
+
out.line(` ${out.red('✖')} ${err}`);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
async secret(q, o = {}) {
|
|
44
|
+
for (;;) {
|
|
45
|
+
const a = (await ask(` ${out.cyan('?')} ${out.bold(q)} `, true)).trim();
|
|
46
|
+
if (a || o.allowEmpty)
|
|
47
|
+
return a;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
async select(q, choices, def = 0) {
|
|
51
|
+
out.line(` ${out.cyan('?')} ${out.bold(q)}`);
|
|
52
|
+
choices.forEach((c, i) => out.line(` ${out.cyan(String(i + 1).padStart(2))} ${c.label}${c.hint ? ` ${out.dim(c.hint)}` : ''}`));
|
|
53
|
+
for (;;) {
|
|
54
|
+
const a = (await ask(` ${words.choose} ${out.dim(`(${def + 1})`)} `)).trim();
|
|
55
|
+
const n = a === '' ? def + 1 : Number(a);
|
|
56
|
+
if (Number.isInteger(n) && n >= 1 && n <= choices.length)
|
|
57
|
+
return choices[n - 1].value;
|
|
58
|
+
out.line(` ${out.red('✖')} ${words.invalid}`);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
async confirm(q, def = true) {
|
|
62
|
+
const a = (await ask(` ${out.cyan('?')} ${out.bold(q)} ${out.dim(def ? `(${words.yes}/${words.no.toLowerCase()})` : `(${words.yes.toLowerCase()}/${words.no})`)} `)).trim().toLowerCase();
|
|
63
|
+
if (!a)
|
|
64
|
+
return def;
|
|
65
|
+
return /^(s|y|sí|si|sim|yes|1)/.test(a);
|
|
66
|
+
},
|
|
67
|
+
close() {
|
|
68
|
+
rl?.close();
|
|
69
|
+
rl = null;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Ready-made answers, in order (tests). Throws if an answer is missing: the test stays explicit. */
|
|
74
|
+
export function scriptedPrompter(answers) {
|
|
75
|
+
const asked = [];
|
|
76
|
+
const next = (q) => {
|
|
77
|
+
asked.push(q);
|
|
78
|
+
if (!answers.length)
|
|
79
|
+
throw new Error(`sem resposta para: ${q}`);
|
|
80
|
+
return answers.shift();
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
asked,
|
|
84
|
+
async text(q, o = {}) {
|
|
85
|
+
const a = String(next(q)) || o.default || '';
|
|
86
|
+
const err = o.validate?.(a);
|
|
87
|
+
if (err)
|
|
88
|
+
throw new Error(`resposta inválida para "${q}": ${err}`);
|
|
89
|
+
return a;
|
|
90
|
+
},
|
|
91
|
+
async secret(q) {
|
|
92
|
+
return String(next(q));
|
|
93
|
+
},
|
|
94
|
+
async select(q, choices, def = 0) {
|
|
95
|
+
const a = next(q);
|
|
96
|
+
if (a === '')
|
|
97
|
+
return choices[def].value;
|
|
98
|
+
const hit = typeof a === 'number' ? choices[a - 1] : choices.find((c) => c.value === a);
|
|
99
|
+
if (!hit)
|
|
100
|
+
throw new Error(`opção inválida para "${q}": ${a}`);
|
|
101
|
+
return hit.value;
|
|
102
|
+
},
|
|
103
|
+
async confirm(q) {
|
|
104
|
+
return Boolean(next(q));
|
|
105
|
+
},
|
|
106
|
+
close() { },
|
|
107
|
+
};
|
|
108
|
+
}
|
package/dist/ui/term.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Terminal output: colors (respects NO_COLOR and colorless terminals), numbered steps, and a copy WITHOUT color in
|
|
2
|
+
// .overture/install.log (and in --log, which is where the video text comes from).
|
|
3
|
+
import { appendFileSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
import { hexToRgb } from "../theme/vendor/color.js";
|
|
6
|
+
const ESC = '\x1b[';
|
|
7
|
+
export const stripAnsi = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
8
|
+
export class Out {
|
|
9
|
+
color;
|
|
10
|
+
logFiles = [];
|
|
11
|
+
w;
|
|
12
|
+
t0 = Date.now();
|
|
13
|
+
constructor(o = {}) {
|
|
14
|
+
this.w = o.write ?? ((s) => process.stdout.write(s));
|
|
15
|
+
this.color = o.color ?? (!process.env.NO_COLOR && !!process.stdout.isTTY && process.env.TERM !== 'dumb');
|
|
16
|
+
}
|
|
17
|
+
logTo(file) {
|
|
18
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
19
|
+
if (!this.logFiles.includes(file))
|
|
20
|
+
this.logFiles.push(file);
|
|
21
|
+
}
|
|
22
|
+
/** writes to the terminal and (without color) to the logs */
|
|
23
|
+
raw(s) {
|
|
24
|
+
this.w(this.color ? s : stripAnsi(s));
|
|
25
|
+
for (const f of this.logFiles) {
|
|
26
|
+
try {
|
|
27
|
+
appendFileSync(f, stripAnsi(s));
|
|
28
|
+
}
|
|
29
|
+
catch { }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
line(s = '') {
|
|
33
|
+
this.raw(s + '\n');
|
|
34
|
+
}
|
|
35
|
+
/** on SCREEN the full text; in the logs on disk the masked version (e.g. first-access link, which is a credential) */
|
|
36
|
+
secretLine(s, masked) {
|
|
37
|
+
this.w((this.color ? s : stripAnsi(s)) + '\n');
|
|
38
|
+
for (const f of this.logFiles) {
|
|
39
|
+
try {
|
|
40
|
+
appendFileSync(f, stripAnsi(masked) + '\n');
|
|
41
|
+
}
|
|
42
|
+
catch { }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** log only (technical detail) */
|
|
46
|
+
log(s) {
|
|
47
|
+
for (const f of this.logFiles) {
|
|
48
|
+
try {
|
|
49
|
+
appendFileSync(f, stripAnsi(s) + '\n');
|
|
50
|
+
}
|
|
51
|
+
catch { }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
c = (code, s) => (this.color ? `${ESC}${code}m${s}${ESC}0m` : s);
|
|
55
|
+
bold = (s) => this.c('1', s);
|
|
56
|
+
dim = (s) => this.c('2', s);
|
|
57
|
+
green = (s) => this.c('32', s);
|
|
58
|
+
red = (s) => this.c('31', s);
|
|
59
|
+
yellow = (s) => this.c('33', s);
|
|
60
|
+
cyan = (s) => this.c('36', s);
|
|
61
|
+
magenta = (s) => this.c('35', s);
|
|
62
|
+
/** color block (truecolor background) with optional text on top */
|
|
63
|
+
swatch(bgHex, text = ' ', fgHex) {
|
|
64
|
+
if (!this.color)
|
|
65
|
+
return text.trim() ? `[${text.trim()}]` : '';
|
|
66
|
+
const [r, g, b] = hexToRgb(bgHex).map((x) => Math.round(x * 255));
|
|
67
|
+
const fg = fgHex ? hexToRgb(fgHex).map((x) => Math.round(x * 255)) : null;
|
|
68
|
+
return `${ESC}48;2;${r};${g};${b}m${fg ? `${ESC}38;2;${fg[0]};${fg[1]};${fg[2]}m` : ''}${text}${ESC}0m`;
|
|
69
|
+
}
|
|
70
|
+
elapsed() {
|
|
71
|
+
const s = Math.round((Date.now() - this.t0) / 1000);
|
|
72
|
+
return `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`;
|
|
73
|
+
}
|
|
74
|
+
step(n, total, title) {
|
|
75
|
+
this.line(`${this.dim(`[${this.elapsed()}]`)} ${this.cyan(`${n}/${total}`)} ${this.bold(title)}`);
|
|
76
|
+
}
|
|
77
|
+
ok(s) {
|
|
78
|
+
this.line(` ${this.green('✔')} ${s}`);
|
|
79
|
+
}
|
|
80
|
+
skip(n, total, title, why) {
|
|
81
|
+
this.line(`${this.dim(`[${this.elapsed()}]`)} ${this.dim(`${n}/${total}`)} ${title} ${this.dim(`— ${why}`)}`);
|
|
82
|
+
}
|
|
83
|
+
info(s) {
|
|
84
|
+
this.line(` ${this.dim('·')} ${s}`);
|
|
85
|
+
}
|
|
86
|
+
warn(s) {
|
|
87
|
+
this.line(` ${this.yellow('!')} ${s}`);
|
|
88
|
+
}
|
|
89
|
+
cmd(s) {
|
|
90
|
+
this.line(` ${this.dim('$')} ${s}`);
|
|
91
|
+
}
|
|
92
|
+
}
|