Skip to content
This repository was archived by the owner on Jul 13, 2024. It is now read-only.

Commit ba4f413

Browse files
authored
Merge pull request #287 from nicoespeon/browser-bundle
Generate browser bundle for @gitgraph/js
2 parents b73ce45 + ea5e29f commit ba4f413

File tree

15 files changed

+171
-53
lines changed

15 files changed

+171
-53
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
import build from "../../rollup.config";
2-
3-
export default build("gitgraph.core");
1+
export default {
2+
input: "lib/index.js",
3+
output: {
4+
file: "lib/bundle.umd.js",
5+
format: "umd",
6+
},
7+
};

packages/gitgraph-core/src/__tests__/gitgraph.getRenderedData.position.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { GitgraphCore, Mode } from "../gitgraph";
1+
import { GitgraphCore } from "../gitgraph";
2+
import { Mode } from "../mode";
23
import { Orientation } from "../orientation";
34

45
describe("Gitgraph.getRenderedData.position", () => {

packages/gitgraph-core/src/__tests__/gitgraph.getRenderedData.style.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { GitgraphCore, Mode } from "../gitgraph";
1+
import { GitgraphCore } from "../gitgraph";
2+
import { Mode } from "../mode";
23
import { BranchOptions } from "../branch";
34
import { metroTemplate, TemplateName, blackArrowTemplate } from "../template";
45
import { Orientation } from "../orientation";

packages/gitgraph-core/src/__tests__/gitgraph.getRenderedData.tags.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { GitgraphCore } from "../gitgraph";
2-
import { Tag } from "../tag";
32

43
describe("Gitgraph.getRenderedData.tags", () => {
54
it("should tag a commit", () => {

packages/gitgraph-core/src/gitgraph.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Branch, DELETED_BRANCH_NAME, createDeletedBranch } from "./branch";
22
import { Commit } from "./commit";
33
import { createGraphRows, GraphRows } from "./graph-rows";
4+
import { Mode } from "./mode";
45
import { BranchesOrder, CompareBranchesOrder } from "./branches-order";
56
import {
67
Template,
@@ -18,11 +19,7 @@ import {
1819
GitgraphTagOptions,
1920
} from "./user-api/gitgraph-user-api";
2021

21-
export { Mode, GitgraphOptions, RenderedData, GitgraphCore };
22-
23-
enum Mode {
24-
Compact = "compact",
25-
}
22+
export { GitgraphOptions, RenderedData, GitgraphCore };
2623

2724
interface GitgraphOptions {
2825
template?: TemplateName | Template;

packages/gitgraph-core/src/graph-rows/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Mode } from "../gitgraph";
1+
import { Mode } from "../mode";
22
import { Commit } from "../commit";
33

44
import { CompactGraphRows } from "./compact";

packages/gitgraph-core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export { GitgraphCore, GitgraphOptions, RenderedData, Mode } from "./gitgraph";
1+
export { GitgraphCore, GitgraphOptions, RenderedData } from "./gitgraph";
2+
export { Mode } from "./mode";
23
export {
34
GitgraphUserApi,
45
GitgraphCommitOptions,

packages/gitgraph-core/src/mode.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { Mode };
2+
3+
enum Mode {
4+
Compact = "compact",
5+
}

packages/gitgraph-core/src/user-api/branch-user-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { GitgraphCore, Mode } from "../gitgraph";
1+
import { GitgraphCore } from "../gitgraph";
2+
import { Mode } from "../mode";
23
import {
34
GitgraphCommitOptions,
45
GitgraphBranchOptions,

packages/gitgraph-js/README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@ Draw pretty git graphs with vanilla JS.
1313

1414
## Get started
1515

16+
### Example with ParcelJS
17+
1618
> You need to have [npm][get-npm] installed.
1719
20+
Create a new folder for your project and go there: `mkdir your-project && cd your-project`
21+
22+
Initialize your npm project: `npm init -y`
23+
1824
Install the package with npm: `npm i --save @gitgraph/js`
1925

26+
Install Parcel bundler: `npm i --save-dev parcel-bundler`
27+
2028
Now you can use `createGitgraph` to render your graph in a DOM element:
2129

30+
Create an `index.html` file:
31+
2232
```html
2333
<!DOCTYPE html>
2434
<html>
@@ -27,13 +37,18 @@ Now you can use `createGitgraph` to render your graph in a DOM element:
2737
</head>
2838
<body>
2939
<!-- DOM element in which we'll mount our graph -->
30-
<div id="#graph-container"></div>
40+
<div id="graph-container"></div>
41+
42+
<!-- This is for ParcelJS bundler -->
43+
<script src="./index.js"></script>
3144
</body>
3245
</html>
3346
```
3447

48+
Create an `index.js` file:
49+
3550
```js
36-
const { createGitgraph } = require("@gitgraph/js");
51+
import { createGitgraph } from "@gitgraph/js";
3752

3853
// Get the graph container HTML element.
3954
const graphContainer = document.getElementById("graph-container");
@@ -60,10 +75,25 @@ develop.commit("Prepare v1");
6075
master.merge(develop).tag("v1.0.0");
6176
```
6277

63-
This code will render the following graph:
78+
Add start command in your `package.json`:
79+
80+
```diff
81+
{
82+
"name": "your-project",
83+
"version": "1.0.0",
84+
"scripts": {
85+
+ "start": "parcel index.html"
86+
}
87+
```
88+
89+
Run `npm start`. You should see the following graph:
6490

6591
![Example of usage](./assets/example-usage.png)
6692

93+
### Example with browser bundle
94+
95+
TODO: fill
96+
6797
## More examples
6898

6999
[A bunch of scenarios][stories] has been simulated in our Storybook. You can give them a look 👀
@@ -72,3 +102,7 @@ This code will render the following graph:
72102
[gitgraph-repo]: https://github.com/nicoespeon/gitgraph.js/
73103
[stories]: https://github.com/nicoespeon/gitgraph.js/tree/master/packages/stories/src/gitgraph-js/
74104
[migration-guide]: https://github.com/nicoespeon/gitgraph.js/blob/master/packages/gitgraph-js/MIGRATE_FROM_GITGRAPH.JS.md
105+
106+
```
107+
108+
```

0 commit comments

Comments
 (0)