@ndp-software/lit-md 0.3.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.
- package/LICENSE.md +3 -0
- package/README.md +125 -0
- package/dist/cli.js +1273 -0
- package/dist/cli.js.map +7 -0
- package/docs/cli.md +74 -0
- package/docs/how-wait-mode-works.md +381 -0
- package/docs/shell-examples.md +254 -0
- package/package.json +58 -0
- package/src/cli.ts +327 -0
- package/src/describe-format.ts +53 -0
- package/src/docs/README.lit-md.ts +126 -0
- package/src/docs/cli.lit-md.ts +44 -0
- package/src/docs/shell-examples.lit-md.ts +243 -0
- package/src/index.ts +7 -0
- package/src/parser.ts +970 -0
- package/src/renderer.ts +130 -0
- package/src/resolver.ts +65 -0
- package/src/shell.ts +362 -0
- package/src/typecheck.ts +51 -0
package/LICENSE.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @ndp-software/lit-md
|
|
2
|
+
|
|
3
|
+
Literate test files that generate `README.md`s.
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
Some projects, especially libraries, require numerous and
|
|
8
|
+
detailed code examples. For those responsible for updating
|
|
9
|
+
a README, or other documentation, this can be burdensome
|
|
10
|
+
and error-prone.
|
|
11
|
+
|
|
12
|
+
With lit-md, you write your documentation with embedded code samples
|
|
13
|
+
that are automatically type-checked and run through node to
|
|
14
|
+
verify them. Every example actually works!
|
|
15
|
+
|
|
16
|
+
Key features:
|
|
17
|
+
- works with Typescript or Javascript
|
|
18
|
+
- provides utilities to include shell commands and their outputs
|
|
19
|
+
as part of your documentation. This is important if you tool has
|
|
20
|
+
a CLI, or you just need to show how it works in the terminal.
|
|
21
|
+
- supports flexible assertion methods for both code examples and shell commands,
|
|
22
|
+
with options to display actual outputs in the generated markdown
|
|
23
|
+
- fully tested with its own test suite, which also serves as
|
|
24
|
+
documentation and examples for users
|
|
25
|
+
|
|
26
|
+
There _are_ other tools with the same aims (e.g. [TwoSlash](https://github.com/microsoft/TypeScript-Website/tree/v2/packages/ts-twoslasher)),
|
|
27
|
+
but this follows in the Literate programming tradition but updated
|
|
28
|
+
for the Typescript and TDD era. I have aimed to provide a great DX
|
|
29
|
+
for writing documentation, with a simple syntax and powerful features
|
|
30
|
+
that work well with the node ecosystem.
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
# You can "run" your documentation as a test:
|
|
34
|
+
node --test README.lit-md.ts
|
|
35
|
+
# You can also typecheck:
|
|
36
|
+
tsc README.lit-md.ts
|
|
37
|
+
# An it can be converted from Typescript to a plain old markdown
|
|
38
|
+
# README file with `lit-md`:
|
|
39
|
+
lit-md README.lit-md.ts # generates README.md
|
|
40
|
+
|
|
41
|
+
# Or, you can do it all in one step with:
|
|
42
|
+
lit-md --test --typecheck README.lit-md.ts # all-in-one!
|
|
43
|
+
```
|
|
44
|
+
## How it Works
|
|
45
|
+
A **lit-md** file contains prose in comments and examples in test bodies.
|
|
46
|
+
At a basic level, a file is processed and
|
|
47
|
+
- comments are directly transferred into markdown, and
|
|
48
|
+
- example (or `test`, `it`, `spec`) bodies become fenced code blocks.
|
|
49
|
+
To make this work well, there are quite a few nuances and features to control
|
|
50
|
+
what appears in the output and how it looks.
|
|
51
|
+
|
|
52
|
+
# A simple example
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
|
|
56
|
+
describe('My Project README.', () => {
|
|
57
|
+
/*
|
|
58
|
+
This is a really great project!
|
|
59
|
+
Adding numbers is as simple as using the "+" operator:
|
|
60
|
+
*/
|
|
61
|
+
example('add example', () => {
|
|
62
|
+
const a = 1
|
|
63
|
+
const b = 2
|
|
64
|
+
console.log(a + b) // => 3
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Also supported is multiplication:
|
|
68
|
+
example('multiply example', () => {
|
|
69
|
+
const x = 3
|
|
70
|
+
const y = 4
|
|
71
|
+
console.log(x * y) // => 12
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
$ lit-md tmp.ts --out out.md
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Output file `out.md`:
|
|
82
|
+
````markdown
|
|
83
|
+
## My Project README.
|
|
84
|
+
|
|
85
|
+
This is a really great project!
|
|
86
|
+
Adding numbers is as simple as using the "+" operator:
|
|
87
|
+
```ts
|
|
88
|
+
const a = 1
|
|
89
|
+
const b = 2
|
|
90
|
+
console.log(a + b) // => 3
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Also supported is multiplication:
|
|
94
|
+
```ts
|
|
95
|
+
const x = 3
|
|
96
|
+
const y = 4
|
|
97
|
+
console.log(x * y) // => 12
|
|
98
|
+
```
|
|
99
|
+
````
|
|
100
|
+
|
|
101
|
+
For more information on the CLI, see [CLI documentation](./docs/cli.md).
|
|
102
|
+
|
|
103
|
+
## Shell examples
|
|
104
|
+
|
|
105
|
+
Use `shellExample` to include executable shell commands in the README.
|
|
106
|
+
It verifies a 0 return code and provides flexible assertion and display options.
|
|
107
|
+
|
|
108
|
+
### shellExample function
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
shellExample('echo "hello world"', { stdout: { display: true } })
|
|
112
|
+
```
|
|
113
|
+
becomes
|
|
114
|
+
```sh
|
|
115
|
+
$ echo "hello world"
|
|
116
|
+
hello world
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
For more information on the `shellExample`, see [shellCommand documentation](./docs/shell-examples.md).
|
|
120
|
+
## CREDITS
|
|
121
|
+
|
|
122
|
+
Built by Andrew J. Peterson, although there was some manual code changes,
|
|
123
|
+
most of the code was Github Copilot CLI, using mostly Claude Haiku 4.5
|
|
124
|
+
and some Claude Sonnet 4.6.
|
|
125
|
+
Most tasks used a plan-autopilot loop, but other approaches were used as well.
|