1.4.0 • Published 8 months ago

protodef-yaml v1.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

protodef-yaml

NPM version Build Status Discord Try it on gitpod

Transforms YAML-like syntax to ProtoDef JSON schema and HTML documentation.

Usage

npm install -g protodef-yaml
protodef-yaml <input yaml file> <output json file> # generate json
protodef-yaml <input yaml file> <output html file> # generate docs

or through npx,

npx protodef-yaml input.yml
npx protodef-yaml input.yml docs.html

API

See API.md

Syntax

Refer to this documentation, also see test/ for example files

Example input:

ScoreEntries:
   type: u8 =>
      0: change
      1: remove
   entries: []varint
      scoreboard_id: zigzag64
      objective_name: string
      score: li32
      _: type?
         if remove:
            entry_type: i8 =>
               1: player
               2: entity
               3: fake_player
            _: entry_type?
               if player or entity:
                  entity_unique_id: zigzag64
               if fake_player:
                  custom_name: string

Output

{
  "ScoreEntries": [
    "container",
    [
      {
        "name": "type",
        "type": [
          "mapper",
          {
            "type": "u8",
            "mappings": {
              "0": "change",
              "1": "remove"
            }
          }
        ]
      },
      {
        "name": "entries",
        "type": [
          "array",
          {
            "countType": "varint",
            "type": [
              "container",
              [
                {
                  "name": "scoreboard_id",
                  "type": "zigzag64"
                },
                {
                  "name": "objective_name",
                  "type": "string"
                },
                {
                  "name": "score",
                  "type": "li32"
                },
                {
                  "anon": true,
                  "type": [
                    "switch",
                    {
                      "compareTo": "../type",
                      "fields": {
                        "remove": [
                          "container",
                          [
                            {
                              "name": "entry_type",
                              "type": [
                                "mapper",
                                {
                                  "type": "i8",
                                  "mappings": {
                                    "1": "player",
                                    "2": "entity",
                                    "3": "fake_player"
                                  }
                                }
                              ]
                            },
                            {
                              "anon": true,
                              "type": [
                                "switch",
                                {
                                  "compareTo": "entry_type",
                                  "fields": {
                                    "player": [
                                      "container",
                                      [
                                        {
                                          "name": "entity_unique_id",
                                          "type": "zigzag64"
                                        }
                                      ]
                                    ],
                                    "entity": [
                                      "container",
                                      [
                                        {
                                          "name": "entity_unique_id",
                                          "type": "zigzag64"
                                        }
                                      ]
                                    ],
                                    "fake_player": [
                                      "container",
                                      [
                                        {
                                          "name": "custom_name",
                                          "type": "string"
                                        }
                                      ]
                                    ]
                                  },
                                  "default": "void"
                                }
                              ]
                            }
                          ]
                        ]
                      },
                      "default": "void"
                    }
                  ]
                }
              ]
            ]
          }
        ]
      }
    ]
  ]
}

Info

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:

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:

SomeType:
   some_string: '["pstring", {"countType": "i32"}]'
1.4.0

8 months ago

1.2.5

3 years ago

1.3.0

3 years ago

1.2.4

3 years ago

1.2.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago