politty 0.4.8 → 0.4.9
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/dist/docs/index.cjs +46 -3
- package/dist/docs/index.cjs.map +1 -1
- package/dist/docs/index.d.cts +1 -1
- package/dist/docs/index.d.cts.map +1 -1
- package/dist/docs/index.d.ts +1 -1
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +46 -3
- package/dist/docs/index.js.map +1 -1
- package/package.json +2 -2
package/dist/docs/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ const SECTION_TYPES = [
|
|
|
22
22
|
"usage",
|
|
23
23
|
"arguments",
|
|
24
24
|
"options",
|
|
25
|
+
"global-options-link",
|
|
25
26
|
"subcommands",
|
|
26
27
|
"examples",
|
|
27
28
|
"notes"
|
|
@@ -570,7 +571,7 @@ function createCommandRenderer(options = {}) {
|
|
|
570
571
|
}
|
|
571
572
|
{
|
|
572
573
|
const globalLink = getGlobalOptionsLink(info);
|
|
573
|
-
if (globalLink) sections.push(globalLink);
|
|
574
|
+
if (globalLink) sections.push(wrapWithMarker("global-options-link", scope, globalLink));
|
|
574
575
|
}
|
|
575
576
|
if (info.subCommands.length > 0) {
|
|
576
577
|
const effectiveAnchors = generateAnchors && includeSubcommandDetails;
|
|
@@ -1404,6 +1405,26 @@ function insertCommandSections(content, commandPath, newSection, specifiedOrder)
|
|
|
1404
1405
|
return content.trimEnd() + "\n" + newSection + "\n";
|
|
1405
1406
|
}
|
|
1406
1407
|
/**
|
|
1408
|
+
* Remove all section markers for a command from content.
|
|
1409
|
+
* Returns the content with all markers for the command removed and excess blank lines cleaned up.
|
|
1410
|
+
*/
|
|
1411
|
+
function removeCommandSections(content, commandPath) {
|
|
1412
|
+
const markers = collectSectionMarkers(content, commandPath);
|
|
1413
|
+
for (const type of markers) {
|
|
1414
|
+
const start = sectionStartMarker(type, commandPath);
|
|
1415
|
+
const end = sectionEndMarker(type, commandPath);
|
|
1416
|
+
let startIndex = content.indexOf(start);
|
|
1417
|
+
while (startIndex !== -1) {
|
|
1418
|
+
const endIndex = content.indexOf(end, startIndex);
|
|
1419
|
+
if (endIndex === -1) break;
|
|
1420
|
+
content = content.slice(0, startIndex) + content.slice(endIndex + end.length);
|
|
1421
|
+
startIndex = content.indexOf(start, startIndex);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
content = content.replace(/\n{3,}/g, "\n\n");
|
|
1425
|
+
return content;
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1407
1428
|
* Extract a marker section from content
|
|
1408
1429
|
* Returns the content between start and end markers (including markers)
|
|
1409
1430
|
*/
|
|
@@ -1968,6 +1989,25 @@ async function generateDoc(config) {
|
|
|
1968
1989
|
}
|
|
1969
1990
|
}
|
|
1970
1991
|
}
|
|
1992
|
+
if (existingContent) {
|
|
1993
|
+
const existingMarkerPaths = collectSectionMarkerPaths(existingContent);
|
|
1994
|
+
const commandPathSet = new Set(commandPaths);
|
|
1995
|
+
if (updateMode) {
|
|
1996
|
+
let removedAny = false;
|
|
1997
|
+
for (const markerPath of existingMarkerPaths) if (!commandPathSet.has(markerPath)) {
|
|
1998
|
+
existingContent = removeCommandSections(existingContent, markerPath);
|
|
1999
|
+
removedAny = true;
|
|
2000
|
+
}
|
|
2001
|
+
if (removedAny) {
|
|
2002
|
+
writeFile(filePath, existingContent);
|
|
2003
|
+
if (fileStatus !== "created") fileStatus = "updated";
|
|
2004
|
+
}
|
|
2005
|
+
} else for (const markerPath of existingMarkerPaths) if (!commandPathSet.has(markerPath)) {
|
|
2006
|
+
hasError = true;
|
|
2007
|
+
fileStatus = "diff";
|
|
2008
|
+
diffs.push(`Found orphaned section markers for deleted command "${formatCommandPath(markerPath)}"`);
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
1971
2011
|
} else {
|
|
1972
2012
|
const generatedMarkdown = await applyFormatter(generateFileMarkdown(commandPaths, allCommands, render, filePath, fileMap, specifiedCommands, fileConfig, rootDoc?.path, globalOptionDefinitions.size > 0), formatter);
|
|
1973
2013
|
const comparison = compareWithExisting(generatedMarkdown, filePath);
|
|
@@ -2017,8 +2057,11 @@ async function generateDoc(config) {
|
|
|
2017
2057
|
if (headerMarkerResult.wasUpdated) markerUpdated = true;
|
|
2018
2058
|
}
|
|
2019
2059
|
if (!usingPathConfig) {
|
|
2020
|
-
const unexpectedSectionPaths =
|
|
2021
|
-
if (unexpectedSectionPaths.length > 0) {
|
|
2060
|
+
const unexpectedSectionPaths = collectSectionMarkerPaths(content);
|
|
2061
|
+
if (unexpectedSectionPaths.length > 0) if (updateMode) {
|
|
2062
|
+
for (const commandPath of unexpectedSectionPaths) content = removeCommandSections(content, commandPath);
|
|
2063
|
+
markerUpdated = true;
|
|
2064
|
+
} else {
|
|
2022
2065
|
hasError = true;
|
|
2023
2066
|
rootDocDiffs.push(`Found unexpected section markers in rootDoc: ${unexpectedSectionPaths.map((commandPath) => `"${formatCommandPath(commandPath)}"`).join(", ")}.`);
|
|
2024
2067
|
}
|