Skip to content

Commit 398363a

Browse files
authored
Merge pull request #82 from rtfpessoa/bump-diff2html
bump: Prepare for diff2html 3 release
2 parents b18cb93 + a33d33e commit 398363a

File tree

7 files changed

+1358
-733
lines changed

7 files changed

+1358
-733
lines changed

README.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,11 @@ Diff to Html generates pretty HTML diffs from unified and git diff output in you
5454
5555
## Distributions
5656

57+
- [NPM CLI](https://www.npmjs.org/package/diff2html-cli)
58+
- [NPM / Node.js library [ES5 & ES6]](https://github.com/rtfpessoa/diff2html)
59+
- [CDNJS](https://cdnjs.com/libraries/diff2html)
5760
- [WebJar](http://www.webjars.org/)
5861

59-
- [Node Module](https://www.npmjs.org/package/diff2html)
60-
61-
- [Bower Package](http://bower.io/search/?q=diff2html)
62-
63-
- [Node CLI](https://www.npmjs.org/package/diff2html-cli)
64-
65-
- Manually download and import
66-
[diff2html.min.js](https://raw.githubusercontent.com/rtfpessoa/diff2html/master/dist/diff2html.min.js) into your page
67-
6862
## Setup
6963

7064
npm install -g diff2html-cli
@@ -106,17 +100,15 @@ they are here:
106100
```
107101
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css" />
108102
<!--diff2html-css-->
109-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js"></script>
110-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/highlight.min.js"></script>
111-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/languages/scala.min.js"></script>
112103
<!--diff2html-js-ui-->
113104
<script>
114-
$(document).ready(function() {
115-
var diff2htmlUi = new Diff2HtmlUI();
116-
//diff2html-fileListCloseable
117-
//diff2html-synchronisedScroll
118-
//diff2html-highlightCode
119-
});
105+
document.addEventListener("DOMContentLoaded", () => {
106+
const targetElement = document.getElementById("diff");
107+
const diff2htmlUi = new Diff2HtmlUI(targetElement);
108+
//diff2html-fileListToggle
109+
//diff2html-synchronisedScroll
110+
//diff2html-highlightCode
111+
});
120112
</script>
121113
```
122114

@@ -168,7 +160,7 @@ your changes following the guidelines described in `CONTRIBUTING.md`. I will try
168160

169161
## Developing
170162

171-
Make some changes and then `node src/main.js` 😉
163+
Make some changes, `yarn build` and then `./bin/diff2html` 😉
172164

173165
## License
174166

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module.exports = {
77
collectCoverageFrom: ['src/**/*.ts', '!src/__tests__/**', '!node_modules/**'],
88
coverageThreshold: {
99
global: {
10-
statements: 35,
11-
branches: 14,
10+
statements: 34,
11+
branches: 10,
1212
functions: 33,
1313
lines: 34,
1414
},

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@
6464
"types": "./lib/diff2html.d.ts",
6565
"dependencies": {
6666
"clipboardy": "^2.1.0",
67-
"diff2html": "^2.12.1",
67+
"diff2html": "3.0.0-master.df4481f",
6868
"open": "^7.0.0",
6969
"request": "^2.88.0",
7070
"yargs": "^15.0.2"
7171
},
7272
"devDependencies": {
73-
"@types/request": "2.48.4",
73+
"@types/hogan.js": "^3.0.0",
7474
"@types/jest": "24.9.0",
7575
"@types/node": "13.1.8",
76+
"@types/request": "2.48.4",
7677
"@typescript-eslint/eslint-plugin": "2.16.0",
7778
"@typescript-eslint/parser": "2.16.0",
7879
"codacy-coverage": "3.4.0",

src/cli.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44

55
import * as clipboardy from 'clipboardy';
66
import open = require('open');
7-
import { Diff2Html } from 'diff2html';
7+
import { parse, html, Diff2HtmlConfig } from 'diff2html';
88

99
import * as http from './http-utils';
1010
import * as log from './logger';
@@ -26,10 +26,10 @@ function prepareHTML(diffHTMLContent: string, config: Configuration): string {
2626

2727
const diff2htmlPath = path.join(path.dirname(require.resolve('diff2html')), '..');
2828

29-
const cssFilePath = path.resolve(diff2htmlPath, 'dist', 'diff2html.min.css');
29+
const cssFilePath = path.resolve(diff2htmlPath, 'bundles', 'css', 'diff2html.min.css');
3030
const cssContent = utils.readFile(cssFilePath);
3131

32-
const jsUiFilePath = path.resolve(diff2htmlPath, 'dist', 'diff2html-ui.min.js');
32+
const jsUiFilePath = path.resolve(diff2htmlPath, 'bundles', 'js', 'diff2html-ui-slim.min.js');
3333
const jsUiContent = utils.readFile(jsUiFilePath);
3434

3535
/* HACK:
@@ -40,16 +40,16 @@ function prepareHTML(diffHTMLContent: string, config: Configuration): string {
4040
{ searchValue: '<!--diff2html-css-->', replaceValue: `<style>\n${cssContent}\n</style>` },
4141
{ searchValue: '<!--diff2html-js-ui-->', replaceValue: `<script>\n${jsUiContent}\n</script>` },
4242
{
43-
searchValue: '//diff2html-fileListCloseable',
44-
replaceValue: `diff2htmlUi.fileListCloseable("#diff", ${config.showFilesOpen});`,
43+
searchValue: '//diff2html-fileListToggle',
44+
replaceValue: `diff2htmlUi.fileListToggle(${config.showFilesOpen});`,
4545
},
4646
{
4747
searchValue: '//diff2html-synchronisedScroll',
48-
replaceValue: `diff2htmlUi.synchronisedScroll("#diff", ${config.synchronisedScroll});`,
48+
replaceValue: config.synchronisedScroll ? `diff2htmlUi.synchronisedScroll();` : '',
4949
},
5050
{
5151
searchValue: '//diff2html-highlightCode',
52-
replaceValue: config.highlightCode ? `diff2htmlUi.highlightCode("#diff");` : '',
52+
replaceValue: config.highlightCode ? `diff2htmlUi.highlightCode();` : '',
5353
},
5454
{ searchValue: '<!--diff2html-diff-->', replaceValue: diffHTMLContent },
5555
].reduce(
@@ -78,15 +78,15 @@ export async function getInput(inputType: InputType, inputArgs: string[], ignore
7878
}
7979
}
8080

81-
export function getOutput(options: Diff2Html.Options, config: Configuration, input: string): string {
81+
export function getOutput(options: Diff2HtmlConfig, config: Configuration, input: string): string {
8282
if (config.htmlWrapperTemplate && !fs.existsSync(config.htmlWrapperTemplate)) {
8383
throw new Error(`Template ('${config.htmlWrapperTemplate}') not found!`);
8484
}
8585

86-
const diffJson = Diff2Html.getJsonFromDiff(input, options);
86+
const diffJson = parse(input, options);
8787

8888
if (config.formatType === 'html') {
89-
const htmlContent = Diff2Html.getPrettyHtml(diffJson, { ...options, inputFormat: 'json' });
89+
const htmlContent = html(diffJson, { ...options });
9090
return prepareHTML(htmlContent, config);
9191
} else if (config.formatType === 'json') {
9292
return JSON.stringify(diffJson);

src/configuration.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@ import * as path from 'path';
22

33
import { Configuration } from './types';
44
import { Argv } from './yargs';
5+
import { Diff2HtmlConfig } from 'diff2html';
6+
import { OutputFormatType, DiffStyleType, LineMatchingType } from 'diff2html/lib/types';
57

6-
export function parseArgv(argv: Argv): [Diff2Html.Options, Configuration] {
7-
const diff2htmlOptions: Diff2Html.Options = {
8-
inputFormat: 'diff',
9-
outputFormat: argv.style === 'side' ? 'side-by-side' : 'line-by-line',
10-
showFiles: argv.summary !== 'hidden',
11-
diffStyle: argv.diffStyle,
12-
matching: argv.matching,
8+
export function parseArgv(argv: Argv): [Diff2HtmlConfig, Configuration] {
9+
const diff2htmlOptions: Diff2HtmlConfig = {
10+
outputFormat:
11+
argv.style === 'side'
12+
? OutputFormatType.SIDE_BY_SIDE
13+
: argv.style === 'line'
14+
? OutputFormatType.LINE_BY_LINE
15+
: undefined,
16+
diffStyle:
17+
argv.diffStyle === 'char' ? DiffStyleType.CHAR : argv.diffStyle === 'word' ? DiffStyleType.WORD : undefined,
18+
matching:
19+
argv.matching === 'lines'
20+
? LineMatchingType.LINES
21+
: argv.matching === 'words'
22+
? LineMatchingType.WORDS
23+
: argv.matching === 'none'
24+
? LineMatchingType.NONE
25+
: undefined,
26+
drawFileList: argv.summary !== 'hidden',
1327
matchWordsThreshold: argv.matchWordsThreshold,
1428
matchingMaxComparisons: argv.matchingMaxComparisons,
1529
};

template.html

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,19 @@
77
<!--
88
Diff to HTML (template.html)
99
Author: rtfpessoa
10-
-->
10+
-->
1111

1212
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css" />
1313

1414
<!--diff2html-css-->
1515

16-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js"></script>
17-
18-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/highlight.min.js"></script>
19-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/languages/scala.min.js"></script>
20-
2116
<!--diff2html-js-ui-->
2217

2318
<script>
24-
$(document).ready(function() {
25-
var diff2htmlUi = new Diff2HtmlUI();
26-
//diff2html-fileListCloseable
19+
document.addEventListener('DOMContentLoaded', () => {
20+
const targetElement = document.getElementById('diff');
21+
const diff2htmlUi = new Diff2HtmlUI(targetElement);
22+
//diff2html-fileListToggle
2723
//diff2html-synchronisedScroll
2824
//diff2html-highlightCode
2925
});

0 commit comments

Comments
 (0)