@basaltkit/deploy-ui 0.3.0 → 0.5.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,5 +1,6 @@
1
1
  import { confirmDialog } from './dialog.js';
2
2
  import { append, button, card, el, emptyState, pageHead, replace } from './dom.js';
3
+ import { t } from './i18n.js';
3
4
  import { icon } from './icons.js';
4
5
  import { banner, describe, diagnosticsBlock, problem } from './reply.js';
5
6
  import { ApiError } from './api.js';
@@ -8,21 +9,21 @@ import { commitsBlock, rangeSpan, validCommits } from './view-commits.js';
8
9
  export function renderPlan(app) {
9
10
  const reply = app.planReply;
10
11
  const plan = app.plan;
11
- const root = el('section', { aria: { labelledby: 'plan-title' } }, pageHead('plan-title', 'Plan & deploy', 'plan changes nothing on the server. Its preflight may reach the git remote, so it can take a while.', button(app.planBusy ? 'Planning…' : plan ? 'Plan again' : 'Run plan', () => { void app.runPlan(); }, { disabled: app.planBusy, class: plan ? '' : 'primary' })));
12
+ const root = el('section', { aria: { labelledby: 'plan-title' } }, pageHead('plan-title', t('screen.plan'), t('plan.sub'), button(app.planBusy ? t('plan.planning') : plan ? t('plan.again') : t('plan.run'), () => { void app.runPlan(); }, { disabled: app.planBusy, class: plan ? '' : 'primary' })));
12
13
  if (!reply) {
13
14
  append(root, app.planBusy
14
- ? emptyState('refresh', 'Planning…', 'Preflight checks and the plan run on the server; nothing changes there.')
15
- : emptyState('plan', 'No plan yet', 'Run a plan to see what a deploy would do, the questions it would ask, and anything that would stop it.'));
15
+ ? emptyState('refresh', t('plan.planning'), t('plan.planningText'))
16
+ : emptyState('plan', t('plan.none'), t('plan.noneText')));
16
17
  return root;
17
18
  }
18
19
  if (!plan) {
19
- append(root, problem(reply) ?? el('p', {}, 'No plan came back.'));
20
+ append(root, problem(reply) ?? el('p', {}, t('plan.noneBack')));
20
21
  return root;
21
22
  }
22
23
  append(root, ...findings(plan.findings));
23
24
  append(root, outgoing(plan.commits));
24
25
  if (plan.lines.length > 0) {
25
- append(root, card('What a run would do', [el('div', { class: 'table-wrap' }, el('table', { class: 'plan-lines' }, el('tbody', {}, ...plan.lines.map((line) => el('tr', {}, el('th', { scope: 'row' }, el('span', { class: 'step-chip' }, line.step)), el('td', {}, line.text))))))], { bodyClass: 'flush' }));
26
+ append(root, card(t('plan.wouldDo'), [el('div', { class: 'table-wrap' }, el('table', { class: 'plan-lines' }, el('tbody', {}, ...plan.lines.map((line) => el('tr', {}, el('th', { scope: 'row' }, el('span', { class: 'step-chip' }, line.step)), el('td', {}, line.text))))))], { bodyClass: 'flush' }));
26
27
  }
27
28
  if (reply.diagnostics.length > 0)
28
29
  append(root, diagnosticsBlock(reply.diagnostics));
