@basaltkit/deploy-ui 0.2.2 → 0.4.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,6 +1,7 @@
1
1
  import { ApiError } from './api.js';
2
2
  import { confirmDialog } from './dialog.js';
3
3
  import { append, button, el, quiet, replace } from './dom.js';
4
+ import { serverText, t } from './i18n.js';
4
5
  import { icon } from './icons.js';
5
6
  import { findingItem } from './view-plan.js';
6
7
  import { banner, describe, errorBanner, problem } from './reply.js';
@@ -45,14 +46,14 @@ export class RunView {
45
46
  this.target = target;
46
47
  this.runId = runId;
47
48
  this.stateLine = el('p', { class: 'run-state', role: 'status', aria: { live: 'polite' } });
48
- this.steps = el('ol', { class: 'steps', aria: { label: 'Steps' } });
49
- this.findings = el('ul', { class: 'findings', aria: { label: 'Findings' } });
50
- this.log = el('ol', { class: 'log', aria: { label: 'Log' } });
49
+ this.steps = el('ol', { class: 'steps', aria: { label: t('run.steps') } });
50
+ this.findings = el('ul', { class: 'findings', aria: { label: t('run.findings') } });
51
+ this.log = el('ol', { class: 'log', aria: { label: t('run.log') } });
51
52
  this.outcome = el('div', { class: 'run-outcome' });
52
53
  this.actions = el('div', { class: 'page-actions' });
53
54
  this.diagnostics = el('pre', { class: 'diagnostics', hidden: true });
54
- this.findingsCard = el('div', { class: 'card', hidden: true }, el('div', { class: 'card-head' }, el('h3', {}, 'Findings')), el('div', { class: 'card-body flush' }, this.findings));
55
- this.element = el('section', { aria: { labelledby: 'run-title' } }, el('header', { class: 'page-head' }, el('div', { class: 'page-title' }, el('h2', { id: 'run-title', class: 'mono-title' }, title), el('p', { class: 'page-sub' }, `${target.name} · ${target.ssh} · ${target.dir}`)), this.actions), this.stateLine, this.outcome, el('div', { class: 'run-grid' }, el('div', { class: 'card' }, el('div', { class: 'card-head' }, el('h3', {}, 'Steps')), el('div', { class: 'card-body' }, this.steps)), el('div', { class: 'console' }, el('div', { class: 'console-head' }, el('h3', {}, icon('terminal'), 'Log'), el('span', { class: 'console-meta' }, target.name)), this.log)), this.findingsCard, this.diagnostics);
55
+ this.findingsCard = el('div', { class: 'card', hidden: true }, el('div', { class: 'card-head' }, el('h3', {}, t('run.findings'))), el('div', { class: 'card-body flush' }, this.findings));
56
+ this.element = el('section', { aria: { labelledby: 'run-title' } }, el('header', { class: 'page-head' }, el('div', { class: 'page-title' }, el('h2', { id: 'run-title', class: 'mono-title' }, title), el('p', { class: 'page-sub' }, `${target.name} · ${target.ssh} · ${target.dir}`)), this.actions), this.stateLine, this.outcome, el('div', { class: 'run-grid' }, el('div', { class: 'card' }, el('div', { class: 'card-head' }, el('h3', {}, t('run.steps'))), el('div', { class: 'card-body' }, this.steps)), el('div', { class: 'console' }, el('div', { class: 'console-head' }, el('h3', {}, icon('terminal'), t('run.log')), el('span', { class: 'console-meta' }, target.name)), this.log)), this.findingsCard, this.diagnostics);
56
57
  this.renderActions();
57
58
  }
58
59
  /** Where to resume: the seq after the last one this tab saw for this run, kept in sessionStorage (not a secret). */
@@ -76,7 +77,7 @@ export class RunView {
76
77
  if (!this.runId)
77
78
  return;
78
79
  if (fromSeq > 0)
79
- this.note(`(resuming from event ${fromSeq}: earlier events were shown before; "Show from the start" replays them)`);
80
+ this.note(t('run.resuming', { seq: fromSeq }));
80
81
  await this.consume('attach', { target: this.target.name, runId: this.runId, fromSeq });
81
82
  }
