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

15 files changed

+171
-53
lines changed
+7-3
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

+2-1
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

+2-1
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

-1
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

+2-5
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

+1-1
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

+2-1
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

+5
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

+2-1
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

+37-3
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+
```

packages/gitgraph-js/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"publishConfig": {
2727
"access": "public"
2828
},
29-
"main": "./lib/bundle.umd.js",
29+
"main": "./lib/index.js",
30+
"browser": "./lib/gitgraph.umd.js",
3031
"module": "./lib/index.js",
3132
"jsnext:main": "./lib/index.js",
3233
"typings": "./lib/index.d.ts",
@@ -42,8 +43,7 @@
4243
"build:clear": "rimraf ./lib",
4344
"build:tsc": "tsc",
4445
"build:bundle": "rollup -c rollup.config.js",
45-
"build:browserify": "browserify ./lib/bundle.umd.js -o ./lib/bundle.js",
46-
"build:minify": "uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.js",
46+
"build:minify": "uglifyjs -c -m -o ./lib/gitgraph.umd.min.js -- ./lib/gitgraph.umd.js",
4747
"prepare": "npm run build",
4848
"version": "auto-changelog -p -l 0 --tag-prefix @gitgraph/js@ && git add CHANGELOG.md"
4949
},
@@ -53,10 +53,11 @@
5353
"devDependencies": {
5454
"@types/node": "^9.4.6",
5555
"auto-changelog": "1.12.1",
56-
"browserify": "^14.5.0",
5756
"npm-run-all": "^4.1.2",
5857
"rimraf": "^2.6.2",
59-
"rollup": "^0.51.8",
58+
"rollup": "1.10.1",
59+
"rollup-plugin-commonjs": "9.3.4",
60+
"rollup-plugin-node-resolve": "4.2.3",
6061
"typescript": "3.3.4000",
6162
"uglify-es": "^3.3.9"
6263
}

packages/gitgraph-js/rollup.config.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
import build from "../../rollup.config";
1+
import resolve from "rollup-plugin-node-resolve";
2+
import commonJS from "rollup-plugin-commonjs";
23

3-
export default build("gitgraph.core");
4+
export default {
5+
input: "lib/index.js",
6+
output: {
7+
file: "lib/gitgraph.umd.js",
8+
format: "umd",
9+
name: "GitgraphJS",
10+
},
11+
plugins: [resolve(), commonJS()],
12+
};
+24-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1-
import build from "../../rollup.config";
1+
const globals = {
2+
"@gitgraph/core": "gitgraph.core",
3+
};
24

3-
export default build("gitgraph.core");
5+
export default {
6+
input: "lib/index.js",
7+
output: {
8+
file: "lib/bundle.umd.js",
9+
format: "umd",
10+
},
11+
name: "GitgraphReact",
12+
exports: "named",
13+
sourcemap: true,
14+
external: Object.keys(globals),
15+
onwarn,
16+
globals,
17+
};
18+
19+
function onwarn(message) {
20+
const suppressed = ["UNRESOLVED_IMPORT", "THIS_IS_UNDEFINED"];
21+
22+
if (!suppressed.find((code) => message.code === code)) {
23+
return console.warn(message.message);
24+
}
25+
}

rollup.config.js

-26
This file was deleted.

0 commit comments

Comments
 (0)