@epekta/armarius-astro 0.1.0 → 0.1.1

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 CHANGED
@@ -128,7 +128,7 @@ Le build écrit, dans le dossier du site :
128
128
 
129
129
  - `.armarius/sync/pages.json`, `contents.json`, `page-contents.json` : les corps que la CI du site
130
130
  poste, dans cet ordre, à `POST /api/nuxt/pages`, `/api/nuxt/contents` et `/api/nuxt/page-contents` ;
131
- - `.armarius/manifest.json` : l'empreinte de chaque texte du code, que lit `check`.
131
+ - `.armarius/manifest.json` : l'empreinte et la valeur de chaque texte du code, que lit `check`.
132
132
 
133
133
  Le kit ne signe rien : le modèle de CI du site signe chaque envoi sous la forme horodatée,
134
134
  `X-Signature: <ts>.<hex>`, un HMAC-SHA256 (clé `API_NUXT_SECRET` d'Armarius) qui lie l'horodatage, la
@@ -147,8 +147,11 @@ npx armarius-astro check
147
147
  ```
148
148
 
149
149
  En lecture seule, depuis le manifeste du dernier build : nomme les textes changés à la fois dans le
150
- code et dans l'administration, dont la synchro garde la valeur de l'administration. Le build imprime
151
- le même rapport. Rend toujours 0 ; ce qu'il ne peut pas lire (pas de manifeste, API injoignable,
150
+ code et dans l'administration, dont la synchro garde la valeur de l'administration. Sous chacun, une
151
+ ligne par valeur, ramenée sur une ligne et coupée au milieu au-delà de 72 caractères : celle de
152
+ l'administration (`admin (kept)`), puis celle du code (`code (discarded)`). Un manifeste écrit par
153
+ la version 0.1.0 n'a que l'empreinte : la valeur du code y manque jusqu'au build suivant. Le build
154
+ imprime le même rapport. Rend toujours 0 ; ce qu'il ne peut pas lire (pas de manifeste, API injoignable,
152
155
  `src/` plus récent que le build), il le dit.
153
156
 
154
157
  ## Import
package/dist/check.d.ts CHANGED
@@ -1,9 +1,23 @@
1
1
  import { type StoredText } from './render.js';
2
2
  import type { BuildManifest } from './sync.js';
3
3
  export declare const MANIFEST_PATH = ".armarius/manifest.json";
4
+ /** Characters a value keeps on its line of the report, cut in the middle beyond. */
5
+ export declare const REPORT_VALUE_WIDTH = 72;
6
+ export interface TextConflict {
7
+ name: string;
8
+ /** What the admin holds, and the sync keeps. */
9
+ adminValue: string;
10
+ /** What the code holds, and the sync discards; null from a manifest of 0.1.0, which kept only its hash. */
11
+ codeValue: string | null;
12
+ }
4
13
  /** Texts changed in the code since the last sync, and in the admin too: the sync will keep the admin's. */
5
- export declare function conflicts(manifest: Pick<BuildManifest, 'texts'>, stored: Record<string, StoredText>): string[];
6
- export declare function conflictReport(names: string[]): string[];
14
+ export declare function conflicts(manifest: Pick<BuildManifest, 'texts' | 'codeValues'>, stored: Record<string, StoredText>): TextConflict[];
15
+ /**
16
+ * A value on one line: its whitespace runs as one space, its control and bidirectional characters dropped (an
17
+ * admin's text must not repaint the terminal nor the CI log), and its middle cut out beyond `width` characters.
18
+ */
19
+ export declare function oneLine(value: string, width?: number): string;
20
+ export declare function conflictReport(found: TextConflict[]): string[];
7
21
  /**
8
22
  * `armarius-astro check`, read only: from the manifest of the last build, asks Armarius for the texts and
9
23
  * prints the conflicts. Always ends with code 0; what it cannot read, it says.
package/dist/check.js CHANGED
@@ -7,18 +7,41 @@ export const MANIFEST_PATH = '.armarius/manifest.json';
7
7
  /** Conflicts are rare and the check informs: one attempt more than none is enough. */
8
8
  const CHECK_RETRIES = 1;
9
9
  const CHECK_TIMEOUT_MS = 10_000;
10
+ /** Characters a value keeps on its line of the report, cut in the middle beyond. */
11
+ export const REPORT_VALUE_WIDTH = 72;
10
12
  /** Texts changed in the code since the last sync, and in the admin too: the sync will keep the admin's. */
11
13
  export function conflicts(manifest, stored) {
12
14
  return Object.keys(manifest.texts)
13
15
  .filter(name => isConflict(manifest.texts[name], stored[name]))
14
- .sort();
16
+ .sort()
17
+ .map(name => ({
18
+ name,
19
+ adminValue: stored[name]?.content ?? '',
20
+ codeValue: manifest.codeValues?.[name] ?? null,
21
+ }));
15
22
  }
16
- export function conflictReport(names) {
17
- if (names.length === 0)
23
+ /**
24
+ * A value on one line: its whitespace runs as one space, its control and bidirectional characters dropped (an
25
+ * admin's text must not repaint the terminal nor the CI log), and its middle cut out beyond `width` characters.
26
+ */
27
+ export function oneLine(value, width = REPORT_VALUE_WIDTH) {
28
+ const characters = Array.from(value.replace(/\s+/g, ' ').replace(/[\p{Cc}\u202A-\u202E\u2066-\u2069]/gu, '').trim());
29
+ if (characters.length <= width)
30
+ return characters.join('');
31
+ const kept = width - 1;
32
+ const head = Math.ceil(kept / 2);
33
+ return `${characters.slice(0, head).join('')}…${characters.slice(characters.length - (kept - head)).join('')}`;
34
+ }
35
+ export function conflictReport(found) {
36
+ if (found.length === 0)
18
37
  return ['armarius-astro check: no text changed both in the code and in the admin.'];
19
38
  return [
20
- `armarius-astro check: ${names.length} text(s) changed both in the code and in the admin; the sync keeps the admin's value:`,
21
- ...names.map(name => ` - ${name}`),
39
+ `armarius-astro check: ${found.length} text(s) changed both in the code and in the admin; the sync keeps the admin's value:`,
40
+ ...found.flatMap(conflict => [
41
+ ` - ${conflict.name}`,
42
+ ` admin (kept): ${oneLine(conflict.adminValue)}`,
43
+ ` code (discarded): ${conflict.codeValue === null ? '(not in this manifest; build again to see it)' : oneLine(conflict.codeValue)}`,
44
+ ]),
22
45
  ];
