@textmode/docs 0.4.0 → 0.4.2

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
@@ -171,3 +171,13 @@ The `@textmode/docs` package is licensed under the [CC0 1.0 Universal](./LICENSE
171
171
  - **[`typedoc-plugin-markdown`](https://typedoc-plugin-markdown.org/)**
172
172
  - Markdown output and the frontmatter and VitePress theme plugins used for API pages.
173
173
  - License: [MIT License](https://github.com/typedoc2md/typedoc-plugin-markdown/blob/main/LICENSE).
174
+
175
+ ### Preserve published page dates
176
+
177
+ After generating documentation and applying all publishing transformations, reconcile the final Markdown against the previous published pages:
178
+
179
+ ```sh
180
+ textmode-docs dates reconcile --baseline ./previous-api --target ./new-api
181
+ ```
182
+
183
+ The command preserves `lastModified` when a page is unchanged, ignoring the date field itself. It assigns the current UTC date to changed pages, new pages, and unchanged pages without a previous date. Deleted pages are ignored. `--date YYYY-MM-DD` can supply a date for reproducible builds. Keep the baseline outside the target directory: TypeDoc cleans its output during generation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textmode/docs",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "license": "CC0-1.0",
6
6
  "description": "Shared documentation generation and validation for the textmode.js ecosystem",
@@ -4,6 +4,7 @@ import fs from 'node:fs';
4
4
  import process from 'node:process';
5
5
  import { parseArgs } from 'node:util';
6
6
 
7
+ import { reconcileDates } from '../internal/reconcile-dates.js';
7
8
  import { formatResolvedConfig, resolveDocsConfig } from '../internal/config.js';
8
9
  import {
9
10
  addApiLinks,
@@ -25,6 +26,7 @@ function printGeneralHelp() {
25
26
  console.log(' check Validate generated docs, public API docs, and examples');
26
27
  console.log(' build [--out <directory>] Generate documentation');
27
28
  console.log(' watch [--out <directory>] Generate documentation and watch for changes');
29
+ console.log(' dates reconcile --baseline <directory> --target <directory> [--date YYYY-MM-DD]');
28
30
  console.log(' links add Insert or update public API links in source JSDoc');
29
31
  console.log(' api-check [--include-accessors]');
30
32
  console.log(' Run the focused public API documentation check');
@@ -123,6 +125,25 @@ function commandDetails(command) {
123
125
  }
124
126
 
125
127
  async function run(argv) {
128
+ if (argv[0] === 'dates' && argv[1] === 'reconcile') {
129
+ try {
130
+ const { values, positionals } = parseArgs({
131
+ args: argv.slice(2),
132
+ strict: true,
133
+ options: { baseline: { type: 'string' }, target: { type: 'string' }, date: { type: 'string' } },
134
+ });
135
+ if (positionals.length || !values.baseline || !values.target)
136
+ throw new Error(
137
+ 'Usage: textmode-docs dates reconcile --baseline <directory> --target <directory> [--date YYYY-MM-DD]'
138
+ );
139
+ const count = await reconcileDates(values);
140
+ console.log(`Reconciled dates for ${count} pages.`);
141
+ } catch (error) {
142
+ console.error(error instanceof Error ? error.message : String(error));
143
+ process.exitCode = 1;
144
+ }
145
+ return;
146
+ }
126
147
  let cli;
127
148
  try {
128
149
  cli = parseCli(argv);
@@ -0,0 +1,72 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ // Work on the YAML block as text so other fields and the page body stay byte-for-byte intact.
5
+ function splitDate(markdown) {
6
+ const match = /^(---\r?\n)([\s\S]*?)(^---[ \t]*\r?\n|^---[ \t]*$)/m.exec(markdown);
7
+ if (!match || match.index !== 0) throw new Error('Markdown page is missing YAML frontmatter.');
8
+ let date;
9
+ const fields = match[2].replace(/^lastModified:[ \t]*([^\r\n]*)\r?\n/gm, (_, value) => {
10
+ if (date !== undefined) throw new Error('Duplicate lastModified field.');
11
+ date = value.trim().replace(/^['"]|['"]$/g, '');
12
+ return '';
13
+ });
14
+ return { date, content: match[1] + fields + match[3] + markdown.slice(match[0].length) };
15
+ }
16
+
17
+ async function markdownFiles(directory, prefix = '') {
18
+ const entries = await fs.readdir(path.join(directory, prefix), { withFileTypes: true });
19
+ const files = [];
20
+ for (const entry of entries) {
21
+ const relative = path.join(prefix, entry.name);
22
+ if (entry.isDirectory()) files.push(...(await markdownFiles(directory, relative)));
23
+ else if (entry.isFile() && entry.name.endsWith('.md')) files.push(relative);
24
+ }
25
+ return files.sort();
26
+ }
27
+
28
+ export async function reconcileDates({ baseline, target, date = new Date().toISOString().slice(0, 10) }) {
29
+ baseline = path.resolve(baseline);
30
+ target = path.resolve(target);
31
+ if (baseline === target || baseline.startsWith(target + path.sep) || target.startsWith(baseline + path.sep)) {
32
+ throw new Error('Baseline and target must be separate directories.');
33
+ }
34
+ const timestamp = Date.parse(`${date}T00:00:00Z`);
35
+ if (
36
+ !/^\d{4}-\d{2}-\d{2}$/.test(date) ||
37
+ Number.isNaN(timestamp) ||
38
+ new Date(timestamp).toISOString().slice(0, 10) !== date
39
+ ) {
40
+ throw new Error('Date must be in YYYY-MM-DD format.');
41
+ }
42
+ await fs.access(baseline);
43
+ const files = await markdownFiles(target);
44
+ for (const file of files) {
45
+ const targetPath = path.join(target, file);
46
+ const current = splitDate(await fs.readFile(targetPath, 'utf8'));
47
+ let previous;
48
+ try {
49
+ previous = splitDate(await fs.readFile(path.join(baseline, file), 'utf8'));
50
+ } catch (error) {
51
+ if (error.code !== 'ENOENT') throw error;
52
+ }
53
+ const lastModified = previous && previous.content === current.content && previous.date ? previous.date : date;
54
+ const output = current.content.replace(
55
+ /^(---\r?\n)([\s\S]*?)(^---[ \t]*\r?\n|^---[ \t]*$)/m,
56
+ (_, opening, fields, closing) => {
57
+ const marker = /^(?:hasConstructor|isInterface):/m.exec(fields);
58
+ const position = marker ? marker.index : fields.length;
59
+ const newline = opening.endsWith('\r\n') ? '\r\n' : '\n';
60
+ return (
61
+ opening +
62
+ fields.slice(0, position) +
63
+ `lastModified: ${lastModified}${newline}` +
64
+ fields.slice(position) +
65
+ closing
66
+ );
67
+ }
68
+ );
69
+ await fs.writeFile(targetPath, output);
70
+ }
71
+ return files.length;
72
+ }
@@ -32,7 +32,7 @@ Descriptions come from the first useful TypeDoc comment summary on the reflectio
32
32
  setter signature. The summary is reduced to the first paragraph, sanitized for YAML frontmatter, and truncated to a
33
33
  short SEO-friendly length. If no summary exists, the plugin generates a kind-specific fallback description.
34
34
 
35
- `lastModified` preserves an explicitly supplied source date. A regeneration does not invent a new modification date. The documentation site uses Git history for last-updated and sitemap dates.
35
+ `lastModified` preserves an explicitly supplied source date. A regeneration does not invent a new modification date. Run `textmode-docs dates reconcile` after all publishing transformations to retain and update published page dates. The documentation site separately uses Git history for last-updated and sitemap dates.
36
36
 
37
37
  Packages whose names start with `textmode` are assigned to the `textmode.js` ecosystem. Other package names use their
38
38
  own name as the ecosystem.