Skip to content

Commit 8731f97

Browse files
authored
Merge pull request #297 from rtfpessoa/release-major-version
release: New major refactor of diff2html to Typescript
2 parents df4481f + e53c7f0 commit 8731f97

File tree

10 files changed

+1134
-977
lines changed

10 files changed

+1134
-977
lines changed

.circleci/config.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ jobs:
1010
- run:
1111
name: Get next version
1212
command: |
13-
# Hack: Set a unique fake name for the release branch to avoid releasing master as the new 3.x major release for now
14-
export NEXT_VERSION="$(/bin/git-version --folder=$PWD --release-branch=FAKE-RELEASE-BRANCH-NAME)"
13+
export NEXT_VERSION="$(/bin/git-version --folder=$PWD --release-branch=master)"
1514
echo "Next version is ${NEXT_VERSION}"
1615
echo "${NEXT_VERSION}" > .version
1716
- run:
1817
name: Get next npm tag name
1918
command: |
20-
if [ "${GITHUB_REF#refs/heads/}" = "master" ]; then
19+
if [ "${CIRCLE_BRANCH}" = "master" ]; then
2120
export PUBLISH_TAG="latest"
22-
elif [ "${GITHUB_REF#refs/heads/}" = "next" ]; then
21+
elif [ "${CIRCLE_BRANCH}" = "next" ]; then
2322
export PUBLISH_TAG="next"
2423
else
2524
export PUBLISH_TAG="pr"
@@ -132,6 +131,7 @@ jobs:
132131
command: |
133132
# Update version in packages to publish
134133
yarn version --non-interactive --new-version $(cat .version)
134+
git push --tags "https://rtfpessoa:$GPR_AUTH_TOKEN@github.com/rtfpessoa/diff2html"
135135
- run:
136136
name: Setup npm credentials
137137
command: |
@@ -208,3 +208,7 @@ workflows:
208208
- publish_website:
209209
requires:
210210
- publish_approval
211+
filters:
212+
branches:
213+
only:
214+
- master

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
[![node](https://img.shields.io/node/v/diff2html.svg)]() [![npm](https://img.shields.io/npm/l/diff2html.svg)]()
1313
[![npm](https://img.shields.io/npm/dm/diff2html.svg)](https://www.npmjs.com/package/diff2html)
14-
[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-)
14+
[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors)
1515
[![Gitter](https://badges.gitter.im/rtfpessoa/diff2html.svg)](https://gitter.im/rtfpessoa/diff2html?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
1616

1717
diff2html generates pretty HTML diffs from git diff or unified diff output.
@@ -25,13 +25,14 @@ diff2html generates pretty HTML diffs from git diff or unified diff output.
2525
- [Features](#features)
2626
- [Online Example](#online-example)
2727
- [Distributions](#distributions)
28+
- [Usage](#usage)
2829
- [Diff2Html Usage](#diff2html-usage)
2930
- [Diff2Html API](#diff2html-api)
3031
- [Diff2Html Configuration](#diff2html-configuration)
3132
- [Diff2Html Browser](#diff2html-browser)
3233
- [Diff2Html NPM / Node.js Library](#diff2html-npm--nodejs-library)
3334
- [Diff2Html Examples](#diff2html-examples)
34-
- [Diff2HtmlUI](#diff2htmlui)
35+
- [Diff2HtmlUI Usage](#diff2htmlui-usage)
3536
- [Diff2HtmlUI API](#diff2htmlui-api)
3637
- [Diff2HtmlUI Configuration](#diff2htmlui-configuration)
3738
- [Diff2HtmlUI Browser](#diff2htmlui-browser)
@@ -101,6 +102,17 @@ diff2html generates pretty HTML diffs from git diff or unified diff output.
101102
including a `highlight.js` implementation. You can use it without syntax highlight or by passing your own
102103
implementation with the languages you prefer
103104

105+
## Usage
106+
107+
Diff2Html can be used in various ways as listed in the [distributions](#distributions) section. The two main ways are:
108+
109+
- [Diff2Html](#diff2html-usage): using the parser and html generator directly from the library gives you complete
110+
control about what you can do with the json or html generated.
111+
- [Diff2HtmlUI](#diff2htmlui-usage): using this wrapper makes it easy to inject the html in the DOM and adds some nice
112+
features to the diff, like syntax highlight.
113+
114+
Bellow you can find more details and exemples about each option.
115+
104116
## Diff2Html Usage
105117

106118
To load correctly in the Browser you always need to include the stylesheet in the final HTML.
@@ -135,11 +147,11 @@ function html(diffInput: string | DiffFile[], configuration: Diff2HtmlConfig = {
135147
The HTML output accepts a Javascript object with configuration. Possible options:
136148

137149
- `outputFormat`: the format of the output data: `'line-by-line'` or `'side-by-side'`, default is `'line-by-line'`
138-
- `drawFileList`: show a file list before the diff: `true` or `false`, default is `false`
150+
- `drawFileList`: show a file list before the diff: `true` or `false`, default is `true`
139151
- `diffStyle`: show differences level in each line: `word` or `char`, default is `word`
140152
- `matching`: matching level: `'lines'` for matching lines, `'words'` for matching lines and words or `'none'`, default
141153
is `none`
142-
- `matchWordsThreshold`: similarity threshold for word matching, default is 0.25
154+
- `matchWordsThreshold`: similarity threshold for word matching, default is `0.25`
143155
- `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is
144156
`2500`
145157
- `maxLineSizeInBlockForComparison`: maximum number os characters of the bigger line in a block to apply comparison,
@@ -266,7 +278,7 @@ export default {
266278
</script>
267279
```
268280

269-
## Diff2HtmlUI
281+
## Diff2HtmlUI Usage
270282

271283
> Simple wrapper to ease simple tasks in the browser such as: code highlight and js effects
272284

package.json

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"repository": {
2828
"type": "git",
29-
"url": "https://www.github.com/rtfpessoa/diff2html.git"
29+
"url": "git://github.com/rtfpessoa/diff2html.git"
3030
},
3131
"bugs": {
3232
"url": "https://www.github.com/rtfpessoa/diff2html/issues"
@@ -48,8 +48,9 @@
4848
"build:css": "rm -rf ./bundles/css; postcss --config ./postcss.config.js --no-map -o ./bundles/css/diff2html.min.css ./src/ui/css/diff2html.css",
4949
"build:templates": "ts-node ./scripts/hulk.ts --wrapper ts --variable 'defaultTemplates' ./src/templates/*.mustache > ./src/diff2html-templates.ts",
5050
"build:website": "rm -rf docs; webpack ---display-reasons --display-modules --mode production --config webpack.website.ts",
51-
"build:toc-base": "markdown-toc --maxdepth 3 --bullets='-' -i",
52-
"build:toc": "yarn run build:toc-base README.md",
51+
"gen": "yarn run gen:toc",
52+
"gen:toc-base": "markdown-toc --maxdepth 3 --bullets='-' -i",
53+
"gen:toc": "yarn run gen:toc-base README.md",
5354
"test": "is-ci 'test:coverage' 'test:watch'",
5455
"test:coverage": "jest --coverage",
5556
"test:watch": "jest --watch",
@@ -74,40 +75,37 @@
7475
"lint-staged": {
7576
"**/*.+(js|jsx|ts|tsx|json)": [
7677
"prettier --write",
77-
"eslint --fix",
78-
"git add"
78+
"eslint --fix"
7979
],
8080
"**/*.+(css|html|md|mdx)": [
81-
"prettier --write",
82-
"git add"
81+
"prettier --write"
8382
],
8483
"README.md": [
85-
"yarn run build:toc-base",
86-
"git add"
84+
"yarn run gen:toc-base"
8785
]
8886
},
8987
"dependencies": {
9088
"diff": "4.0.2",
9189
"hogan.js": "3.0.2"
9290
},
9391
"optionalDependencies": {
94-
"highlight.js": "9.17.1"
92+
"highlight.js": "9.18.1"
9593
},
9694
"devDependencies": {
9795
"@types/clipboard": "2.0.1",
9896
"@types/copy-webpack-plugin": "5.0.0",
9997
"@types/diff": "4.0.2",
10098
"@types/highlight.js": "9.12.3",
10199
"@types/hogan.js": "3.0.0",
102-
"@types/html-webpack-plugin": "3.2.1",
103-
"@types/jest": "24.9.0",
100+
"@types/html-webpack-plugin": "3.2.2",
101+
"@types/jest": "25.1.1",
104102
"@types/mini-css-extract-plugin": "0.9.0",
105103
"@types/mkdirp": "0.5.2",
106-
"@types/node": "13.1.8",
104+
"@types/node": "13.7.0",
107105
"@types/nopt": "3.0.29",
108-
"@types/webpack": "4.41.2",
109-
"@typescript-eslint/eslint-plugin": "2.16.0",
110-
"@typescript-eslint/parser": "2.16.0",
106+
"@types/webpack": "4.41.5",
107+
"@typescript-eslint/eslint-plugin": "2.19.0",
108+
"@typescript-eslint/parser": "2.19.0",
111109
"autoprefixer": "9.7.4",
112110
"bulma": "^0.8.0",
113111
"clipboard": "2.0.4",
@@ -116,41 +114,41 @@
116114
"css-loader": "3.4.2",
117115
"cssnano": "4.1.10",
118116
"eslint": "6.8.0",
119-
"eslint-config-prettier": "6.9.0",
120-
"eslint-plugin-import": "2.20.0",
117+
"eslint-config-prettier": "6.10.0",
118+
"eslint-plugin-import": "2.20.1",
121119
"eslint-plugin-jest": "23.6.0",
122120
"eslint-plugin-json": "2.0.1",
123121
"eslint-plugin-node": "11.0.0",
124122
"eslint-plugin-optimize-regex": "1.1.7",
125123
"eslint-plugin-promise": "4.2.1",
126124
"eslint-plugin-sonarjs": "0.5.0",
127125
"file-loader": "5.0.2",
128-
"handlebars": "4.7.2",
126+
"handlebars": "4.7.3",
129127
"handlebars-loader": "1.7.1",
130128
"html-webpack-plugin": "3.2.0",
131-
"husky": "4.0.10",
129+
"husky": "4.2.1",
132130
"image-webpack-loader": "6.0.0",
133131
"is-ci-cli": "2.0.0",
134-
"jest": "24.9.0",
135-
"lint-staged": "9.5.0",
132+
"jest": "25.1.0",
133+
"lint-staged": "10.0.7",
136134
"markdown-toc": "^1.2.0",
137135
"mini-css-extract-plugin": "0.9.0",
138-
"mkdirp": "0.5.1",
136+
"mkdirp": "1.0.3",
139137
"nopt": "4.0.1",
140138
"postcss": "7.0.26",
141139
"postcss-cli": "7.1.0",
142140
"postcss-import": "12.0.1",
143141
"postcss-loader": "3.0.0",
144142
"postcss-preset-env": "6.7.0",
145143
"prettier": "1.19.1",
146-
"ts-jest": "24.3.0",
144+
"ts-jest": "25.2.0",
147145
"ts-loader": "6.2.1",
148146
"ts-node": "8.6.2",
149147
"typescript": "3.7.5",
150148
"url-loader": "3.0.0",
151149
"webpack": "4.41.5",
152150
"webpack-cli": "3.3.10",
153-
"webpack-dev-server": "3.10.1",
151+
"webpack-dev-server": "3.10.3",
154152
"whatwg-fetch": "3.0.0"
155153
},
156154
"resolutions": {

src/render-utils.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ import { unifyPath, hashCode } from './utils';
44
import * as rematch from './rematch';
55
import { LineMatchingType, DiffStyleType, LineType, DiffLineParts, DiffFile, DiffFileName } from './types';
66

7-
export enum CSSLineClass {
8-
INSERTS = 'd2h-ins',
9-
DELETES = 'd2h-del',
10-
CONTEXT = 'd2h-cntx',
11-
INFO = 'd2h-info',
12-
INSERT_CHANGES = 'd2h-ins d2h-change',
13-
DELETE_CHANGES = 'd2h-del d2h-change',
14-
}
7+
export type CSSLineClass =
8+
| 'd2h-ins'
9+
| 'd2h-del'
10+
| 'd2h-cntx'
11+
| 'd2h-info'
12+
| 'd2h-ins d2h-change'
13+
| 'd2h-del d2h-change';
14+
15+
export const CSSLineClass: { [_: string]: CSSLineClass } = {
16+
INSERTS: 'd2h-ins',
17+
DELETES: 'd2h-del',
18+
CONTEXT: 'd2h-cntx',
19+
INFO: 'd2h-info',
20+
INSERT_CHANGES: 'd2h-ins d2h-change',
21+
DELETE_CHANGES: 'd2h-del d2h-change',
22+
};
1523

1624
export type HighlightedLines = {
1725
oldLine: {

src/types.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,24 @@ export interface DiffFile extends DiffFileName {
6969
mode?: string;
7070
}
7171

72-
export enum OutputFormatType {
73-
LINE_BY_LINE = 'line-by-line',
74-
SIDE_BY_SIDE = 'side-by-side',
75-
}
72+
export type OutputFormatType = 'line-by-line' | 'side-by-side';
7673

77-
export enum LineMatchingType {
78-
LINES = 'lines',
79-
WORDS = 'words',
80-
NONE = 'none',
81-
}
74+
export const OutputFormatType: { [_: string]: OutputFormatType } = {
75+
LINE_BY_LINE: 'line-by-line',
76+
SIDE_BY_SIDE: 'side-by-side',
77+
};
8278

83-
export enum DiffStyleType {
84-
WORD = 'word',
85-
CHAR = 'char',
86-
}
79+
export type LineMatchingType = 'lines' | 'words' | 'none';
80+
81+
export const LineMatchingType: { [_: string]: LineMatchingType } = {
82+
LINES: 'lines',
83+
WORDS: 'words',
84+
NONE: 'none',
85+
};
86+
87+
export type DiffStyleType = 'word' | 'char';
88+
89+
export const DiffStyleType: { [_: string]: DiffStyleType } = {
90+
WORD: 'word',
91+
CHAR: 'char',
92+
};

0 commit comments

Comments
 (0)