Skip to content

Commit

Permalink
Update readme and cli (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
extremeheat committed Jun 23, 2024
1 parent fd47138 commit df1567d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ if (!process.argv[2]) {

if (out.endsWith('.html')) {
const intermediary = parse(inp, true, true)
const html = htmlGen(intermediary, { includeHeader: true })
const schemaSegmented = Object.keys(intermediary).some(key => key.startsWith('^') || key.startsWith('%container,^'))
const html = htmlGen(intermediary, { includeHeader: true, schemaSegmented })
fs.writeFileSync(out, html)
} else {
compile(inp, out)
Expand Down
10 changes: 2 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ npx protodef-yaml input.yml docs.html
See [API.md](docs/API.md)

### Syntax
Refer to [this documentation](https://github.com/PrismarineJS/bedrock-protocol/blob/master/CONTRIBUTING.md#packet-serialization), also see test/ for example files
Refer to [this documentation](https://github.com/PrismarineJS/bedrock-protocol/blob/master/docs/CONTRIBUTING.md#packet-serialization), also see test/ for example files.

Example input:

Expand Down Expand Up @@ -189,14 +189,8 @@ The differences to YAML:
* parent nodes with children can have a value
* keys starting with '!' are ignored in the final output

You can also embed JSON for custom ProtoDef types as usual, for example:
You can also embed JSON for custom ProtoDef types as usual as YAML is a superset of JSON, for example:

```yaml
string: ["pstring", {"countType": "i32"}]
```
*Note:* the parser only supports this at a root level. To use nested json inside yaml, you can encapsulate a JSON array with a single quote. For example:
```yaml
SomeType:
some_string: '["pstring", {"countType": "i32"}]'
```
1 change: 1 addition & 0 deletions generators/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function generate(parsedSchema, options = {}) {

if (options.schemaSegmented) {
for (const k in parsedSchema) {
if (k.startsWith('!')) continue
const value = parsedSchema[k]
// protodef-yaml treats "segmented" schemas as standard containers! we unwrap.
const key = k.split(',')[1]
Expand Down

0 comments on commit df1567d

Please sign in to comment.