Skip to content

Commit 8c7f181

Browse files
committed
docs: automate demo generation
1 parent bdcd2bc commit 8c7f181

16 files changed

+476
-2
lines changed

.dockerignore

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
.github
2+
*deleteme*
3+
4+
.deno_cache/
5+
6+
### Deno ###
7+
/.idea/
8+
/.vscode/
9+
10+
/node_modules
11+
12+
.env
13+
*.orig
14+
*.pyc
15+
*.swp
16+
17+
### Dropbox ###
18+
# Dropbox settings and caches
19+
.dropbox
20+
.dropbox.attr
21+
.dropbox.cache
22+
23+
### Linux ###
24+
*~
25+
26+
# temporary files which can be created if a process still has a handle open of a deleted file
27+
.fuse_hidden*
28+
29+
# KDE directory preferences
30+
.directory
31+
32+
# Linux trash folder which might appear on any partition or disk
33+
.Trash-*
34+
35+
# .nfs files are created when an open file is removed but is still being accessed
36+
.nfs*
37+
38+
### macOS ###
39+
# General
40+
.DS_Store
41+
.AppleDouble
42+
.LSOverride
43+
44+
# Icon must end with two \r
45+
Icon
46+
47+
# Thumbnails
48+
._*
49+
50+
# Files that might appear in the root of a volume
51+
.DocumentRevisions-V100
52+
.fseventsd
53+
.Spotlight-V100
54+
.TemporaryItems
55+
.Trashes
56+
.VolumeIcon.icns
57+
.com.apple.timemachine.donotpresent
58+
59+
# Directories potentially created on remote AFP share
60+
.AppleDB
61+
.AppleDesktop
62+
Network Trash Folder
63+
Temporary Items
64+
.apdisk
65+
66+
### macOS Patch ###
67+
# iCloud generated files
68+
*.icloud
69+
70+
### Node ###
71+
# Logs
72+
logs
73+
*.log
74+
npm-debug.log*
75+
yarn-debug.log*
76+
yarn-error.log*
77+
lerna-debug.log*
78+
.pnpm-debug.log*
79+
80+
# Diagnostic reports (https://nodejs.org/api/report.html)
81+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
82+
83+
# Runtime data
84+
pids
85+
*.pid
86+
*.seed
87+
*.pid.lock
88+
89+
# Directory for instrumented libs generated by jscoverage/JSCover
90+
lib-cov
91+
92+
# Coverage directory used by tools like istanbul
93+
coverage
94+
*.lcov
95+
96+
# nyc test coverage
97+
.nyc_output
98+
99+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
100+
.grunt
101+
102+
# Bower dependency directory (https://bower.io/)
103+
bower_components
104+
105+
# node-waf configuration
106+
.lock-wscript
107+
108+
# Compiled binary addons (https://nodejs.org/api/addons.html)
109+
build/Release
110+
111+
# Dependency directories
112+
node_modules/
113+
jspm_packages/
114+
115+
# Snowpack dependency directory (https://snowpack.dev/)
116+
web_modules/
117+
118+
# TypeScript cache
119+
*.tsbuildinfo
120+
121+
# Optional npm cache directory
122+
.npm
123+
124+
# Optional eslint cache
125+
.eslintcache
126+
127+
# Optional stylelint cache
128+
.stylelintcache
129+
130+
# Microbundle cache
131+
.rpt2_cache/
132+
.rts2_cache_cjs/
133+
.rts2_cache_es/
134+
.rts2_cache_umd/
135+
136+
# Optional REPL history
137+
.node_repl_history
138+
139+
# Output of 'npm pack'
140+
*.tgz
141+
142+
# Yarn Integrity file
143+
.yarn-integrity
144+
145+
# dotenv environment variable files
146+
.env.development.local
147+
.env.test.local
148+
.env.production.local
149+
.env.local
150+
151+
# parcel-bundler cache (https://parceljs.org/)
152+
.cache
153+
.parcel-cache
154+
155+
# Next.js build output
156+
.next
157+
out
158+
159+
# Nuxt.js build / generate output
160+
.nuxt
161+
dist
162+
163+
# Gatsby files
164+
.cache/
165+
# Comment in the public line in if your project uses Gatsby and not Next.js
166+
# https://nextjs.org/blog/next-9-1#public-directory-support
167+
# public
168+
169+
# vuepress build output
170+
.vuepress/dist
171+
172+
# vuepress v2.x temp and cache directory
173+
.temp
174+
175+
# Docusaurus cache and generated files
176+
.docusaurus
177+
178+
# Serverless directories
179+
.serverless/
180+
181+
# FuseBox cache
182+
.fusebox/
183+
184+
# DynamoDB Local files
185+
.dynamodb/
186+
187+
# TernJS port file
188+
.tern-port
189+
190+
# Stores VSCode versions used for testing VSCode extensions
191+
.vscode-test
192+
193+
# yarn v2
194+
.yarn/cache
195+
.yarn/unplugged
196+
.yarn/build-state.yml
197+
.yarn/install-state.gz
198+
.pnp.*
199+
200+
### Node Patch ###
201+
# Serverless Webpack directories
202+
.webpack/
203+
204+
# Optional stylelint cache
205+
206+
# SvelteKit build / generate output
207+
.svelte-kit
208+
209+
### VisualStudioCode ###
210+
.vscode/*
211+
!.vscode/settings.json
212+
!.vscode/tasks.json
213+
!.vscode/launch.json
214+
!.vscode/extensions.json
215+
!.vscode/*.code-snippets
216+
217+
# Local History for Visual Studio Code
218+
.history/
219+
220+
# Built Visual Studio Code Extensions
221+
*.vsix
222+
223+
### VisualStudioCode Patch ###
224+
# Ignore all local history of files
225+
.history
226+
.ionide
227+
228+
### Windows ###
229+
# Windows thumbnail cache files
230+
Thumbs.db
231+
Thumbs.db:encryptable
232+
ehthumbs.db
233+
ehthumbs_vista.db
234+
235+
# Dump file
236+
*.stackdump
237+
238+
# Folder config file
239+
[Dd]esktop.ini
240+
241+
# Recycle Bin used on file shares
242+
$RECYCLE.BIN/
243+
244+
# Windows Installer files
245+
*.cab
246+
*.msi
247+
*.msix
248+
*.msm
249+
*.msp
250+
251+
# Windows shortcuts
252+
*.lnk

.github/demos/Dockerfile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
FROM ghcr.io/charmbracelet/vhs:v0.2.0
22

3+
ARG MDRB_VERSION
4+
5+
RUN [ -z "$MDRB_VERSION" ] && echo "MDRB_VERSION is required" && exit 1 || true
6+
37
ENV PATH="$PATH:/root/.deno/bin"
48

59
RUN echo 'export PATH="$PATH:/root/.deno/bin"' >> ~/.bashrc
610

711
RUN apt install curl unzip bat -y \
8-
&& curl -fsSL https://deno.land/x/install/install.sh | sh \
9-
&& deno install --unstable -Arfn mdrb https://deno.land/x/mdrb/mod.ts
12+
&& curl -fsSL https://deno.land/x/install/install.sh | sh
13+
14+
RUN deno install -Arfn mdrb https://deno.land/x/mdrb@${MDRB_VERSION}/mod.ts
15+
16+
ADD deno.lock deps.ts deps.dev.ts /tmp/
17+
18+
RUN deno cache --lock=/tmp/deno.lock /tmp/deps.ts /tmp/deps.dev.ts
19+
20+
RUN mdrb https://deno.land/x/mdrb@${MDRB_VERSION}/demo.md --mode isolated
1021

1122
ENTRYPOINT [] # override parent layer
1223

.github/demos/generate.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { $ } from "../../deps.ts";
2+
3+
const root = $.relativePath(import.meta.url, "..", "..");
4+
const latestTag = await $`git describe --tags --abbrev=0`.cwd(root).text();
5+
const img = "mdrb-demos:latest";
6+
const demosDir = $.path.join(".github", "demos");
7+
const dockerfile = $.path.join(demosDir, "Dockerfile");
8+
9+
await $`docker build --build-arg MDRB_VERSION=${latestTag} -t ${img} -f ${dockerfile} .`
10+
.cwd(root);
11+
12+
for await (
13+
const tape of $.fs.expandGlob($.path.joinGlobs([demosDir, "*.tape"]))
14+
) {
15+
await $`docker run --rm -v ${root}:/vhs ${img} vhs ${demosDir}/${tape.name}`
16+
.cwd(root);
17+
}
18+
19+
const me = Deno.env.get("USER");
20+
await $`sudo chown -R ${me}:${me} ${demosDir}`;

.github/demos/usage-basic.gif

-359 Bytes
Loading

.github/demos/usage-basic.tape

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Output .github/demos/usage-basic.gif
2+
3+
Require deno
4+
Require mdrb
5+
6+
Set Theme "Gruvbox Dark"
7+
Set Shell bash
8+
Set FontFamily "JetBrainsMono Nerd Font"
9+
10+
# pre-cache runtime deps
11+
Hide
12+
Type "mdrb demo.md --mode isolated"
13+
Enter
14+
Sleep 5s
15+
Type "clear"
16+
Enter
17+
Sleep 500ms
18+
Show
19+
20+
Type "mdrb demo.md"
21+
Enter
22+
Sleep 1s
23+
24+
Type "y"
25+
Sleep 500ms
26+
Enter
27+
Sleep 1s
28+
29+
Type "y"
30+
Sleep 500ms
31+
Enter
32+
Sleep 1s
33+
34+
Sleep 3s

.github/demos/usage-dax.gif

-1.31 MB
Loading

.github/demos/usage-dax.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# What can `$` do?
2+
3+
<details data-mdrb>
4+
<summary>make an http request and do stuff with results</summary>
5+
</details>
6+
7+
```ts
8+
const html = await $.request("https://example.com").text();
9+
10+
$.log("example.com is", html.length, "characters");
11+
```
12+
13+
<details data-mdrb>
14+
<summary>prompt the user</summary>
15+
</details>
16+
17+
```ts
18+
const fruits = ["apples", "bananas", "oranges"];
19+
const faves = await $.multiSelect({ message: "favorite fruits?", options: fruits })
20+
.then((chosen) => chosen.map((idx) => fruits.at(idx)));
21+
22+
$.log("your faves are:", faves);
23+
```
24+
25+
<details data-mdrb>
26+
<summary>run shell commands</summary>
27+
</details>
28+
29+
```ts
30+
const thisDir = $.path.dirname($.path.fromFileUrl(import.meta.url));
31+
await $`ls ${thisDir}`.printCommand(true);
32+
```

0 commit comments

Comments
 (0)