diff --git a/.circleci/config.yml b/.circleci/config.yml
index 56d463f..c7f95d4 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -8,13 +8,13 @@ jobs:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
- - run: npm install
+ - run: yarn
- save_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
paths:
- ./node_modules
- - run: npm run coverage
- - run: npm run check-coverage
+ - run: yarn run build
+ - run: yarn run coverage
build-latest: &latest-build
docker:
@@ -29,49 +29,35 @@ jobs:
key: dependency-cache-{{ checksum "yarn.lock" }}
paths:
- ./node_modules
- - run: yarn run test
+ - run: yarn run build
- run: yarn run lint
+ - run: yarn run coverage
- run: yarn run codacy
- persist_to_workspace:
root: ~/diff2html
paths:
- docs
- - dist
-
- build-node_4:
- <<: *common-build
- docker:
- - image: node:4
-
- build-node_5:
- <<: *common-build
- docker:
- - image: node:5
-
- build-node_6:
- <<: *common-build
- docker:
- - image: node:6
-
- build-node_7:
- <<: *common-build
- docker:
- - image: node:7
+ - build
build-node_8:
<<: *common-build
docker:
- image: node:8
- build-node_9:
+ build-node_10:
<<: *common-build
docker:
- - image: node:9
+ - image: node:10
- build-node_10:
+ build-node_11:
+ <<: *common-build
+ docker:
+ - image: node:11
+
+ build-node_12:
<<: *latest-build
docker:
- - image: node:10
+ - image: node:12
deploy:
machine:
@@ -80,11 +66,6 @@ jobs:
steps:
- attach_workspace:
at: .
- - run:
- name: Prepare website sources
- command: |
- rm -f docs/assets
- mv dist docs/assets
- run:
name: Deploy
working_directory: ~/diff2html/docs
@@ -94,16 +75,13 @@ workflows:
version: 2
build:
jobs:
- - build-node_4
- - build-node_5
- - build-node_6
- - build-node_7
- build-node_8
- - build-node_9
- build-node_10
+ - build-node_11
+ - build-node_12
- deploy:
requires:
- - build-node_10
+ - build-node_12
filters:
branches:
only: master
diff --git a/.eslintignore b/.eslintignore
index 74776ac..35da219 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,11 +1,10 @@
-# Skip coverage and build folders
+# Skip build results
+_target/**
coverage/**
-dist/**
-
-# Ignore symlink to build folder
+bundles/**
docs/**
-
-# Ignore HTML templates generated code
-src/**
-!src/*.js
-!src/ui/js/*.js
+lib/**
+lib-esm/**
+node_modules/**
+src/diff2html-templates.*
+typings/**
diff --git a/.eslintrc.json b/.eslintrc.json
index 0096a89..a20ab3b 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,343 +1,30 @@
{
+ "parser": "@typescript-eslint/parser",
"parserOptions": {
- "ecmaVersion": 6,
+ "ecmaVersion": 2018,
+ "sourceType": "module",
"ecmaFeatures": {
+ "experimentalObjectRestSpread": true,
"jsx": true
- },
- "sourceType": "module"
+ }
},
"env": {
"es6": true,
"node": true,
"browser": true,
- "commonjs": true,
- "jquery": true,
- "phantomjs": true,
- "jasmine": true,
- "mocha": true,
- "amd": true,
- "worker": true,
- "qunit": true
+ "commonjs": true
},
- "plugins": [
- "standard",
- "promise"
- ],
+ "plugins": ["standard", "node", "import", "promise", "@typescript-eslint", "jest"],
"globals": {
"document": false,
"navigator": false,
"window": false
},
- "rules": {
- "accessor-pairs": 2,
- "arrow-spacing": [
- 2,
- {
- "before": true,
- "after": true
- }
- ],
- "block-spacing": [
- 2,
- "always"
- ],
- "brace-style": [
- 2,
- "1tbs",
- {
- "allowSingleLine": true
- }
- ],
- "camelcase": [
- 2,
- {
- "properties": "never"
- }
- ],
- "comma-dangle": [
- 2,
- "never"
- ],
- "comma-spacing": [
- 2,
- {
- "before": false,
- "after": true
- }
- ],
- "comma-style": [
- 2,
- "last"
- ],
- "constructor-super": 2,
- "curly": [
- 2,
- "multi-line"
- ],
- "dot-location": [
- 2,
- "property"
- ],
- "eol-last": 2,
- "eqeqeq": [
- 2,
- "allow-null"
- ],
- "generator-star-spacing": [
- 2,
- {
- "before": true,
- "after": true
- }
- ],
- "handle-callback-err": [
- 2,
- "^(err|error)$"
- ],
- "indent": [
- 2,
- 2,
- {
- "SwitchCase": 1
- }
- ],
- "jsx-quotes": [
- 2,
- "prefer-single"
- ],
- "key-spacing": [
- 2,
- {
- "beforeColon": false,
- "afterColon": true
- }
- ],
- "keyword-spacing": [
- 2,
- {
- "before": true,
- "after": true
- }
- ],
- "new-cap": [
- 2,
- {
- "newIsCap": true,
- "capIsNew": false
- }
- ],
- "new-parens": 2,
- "no-array-constructor": 2,
- "no-caller": 2,
- "no-class-assign": 2,
- "no-cond-assign": 2,
- "no-const-assign": 2,
- "no-control-regex": 2,
- "no-debugger": 2,
- "no-delete-var": 2,
- "no-dupe-args": 2,
- "no-dupe-class-members": 2,
- "no-dupe-keys": 2,
- "no-duplicate-case": 2,
- "no-duplicate-imports": 2,
- "no-empty-character-class": 2,
- "no-empty-pattern": 2,
- "no-eval": 2,
- "no-ex-assign": 2,
- "no-extend-native": 2,
- "no-extra-bind": 2,
- "no-extra-boolean-cast": 2,
- "no-extra-parens": [
- 2,
- "functions"
- ],
- "no-fallthrough": 2,
- "no-floating-decimal": 2,
- "no-func-assign": 2,
- "no-implied-eval": 2,
- "no-inner-declarations": [
- 2,
- "functions"
- ],
- "no-invalid-regexp": 2,
- "no-irregular-whitespace": 2,
- "no-iterator": 2,
- "no-label-var": 2,
- "no-labels": [
- 2,
- {
- "allowLoop": false,
- "allowSwitch": false
- }
- ],
- "no-lone-blocks": 2,
- "no-mixed-spaces-and-tabs": 2,
- "no-multi-spaces": 2,
- "no-multi-str": 2,
- "no-multiple-empty-lines": [
- 2,
- {
- "max": 1
- }
- ],
- "no-native-reassign": 2,
- "no-negated-in-lhs": 2,
- "no-new": 2,
- "no-new-func": 2,
- "no-new-object": 2,
- "no-new-require": 2,
- "no-new-symbol": 2,
- "no-new-wrappers": 2,
- "no-obj-calls": 2,
- "no-octal": 2,
- "no-octal-escape": 2,
- "no-path-concat": 2,
- "no-proto": 2,
- "no-redeclare": 2,
- "no-regex-spaces": 2,
- "no-return-assign": [
- 2,
- "except-parens"
- ],
- "no-self-assign": 2,
- "no-self-compare": 2,
- "no-sequences": 2,
- "no-shadow-restricted-names": 2,
- "no-spaced-func": 2,
- "no-sparse-arrays": 2,
- "no-this-before-super": 2,
- "no-throw-literal": 2,
- "no-trailing-spaces": 2,
- "no-undef": 2,
- "no-undef-init": 2,
- "no-unexpected-multiline": 2,
- "no-unmodified-loop-condition": 2,
- "no-unneeded-ternary": [
- 2,
- {
- "defaultAssignment": false
- }
- ],
- "no-unreachable": 2,
- "no-unsafe-finally": 2,
- "no-unused-vars": [
- 2,
- {
- "vars": "all",
- "args": "none"
- }
- ],
- "no-useless-call": 2,
- "no-useless-computed-key": 2,
- "no-useless-constructor": 2,
- "no-useless-escape": 2,
- "no-whitespace-before-property": 2,
- "no-with": 2,
- "one-var": [
- 2,
- {
- "initialized": "never"
- }
- ],
- "operator-linebreak": [
- 2,
- "after",
- {
- "overrides": {
- "?": "before",
- ":": "before"
- }
- }
- ],
- "padded-blocks": [
- 2,
- "never"
- ],
- "quotes": [
- 2,
- "single",
- "avoid-escape"
- ],
- "semi": [
- 2,
- "always"
- ],
- "semi-spacing": [
- 2,
- {
- "before": false,
- "after": true
- }
- ],
- "space-before-blocks": [
- 2,
- "always"
- ],
- "space-before-function-paren": [
- 2,
- "never"
- ],
- "space-in-parens": [
- 2,
- "never"
- ],
- "space-infix-ops": 2,
- "space-unary-ops": [
- 2,
- {
- "words": true,
- "nonwords": false
- }
- ],
- "spaced-comment": [
- 2,
- "always",
- {
- "markers": [
- "global",
- "globals",
- "eslint",
- "eslint-disable",
- "*package",
- "!",
- ","
- ]
- }
- ],
- "template-curly-spacing": [
- 2,
- "never"
- ],
- "use-isnan": 2,
- "valid-typeof": 2,
- "wrap-iife": [
- 2,
- "any"
- ],
- "yield-star-spacing": [
- 2,
- "both"
- ],
- "yoda": [
- 2,
- "never"
- ],
- "standard/object-curly-even-spacing": [
- 2,
- "either"
- ],
- "standard/array-bracket-even-spacing": [
- 2,
- "either"
- ],
- "standard/computed-property-even-spacing": [
- 2,
- "even"
- ],
- "promise/param-names": 2,
- "linebreak-style": [
- 2,
- "unix"
- ]
- }
+ "extends": [
+ "plugin:@typescript-eslint/recommended",
+ "plugin:jest/recommended",
+ "plugin:promise/recommended",
+ "standard",
+ "plugin:prettier/recommended"
+ ]
}
diff --git a/.gitignore b/.gitignore
index bde6b2f..f389625 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,3 +28,10 @@ bower_components/
# Terraform
/terraform/.terraform
+
+/_target
+/src/diff2html-templates.*
+/docs/
+/bundles/
+/lib/
+/lib-esm/
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..55712c1
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "typescript.tsdk": "node_modules/typescript/lib"
+}
\ No newline at end of file
diff --git a/docs/CNAME b/CNAME
similarity index 100%
rename from docs/CNAME
rename to CNAME
diff --git a/README.md b/README.md
index c5f5840..3495330 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,8 @@
# diff2html
-[](https://www.codacy.com/app/rtfpessoa/diff2html?utm_source=github.com&utm_medium=referral&utm_content=rtfpessoa/diff2html&utm_campaign=Badge_Grade)
+[](https://www.codacy.com/app/rtfpessoa/diff2html?utm_source=github.com&utm_medium=referral&utm_content=rtfpessoa/diff2html&utm_campaign=Badge_Grade)
[](https://www.codacy.com/app/rtfpessoa/diff2html?utm_source=github.com&utm_medium=referral&utm_content=rtfpessoa/diff2html&utm_campaign=Badge_Coverage)
[](https://circleci.com/gh/rtfpessoa/diff2html)
-[](https://dependencyci.com/github/rtfpessoa/diff2html)
[](https://www.npmjs.com/package/diff2html)
[](https://david-dm.org/rtfpessoa/diff2html)
@@ -22,21 +21,21 @@ diff2html generates pretty HTML diffs from git or unified diff output.
## Features
-* Supports git and unified diffs
+- Supports git and unified diffs
-* Line by line and Side by side diff
+- Line by line and Side by side diff
-* New and old line numbers
+- New and old line numbers
-* Inserted and removed lines
+- Inserted and removed lines
-* GitHub like style
+- GitHub like style
-* Code syntax highlight
+- Code syntax highlight
-* Line similarity matching
+- Line similarity matching
-* Easy code selection
+- Easy code selection
## Online Example
@@ -44,15 +43,16 @@ diff2html generates pretty HTML diffs from git or unified diff output.
## Distributions
-* [WebJar](http://www.webjars.org/)
-
-* [Node Module](https://www.npmjs.org/package/diff2html)
-
-* [Bower Package](http://bower.io/search/?q=diff2html)
-
-* [Node CLI](https://www.npmjs.org/package/diff2html-cli)
-
-* Manually download and import [dist/diff2html.min.js](./dist/diff2html.min.js) into your page
+- [WebJar](http://www.webjars.org/)
+- [Node Module](https://www.npmjs.org/package/diff2html)
+- [Node CLI](https://www.npmjs.org/package/diff2html-cli)
+- Manually download and import:
+ - Browser
+ - [bundles/js/diff2html.min.js](./bundles/js/diff2html.min.js) - includes the diff parser and html generator
+ - [bundles/js/diff2html-ui.min.js](./bundles/js/diff2html-ui.min.js) - includes the wrapper of diff2html that adds highlight, synchronized scroll, and other nice features
+ - Node.js
+ - [lib/diff2html.js](./lib/diff2html.js) - targeted for es5, includes the diff parser and html generator
+ - [lib-esm/diff2html.js](./lib-esm/diff2html.js) - targeted for es6 - includes the diff parser and html generator
## How to use
@@ -62,7 +62,7 @@ Import the stylesheet
```html
-
+
```
You can also refer to it from a CDN like [CDNJS](https://cdnjs.com/libraries/diff2html).
@@ -73,37 +73,41 @@ Import the stylesheet and the library code
```html
-
+
-
+
```
It will now be available as a global variable named `Diff2Html`.
```js
-var diffHtml = Diff2Html.getPrettyHtml(
- '',
- {inputFormat: 'diff', showFiles: true, matching: 'lines', outputFormat: 'side-by-side'}
-);
-document.getElementById("destination-elem-id").innerHTML = diffHtml;
+document.addEventListener("DOMContentLoaded", () => {
+ var diffHtml = global.Diff2Html.html("", {
+ drawFileList: true,
+ matching: "lines",
+ outputFormat: "side-by-side"
+ });
+ document.getElementById("destination-elem-id").innerHTML = diffHtml;
+});
```
### Node Module
```js
-let diff2html = require("diff2html").Diff2Html
+const Diff2html = require("diff2html");
+const diffJson = Diff2html.parse("");
+const diffHtml = Diff2html.html(diffJson, { drawFileList: true });
+document.getElementById("destination-elem-id").innerHTML = diffHtml;
```
### Angular
-* Typescript
+- Typescript
```typescript
-// import diff2html
-import {Diff2Html} from 'diff2html'
-import {Component, OnInit} from '@angular/core';
-
+import * as Diff2Html from "diff2html";
+import { Component, OnInit } from "@angular/core";
export class AppDiffComponent implements OnInit {
outputHtml: string;
@@ -111,18 +115,18 @@ export class AppDiffComponent implements OnInit {
this.init();
}
- ngOnInit() {
- }
+ ngOnInit() {}
init() {
- let strInput = "--- a/server/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go\n+++ b/server/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go\n@@ -1035,6 +1035,17 @@ func Prctl(option int, arg2 uintptr, arg3 uintptr, arg4 uintptr, arg5 uintptr) (\n \n // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n \n+func Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) {\n+\tr0, _, e1 := Syscall6(SYS_PSELECT6, uintptr(nfd), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask)))\n+\tn = int(r0)\n+\tif e1 != 0 {\n+\t\terr = errnoErr(e1)\n+\t}\n+\treturn\n+}\n+\n+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n+\n func read(fd int, p []byte) (n int, err error) {\n \tvar _p0 unsafe.Pointer\n \tif len(p) > 0 {\n";
- let outputHtml = Diff2Html.getPrettyHtml(strInput, {inputFormat: 'diff', showFiles: true, matching: 'lines'});
+ let strInput =
+ "--- a/server/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go\n+++ b/server/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go\n@@ -1035,6 +1035,17 @@ func Prctl(option int, arg2 uintptr, arg3 uintptr, arg4 uintptr, arg5 uintptr) (\n \n // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n \n+func Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) {\n+\tr0, _, e1 := Syscall6(SYS_PSELECT6, uintptr(nfd), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask)))\n+\tn = int(r0)\n+\tif e1 != 0 {\n+\t\terr = errnoErr(e1)\n+\t}\n+\treturn\n+}\n+\n+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n+\n func read(fd int, p []byte) (n int, err error) {\n \tvar _p0 unsafe.Pointer\n \tif len(p) > 0 {\n";
+ let outputHtml = Diff2Html.html(strInput, { drawFileList: true, matching: "lines" });
this.outputHtml = outputHtml;
}
}
```
-* HTML
+- HTML
```html
@@ -136,7 +140,7 @@ export class AppDiffComponent implements OnInit {