82
83
  async streamAttended(route, body) {
@@ -102,7 +103,7 @@ export class RunView {
102
103
  this.following = false;
103
104
  if (!this.ended) {
104
105
  this.settleSteps();
105
- this.setState(this.controller.signal.aborted ? 'Stopped watching (the run goes on on the server).' : 'The stream ended.');
106
+ this.setState(this.controller.signal.aborted ? t('run.stoppedWatching') : t('run.streamEnded'));
106
107
  }
107
108
  this.renderActions();
108
109
  }
@@ -125,9 +126,9 @@ export class RunView {
125
126
  }
126
127
  state(message) {
127
128
  if (message.state === 'connecting')
128
- return this.setState(`Connecting to ${this.target.ssh}…`, 'live');
129
+ return this.setState(t('run.connecting', { ssh: this.target.ssh }), 'live');
129
130
  if (message.state === 'reconnecting') {
130
- return this.setState(`Connection lost (${clean(message.reason)}); reconnecting in ${Math.round((message.retryInMs ?? 0) / 1000)} s from event ${this.lastSeq === undefined ? 0 : this.lastSeq + 1}…`, 'live');
131
+ return this.setState(t('run.reconnecting', { reason: clean(message.reason), seconds: Math.round((message.retryInMs ?? 0) / 1000), seq: this.lastSeq === undefined ? 0 : this.lastSeq + 1 }), 'live');
131
132
  }
132
133
  this.ended = true;
133
134
  if (message.exitCode !== undefined)
@@ -135,7 +136,7 @@ export class RunView {
135
136
  if (this.runId && message.exitCode !== undefined && !message.code) {
136
137
  this.runFinished = true;
137
138
  if (message.reason)
138
- this.note(`(${clean(message.reason)})`);
139
+ this.note(`(${serverText(clean(message.reason))})`);
139
140
  }
140
141
  if (message.code) {
141
142
  this.failed = { code: message.code, ...(message.reason ? { reason: message.reason } : {}), ...(message.hint ? { hint: message.hint } : {}) };
@@ -153,16 +154,16 @@ export class RunView {
153
154
  }
154
155
  }
155
156
  if (!known)
156
- return this.line('warn', `an event this UI does not know (${event.type}): ignored`);
157
+ return this.line('warn', t('run.unknownEvent', { type: event.type }));
157
158
  switch (event.type) {
158
159
  case 'hello':
159
160
  return;
160
161
  case 'step-start': {
161
- const node = el('li', { class: 'step is-running' }, el('span', { class: 'step-icon', aria: { hidden: 'true' } }, '▸'), ' ', el('span', { class: 'step-title' }, event.title), el('span', { class: 'step-meta' }, quiet(' '), quiet('…'), el('span', { class: 'step-status', aria: { hidden: 'true' } }, 'running')));
162
+ const node = el('li', { class: 'step is-running' }, el('span', { class: 'step-icon', aria: { hidden: 'true' } }, '▸'), ' ', el('span', { class: 'step-title' }, event.title), el('span', { class: 'step-meta' }, quiet(' '), quiet('…'), el('span', { class: 'step-status', aria: { hidden: 'true' } }, t('step.running'))));
162
163
  this.stepNodes.set(event.id, node);
163
164
  this.stepTitles.set(event.id, event.title);
164
165
  this.steps.append(node);
165
- this.setState(`Step: ${event.title}`, 'live');
166
+ this.setState(t('run.step', { title: event.title }), 'live');
166
167
  return;
167
168
  }
168
169
  case 'step-end': {
@@ -172,7 +173,7 @@ export class RunView {
172
173
  const title = this.stepTitles.get(event.id) ?? event.id;
173
174
  node.className = `step is-${event.status === 'ok' ? 'ok' : event.status === 'skipped' ? 'skipped' : 'failed'}`;
174
175
  // The text reads "✓ build — ok, 1.5 s"; the layout draws the mark as an icon and the duration in a column.
175
- replace(node, el('span', { class: 'step-icon', aria: { hidden: 'true' } }, mark), quiet(' '), el('span', { class: 'step-title' }, title), el('span', { class: 'step-meta' }, quiet(' — '), el('span', { class: 'step-status' }, event.status), quiet(', '), el('span', { class: 'step-dur' }, `${(event.durationMs / 1000).toFixed(1)} s`)));
176
+ replace(node, el('span', { class: 'step-icon', aria: { hidden: 'true' } }, mark), quiet(' '), el('span', { class: 'step-title' }, title), el('span', { class: 'step-meta' }, quiet(' — '), el('span', { class: 'step-status' }, stepStatus(event.status)), quiet(', '), el('span', { class: 'step-dur' }, `${(event.durationMs / 1000).toFixed(1)} s`)));
176
177
  if (!node.parentNode)
177
178
  this.steps.append(node);
178
179
  return;
@@ -184,9 +185,9 @@ export class RunView {
184
185
  this.findings.append(findingItem(event));
185
186
  return;
186
187
  case 'prompt':
187
- return this.line('warn', `the deploy asks: ${event.message} (answer it in the form and run again)`);
188
+ return this.line('warn', t('run.asks', { message: event.message }));
188
189
  case 'result':
189
- this.outcome.append(resultBanner(event.command, event.data));
190
+ this.outcome.append(resultBanner(event.command, event.data, this.runId ? this.app.previewedRollbacks.get(this.runId) : undefined));
190
191
  return;
191
192
  case 'error':
192
193
  this.lastError = event;
@@ -199,7 +200,7 @@ export class RunView {
199
200
  return;
200
201
  case 'event':
201
202
  // Only the server unwraps attach; a nested wrapper here is a log-worthy oddity.
202
- return this.line('warn', 'an unexpected wrapped event was ignored');
203
+ return this.line('warn', t('run.wrapped'));
203
204
  }
204
205
  }
205
206
  line(level, textValue, source, ts) {
@@ -227,7 +228,7 @@ export class RunView {
227
228
  node.classList.replace('is-running', 'is-aborted');
228
229
  const status = node.querySelector('.step-status');
229
230
  if (status)
230
- replace(status, 'no end seen');
231
+ replace(status, t('run.noEnd'));
231
232
  }
232
233
  }
233
234
  setDropped() {
@@ -235,7 +236,7 @@ export class RunView {
235
236
  }
236
237
  setState(textValue, tone) {
237
238
  this.stateLine.className = `run-state${tone ? ` is-${tone}` : ''}`;
238
- replace(this.stateLine, textValue, this.dropped > 0 ? ` (${this.dropped} older log lines dropped from the page)` : '');
239
+ replace(this.stateLine, textValue, this.dropped > 0 ? t('run.dropped', { count: this.dropped }) : '');
239
240
  }
240
241
  finish() {
241
242
  // Status is refreshed once after any action (no polling loop).
@@ -243,34 +244,36 @@ export class RunView {
243
244
  this.settleSteps();
244
245
  if (this.failed && this.exitCode === undefined) {
245
246
  const reconnectable = this.runId !== undefined;
246
- this.setState(`Stopped: ${clean(this.failed.reason ?? this.failed.code)}`, 'err');
247
- this.outcome.append(banner('err', this.failed.reason ?? 'the stream ended', [this.failed.hint ?? '', reconnectable ? 'The run may still be going on the server: re-attach to see.' : ''], [], this.failed.code));
247
+ const reason = this.failed.reason === undefined ? undefined : serverText(clean(this.failed.reason));
248
+ this.setState(t('run.stoppedBecause', { why: reason ?? clean(this.failed.code) }), 'err');
249
+ this.outcome.append(banner('err', reason ?? t('run.streamEndedLower'), [this.failed.hint ? serverText(clean(this.failed.hint)) : '', reconnectable ? t('run.mayStillRun') : ''], [], this.failed.code));
248
250
  }
249
251
  else if (this.exitCode === 0) {
250
- this.setState('Done.', 'ok');
251
- this.outcome.append(banner('ok', 'Finished: exit 0'));
252
+ this.setState(t('run.done'), 'ok');
253
+ this.outcome.append(banner('ok', t('run.finishedOk')));
252
254
  }
253
255
  else {
254
- this.setState(`Finished with exit ${this.exitCode ?? 'unknown'}`, 'err');
256
+ const finished = t('run.finishedWith', { code: this.exitCode ?? t('unknown') });
257
+ this.setState(finished, 'err');
255
258
  if (!this.lastError)
256
- this.outcome.append(banner('err', `Finished with exit ${this.exitCode ?? 'unknown'}`));
259
+ this.outcome.append(banner('err', finished));
257
260
  }
258
261
  this.renderActions();
259
262
  }
260
263
  renderActions() {
261
264
  const buttons = [];
262
265
  if (this.runId && !this.ended && this.following) {
263
- buttons.push(button(this.cancels > 0 ? 'Cancel again (stop now)…' : 'Cancel…', () => { void this.cancel(this.cancels > 0); }, { class: 'danger' }));
264
- buttons.push(button('Stop watching', () => this.stop()));
266
+ buttons.push(button(this.cancels > 0 ? t('run.cancelAgain') : t('run.cancel'), () => { void this.cancel(this.cancels > 0); }, { class: 'danger' }));
267
+ buttons.push(button(t('run.stopWatching'), () => this.stop()));
265
268
  }
266
269
  if (this.runId && !this.following) {
267
270
  // A finished run has nothing more to attach to: only a replay makes sense.
268
271
  if (!this.runFinished)
269
- buttons.push(button('Re-attach', () => { void this.attach(this.lastSeq === undefined ? 0 : this.lastSeq + 1); }, { class: 'primary' }));
270
- buttons.push(button('Show from the start', () => { this.app.watch(this.runId, `run ${this.runId}`, true); }, this.runFinished ? { class: 'primary' } : {}));
272
+ buttons.push(button(t('run.reattach'), () => { void this.attach(this.lastSeq === undefined ? 0 : this.lastSeq + 1); }, { class: 'primary' }));
273
+ buttons.push(button(t('run.fromStart'), () => { this.app.watch(this.runId, t('run.title', { runId: this.runId }), true); }, this.runFinished ? { class: 'primary' } : {}));
271
274
  }
272
275
  if (!this.following)
273
- buttons.push(button('Refresh status', () => { void this.app.refreshStatus().then(() => this.app.show('status')); }));
276
+ buttons.push(button(t('run.refreshStatus'), () => { void this.app.refreshStatus().then(() => this.app.show('status')); }));
274
277
  replace(this.actions, ...buttons);
275
278
  }
276
279
  /** Two separate confirmations: the second one ends the deploy at once. */
@@ -279,22 +282,19 @@ export class RunView {
279
282
  return;
280
283
  const ok = await confirmDialog(second
281
284
  ? {
282
- title: 'Stop the deploy NOW?',
285
+ title: t('run.stopNowTitle'),
283
286
  lines: [
284
- 'This ends the deploy at once, mid-step.',
285
- el('strong', {}, 'A migration may be left half-applied'),
286
- 'The restore command for the pre-deploy dump is in the log. The lock is left stale.',
287
+ t('run.stopNowLine'),
288
+ el('strong', {}, t('run.halfApplied')),
289
+ t('run.restoreInLog'),
287
290
  ],
288
- confirmLabel: 'Stop it now',
291
+ confirmLabel: t('run.stopItNow'),
289
292
  danger: true,
290
293
  }
291
294
  : {
292
- title: `Cancel the run on ${this.target.name}?`,
293
- lines: [
294
- 'It stops at the next step boundary before the migration; from the migration on, the deploy finishes first.',
295
- 'A second cancel would stop it at once. If this run was already cancelled once (from a terminal or another session), nothing is sent now: you are asked again first.',
296
- ],
297
- confirmLabel: 'Cancel the run',
295
+ title: t('run.cancelTitle', { name: this.target.name }),
296
+ lines: [t('run.cancelLine'), t('run.cancelSecondLine')],
297
+ confirmLabel: t('run.cancelRun'),
298
298
  danger: true,
299
299
  });
300
300
  if (!ok)
@@ -312,27 +312,37 @@ export class RunView {
312
312
  if (reply.ok) {
313
313
  this.cancels++;
314
314
  const result = reply.result;
315
- this.note(result?.second ? 'cancel sent a second time: the deploy stops at once' : 'cancel sent: the deploy stops at its next safe point');
315
+ this.note(result?.second ? t('run.cancelSentTwice') : t('run.cancelSent'));
316
316
  this.renderActions();
317
317
  return;
318
318
  }
319
319
  this.outcome.append(problem(reply));
320
320
  }
321
321
  }
322
- function resultBanner(command, data) {
322
+ function resultBanner(command, data, previewed) {
323
323
  const d = (data ?? {});
324
324
  if (command === 'run') {
325
- return banner(d['status'] === 'ok' ? 'ok' : 'err', `Release ${clean(d['sha']).slice(0, 12)}: ${clean(d['status'])}`, [
325
+ return banner(d['status'] === 'ok' ? 'ok' : 'err', t('run.release', { sha: clean(d['sha']).slice(0, 12), status: stepStatus(clean(d['status'])) }), [
326
326
  d['url'] ? `${clean(d['url'])}` : '',
327
- Array.isArray(d['migrations']) && d['migrations'].length > 0 ? `migrations: ${d['migrations'].map(clean).join(', ')}` : '',
327
+ Array.isArray(d['migrations']) && d['migrations'].length > 0 ? t('run.migrations', { list: d['migrations'].map(clean).join(', ') }) : '',
328
328
  d['note'] ? clean(d['note']) : '',
329
329
  ]);
330
330
  }
331
- if (command === 'rollback')
332
- return banner(d['status'] === 'ok' ? 'ok' : 'err', `Rolled back to ${clean(d['to']).slice(0, 12)}: ${clean(d['status'])}`, [`${clean(d['held']).slice(0, 12)} is held`]);
331
+ if (command === 'rollback') {
332
+ const to = clean(d['to']);
333
+ return banner(d['status'] === 'ok' ? 'ok' : 'err', t('run.rolledBack', { sha: to.slice(0, 12), status: stepStatus(clean(d['status'])) }), [
334
+ t('run.isHeld', { sha: clean(d['held']).slice(0, 12) }),
335
+ // The releases moved between the preview and the run: say which commit the deploy chose.
336
+ previewed && to && previewed !== to ? el('strong', {}, t('run.deployChose', { to: to.slice(0, 12), previewed: clean(previewed).slice(0, 12) })) : '',
337
+ ]);
338
+ }
333
339
  if (command === 'env') {
334
340
  const changes = Array.isArray(d['changes']) ? d['changes'] : [];
335
- return banner('ok', `.env written (${changes.length} change${changes.length === 1 ? '' : 's'})`, changes.map((c) => `${clean(c['kind'])} ${clean(c['key'])}: ${clean(c['reason'])}`));
341
+ return banner('ok', t('run.envWritten', { count: changes.length }), changes.map((c) => `${clean(c['kind'])} ${clean(c['key'])}: ${clean(c['reason'])}`));
336
342
  }
337
- return banner('ok', `${clean(command)} result`);
343
+ return banner('ok', t('run.result', { command: clean(command) }));
344
+ }
345
+ /** A step's or a release's status in the page's language; one this UI does not know is shown as the server wrote it. */
346
+ function stepStatus(status) {
347
+ return status === 'ok' || status === 'skipped' || status === 'failed' ? t(`step.${status}`) : status;
338
348
  }
@@ -1,4 +1,5 @@
1
1
  import { button, card, el, emptyState, kv, pageHead, pill, quiet, when } from './dom.js';
2
+ import { t } from './i18n.js';
2
3
  import { icon } from './icons.js';
3
4
  import { banner, diagnosticsBlock, problem } from './reply.js';
4
5
  import { short } from './sanitize.js';
@@ -6,55 +7,55 @@ import { short } from './sanitize.js';
6
7
  export function renderStatus(app) {
7
8
  const reply = app.statusReply;
8
9
  const status = app.status;
9
- return el('section', { aria: { labelledby: 'status-title' } }, pageHead('status-title', 'Status', 'What runs on the server now: the release, the process, the lock and the last runs.', el('button', { type: 'button', disabled: app.statusBusy, on: { click: () => { void app.refreshStatus(); } } }, icon('refresh'), app.statusBusy ? 'Refreshing…' : 'Refresh')), !reply && !app.statusBusy ? emptyState('status', 'Not loaded yet.', 'Refresh to ask the server for its state.') : null, !reply && app.statusBusy ? emptyState('refresh', 'Asking the server…', 'Over your ssh; this can take a few seconds.') : null, reply && !status ? problem(reply) : null, ...(status ? statusPanels(app, status) : []), status && reply?.error ? problem(reply) : null, reply && reply.diagnostics.length > 0 && status ? diagnosticsBlock(reply.diagnostics) : null);
10
+ return el('section', { aria: { labelledby: 'status-title' } }, pageHead('status-title', t('screen.status'), t('status.sub'), el('button', { type: 'button', disabled: app.statusBusy, on: { click: () => { void app.refreshStatus(); } } }, icon('refresh'), app.statusBusy ? t('refreshing') : t('refresh'))), !reply && !app.statusBusy ? emptyState('status', t('status.notLoaded'), t('status.notLoadedText')) : null, !reply && app.statusBusy ? emptyState('refresh', t('status.asking'), t('status.askingText')) : null, reply && !status ? problem(reply) : null, ...(status ? statusPanels(app, status) : []), status && reply?.error ? problem(reply) : null, reply && reply.diagnostics.length > 0 && status ? diagnosticsBlock(reply.diagnostics) : null);
10
11
  }
11
12
  function statusPanels(app, s) {
12
13
  const current = s.releases.find((r) => r.status === 'ok');
13
14
  const panels = [];
14
15
  if (s.hold) {
15
- panels.push(banner('warn', `Commit ${short(s.hold.sha)} is held since ${when(s.hold.at)} by ${s.hold.actor}`, [
16
+ panels.push(banner('warn', t('status.held', { sha: short(s.hold.sha), at: when(s.hold.at), actor: s.hold.actor }), [
16
17
  s.hold.note,
17
- 'A run refuses it until the branch moves on; "Deploy anyway" in Plan & deploy overrides that once.',
18
+ t('status.heldHelp'),
18
19
  ]));
19
20
  }
20
21
  if (s.activeRun) {
21
22
  const run = s.activeRun;
22
- panels.push(card('Active run', [
23
- el('p', { class: 'lead' }, run.alive ? pill('run', 'alive') : pill('warn', 'not seen alive'), el('span', { class: 'mono' }, run.runId)),
24
- kv([['Command', run.command], ['Actor', run.actor], ['Started', el('span', { class: 'num' }, when(run.startedAt))]]),
25
- ], { class: 'accent', actions: [button('Attach', () => { app.watch(run.runId, `${run.command} ${run.runId}`); }, { class: 'primary' })] }));
23
+ panels.push(card(t('status.activeRun'), [
24
+ el('p', { class: 'lead' }, run.alive ? pill('run', t('status.alive')) : pill('warn', t('status.notSeenAlive')), el('span', { class: 'mono' }, run.runId)),
25
+ kv([[t('status.command'), run.command], [t('status.actor'), run.actor], [t('status.started'), el('span', { class: 'num' }, when(run.startedAt))]]),
26
+ ], { class: 'accent', actions: [button(t('status.attach'), () => { app.watch(run.runId, `${run.command} ${run.runId}`); }, { class: 'primary' })] }));
26
27
  }
27
- const releaseCard = card('Current release', current
28
+ const releaseCard = card(t('status.currentRelease'), current
28
29
  ? [
29
- el('p', { class: 'lead' }, pill('ok', 'healthy'), el('code', {}, short(current.sha))),
30
+ el('p', { class: 'lead' }, pill('ok', t('status.healthy')), el('code', {}, short(current.sha))),
30
31
  kv([
31
- ['Deployed', el('span', { class: 'num' }, when(current.at))],
32
- ['By', `${current.actor ?? current.user}${current.via ? ` via ${current.via}` : ''}`],
33
- current.migrations.length > 0 ? ['Migrations', el('span', { class: 'mono' }, current.migrations.join(', '))] : null,
32
+ [t('status.deployed'), el('span', { class: 'num' }, when(current.at))],
33
+ [t('status.by'), current.via ? t('status.via', { who: current.actor ?? current.user, via: current.via }) : current.actor ?? current.user],
34
+ current.migrations.length > 0 ? [t('status.migrations'), el('span', { class: 'mono' }, current.migrations.join(', '))] : null,
34
35
  ]),
35
36
  ]
36
- : [el('p', { class: 'muted' }, 'No healthy release recorded yet.')]);
37
- const processCard = card('Process', s.process.kind === 'pm2'
37
+ : [el('p', { class: 'muted' }, t('status.noHealthy'))]);
38
+ const processCard = card(t('status.process'), s.process.kind === 'pm2'
38
39
  ? [
39
- el('p', { class: 'lead' }, el('span', { class: 'mono' }, `pm2 ${s.process.name}`), quiet(': '), s.process.running ? pill('ok', 'running') : pill('err', 'not running'), s.process.status ? el('span', { class: 'muted' }, ` (${s.process.status})`) : ''),
40
- kv([['Manager', 'pm2'], ['Name', el('span', { class: 'mono' }, s.process.name)], s.process.pid !== undefined ? ['PID', el('span', { class: 'num mono' }, String(s.process.pid))] : null]),
40
+ el('p', { class: 'lead' }, el('span', { class: 'mono' }, `pm2 ${s.process.name}`), quiet(': '), s.process.running ? pill('ok', t('status.running')) : pill('err', t('status.notRunning')), s.process.status ? el('span', { class: 'muted' }, ` (${s.process.status})`) : ''),
41
+ kv([[t('status.manager'), 'pm2'], [t('status.name'), el('span', { class: 'mono' }, s.process.name)], s.process.pid !== undefined ? ['PID', el('span', { class: 'num mono' }, String(s.process.pid))] : null]),
41
42
  ]
42
43
  : [el('pre', { class: 'diagnostics' }, s.process.lines.join('\n'))]);
43
44
  const lock = s.lock;
44
- const lockCard = card('Lock', !lock
45
- ? [el('p', { class: 'lead' }, pill('ok', 'free'), el('span', { class: 'muted' }, 'Free. No deploy holds it.'))]
45
+ const lockCard = card(t('status.lock'), !lock
46
+ ? [el('p', { class: 'lead' }, pill('ok', t('status.free')), el('span', { class: 'muted' }, t('status.freeText')))]
46
47
  : [
47
- el('p', { class: 'lead' }, lock.corrupt ? pill('err', 'corrupt') : lock.stale ? pill('warn', 'stale') : pill('run', 'held'), lock.corrupt ? el('strong', { class: 'status-err' }, 'Corrupt lock file. ') : null),
48
- lock.holder ? el('p', {}, `Held by pid ${lock.holder.pid} on ${lock.holder.host} — ${lock.holder.actor}, ${lock.holder.command}, since ${when(lock.holder.startedAt)}`) : null,
49
- lock.stale ? el('p', { class: 'status-warn' }, el('strong', {}, ' (stale: that process is gone)')) : null,
48
+ el('p', { class: 'lead' }, lock.corrupt ? pill('err', t('status.corrupt')) : lock.stale ? pill('warn', t('status.stale')) : pill('run', t('status.heldPill')), lock.corrupt ? el('strong', { class: 'status-err' }, t('status.corruptLock')) : null),
49
+ lock.holder ? el('p', {}, t('status.lockHolder', { ...lock.holder, since: when(lock.holder.startedAt) })) : null,
50
+ lock.stale ? el('p', { class: 'status-warn' }, el('strong', {}, t('status.staleNote'))) : null,
50
51
  ]);
51
- const lastRunCard = s.lastRun ? lastRun(app, s.lastRun) : card('Last run', [el('p', { class: 'muted' }, 'No run recorded yet.')]);
52
+ const lastRunCard = s.lastRun ? lastRun(app, s.lastRun) : card(t('status.lastRun'), [el('p', { class: 'muted' }, t('status.noRun'))]);
52
53
  panels.push(el('div', { class: 'grid-2' }, releaseCard, processCard, lockCard, lastRunCard));
53
54
  return panels;
54
55
  }
55
56
  function lastRun(app, run) {
56
- return card('Last run', [
57
- el('p', { class: 'lead' }, run.complete ? pill(run.exitCode === 0 ? 'ok' : 'err', `exit ${run.exitCode}`) : pill('warn', 'did not end with done'), el('span', { class: 'mono' }, run.runId)),
58
- kv([['Command', run.command || 'unknown command'], run.endedAt ? ['Ended', el('span', { class: 'num' }, when(run.endedAt))] : null]),
59
- ], { actions: [button('Show its log', () => { app.watch(run.runId, `${run.command} ${run.runId}`, true); }, { class: 'sm' })] });
57
+ return card(t('status.lastRun'), [
58
+ el('p', { class: 'lead' }, run.complete ? pill(run.exitCode === 0 ? 'ok' : 'err', t('status.exit', { code: run.exitCode })) : pill('warn', t('status.noDone')), el('span', { class: 'mono' }, run.runId)),
59
+ kv([[t('status.command'), run.command || t('status.unknownCommand')], run.endedAt ? [t('status.ended'), el('span', { class: 'num' }, when(run.endedAt))] : null]),
60
+ ], { actions: [button(t('status.showLog'), () => { app.watch(run.runId, `${run.command} ${run.runId}`, true); }, { class: 'sm' })] });
60
61
  }
@@ -1,33 +1,34 @@
1
1
  import { ApiError } from './api.js';
2
2
  import { confirmDialog } from './dialog.js';
3
3
  import { button, card, el, emptyState, pageHead, replace } from './dom.js';
4
+ import { serverText, t } from './i18n.js';
4
5
  import { icon } from './icons.js';
5
6
  import { banner, describe, problem } from './reply.js';
6
7
  const FIELDS = [
7
- { key: 'name', label: 'Name', help: 'lowercase letters, digits and -, e.g. staging' },
8
- { key: 'ssh', label: 'SSH destination', help: '[user@]host, or a Host alias from your ~/.ssh/config (jump hosts and keys go there)' },
9
- { key: 'port', label: 'Port', help: 'optional; default: your ~/.ssh/config, else 22', type: 'number' },
10
- { key: 'dir', label: 'Checkout on the server', help: 'absolute path, e.g. /srv/myapp' },
11
- { key: 'node', label: 'node on the server', help: 'optional absolute path, when a non-interactive shell has no node on PATH' },
12
- { key: 'config', label: 'Config file', help: 'optional, relative to the checkout (default deploy.config.ts)' },
13
- { key: 'protected', label: 'Protected: type the name to deploy or roll back', help: '', type: 'checkbox' },
8
+ { key: 'name', label: 'field.name', help: 'field.name.help' },
9
+ { key: 'ssh', label: 'field.ssh', help: 'field.ssh.help' },
10
+ { key: 'port', label: 'field.port', help: 'field.port.help', type: 'number' },
11
+ { key: 'dir', label: 'field.dir', help: 'field.dir.help' },
12
+ { key: 'node', label: 'field.node', help: 'field.node.help' },
13
+ { key: 'config', label: 'field.config', help: 'field.config.help' },
14
+ { key: 'protected', label: 'field.protected', type: 'checkbox' },
14
15
  ];
15
16
  /** Targets: list, add/edit/remove, check the connection. */
16
17
  export function renderTargets(app) {
17
18
  const root = el('section', { aria: { labelledby: 'targets-title' } });
18
19
  const checkArea = el('div', { aria: { live: 'polite' } });
19
20
  const formArea = el('div');
20
- const t = app.targets;
21
- const list = t.targets.length === 0
22
- ? emptyState('targets', 'No target yet', 'No target yet. Add the server you already reach with ssh as the app user.')
23
- : card('Servers', [el('div', { class: 'table-wrap' }, el('table', {}, el('thead', {}, el('tr', {}, el('th', { scope: 'col' }, 'Name'), el('th', { scope: 'col' }, 'SSH'), el('th', { scope: 'col' }, 'Checkout'), el('th', { scope: 'col' }, el('span', { class: 'sr-only' }, 'Protection')), el('th', { scope: 'col', class: 'num' }, 'Actions'))), el('tbody', {}, ...t.targets.map((target) => el('tr', {}, el('td', { class: 'target-name' }, target.name), el('td', { class: 'mono' }, `${target.ssh}${target.port ? ` -p ${target.port}` : ''}`), el('td', { class: 'mono' }, target.dir), el('td', {}, target.protected ? el('span', { class: 'badge badge-protected' }, icon('shield'), 'protected') : ''), el('td', { class: 'num' }, el('div', { class: 'row' }, button('Use', () => { app.select(target.name); app.show('status'); void app.refreshStatus(); }, { class: target.name === app.current?.name ? 'sm ghost' : 'sm' }), button('Check connection', () => { void check(app, target, checkArea); }, { class: 'sm' }), button('Edit', () => replace(formArea, targetForm(app, target)), { class: 'sm ghost' }), button('Remove', () => { void remove(app, target); }, { class: 'sm ghost danger' }))))))))], { bodyClass: 'flush', actions: [el('span', { class: 'muted num' }, `${t.targets.length} target${t.targets.length === 1 ? '' : 's'}`)] });
24
- replace(root, pageHead('targets-title', 'Targets', ['Stored on this machine only, in ', el('code', {}, t.path), ' (0600). They hold no secret.'], el('button', { type: 'button', class: 'primary', on: { click: () => replace(formArea, targetForm(app, undefined)) } }, 'Add a target')), t.error ? banner('err', t.error) : null, list, checkArea, formArea, actorForm(app));
25
- if (t.targets.length === 0 && !t.error)
21
+ const file = app.targets;
22
+ const list = file.targets.length === 0
23
+ ? emptyState('targets', t('targets.none'), t('targets.noneText'))
24
+ : card(t('targets.servers'), [el('div', { class: 'table-wrap' }, el('table', {}, el('thead', {}, el('tr', {}, el('th', { scope: 'col' }, t('field.name')), el('th', { scope: 'col' }, t('targets.ssh')), el('th', { scope: 'col' }, t('targets.checkout')), el('th', { scope: 'col' }, el('span', { class: 'sr-only' }, t('targets.protection'))), el('th', { scope: 'col', class: 'num' }, t('targets.actions')))), el('tbody', {}, ...file.targets.map((target) => el('tr', {}, el('td', { class: 'target-name' }, target.name), el('td', { class: 'mono' }, `${target.ssh}${target.port ? ` -p ${target.port}` : ''}`), el('td', { class: 'mono' }, target.dir), el('td', {}, target.protected ? el('span', { class: 'badge badge-protected' }, icon('shield'), t('targets.protected')) : ''), el('td', { class: 'num' }, el('div', { class: 'row' }, button(t('targets.use'), () => { app.select(target.name); app.show('status'); void app.refreshStatus(); }, { class: target.name === app.current?.name ? 'sm ghost' : 'sm' }), button(t('targets.check'), () => { void check(app, target, checkArea); }, { class: 'sm' }), button(t('targets.edit'), () => replace(formArea, targetForm(app, target)), { class: 'sm ghost' }), button(t('targets.remove'), () => { void remove(app, target); }, { class: 'sm ghost danger' }))))))))], { bodyClass: 'flush', actions: [el('span', { class: 'muted num' }, t('targets.count', { count: file.targets.length }))] });
25
+ replace(root, pageHead('targets-title', t('screen.targets'), [t('targets.storedIn'), el('code', {}, file.path), t('targets.storedTail')], el('button', { type: 'button', class: 'primary', on: { click: () => replace(formArea, targetForm(app, undefined)) } }, t('targets.add'))), file.error ? banner('err', file.error) : null, list, checkArea, formArea, actorForm(app));
26
+ if (file.targets.length === 0 && !file.error)
26
27
  replace(formArea, targetForm(app, undefined));
27
28
  return root;
28
29
  }
29
30
  async function check(app, target, area) {
30
- replace(area, el('p', { class: 'muted' }, `Connecting to ${target.ssh}…`));
31
+ replace(area, el('p', { class: 'muted' }, t('targets.connecting', { ssh: target.ssh })));
31
32
  let reply;
32
33
  try {
33
34
  reply = await app.api.post('status', { target: target.name });
@@ -37,7 +38,7 @@ async function check(app, target, area) {
37
38
  return;
38
39
  }
39
40
  if (reply.hello?.protocol === 1 && !reply.failure) {
40
- replace(area, banner('ok', `${target.name} answers: @basaltkit/deploy ${reply.hello.version}, protocol 1, host ${reply.hello.host}`));
41
+ replace(area, banner('ok', t('targets.answers', { name: target.name, version: reply.hello.version, host: reply.hello.host })));
41
42
  if (app.current?.name === target.name) {
42
43
  app.statusReply = reply;
43
44
  app.hello = reply.hello;
@@ -48,7 +49,7 @@ async function check(app, target, area) {
48
49
  replace(area, problem(reply));
49
50
  }
50
51
  async function remove(app, target) {
51
- const ok = await confirmDialog({ title: `Remove ${target.name}?`, lines: ['Only this UI forgets it; nothing changes on the server.'], confirmLabel: 'Remove', danger: true });
52
+ const ok = await confirmDialog({ title: t('targets.removeTitle', { name: target.name }), lines: [t('targets.removeLine')], confirmLabel: t('targets.remove'), danger: true });
52
53
  if (!ok)
53
54
  return;
54
55
  try {
@@ -63,13 +64,13 @@ async function remove(app, target) {
63
64
  }
64
65
  function actorForm(app) {
65
66
  const input = el('input', { type: 'text', id: 'actor', value: app.targets.actor ?? '', autocomplete: 'off', spellcheck: false, aria: { describedby: 'actor-help' } });
66
- const message = el('span', { id: 'actor-help', class: 'muted' }, 'Recorded with each release as --actor (letters, digits and ._@+-).');
67
- const form = el('form', { class: 'card', aria: { label: 'Audit actor' }, on: { submit: (event) => {
67
+ const message = el('span', { id: 'actor-help', class: 'muted' }, t('targets.actorHelp'));
68
+ const form = el('form', { class: 'card', aria: { label: t('targets.auditActor') }, on: { submit: (event) => {
68
69
  event.preventDefault();
69
70
  void app.api.post('targets/save', { actor: input.value.trim() === '' ? null : input.value.trim() })
70
- .then((reply) => { app.targets = reply; replace(message, 'Saved.'); })
71
+ .then((reply) => { app.targets = reply; replace(message, t('targets.saved')); })
71
72
  .catch((error) => { replace(message, el('span', { class: 'field-error' }, describe(error))); });
72
- } } }, el('div', { class: 'card-head' }, el('h3', {}, 'Audit')), el('div', { class: 'card-body' }, el('div', { class: 'field' }, el('label', { for: 'actor' }, 'Your name in the audit (actor)'), input, message)), el('div', { class: 'card-foot' }, el('button', { type: 'submit' }, 'Save actor')));
73
+ } } }, el('div', { class: 'card-head' }, el('h3', {}, t('targets.audit'))), el('div', { class: 'card-body' }, el('div', { class: 'field' }, el('label', { for: 'actor' }, t('targets.actorLabel')), input, message)), el('div', { class: 'card-foot' }, el('button', { type: 'submit' }, t('targets.saveActor'))));
73
74
  return form;
74
75
  }
75
76
  function targetForm(app, existing) {
@@ -86,9 +87,9 @@ function targetForm(app, existing) {
86
87
  : el('input', { type: field.type === 'number' ? 'number' : 'text', id, value: value === undefined ? '' : String(value), autocomplete: 'off', spellcheck: false, required: field.key === 'name' || field.key === 'ssh' || field.key === 'dir', aria: { describedby: `${id}-help ${id}-error` } });
87
88
  inputs.set(field.key, input);
88
89
  if (field.type === 'checkbox') {
89
- return el('div', { class: 'field check span-2' }, el('label', { for: id }, input, el('span', {}, field.label)), error);
90
+ return el('div', { class: 'field check span-2' }, el('label', { for: id }, input, el('span', {}, t(field.label))), error);
90
91
  }
91
- return el('div', { class: 'field' }, el('label', { for: id }, field.label, field.key === 'name' || field.key === 'ssh' || field.key === 'dir' ? el('span', { class: 'required' }, ' *') : null), input, field.help ? el('span', { id: `${id}-help`, class: 'field-help' }, field.help) : null, error);
92
+ return el('div', { class: 'field' }, el('label', { for: id }, t(field.label), field.key === 'name' || field.key === 'ssh' || field.key === 'dir' ? el('span', { class: 'required' }, ' *') : null), input, field.help ? el('span', { id: `${id}-help`, class: 'field-help' }, t(field.help)) : null, error);
92
93
  });
93
94
  const submit = async (event) => {
94
95
  event.preventDefault();
@@ -121,9 +122,9 @@ function targetForm(app, existing) {
121
122
  for (const [key, message] of Object.entries(fieldErrors)) {
122
123
  const slot = errors.get(key);
123
124
  if (slot)
124
- replace(slot, message);
125
+ replace(slot, serverText(message));
125
126
  else
126
- general.append(el('p', { class: 'field-error' }, `${key}: ${message}`));
127
+ general.append(el('p', { class: 'field-error' }, `${key}: ${serverText(message)}`));
127
128
  }
128
129
  ;
129
130
  (inputs.get(Object.keys(fieldErrors)[0]) ?? inputs.get('name'))?.focus();
@@ -132,5 +133,5 @@ function targetForm(app, existing) {
132
133
  replace(general, problem(undefined, error));
133
134
  }
134
135
  };
135
- return el('form', { class: 'card', aria: { label: existing ? `Edit ${existing.name}` : 'Add a target' }, on: { submit: (event) => { void submit(event); } } }, el('div', { class: 'card-head' }, el('h3', {}, existing ? `Edit ${existing.name}` : 'Add a target')), el('div', { class: 'card-body' }, el('div', { class: 'form-grid' }, ...fields), general), el('div', { class: 'card-foot' }, button('Cancel', () => app.show('targets')), el('button', { type: 'submit', class: 'primary' }, 'Save')));
136
+ return el('form', { class: 'card', aria: { label: existing ? t('targets.editTitle', { name: existing.name }) : t('targets.add') }, on: { submit: (event) => { void submit(event); } } }, el('div', { class: 'card-head' }, el('h3', {}, existing ? t('targets.editTitle', { name: existing.name }) : t('targets.add'))), el('div', { class: 'card-body' }, el('div', { class: 'form-grid' }, ...fields), general), el('div', { class: 'card-foot' }, button(t('cancel'), () => app.show('targets')), el('button', { type: 'submit', class: 'primary' }, t('save'))));
136
137
  }