23
46
  }
24
47
  async function newestModification(directory) {
package/dist/sync.d.ts CHANGED
@@ -35,13 +35,17 @@ export interface SyncBodies {
35
35
  pages: PageContentsPayload[];
36
36
  };
37
37
  }
38
- /** What `armarius-astro check` reads: where the build read, and the hash of each text of the code. */
38
+ /**
39
+ * What `armarius-astro check` reads: where the build read, the hash of each text of the code and, since 0.1.1, its
40
+ * value. A manifest of 0.1.0 has no `codeValues`; `check` reads it all the same.
41
+ */
39
42
  export interface BuildManifest {
40
43
  version: 1;
41
44
  apiOrigin: string;
42
45
  locale: string;
43
46
  builtAt: string;
44
47
  texts: Record<string, string>;
48
+ codeValues?: Record<string, string>;
45
49
  }
46
50
  export declare class ArmariusSyncError extends Error {
47
51
  name: string;
package/dist/sync.js CHANGED
@@ -62,9 +62,12 @@ export function syncBodies(pages, contents) {
62
62
  }
63
63
  export function buildManifest(options, contents, builtAt) {
64
64
  const texts = {};
65
+ const codeValues = {};
65
66
  for (const content of [...contents].sort((left, right) => left.name.localeCompare(right.name))) {
66
- if (content.kind === 'text')
67
- texts[content.name] = codeHash(content.value);
67
+ if (content.kind !== 'text')
68
+ continue;
69
+ texts[content.name] = codeHash(content.value);
70
+ codeValues[content.name] = content.value;
68
71
  }
69
- return { version: 1, apiOrigin: options.apiOrigin, locale: options.locale, builtAt: builtAt.toISOString(), texts };
72
+ return { version: 1, apiOrigin: options.apiOrigin, locale: options.locale, builtAt: builtAt.toISOString(), texts, codeValues };
70
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epekta/armarius-astro",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Kit of a static Astro site rebuilt by Armarius: texts, images, pages and records read at build, sync bodies, in-place editing boot.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",