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.
Input text consists of 2 sections: [option]
and [log]
.
[option]
is optional.
[option]
defaultBranch: <branch>
[log]
...
[log]
...
key | value | default |
---|---|---|
defaultBranch |
string | master |
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>
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.
}