@datalackey/update-markdown-toc 1.0.4 → 1.1.3

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
@@ -1,5 +1,14 @@
1
1
  # update-markdown-toc
2
2
 
3
+ <p align="center">
4
+ <img
5
+ src="doc/demo.gif"
6
+ width="720"
7
+ alt="update-markdown-toc demo">
8
+ </p>
9
+
10
+
11
+
3
12
  <!-- TOC:START -->
4
13
  - [update-markdown-toc](#update-markdown-toc)
5
14
  - [Introduction](#introduction)
@@ -18,6 +27,7 @@
18
27
  - [Single-File Processing (Strict Mode)](#single-file-processing-strict-mode)
19
28
  - [Recursive Folder Traversal (Lenient Mode)](#recursive-folder-traversal-lenient-mode)
20
29
  - [Guidelines For Project Contributors](#guidelines-for-project-contributors)
30
+ - [Known limitations](#known-limitations)
21
31
  <!-- TOC:END -->
22
32
 
23
33
  ## Introduction
@@ -36,12 +46,11 @@ A Node.js command-line **documentation helper** which automatically:
36
46
 
37
47
  ## Why not Some Other Markdown TOC Generator ?
38
48
 
39
- Most Markdown TOC tools (e.g., [markdown-toc](https://github.com/jonschlinkert/markdown-toc),
49
+ Most Markdown TOC tools (e.g., [markdown-toc](https://github.com/jonschlinkert/markdown-toc),
40
50
  [md-toc-cli](https://github.com/eugene-khyst/md-toc-cli))
41
- operate on a **single file at a time**, a mode which our tool also supports.
42
- But we are aware of no other alternative which supports our tool's main distinguishing feature:
43
- the ability to search for, check and update all Markdown documents within an entire folder hierarchy.
44
-
51
+ operate on a single file at a time, a mode which we also support.
52
+ The primary distinguishing feature of our tool is its ability to recursively search for, check, and update all Markdown documents within an entire folder hierarchy, making it suitable for CI and
53
+ large repositories.
45
54
 
46
55
 
47
56
 
@@ -123,20 +132,17 @@ explicitly. Unlike normal operation, --check does not default to README.md.
123
132
  ## TOC Markers
124
133
 
125
134
  The tool operates only on files containing **both** start and end markers,
126
- as *almost* shown below. Don't use these markers exactly as written. Use brackets ('<' and '>'), and not
127
- squiggley braces (i.e., not '{' and '}'). The reason for this documentation
128
- oddity is that, if we used brackets,
129
- then when we run our tool against this code base we would end up getting an unwanted table of contents below !
135
+ as shown below:
136
+
137
+
138
+ &nbsp;&nbsp;&nbsp; &lt;!-- TOC:START --&gt;<br/>
139
+ &nbsp;&nbsp;&nbsp; &lt;!-- TOC:END --&gt;
130
140
 
131
141
 
132
- ```md
133
- {!-- TOC:START --}
134
- {!-- TOC:END --}
135
- ```
136
142
 
137
143
  Any existing content between the region start and end markers is lost. The new content will be the generated TOC that
138
144
  reflects the section headers marked with '#'s in the Markdown document.
139
-
145
+
140
146
  Content outside the markers is preserved verbatim.
141
147
  If either marker is missing, the tool prints an error message and exits with a non-zero status code.
142
148
 
@@ -148,7 +154,7 @@ If either marker is missing, the tool prints an error message and exits with a n
148
154
  ### As Part of code/test/debug Work Flow
149
155
 
150
156
  To ensure that your code is built afresh, passes tests, and that your documentation TOCs are up to date, you could
151
- use invoke the tool in something akin to the package.json below.
157
+ invoke the tool via something akin to the package.json below.
152
158
  Before commit and push, you would type: 'npm run build'
153
159
 
154
160
 
@@ -206,8 +212,7 @@ the tool operates in strict mode.
206
212
  In this mode, any of the following conditions cause an immediate error and a non-zero exit code:
207
213
 
208
214
  - file does not exist, or cannot be read (e.g. due to permissions).
209
- - file does not contain both TOC delimiters ({!-- TOC:START --} and {!-- TOC:END --}).
210
- (See [TOC markers](#toc-markers) section about how we describe markers in this guide.)
215
+ - file does not contain both TOC delimiters (&lt;!-- TOC:START --&gt; and &nbsp; &lt;!-- TOC:END --&gt;).
211
216
  - file is stale (i.e. the existing TOC differs from the generated TOC).
212
217
  - file contains TOC delimiters but no Markdown headings are found from which a TOC can be generated.
213
218
 
@@ -239,6 +244,29 @@ Updated: docs/guide.md
239
244
  Up-to-date: docs/api.md
240
245
  ```
241
246
 
247
+ ## Design Goals and Philosophy
248
+
249
+ This tool was designed in accordance with the top-level
250
+ [Build Philosophy](../../README.md#build-philosophy) of this repository.
251
+
252
+
253
+ - **update mode** (writes files: this should be run locally by developers, and should never run in CI)
254
+ - **check mode** (validates and exits non-zero if stale: mainly intended to be run in CI -- optional for local use)
255
+
256
+ The intended workflow is:
257
+
258
+ 1. Developers run the update command locally.
259
+ 2. Generated TOC content is reviewed and committed.
260
+ 3. CI runs in `--check` mode to ensure no drift exists.
261
+
262
+
242
263
  ## Guidelines For Project Contributors
243
264
 
244
265
  Contributors to the project should consult [this document](GUIDELINES-FOR-PROJECT-CONTRIBUTORS.md)
266
+
267
+
268
+ ## Known limitations
269
+
270
+ - node_modules is excluded from recursive traversal: when using `--recursive` the tool will skip any directory
271
+ named `node_modules` and its contents. This prevents accidental processing or modification of third-party files.
272
+ This exclusion is currently hard-coded and not configurable via command-line flags or configuration files.
@@ -51,6 +51,9 @@ function collectMarkdownFiles(dir) {
51
51
  const full = path.join(dir, entry.name);
52
52
 
53
53
  if (entry.isDirectory()) {
54
+ // Exclude node_modules from recursive traversal to avoid processing third-party files
55
+ if (entry.name === 'node_modules') continue;
56
+
54
57
  results.push(...collectMarkdownFiles(full));
55
58
  } else if (entry.isFile() && entry.name.endsWith(".md")) {
56
59
  results.push(full);
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@datalackey/update-markdown-toc",
3
- "version": "1.0.4",
3
+ "version": "1.1.3",
4
4
  "description": "Auto-generate Table of Contents for a Markdown file (or files, recursively from a top level folder)",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
+ "private": false,
8
+ "scripts": {
9
+ "test": "bash scripts/run-all-tests.sh",
10
+ "prepack": "npm run test"
11
+ },
7
12
  "bin": {
8
13
  "update-markdown-toc": "./bin/update-markdown-toc.js"
9
14
  },
@@ -17,6 +22,7 @@
17
22
  "build",
18
23
  "automation",
19
24
  "javascript",
25
+ "typescript",
20
26
  "node",
21
27
  "documentation",
22
28
  "readme",