0.3.0 • Published 2 years ago

gitgraph-minigram v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

gitgraph-minigram

Provides grammar and parser for git commands (made with pegjs), and API invoker for @gitgraph/js.

This library takes the approach to draw commit graph from the sequence of git command inputs as you usually use in terminal.

Grammar

Input text consists of 2 sections: [option] and [log].

Basic structure of input

  • [option] is optional.
[option]
defaultBranch: <branch>
[log]
...
[log]
...

Options in [option] section

keyvaluedefault
defaultBranchstringmaster

Supported git commands in [log] section

git commit
git commit -m '<message>'
git commit -m "<message>"
git branch <branch>
git checkout <branch>
git checkout -b <branch>
git switch <branch>
git switch -c <branch>
git merge <branch>
git tag <tag>

Basic usage

import { createGitgraph } from '@gitgraph/js';
import { Format2Parser, Generator } from 'gitgraph-minigram';

const parser = new Format2Parser();
const generator = new Generator();

const input = ...; // Prepare text written in above grammar.
const parseResult = parser.parse(input);

if (parseResult.parsed()) {
  const container = ...; // HTML element to draw git commit graph.
  const graph = createGitgraph(container);

  generator.generate(graph, parseResult.getParseData());
} else {
  const e = parseResult.getError(); // pegjs syntax error object.
}

Used by