rclnodejs 1.8.3 → 1.9.0-alpha.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.
Files changed (85) hide show
  1. package/README.md +46 -37
  2. package/index.js +29 -0
  3. package/lib/action/client.js +61 -3
  4. package/lib/message_info.js +94 -0
  5. package/lib/node.js +53 -3
  6. package/lib/parameter_event_handler.js +468 -0
  7. package/lib/parameter_watcher.js +12 -12
  8. package/lib/subscription.js +38 -5
  9. package/lib/timer.js +2 -1
  10. package/lib/wait_for_message.js +111 -0
  11. package/package.json +6 -3
  12. package/prebuilds/linux-arm64/humble-jammy-arm64-rclnodejs.node +0 -0
  13. package/prebuilds/linux-arm64/jazzy-noble-arm64-rclnodejs.node +0 -0
  14. package/prebuilds/linux-arm64/kilted-noble-arm64-rclnodejs.node +0 -0
  15. package/prebuilds/linux-x64/humble-jammy-x64-rclnodejs.node +0 -0
  16. package/prebuilds/linux-x64/jazzy-noble-x64-rclnodejs.node +0 -0
  17. package/prebuilds/linux-x64/kilted-noble-x64-rclnodejs.node +0 -0
  18. package/scripts/run_asan_test.sh +118 -0
  19. package/src/executor.cpp +36 -2
  20. package/src/executor.h +11 -0
  21. package/src/rcl_action_client_bindings.cpp +70 -1
  22. package/src/rcl_context_bindings.cpp +3 -3
  23. package/src/rcl_graph_bindings.cpp +2 -2
  24. package/src/rcl_subscription_bindings.cpp +70 -2
  25. package/src/rcl_utilities.cpp +2 -2
  26. package/tools/jsdoc/Makefile +5 -0
  27. package/tools/jsdoc/README.md +96 -0
  28. package/tools/jsdoc/build-index.js +610 -0
  29. package/tools/jsdoc/publish.js +854 -0
  30. package/tools/jsdoc/regenerate-published-docs.js +605 -0
  31. package/tools/jsdoc/static/fonts/OpenSans-Bold-webfont.eot +0 -0
  32. package/tools/jsdoc/static/fonts/OpenSans-Bold-webfont.svg +1830 -0
  33. package/tools/jsdoc/static/fonts/OpenSans-Bold-webfont.woff +0 -0
  34. package/tools/jsdoc/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  35. package/tools/jsdoc/static/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  36. package/tools/jsdoc/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  37. package/tools/jsdoc/static/fonts/OpenSans-Italic-webfont.eot +0 -0
  38. package/tools/jsdoc/static/fonts/OpenSans-Italic-webfont.svg +1830 -0
  39. package/tools/jsdoc/static/fonts/OpenSans-Italic-webfont.woff +0 -0
  40. package/tools/jsdoc/static/fonts/OpenSans-Light-webfont.eot +0 -0
  41. package/tools/jsdoc/static/fonts/OpenSans-Light-webfont.svg +1831 -0
  42. package/tools/jsdoc/static/fonts/OpenSans-Light-webfont.woff +0 -0
  43. package/tools/jsdoc/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  44. package/tools/jsdoc/static/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  45. package/tools/jsdoc/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  46. package/tools/jsdoc/static/fonts/OpenSans-Regular-webfont.eot +0 -0
  47. package/tools/jsdoc/static/fonts/OpenSans-Regular-webfont.svg +1831 -0
  48. package/tools/jsdoc/static/fonts/OpenSans-Regular-webfont.woff +0 -0
  49. package/tools/jsdoc/static/scripts/linenumber.js +25 -0
  50. package/tools/jsdoc/static/scripts/prettify/Apache-License-2.0.txt +202 -0
  51. package/tools/jsdoc/static/scripts/prettify/lang-css.js +36 -0
  52. package/tools/jsdoc/static/scripts/prettify/prettify.js +738 -0
  53. package/tools/jsdoc/static/styles/jsdoc-default.css +1012 -0
  54. package/tools/jsdoc/static/styles/prettify-jsdoc.css +111 -0
  55. package/tools/jsdoc/static/styles/prettify-tomorrow.css +132 -0
  56. package/tools/jsdoc/tmpl/augments.tmpl +10 -0
  57. package/tools/jsdoc/tmpl/container.tmpl +193 -0
  58. package/tools/jsdoc/tmpl/details.tmpl +143 -0
  59. package/tools/jsdoc/tmpl/example.tmpl +2 -0
  60. package/tools/jsdoc/tmpl/examples.tmpl +13 -0
  61. package/tools/jsdoc/tmpl/exceptions.tmpl +17 -0
  62. package/tools/jsdoc/tmpl/layout.tmpl +83 -0
  63. package/tools/jsdoc/tmpl/mainpage.tmpl +163 -0
  64. package/tools/jsdoc/tmpl/members.tmpl +43 -0
  65. package/tools/jsdoc/tmpl/method.tmpl +124 -0
  66. package/tools/jsdoc/tmpl/params.tmpl +133 -0
  67. package/tools/jsdoc/tmpl/properties.tmpl +110 -0
  68. package/tools/jsdoc/tmpl/returns.tmpl +12 -0
  69. package/tools/jsdoc/tmpl/source.tmpl +8 -0
  70. package/tools/jsdoc/tmpl/tutorial.tmpl +19 -0
  71. package/tools/jsdoc/tmpl/type.tmpl +7 -0
  72. package/types/action_client.d.ts +8 -0
  73. package/types/index.d.ts +34 -0
  74. package/types/message_info.d.ts +72 -0
  75. package/types/node.d.ts +21 -0
  76. package/types/parameter_event_handler.d.ts +139 -0
  77. package/types/subscription.d.ts +14 -2
  78. package/test_data_integrity.js +0 -108
  79. package/test_repro_exact.js +0 -57
  80. package/test_repro_hz.js +0 -86
  81. package/test_repro_pub.js +0 -36
  82. package/test_repro_stress.js +0 -83
  83. package/test_repro_sub.js +0 -64
  84. package/test_xproc_data.js +0 -64
  85. package/types/interfaces.d.ts +0 -8895
@@ -0,0 +1,605 @@
1
+ // Copyright (c) 2026 The Robot Web Tools Contributors. All rights reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ 'use strict';
16
+
17
+ const childProcess = require('child_process');
18
+ const fs = require('fs');
19
+ const os = require('os');
20
+ const path = require('path');
21
+
22
+ const repoRoot = path.resolve(__dirname, '../..');
23
+ const buildIndexScript = path.join(__dirname, 'build-index.js');
24
+ const defaultOutputRoot = path.join(repoRoot, 'build', 'gh-pages-docs');
25
+ const semverDirectoryPattern = /^\d+\.\d+\.\d+$/;
26
+ const sharedAssetDirectoryName = '_static';
27
+ const sharedAssetFolders = ['fonts', 'scripts', 'styles'];
28
+
29
+ function parseArgs(argv) {
30
+ const options = {
31
+ branch: 'gh-pages',
32
+ outputRoot: defaultOutputRoot,
33
+ versions: null,
34
+ preservePublished: false,
35
+ fullRebuild: false,
36
+ keepWorktrees: false,
37
+ };
38
+
39
+ for (let index = 0; index < argv.length; index += 1) {
40
+ const arg = argv[index];
41
+
42
+ if (arg === '--branch') {
43
+ options.branch = argv[index + 1];
44
+ index += 1;
45
+ } else if (arg === '--out') {
46
+ options.outputRoot = path.resolve(argv[index + 1]);
47
+ index += 1;
48
+ } else if (arg === '--versions') {
49
+ options.versions = argv[index + 1]
50
+ .split(',')
51
+ .map((value) => value.trim())
52
+ .filter(Boolean);
53
+ index += 1;
54
+ } else if (arg === '--preserve-published') {
55
+ options.preservePublished = true;
56
+ } else if (arg === '--full-rebuild') {
57
+ options.fullRebuild = true;
58
+ } else if (arg === '--keep-worktrees') {
59
+ options.keepWorktrees = true;
60
+ } else {
61
+ throw new Error(`Unknown argument: ${arg}`);
62
+ }
63
+ }
64
+
65
+ return options;
66
+ }
67
+
68
+ function runCommand(command, args, options = {}) {
69
+ try {
70
+ return childProcess.execFileSync(command, args, {
71
+ cwd: options.cwd || repoRoot,
72
+ encoding: 'utf8',
73
+ env: options.env || process.env,
74
+ stdio: ['ignore', 'pipe', 'pipe'],
75
+ });
76
+ } catch (error) {
77
+ const stderr = error.stderr ? String(error.stderr).trim() : '';
78
+ const stdout = error.stdout ? String(error.stdout).trim() : '';
79
+ const details = [stderr, stdout].filter(Boolean).join('\n');
80
+
81
+ throw new Error(
82
+ details
83
+ ? `${command} ${args.join(' ')}\n${details}`
84
+ : `${command} ${args.join(' ')} failed`
85
+ );
86
+ }
87
+ }
88
+
89
+ function compareVersionsAsc(left, right) {
90
+ const leftParts = left.split('.').map(Number);
91
+ const rightParts = right.split('.').map(Number);
92
+ const maxLength = Math.max(leftParts.length, rightParts.length);
93
+
94
+ for (let index = 0; index < maxLength; index += 1) {
95
+ const leftValue = leftParts[index] || 0;
96
+ const rightValue = rightParts[index] || 0;
97
+
98
+ if (leftValue !== rightValue) {
99
+ return leftValue - rightValue;
100
+ }
101
+ }
102
+
103
+ return 0;
104
+ }
105
+
106
+ function getPublishedVersions(branch) {
107
+ const output = runCommand('git', [
108
+ 'ls-tree',
109
+ '--name-only',
110
+ `${branch}:docs`,
111
+ ]);
112
+
113
+ return output
114
+ .split(/\r?\n/)
115
+ .map((entry) => entry.trim())
116
+ .filter((entry) => semverDirectoryPattern.test(entry))
117
+ .sort(compareVersionsAsc);
118
+ }
119
+
120
+ function getTaggedReleaseVersions() {
121
+ return runCommand('git', ['tag', '--list'])
122
+ .split(/\r?\n/)
123
+ .map((entry) => entry.trim())
124
+ .filter((entry) => semverDirectoryPattern.test(entry))
125
+ .sort(compareVersionsAsc);
126
+ }
127
+
128
+ function getCurrentWorkspaceVersion() {
129
+ const packageInfo = JSON.parse(
130
+ fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')
131
+ );
132
+
133
+ if (!semverDirectoryPattern.test(packageInfo.version)) {
134
+ throw new Error(
135
+ `Current package.json version is not a release semver: ${packageInfo.version}`
136
+ );
137
+ }
138
+
139
+ return packageInfo.version;
140
+ }
141
+
142
+ function assertTagsExist(versions) {
143
+ const tags = new Set(getTaggedReleaseVersions());
144
+
145
+ const missing = versions.filter((version) => !tags.has(version));
146
+
147
+ if (missing.length) {
148
+ throw new Error(
149
+ `Missing Git tags for requested versions: ${missing.join(', ')}`
150
+ );
151
+ }
152
+ }
153
+
154
+ function ensureCleanOutput(outputRoot) {
155
+ fs.rmSync(outputRoot, { recursive: true, force: true });
156
+ fs.mkdirSync(path.join(outputRoot, 'docs'), { recursive: true });
157
+ }
158
+
159
+ function getGeneratedVersions(outputRoot) {
160
+ const docsRoot = path.join(outputRoot, 'docs');
161
+
162
+ if (!fs.existsSync(docsRoot)) {
163
+ return [];
164
+ }
165
+
166
+ return fs
167
+ .readdirSync(docsRoot, { withFileTypes: true })
168
+ .filter(
169
+ (entry) => entry.isDirectory() && semverDirectoryPattern.test(entry.name)
170
+ )
171
+ .map((entry) => entry.name)
172
+ .sort(compareVersionsAsc);
173
+ }
174
+
175
+ function writeBranchFile(branch, sourcePath, destinationPath) {
176
+ try {
177
+ const contents = runCommand('git', ['show', `${branch}:${sourcePath}`]);
178
+ fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
179
+ fs.writeFileSync(destinationPath, contents, 'utf8');
180
+ } catch (error) {
181
+ if (sourcePath === '.nojekyll') {
182
+ fs.writeFileSync(destinationPath, '', 'utf8');
183
+ return;
184
+ }
185
+
186
+ throw error;
187
+ }
188
+ }
189
+
190
+ function appendJsFiles(directoryPath, inputs) {
191
+ if (!fs.existsSync(directoryPath)) {
192
+ return;
193
+ }
194
+
195
+ fs.readdirSync(directoryPath, { withFileTypes: true })
196
+ .filter((entry) => entry.isFile() && entry.name.endsWith('.js'))
197
+ .sort((left, right) => left.name.localeCompare(right.name))
198
+ .forEach((entry) => {
199
+ inputs.push(path.join(directoryPath, entry.name));
200
+ });
201
+ }
202
+
203
+ function getJsdocInputs(sourceRoot) {
204
+ const inputs = [];
205
+ const indexPath = path.join(sourceRoot, 'index.js');
206
+
207
+ if (fs.existsSync(indexPath)) {
208
+ inputs.push(indexPath);
209
+ }
210
+
211
+ appendJsFiles(path.join(sourceRoot, 'lib'), inputs);
212
+ appendJsFiles(path.join(sourceRoot, 'lib', 'action'), inputs);
213
+
214
+ if (!inputs.length) {
215
+ throw new Error(`No JSDoc input files found for ${sourceRoot}`);
216
+ }
217
+
218
+ return inputs;
219
+ }
220
+
221
+ function sanitizePathSegment(value) {
222
+ return value.replace(/[^a-zA-Z0-9._-]/g, '_');
223
+ }
224
+
225
+ function addWorktree(ref, tempRoot, directoryName = ref) {
226
+ const worktreePath = path.join(tempRoot, sanitizePathSegment(directoryName));
227
+
228
+ runCommand('git', [
229
+ 'worktree',
230
+ 'add',
231
+ '--detach',
232
+ '--force',
233
+ worktreePath,
234
+ ref,
235
+ ]);
236
+
237
+ return worktreePath;
238
+ }
239
+
240
+ function removeWorktree(worktreePath, keepWorktrees) {
241
+ if (keepWorktrees) {
242
+ return;
243
+ }
244
+
245
+ try {
246
+ runCommand('git', ['worktree', 'remove', '--force', worktreePath]);
247
+ } catch {
248
+ fs.rmSync(worktreePath, { recursive: true, force: true });
249
+ }
250
+ }
251
+
252
+ function writeIndexPackage(packageJsonPath, outputRoot) {
253
+ const packageInfo = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
254
+ const trimmedPackageInfo = {
255
+ name: packageInfo.name,
256
+ version: packageInfo.version,
257
+ repository: packageInfo.repository,
258
+ };
259
+ const destinationPath = path.join(outputRoot, '_index-package.json');
260
+
261
+ fs.writeFileSync(
262
+ destinationPath,
263
+ `${JSON.stringify(trimmedPackageInfo, null, 2)}\n`,
264
+ 'utf8'
265
+ );
266
+
267
+ return destinationPath;
268
+ }
269
+
270
+ function copyIfExists(sourcePath, destinationPath) {
271
+ if (!fs.existsSync(sourcePath)) {
272
+ return;
273
+ }
274
+
275
+ fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
276
+ fs.cpSync(sourcePath, destinationPath, { recursive: true, force: true });
277
+ }
278
+
279
+ function copyDirectoryContents(sourceDir, destinationDir) {
280
+ if (!fs.existsSync(sourceDir)) {
281
+ return;
282
+ }
283
+
284
+ fs.mkdirSync(destinationDir, { recursive: true });
285
+
286
+ fs.readdirSync(sourceDir, { withFileTypes: true }).forEach((entry) => {
287
+ fs.cpSync(
288
+ path.join(sourceDir, entry.name),
289
+ path.join(destinationDir, entry.name),
290
+ { recursive: true, force: true }
291
+ );
292
+ });
293
+ }
294
+
295
+ function copyPublishedSnapshot(branch, outputRoot, tempRoot, keepWorktrees) {
296
+ const worktreePath = addWorktree(branch, tempRoot, `branch-${branch}`);
297
+ const rootFiles = ['.nojekyll', 'README.md', '_index-package.json'];
298
+
299
+ try {
300
+ copyDirectoryContents(
301
+ path.join(worktreePath, 'docs'),
302
+ path.join(outputRoot, 'docs')
303
+ );
304
+
305
+ rootFiles.forEach((fileName) => {
306
+ copyIfExists(
307
+ path.join(worktreePath, fileName),
308
+ path.join(outputRoot, fileName)
309
+ );
310
+ });
311
+ } finally {
312
+ removeWorktree(worktreePath, keepWorktrees);
313
+ }
314
+ }
315
+
316
+ function buildVersionDocs(version, outputDocsRoot, tempRoot, keepWorktrees) {
317
+ const worktreePath = addWorktree(version, tempRoot, version);
318
+
319
+ try {
320
+ const inputs = getJsdocInputs(worktreePath);
321
+
322
+ runCommand(
323
+ 'npx',
324
+ [
325
+ 'jsdoc',
326
+ '--package',
327
+ path.join(worktreePath, 'package.json'),
328
+ ...inputs,
329
+ '-t',
330
+ __dirname,
331
+ '-d',
332
+ outputDocsRoot,
333
+ ],
334
+ { cwd: repoRoot }
335
+ );
336
+
337
+ return {
338
+ worktreePath,
339
+ packageJsonPath: path.join(worktreePath, 'package.json'),
340
+ };
341
+ } catch (error) {
342
+ removeWorktree(worktreePath, keepWorktrees);
343
+ throw error;
344
+ }
345
+ }
346
+
347
+ function buildDocsFromSourceRoot(sourceRoot, outputDocsRoot) {
348
+ const inputs = getJsdocInputs(sourceRoot);
349
+
350
+ runCommand(
351
+ 'npx',
352
+ [
353
+ 'jsdoc',
354
+ '--package',
355
+ path.join(sourceRoot, 'package.json'),
356
+ ...inputs,
357
+ '-t',
358
+ __dirname,
359
+ '-d',
360
+ outputDocsRoot,
361
+ ],
362
+ { cwd: repoRoot }
363
+ );
364
+
365
+ return {
366
+ packageJsonPath: path.join(sourceRoot, 'package.json'),
367
+ };
368
+ }
369
+
370
+ function buildDocsIndex(outputRoot, packageJsonPath) {
371
+ runCommand('node', [buildIndexScript], {
372
+ cwd: repoRoot,
373
+ env: {
374
+ ...process.env,
375
+ RCLNODEJS_DOCS_ROOT: path.join(outputRoot, 'docs'),
376
+ RCLNODEJS_DOCS_INDEX_PATH: path.join(outputRoot, 'docs', 'index.html'),
377
+ RCLNODEJS_LOCAL_INDEX_PATH: '',
378
+ RCLNODEJS_PACKAGE_JSON_PATH: packageJsonPath,
379
+ RCLNODEJS_GIT_CWD: repoRoot,
380
+ },
381
+ });
382
+ }
383
+
384
+ function removeTemporaryPublishArtifacts(outputRoot) {
385
+ ['README.md', '_index-package.json'].forEach((fileName) => {
386
+ fs.rmSync(path.join(outputRoot, fileName), { force: true });
387
+ });
388
+ }
389
+
390
+ function rewriteVersionHtmlToSharedAssets(versionRoot) {
391
+ fs.readdirSync(versionRoot, { withFileTypes: true })
392
+ .filter((entry) => entry.isFile() && entry.name.endsWith('.html'))
393
+ .forEach((entry) => {
394
+ const filePath = path.join(versionRoot, entry.name);
395
+ const original = fs.readFileSync(filePath, 'utf8');
396
+ const rewritten = original.replace(
397
+ /(href|src)="(styles|scripts)\//g,
398
+ '$1="../_static/$2/'
399
+ );
400
+
401
+ if (rewritten !== original) {
402
+ fs.writeFileSync(filePath, rewritten, 'utf8');
403
+ }
404
+ });
405
+ }
406
+
407
+ function hoistSharedAssets(outputRoot) {
408
+ const docsRoot = path.join(outputRoot, 'docs');
409
+ const versions = getGeneratedVersions(outputRoot);
410
+
411
+ if (!versions.length) {
412
+ return;
413
+ }
414
+
415
+ const sourceVersion = versions[versions.length - 1];
416
+ const sourceVersionRoot = path.join(docsRoot, sourceVersion);
417
+ const sharedRoot = path.join(docsRoot, sharedAssetDirectoryName);
418
+
419
+ fs.mkdirSync(sharedRoot, { recursive: true });
420
+
421
+ sharedAssetFolders.forEach((folderName) => {
422
+ fs.cpSync(
423
+ path.join(sourceVersionRoot, folderName),
424
+ path.join(sharedRoot, folderName),
425
+ { recursive: true, force: true }
426
+ );
427
+ });
428
+
429
+ versions.forEach((version) => {
430
+ const versionRoot = path.join(docsRoot, version);
431
+
432
+ rewriteVersionHtmlToSharedAssets(versionRoot);
433
+
434
+ sharedAssetFolders.forEach((folderName) => {
435
+ fs.rmSync(path.join(versionRoot, folderName), {
436
+ recursive: true,
437
+ force: true,
438
+ });
439
+ });
440
+ });
441
+ }
442
+
443
+ function ensureSharedAssetsForVersion(outputRoot, version) {
444
+ const docsRoot = path.join(outputRoot, 'docs');
445
+ const versionRoot = path.join(docsRoot, version);
446
+ const sharedRoot = path.join(docsRoot, sharedAssetDirectoryName);
447
+
448
+ if (!fs.existsSync(versionRoot)) {
449
+ return;
450
+ }
451
+
452
+ fs.mkdirSync(sharedRoot, { recursive: true });
453
+
454
+ sharedAssetFolders.forEach((folderName) => {
455
+ const sourcePath = path.join(versionRoot, folderName);
456
+
457
+ if (!fs.existsSync(sourcePath)) {
458
+ return;
459
+ }
460
+
461
+ fs.cpSync(sourcePath, path.join(sharedRoot, folderName), {
462
+ recursive: true,
463
+ force: true,
464
+ });
465
+ });
466
+
467
+ rewriteVersionHtmlToSharedAssets(versionRoot);
468
+
469
+ sharedAssetFolders.forEach((folderName) => {
470
+ fs.rmSync(path.join(versionRoot, folderName), {
471
+ recursive: true,
472
+ force: true,
473
+ });
474
+ });
475
+ }
476
+
477
+ function main() {
478
+ const options = parseArgs(process.argv.slice(2));
479
+
480
+ if (options.preservePublished && options.fullRebuild) {
481
+ throw new Error(
482
+ 'Use either --preserve-published or --full-rebuild, not both.'
483
+ );
484
+ }
485
+
486
+ const publishedVersions = options.versions
487
+ ? options.versions
488
+ : getPublishedVersions(options.branch);
489
+ const currentVersion = getCurrentWorkspaceVersion();
490
+ const versions = Array.from(
491
+ new Set(publishedVersions.concat(currentVersion))
492
+ ).sort(compareVersionsAsc);
493
+
494
+ if (!versions.length) {
495
+ throw new Error(`No published versions found in ${options.branch}:docs`);
496
+ }
497
+
498
+ assertTagsExist(
499
+ publishedVersions.filter((version) => version !== currentVersion)
500
+ );
501
+ ensureCleanOutput(options.outputRoot);
502
+
503
+ const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'rclnodejs-jsdoc-'));
504
+ const latestVersion = versions[versions.length - 1];
505
+ let latestPackageJsonPath = null;
506
+
507
+ try {
508
+ if (options.preservePublished) {
509
+ copyPublishedSnapshot(
510
+ options.branch,
511
+ options.outputRoot,
512
+ tempRoot,
513
+ options.keepWorktrees
514
+ );
515
+ console.log(
516
+ `Preserved ${publishedVersions.length} published versions from ${options.branch}.`
517
+ );
518
+ } else {
519
+ writeBranchFile(
520
+ options.branch,
521
+ '.nojekyll',
522
+ path.join(options.outputRoot, '.nojekyll')
523
+ );
524
+ writeBranchFile(
525
+ options.branch,
526
+ 'README.md',
527
+ path.join(options.outputRoot, 'README.md')
528
+ );
529
+ }
530
+
531
+ console.log(`Regenerating ${versions.length} documentation versions.`);
532
+
533
+ if (!options.preservePublished || options.fullRebuild) {
534
+ publishedVersions.forEach((version) => {
535
+ if (version === currentVersion) {
536
+ return;
537
+ }
538
+
539
+ console.log(`- ${version}`);
540
+
541
+ const buildResult = buildVersionDocs(
542
+ version,
543
+ path.join(options.outputRoot, 'docs'),
544
+ tempRoot,
545
+ options.keepWorktrees
546
+ );
547
+
548
+ if (version === latestVersion) {
549
+ latestPackageJsonPath = writeIndexPackage(
550
+ buildResult.packageJsonPath,
551
+ options.outputRoot
552
+ );
553
+ }
554
+
555
+ removeWorktree(buildResult.worktreePath, options.keepWorktrees);
556
+ });
557
+ }
558
+
559
+ if (options.preservePublished && !options.fullRebuild) {
560
+ const existingIndexPackagePath = path.join(
561
+ options.outputRoot,
562
+ '_index-package.json'
563
+ );
564
+
565
+ if (fs.existsSync(existingIndexPackagePath)) {
566
+ latestPackageJsonPath = existingIndexPackagePath;
567
+ }
568
+ }
569
+
570
+ console.log(`- ${currentVersion} (current workspace)`);
571
+
572
+ const buildResult = buildDocsFromSourceRoot(
573
+ repoRoot,
574
+ path.join(options.outputRoot, 'docs')
575
+ );
576
+
577
+ if (currentVersion === latestVersion) {
578
+ latestPackageJsonPath = writeIndexPackage(
579
+ buildResult.packageJsonPath,
580
+ options.outputRoot
581
+ );
582
+ }
583
+
584
+ buildDocsIndex(
585
+ options.outputRoot,
586
+ latestPackageJsonPath || path.join(repoRoot, 'package.json')
587
+ );
588
+
589
+ if (options.preservePublished && !options.fullRebuild) {
590
+ ensureSharedAssetsForVersion(options.outputRoot, currentVersion);
591
+ } else {
592
+ hoistSharedAssets(options.outputRoot);
593
+ }
594
+
595
+ removeTemporaryPublishArtifacts(options.outputRoot);
596
+
597
+ console.log(`Published docs tree ready at ${options.outputRoot}`);
598
+ } finally {
599
+ if (!options.keepWorktrees) {
600
+ fs.rmSync(tempRoot, { recursive: true, force: true });
601
+ }
602
+ }
603
+ }
604
+
605
+ main();