@@ -33,25 +34,25 @@ export function renderPlan(app) {
33
34
  function outgoing(commits) {
34
35
  const range = validCommits(commits) && commits.ok ? commits.range : undefined;
35
36
  const summary = !range ? null
36
- : range.relation === 'ahead' ? `${range.addedTotal} commit${range.addedTotal === 1 ? '' : 's'}`
37
- : range.relation === 'diverged' ? `${range.addedTotal} new · ${range.removedTotal} only on the server`
38
- : range.relation === 'behind' ? `${range.removedTotal} behind`
37
+ : range.relation === 'ahead' ? t('plan.commitCount', { count: range.addedTotal })
38
+ : range.relation === 'diverged' ? t('plan.diverged', { added: range.addedTotal, removed: range.removedTotal })
39
+ : range.relation === 'behind' ? t('plan.behindCount', { count: range.removedTotal })
39
40
  : null;
40
- return card('What will go out', [
41
- range?.relation === 'diverged' ? banner('warn', 'The branch was rewritten on the remote', ['A run refuses it: its merge is fast-forward only. The commits only on the server would be lost.']) : null,
42
- range?.relation === 'behind' ? banner('warn', 'The remote\'s branch is behind the server', ['A run refuses it: its merge is fast-forward only.']) : null,
43
- range?.held ? banner('warn', 'This commit is held by a rollback', ['A run refuses it unless you deploy anyway (--unhold).']) : null,
44
- commitsBlock(commits, { added: 'Goes out', removed: 'Only on the server', same: 'Nothing new — the server already runs the tip of the branch.' }),
41
+ return card(t('plan.goesOutTitle'), [
42
+ range?.relation === 'diverged' ? banner('warn', t('plan.rewritten'), [t('plan.rewrittenHelp')]) : null,
43
+ range?.relation === 'behind' ? banner('warn', t('plan.behind'), [t('plan.behindHelp')]) : null,
44
+ range?.held ? banner('warn', t('plan.heldByRollback'), [t('plan.heldByRollbackHelp')]) : null,
45
+ commitsBlock(commits, { added: t('plan.goesOut'), removed: t('plan.onlyOnServer'), same: t('plan.nothingNew') }),
45
46
  ], { actions: range && range.relation !== 'same' ? [summary ? el('span', { class: 'muted' }, summary) : null, rangeSpan(range)] : [] });
46
47
  }
47
48
  function findings(list) {
48
49
  if (list.length === 0)
49
- return [banner('ok', 'No problem found.')];
50
+ return [banner('ok', t('plan.noProblem'))];
50
51
  const sorted = [...list].sort((a, b) => (a.level === b.level ? 0 : a.level === 'error' ? -1 : 1));
51
52
  const errors = list.filter((f) => f.level === 'error').length;
52
- return [card('Findings', [findingList(sorted)], {
53
+ return [card(t('plan.findings'), [findingList(sorted)], {
53
54
  bodyClass: 'flush',
54
- actions: [el('span', { class: 'muted' }, `${errors} error${errors === 1 ? '' : 's'}, ${list.length - errors} warning${list.length - errors === 1 ? '' : 's'}`)],
55
+ actions: [el('span', { class: 'muted' }, `${t('plan.errors', { count: errors })}, ${t('plan.warnings', { count: list.length - errors })}`)],
55
56
  })];
56
57
  }
57
58
  /** Findings with a severity badge; the fix is copyable text, never run by the page. */
@@ -59,24 +60,24 @@ export function findingList(list, label) {
59
60
  return el('ul', { class: 'findings', ...(label ? { aria: { label } } : {}) }, ...list.map((f) => findingItem(f)));
60
61
  }
61
62
  export function findingItem(f) {
62
- return el('li', { class: 'finding' }, el('span', { class: `sev sev-${f.level === 'error' ? 'error' : 'warning'}` }, f.level === 'error' ? 'Error ' : 'Warning '), el('span', { class: 'finding-msg' }, f.id ? el('span', { class: 'finding-id' }, `[${f.id}] `) : null, f.message), f.fix ? el('div', { class: 'fix' }, el('span', { class: 'fix-label' }, 'Fix: '), el('code', {}, f.fix)) : null);
63
+ return el('li', { class: 'finding' }, el('span', { class: `sev sev-${f.level === 'error' ? 'error' : 'warning'}` }, f.level === 'error' ? t('sev.error') : t('sev.warning')), el('span', { class: 'finding-msg' }, f.id ? el('span', { class: 'finding-id' }, `[${f.id}] `) : null, f.message), f.fix ? el('div', { class: 'fix' }, el('span', { class: 'fix-label' }, t('plan.fix')), el('code', {}, f.fix)) : null);
63
64
  }
64
65
  function questionField(question, index) {
65
66
  const id = `q-${index}`;
66
- const label = el('label', { for: id }, question.message, question.optional ? '' : el('span', { class: 'required', title: 'required' }, ' *'), question.key ? el('span', { class: 'field-key' }, ` (${question.key})`) : null);
67
+ const label = el('label', { for: id }, question.message, question.optional ? '' : el('span', { class: 'required', title: t('form.required') }, ' *'), question.key ? el('span', { class: 'field-key' }, ` (${question.key})`) : null);
67
68
  let input;
68
69
  if (question.kind === 'secret') {
69
70
  // No default, no autocomplete, no spellcheck: a secret is typed, sent once, and the field is emptied.
70
71
  input = el('input', { type: 'password', id, autocomplete: 'off', spellcheck: false, required: !question.optional, aria: { describedby: `${id}-error` } });
71
72
  }
72
73
  else if (question.kind === 'choice') {
73
- input = el('select', { id, aria: { describedby: `${id}-error` } }, ...(question.optional ? [el('option', { value: '' }, '(none)')] : []), ...(question.choices ?? []).map((c) => el('option', { value: c }, c)));
74
+ input = el('select', { id, aria: { describedby: `${id}-error` } }, ...(question.optional ? [el('option', { value: '' }, t('form.none'))] : []), ...(question.choices ?? []).map((c) => el('option', { value: c }, c)));
74
75
  if (question.default !== undefined)
75
76
  input.value = question.default;
76
77
  }
77
78
  else if (question.kind === 'confirm') {
78
79
  input = el('input', { type: 'checkbox', id, checked: question.default === 'yes' || question.default === 'true', aria: { describedby: `${id}-error` } });
79
- return { node: el('div', { class: 'field check' }, el('label', { for: id }, input, el('span', {}, question.message, question.optional ? '' : el('span', { class: 'required', title: 'required' }, ' *'), question.key ? el('span', { class: 'field-key' }, ` (${question.key})`) : null)), el('span', { id: `${id}-error`, class: 'field-error' })), field: { question, input } };
80
+ return { node: el('div', { class: 'field check' }, el('label', { for: id }, input, el('span', {}, question.message, question.optional ? '' : el('span', { class: 'required', title: t('form.required') }, ' *'), question.key ? el('span', { class: 'field-key' }, ` (${question.key})`) : null)), el('span', { id: `${id}-error`, class: 'field-error' })), field: { question, input } };
80
81
  }
81
82
  else {
82
83
  input = el('input', { type: 'text', id, value: question.default ?? '', autocomplete: 'off', spellcheck: false, required: !question.optional, aria: { describedby: `${id}-error` } });
@@ -104,7 +105,7 @@ function clearFields(fields) {
104
105
  }
105
106
  }
106
107
  function deployForm(app, questions, blocking) {
107
- const t = app.current;
108
+ const target = app.current;
108
109
  const fields = [];
109
110
  const nodes = questions.map((q, i) => {
110
111
  const { node, field } = questionField(q, i);
@@ -122,7 +123,7 @@ function deployForm(app, questions, blocking) {
122
123
  replace(slot, text);
123
124
  };
124
125
  const send = async (route) => {
125
- if (!t)
126
+ if (!target)
126
127
  return;
127
128
  replace(message);
128
129
  for (let i = 0; i < questions.length; i++) {
@@ -132,33 +133,33 @@ function deployForm(app, questions, blocking) {
132
133
  }
133
134
  const deploy = route === 'run';
134
135
  const ok = await confirmDialog({
135
- title: deploy ? `Deploy to ${t.name}?` : `Write the .env on ${t.name}?`,
136
- context: `${t.ssh} · ${t.dir}${app.hello ? ` · host ${app.hello.host}` : ''}${app.status ? ` · app ${app.status.app}` : ''}`,
136
+ title: deploy ? t('plan.deployTo', { name: target.name }) : t('plan.writeEnvOn', { name: target.name }),
137
+ context: [target.ssh, target.dir, app.hello ? t('ctx.hostPart', { host: app.hello.host }) : null, app.status ? t('ctx.appPart', { app: app.status.app }) : null].filter(Boolean).join(' · '),
137
138
  lines: [
138
- deploy ? 'Fetch, .env, build, migrate, restart, health check — the run goes on on the server if this page closes (unless attended).' : 'The .env and the dedicated infra only; nothing is built or restarted.',
139
- deploy && app.plan?.lines.some((l) => /migrat/i.test(l.step) || /migrat/i.test(l.text)) ? el('strong', {}, 'This will migrate the database.') : null,
139
+ deploy ? t('plan.deployLine') : t('plan.envLine'),
140
+ deploy && app.plan?.lines.some((l) => /migrat/i.test(l.step) || /migrat/i.test(l.text)) ? el('strong', {}, t('plan.willMigrate')) : null,
140
141
  ],
141
- confirmLabel: deploy ? 'Deploy' : 'Write .env',
142
+ confirmLabel: deploy ? t('plan.deploy') : t('plan.writeEnv'),
142
143
  danger: true,
143
- ...(t.protected ? { typeToConfirm: t.name } : {}),
144
+ ...(target.protected ? { typeToConfirm: target.name } : {}),
144
145
  });
145
146
  if (!ok)
146
147
  return;
147
148
  const answers = collectAnswers(fields);
148
149
  clearFields(fields);
149
- const body = { target: t.name, confirm: true, confirmedTarget: t, answers, ...(t.protected ? { confirmName: t.name } : {}) };
150
+ const body = { target: target.name, confirm: true, confirmedTarget: target, answers, ...(target.protected ? { confirmName: target.name } : {}) };
150
151
  if (!deploy) {
151
- app.attended(`env on ${t.name}`, 'env', body);
152
+ app.attended(t('plan.envOn', { name: target.name }), 'env', body);
152
153
  return;
153
154
  }
154
155
  if (unhold.checked)
155
156
  body['unhold'] = true;
156
157
  if (attended.checked) {
157
158
  body['attended'] = true;
158
- app.attended(`run on ${t.name} (attended)`, 'run', body);
159
+ app.attended(t('plan.runAttended', { name: target.name }), 'run', body);
159
160
  return;
160
161
  }
161
- replace(message, el('p', { class: 'muted' }, 'Starting the run on the server…'));
162
+ replace(message, el('p', { class: 'muted' }, t('plan.starting')));
162
163
  let reply;
163
164
  try {
164
165
  reply = await app.api.post('run', body);
@@ -174,15 +175,15 @@ function deployForm(app, questions, blocking) {
174
175
  const result = reply.result;
175
176
  if (reply.ok && result?.runId) {
176
177
  replace(message);
177
- app.watch(result.runId, `run ${result.runId}`);
178
+ app.watch(result.runId, t('run.title', { runId: result.runId }));
178
179
  return;
179
180
  }
180
181
  if (reply.error && /^answer-/.test(reply.error.code)) {
181
182
  const id = /env\.[A-Z_][A-Z0-9_]*/.exec(reply.error.message)?.[0];
182
183
  if (id)
183
- showFieldError(id, `${reply.error.message} — type it again`);
184
+ showFieldError(id, t('plan.typeAgain', { message: reply.error.message }));
184
185
  }
185
186
  replace(message, problem(reply));
186
187
  };
187
- return el('form', { class: 'card', aria: { label: 'Deploy' }, on: { submit: (event) => { event.preventDefault(); void send('run'); } } }, el('div', { class: 'card-head' }, el('h3', {}, questions.length > 0 ? 'What the run will ask' : 'Deploy'), t?.protected ? el('span', { class: 'badge badge-protected' }, icon('shield'), 'PROTECTED') : null), el('div', { class: 'card-body' }, el('p', { class: 'form-note' }, icon(questions.length > 0 ? 'lock' : 'ok'), questions.length > 0 ? 'Secrets are sent once, over your ssh, to the deploy on the server; they are never stored here and the fields are emptied after sending.' : 'Nothing to answer: the .env is complete.'), nodes.length > 0 ? el('div', { class: 'form-section' }, ...nodes) : null, el('div', { class: 'form-section' }, hold ? el('div', { class: 'field check' }, el('label', { for: 'unhold' }, unhold, el('span', {}, ' Deploy anyway: the held commit ', el('code', {}, hold.sha.slice(0, 12)), ' may be deployed (--unhold)'))) : null, el('details', { class: 'advanced' }, el('summary', {}, 'Advanced'), el('div', { class: 'field check' }, el('label', { for: 'attended' }, attended, el('span', {}, ' Attended: the run stops at its next step if this page closes or the UI quits'))))), blocking ? banner('err', 'The plan found problems that stop a run: fix them first.') : null, message), el('div', { class: 'card-foot' }, button('Write .env only…', () => { void send('env'); }), el('button', { type: 'submit', class: 'primary', disabled: blocking }, 'Deploy…')));
188
+ return el('form', { class: 'card', aria: { label: t('plan.deploy') }, on: { submit: (event) => { event.preventDefault(); void send('run'); } } }, el('div', { class: 'card-head' }, el('h3', {}, questions.length > 0 ? t('plan.willAsk') : t('plan.deploy')), target?.protected ? el('span', { class: 'badge badge-protected' }, icon('shield'), t('protected.badge')) : null), el('div', { class: 'card-body' }, el('p', { class: 'form-note' }, icon(questions.length > 0 ? 'lock' : 'ok'), questions.length > 0 ? t('plan.secrets') : t('plan.nothingToAnswer')), nodes.length > 0 ? el('div', { class: 'form-section' }, ...nodes) : null, el('div', { class: 'form-section' }, hold ? el('div', { class: 'field check' }, el('label', { for: 'unhold' }, unhold, el('span', {}, t('plan.unhold'), el('code', {}, hold.sha.slice(0, 12)), t('plan.unholdTail')))) : null, el('details', { class: 'advanced' }, el('summary', {}, t('plan.advanced')), el('div', { class: 'field check' }, el('label', { for: 'attended' }, attended, el('span', {}, t('plan.attended')))))), blocking ? banner('err', t('plan.blocks')) : null, message), el('div', { class: 'card-foot' }, button(t('plan.writeEnvOnly'), () => { void send('env'); }), el('button', { type: 'submit', class: 'primary', disabled: blocking }, t('plan.deployEllipsis'))));
188
189
  }
@@ -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,7 +185,7 @@ 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
190
  this.outcome.append(resultBanner(event.command, event.data, this.runId ? this.app.previewedRollbacks.get(this.runId) : undefined));
190
191
  return;
@@ -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,7 +312,7 @@ 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
  }
@@ -322,23 +322,27 @@ export class RunView {
322
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
331
  if (command === 'rollback') {
332
332
  const to = clean(d['to']);
333
- return banner(d['status'] === 'ok' ? 'ok' : 'err', `Rolled back to ${to.slice(0, 12)}: ${clean(d['status'])}`, [
334
- `${clean(d['held']).slice(0, 12)} is held`,
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
335
  // The releases moved between the preview and the run: say which commit the deploy chose.
336
- previewed && to && previewed !== to ? el('strong', {}, `The deploy chose ${to.slice(0, 12)}, not ${clean(previewed).slice(0, 12)} the preview showed: open History to see what changed.`) : '',
336
+ previewed && to && previewed !== to ? el('strong', {}, t('run.deployChose', { to: to.slice(0, 12), previewed: clean(previewed).slice(0, 12) })) : '',
337
337
  ]);
338
338
  }
339
339
  if (command === 'env') {
340
340
  const changes = Array.isArray(d['changes']) ? d['changes'] : [];
341
- 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'])}`));
342
342
  }
343
- 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;
344
348
  }
@@ -1,60 +1,62 @@
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
+ import { driftBanner } from './version.js';
5
7
  /** Status: from `StatusResult` — release, process, lock, active and last run, hold. Refresh is manual (and once after an action). */
6
8
  export function renderStatus(app) {
7
9
  const reply = app.statusReply;
8
10
  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);
11
+ 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, app.hello ? driftBanner(app.hello.version) : 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
12
  }
11
13
  function statusPanels(app, s) {
12
14
  const current = s.releases.find((r) => r.status === 'ok');
13
15
  const panels = [];
14
16
  if (s.hold) {
15
- panels.push(banner('warn', `Commit ${short(s.hold.sha)} is held since ${when(s.hold.at)} by ${s.hold.actor}`, [
17
+ panels.push(banner('warn', t('status.held', { sha: short(s.hold.sha), at: when(s.hold.at), actor: s.hold.actor }), [
16
18
  s.hold.note,
17
- 'A run refuses it until the branch moves on; "Deploy anyway" in Plan & deploy overrides that once.',
19
+ t('status.heldHelp'),
18
20
  ]));
19
21
  }
20
22
  if (s.activeRun) {
21
23
  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' })] }));
24
+ panels.push(card(t('status.activeRun'), [
25
+ el('p', { class: 'lead' }, run.alive ? pill('run', t('status.alive')) : pill('warn', t('status.notSeenAlive')), el('span', { class: 'mono' }, run.runId)),
26
+ kv([[t('status.command'), run.command], [t('status.actor'), run.actor], [t('status.started'), el('span', { class: 'num' }, when(run.startedAt))]]),
27
+ ], { class: 'accent', actions: [button(t('status.attach'), () => { app.watch(run.runId, `${run.command} ${run.runId}`); }, { class: 'primary' })] }));
26
28
  }
27
- const releaseCard = card('Current release', current
29
+ const releaseCard = card(t('status.currentRelease'), current
28
30
  ? [
29
- el('p', { class: 'lead' }, pill('ok', 'healthy'), el('code', {}, short(current.sha))),
31
+ el('p', { class: 'lead' }, pill('ok', t('status.healthy')), el('code', {}, short(current.sha))),
30
32
  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,
33
+ [t('status.deployed'), el('span', { class: 'num' }, when(current.at))],
34
+ [t('status.by'), current.via ? t('status.via', { who: current.actor ?? current.user, via: current.via }) : current.actor ?? current.user],
35
+ current.migrations.length > 0 ? [t('status.migrations'), el('span', { class: 'mono' }, current.migrations.join(', '))] : null,
34
36
  ]),
35
37
  ]
36
- : [el('p', { class: 'muted' }, 'No healthy release recorded yet.')]);
37
- const processCard = card('Process', s.process.kind === 'pm2'
38
+ : [el('p', { class: 'muted' }, t('status.noHealthy'))]);
39
+ const processCard = card(t('status.process'), s.process.kind === 'pm2'
38
40
  ? [
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]),
41
+ 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})`) : ''),
42
+ 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
43
  ]
42
44
  : [el('pre', { class: 'diagnostics' }, s.process.lines.join('\n'))]);
43
45
  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.'))]
46
+ const lockCard = card(t('status.lock'), !lock
47
+ ? [el('p', { class: 'lead' }, pill('ok', t('status.free')), el('span', { class: 'muted' }, t('status.freeText')))]
46
48
  : [
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,
49
+ 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),
50
+ lock.holder ? el('p', {}, t('status.lockHolder', { ...lock.holder, since: when(lock.holder.startedAt) })) : null,
51
+ lock.stale ? el('p', { class: 'status-warn' }, el('strong', {}, t('status.staleNote'))) : null,
50
52
  ]);
51
- const lastRunCard = s.lastRun ? lastRun(app, s.lastRun) : card('Last run', [el('p', { class: 'muted' }, 'No run recorded yet.')]);
53
+ const lastRunCard = s.lastRun ? lastRun(app, s.lastRun) : card(t('status.lastRun'), [el('p', { class: 'muted' }, t('status.noRun'))]);
52
54
  panels.push(el('div', { class: 'grid-2' }, releaseCard, processCard, lockCard, lastRunCard));
53
55
  return panels;
54
56
  }
55
57
  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' })] });
58
+ return card(t('status.lastRun'), [
59
+ 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)),
60
+ kv([[t('status.command'), run.command || t('status.unknownCommand')], run.endedAt ? [t('status.ended'), el('span', { class: 'num' }, when(run.endedAt))] : null]),
61
+ ], { actions: [button(t('status.showLog'), () => { app.watch(run.runId, `${run.command} ${run.runId}`, true); }, { class: 'sm' })] });
60
62
  }