Skip to content

Commit b449fc8

Browse files
committed
script to generate command pages lives!
1 parent 2de446c commit b449fc8

File tree

21 files changed

+553
-76
lines changed

21 files changed

+553
-76
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import iroh from 'iroh'
2+
3+
iroh.set('doc', 'set', 'example', 'value')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"start": "next start",
99
"lint": "next lint"
1010
},
11+
"type": "module",
1112
"browserslist": "defaults, not ie <= 11",
1213
"dependencies": {
1314
"@algolia/autocomplete-core": "^1.7.3",

scripts/generate-commands-pages.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { readFileSync, writeFileSync } from 'fs'
1+
import { readFileSync, writeFileSync, mkdirSync } from 'fs'
22
import ejs from 'ejs'
33

4-
import {commands} from '../src/app/docs/commands/commands';
4+
import commands from '../src/data/commands.js';
55

66
(function() {
77
try {
88
let templateSource = readFileSync('./templates/command.template.mdx');
99
Object.keys(commands).forEach((key) => {
10-
console.log('Generating commands for %s', key);
10+
console.log('%s commands:', key);
1111
generateCommands(commands[key], templateSource);
1212
});
1313
}
@@ -37,8 +37,8 @@ function generateCommand(command, templateSource) {
3737

3838
// mkdir -p ../src/app/docs/commands/{slug}
3939
mkdir(command.slug);
40-
const path = `../src/app/docs/commands/${slug}/page.mdx`;
41-
console.log('Writing %s with examples %s', path, Object.keys(examples).join(', '));
40+
const path = `../src/app/docs/commands/${command.slug}/page.mdx`;``
41+
console.log(' writing %s with examples: %s', path, Object.keys(examples).filter(k => !!examples[k]).join(', '));
4242
writeFileSync(path, result);
4343
}
4444

Lines changed: 22 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,47 @@
11
{/* THIS FILE IS GENERATED FROM A TEMPLATE. See scripts/generate-commands-pages.js for more */}
22
export const metadata = {
3-
title: "Set Command",
4-
description: "Set an entry in a document"
3+
title: "<%= command.name %>",
4+
description: "<%= command.description %>"
55
}
66

7-
# Set
7+
# <%= command.name %>
88

9-
Set an entry in a document {{ className: 'lead' }}
9+
<%= command.description %> {{ className: 'lead' }}
1010

11+
<% if (command.arguments) { %>
1112
### Arguments
1213

1314
| name | necessity | description |
1415
| ---- | --------- | ----------- |
15-
| KEY | required | Key to the entry (parsed as UTF-8 string) |
16-
| VALUE | required | Content to store for this entry (parsed as UTF-8 string) |
17-
| author | required | Author of this entry. Required unless the author is set through the console or the IROH_AUTHOR environment variable. |
16+
<% command.arguments.forEach((arg) => { %>
17+
| <%= arg.name %> | <%= arg.necessity%> | <%= arg.description %> |
18+
<% }) %>
19+
<% } %>
1820

1921
## Examples
2022

2123
<CodeGroup title="SET">
2224

2325

2426
```text {{ title: 'console' }}
25-
> docs create --use
26-
> set key value
27-
@ydzwyyes…: key = azceusiw… (5 B)
27+
<%- examples.console %>
2828
```
2929

30-
```bash {{ title: 'CLI'}}
31-
# create an author if you haven't already
32-
$ IROH_AUTHOR=$(iroh author create)
33-
34-
# create a document
35-
$ iroh docs create
36-
created d7bb0092bf6d7ee3cb6bd255e88596d3ca16d50ce6935a7721f2ff836a3c0355
30+
<% if (examples.cli) { %>
31+
```bash {{ title: 'CLI' }}
32+
<%- examples.cli %>
33+
```
34+
<% } %>
3735

38-
# set a key
39-
$ iroh doc 674deec7a19fec50fd6f486a5eef20509073ecf7c527b60a27c84baea90d3816 set "key" "value"
40-
@ydzwyyes…: key = azceusiw… (5 B)
36+
<% if (examples.python) { %>
37+
```python {{ title: 'python' }}
38+
<%- examples.python %>
4139
```
40+
<% } %>
4241

42+
<% if (examples.rust) { %>
4343
```rust {{ title: 'rust' }}
44-
#![cfg(feature = "mem-db")]
45-
46-
use anyhow::{anyhow, Result};
47-
use futures::StreamExt;
48-
49-
use iroh::{
50-
collection::IrohCollectionParser,
51-
node::Node,
52-
bytes::util::runtime,
53-
};
54-
use iroh_sync::store::GetFilter;
55-
56-
#[tokio::main]
57-
async fn main() -> Result<()> {
58-
// build the node
59-
let rt = runtime::Handle::from_currrent(1).unwrap();
60-
let db = iroh::baomap::mem::Store::new(rt.clone());
61-
let store = iroh_sync::store::memory::Store::default();
62-
let node = Node::builder(db, store)
63-
.collection_parser(IrohCollectionParser)
64-
.runtime(&rt)
65-
.bind_addr("127.0.0.1:0".parse()?);
66-
67-
// start the node & create a client
68-
let node = node.spawn().await?;
69-
let client = node.client();
70-
71-
// create a document & author
72-
let author = client.create_author().await?;
73-
let doc = client.create_doc().await?;
74-
75-
// set the key "key" to "value"
76-
let key = b"key";
77-
let value = b"value";
78-
doc.set_bytes(author, key.to_vec(), value.to_vec()).await?;
79-
println!("key is set!");
80-
81-
// read the value back
82-
let filter = GetFilter::latest().with_key(key);
83-
let entry = doc.get(filter).await?.next().await.ok_or_else(|| anyhow!("entry not found"))??;
84-
let content = doc.get_content_bytes(&entry).await?;
85-
86-
println!("value bytes: {:?}", content);
87-
88-
Ok(())
89-
}
44+
<%- examples.rust %>
9045
```
91-
46+
<% } %>
9247
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{/* THIS FILE IS GENERATED FROM A TEMPLATE. See scripts/generate-commands-pages.js for more */}
2+
export const metadata = {
3+
title: "author create",
4+
description: "Create a new author"
5+
}
6+
7+
# author create
8+
9+
Create a new author {{ className: 'lead' }}
10+
11+
12+
13+
## Examples
14+
15+
<CodeGroup title="SET">
16+
17+
18+
```text {{ title: 'console' }}
19+
>
20+
```
21+
22+
23+
24+
25+
26+
27+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{/* THIS FILE IS GENERATED FROM A TEMPLATE. See scripts/generate-commands-pages.js for more */}
2+
export const metadata = {
3+
title: "author list",
4+
description: "List authors"
5+
}
6+
7+
# author list
8+
9+
List authors {{ className: 'lead' }}
10+
11+
12+
13+
## Examples
14+
15+
<CodeGroup title="SET">
16+
17+
18+
```text {{ title: 'console' }}
19+
>
20+
```
21+
22+
23+
24+
25+
26+
27+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{/* THIS FILE IS GENERATED FROM A TEMPLATE. See scripts/generate-commands-pages.js for more */}
2+
export const metadata = {
3+
title: "author switch",
4+
description: "Set the active author for doc insertion"
5+
}
6+
7+
# author switch
8+
9+
Set the active author for doc insertion {{ className: 'lead' }}
10+
11+
12+
13+
## Examples
14+
15+
<CodeGroup title="SET">
16+
17+
18+
```text {{ title: 'console' }}
19+
>
20+
```
21+
22+
23+
24+
25+
26+
27+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{/* THIS FILE IS GENERATED FROM A TEMPLATE. See scripts/generate-commands-pages.js for more */}
2+
export const metadata = {
3+
title: "blob add",
4+
description: "Add data from PATH to the running provider&#39;s database"
5+
}
6+
7+
# blob add
8+
9+
Add data from PATH to the running provider&#39;s database {{ className: 'lead' }}
10+
11+
12+
13+
## Examples
14+
15+
<CodeGroup title="SET">
16+
17+
18+
```text {{ title: 'console' }}
19+
>
20+
```
21+
22+
23+
24+
25+
26+
27+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{/* THIS FILE IS GENERATED FROM A TEMPLATE. See scripts/generate-commands-pages.js for more */}
2+
export const metadata = {
3+
title: "blob list",
4+
description: "List availble content on the node"
5+
}
6+
7+
# blob list
8+
9+
List availble content on the node {{ className: 'lead' }}
10+
11+
12+
13+
## Examples
14+
15+
<CodeGroup title="SET">
16+
17+
18+
```text {{ title: 'console' }}
19+
>
20+
```
21+
22+
23+
24+
25+
26+
27+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{/* THIS FILE IS GENERATED FROM A TEMPLATE. See scripts/generate-commands-pages.js for more */}
2+
export const metadata = {
3+
title: "blob share",
4+
description: "Download data to the running provider&#39;s database and provide it"
5+
}
6+
7+
# blob share
8+
9+
Download data to the running provider&#39;s database and provide it {{ className: 'lead' }}
10+
11+
12+
13+
## Examples
14+
15+
<CodeGroup title="SET">
16+
17+
18+
```text {{ title: 'console' }}
19+
>
20+
```
21+
22+
23+
24+
25+
26+
27+
</CodeGroup>

0 commit comments

Comments
 (0)