Skip to content

Commit 4f60763

Browse files
committed
wip: Code and Tests working
1 parent ef08c53 commit 4f60763

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3299
-3205
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ coverage/**
33
build/**
44
docs/**
55
node_modules/**
6-
src/diff2html-templates.js
6+
src/diff2html-templates.*
7+
typings/**

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ bower_components/
3232
/docs/
3333
/dist/
3434
/build/
35-
/src/diff2html-templates.js
35+
/src/diff2html-templates.*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ The HTML output accepts a Javascript object with configuration. Possible options
201201
- `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500`
202202
- `maxLineSizeInBlockForComparison`: maximum number os characters of the bigger line in a block to apply comparison, default is `200`
203203
- `maxLineLengthHighlight`: only perform diff changes highlight if lines are smaller than this, default is `10000`
204-
- `templates`: object with previously compiled templates to replace parts of the html
204+
- `compiledTemplates`: object with previously compiled templates to replace parts of the html
205205
- `rawTemplates`: object with raw not compiled templates to replace parts of the html
206206
- `renderNothingWhenEmpty`: render nothing if the diff shows no change in its comparison: `true` or `false`, default is `false`
207207
> For more information regarding the possible templates look into [src/templates](https://github.com/rtfpessoa/diff2html/tree/master/src/templates)

package.json

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"coverage": "jest --collectCoverage",
4242
"coverage-html": "yarn run coverage && open ./coverage/index.html",
4343
"codacy": "cat ./coverage/lcov.info | codacy-coverage",
44-
"build": "rm -rf build; yarn run build-scripts && yarn run build-css && yarn run build-templates && yarn run build-library && yarn run build-browser-bundle && yarn run build-website",
44+
"build": "rm -rf build docs; yarn run build-scripts && yarn run build-css && yarn run build-templates && yarn run build-library && yarn run build-browser-bundle && yarn run build-website",
4545
"build-scripts": "tsc -p tsconfig.scripts.json",
4646
"build-css": "./scripts/build-css.sh",
4747
"build-templates": "./scripts/build-templates.sh",
@@ -57,41 +57,42 @@
5757
"fs": false
5858
},
5959
"dependencies": {
60-
"diff": "^4.0.1",
61-
"hogan.js": "^3.0.2",
62-
"merge": "^1.2.1",
63-
"whatwg-fetch": "^3.0.0"
60+
"diff": "4.0.1",
61+
"hogan.js": "3.0.2"
6462
},
6563
"devDependencies": {
66-
"@types/hogan.js": "^3.0.0",
64+
"@types/diff": "4.0.2",
65+
"@types/highlight.js": "9.12.3",
6766
"@types/jest": "24.0.18",
68-
"@types/mkdirp": "^0.5.2",
69-
"@types/node": "^12.7.2",
70-
"@types/nopt": "^3.0.29",
67+
"@types/mkdirp": "0.5.2",
68+
"@types/node": "12.7.2",
69+
"@types/nopt": "3.0.29",
7170
"@typescript-eslint/eslint-plugin": "2.0.0",
7271
"@typescript-eslint/parser": "2.0.0",
73-
"autoprefixer": "^9.6.0",
74-
"browserify": "^16.5.0",
75-
"clean-css-cli": "^4.3.0",
76-
"codacy-coverage": "^3.4.0",
72+
"autoprefixer": "9.6.0",
73+
"browserify": "16.5.0",
74+
"clean-css-cli": "4.3.0",
75+
"codacy-coverage": "3.4.0",
7776
"eslint": "6.2.2",
7877
"eslint-config-prettier": "6.1.0",
7978
"eslint-config-standard": "14.0.1",
8079
"eslint-plugin-import": "2.18.2",
8180
"eslint-plugin-jest": "22.15.2",
8281
"eslint-plugin-node": "9.1.0",
8382
"eslint-plugin-prettier": "3.1.0",
84-
"eslint-plugin-promise": "^4.2.1",
85-
"eslint-plugin-standard": "^4.0.1",
86-
"fast-html-parser": "^1.0.1",
83+
"eslint-plugin-promise": "4.2.1",
84+
"eslint-plugin-standard": "4.0.1",
85+
"fast-html-parser": "1.0.1",
86+
"highlight.js": "9.15.10",
8787
"jest": "24.9.0",
88-
"mkdirp": "^0.5.1",
89-
"nopt": "^4.0.1",
90-
"postcss-cli": "^6.1.3",
88+
"mkdirp": "0.5.1",
89+
"nopt": "4.0.1",
90+
"postcss-cli": "6.1.3",
9191
"prettier": "1.18.2",
92-
"terser": "^4.3.8",
93-
"ts-jest": "24.0.2",
94-
"typescript": "^3.6.3"
92+
"terser": "4.3.8",
93+
"ts-jest": "24.1.0",
94+
"typescript": "3.6.4",
95+
"whatwg-fetch": "3.0.0"
9596
},
9697
"resolutions": {
9798
"lodash": "4.17.15"

scripts/build-templates.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ set -e
55
SCRIPT_DIRECTORY="$( cd "$( dirname "$0" )" && pwd )"
66

77
node ${SCRIPT_DIRECTORY}/../build/scripts/hulk.js \
8-
--wrapper node \
9-
--variable 'browserTemplates' \
10-
${SCRIPT_DIRECTORY}/../src/templates/*.mustache > ${SCRIPT_DIRECTORY}/../src/diff2html-templates.js
8+
--wrapper ts \
9+
--variable 'defaultTemplates' \
10+
${SCRIPT_DIRECTORY}/../src/templates/*.mustache > ${SCRIPT_DIRECTORY}/../src/diff2html-templates.ts

scripts/hulk.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as path from "path";
1919
import * as fs from "fs";
2020

2121
import * as hogan from "hogan.js";
22-
import * as nopt from "nopt";
22+
import nopt from "nopt";
2323
import * as mkderp from "mkdirp";
2424

2525
const options = nopt(
@@ -52,10 +52,9 @@ function cyan(text: string): string {
5252
}
5353

5454
function extractFiles(files: string[]): string[] {
55-
const usage = `
56-
${cyan(
57-
"USAGE:"
58-
)} hulk [--wrapper wrapper] [--outputdir outputdir] [--namespace namespace] [--variable variable] FILES
55+
const usage = `${cyan(
56+
"USAGE:"
57+
)} hulk [--wrapper wrapper] [--outputdir outputdir] [--namespace namespace] [--variable variable] FILES
5958
6059
${cyan("OPTIONS:")} [-w, --wrapper] :: wraps the template (i.e. amd)
6160
[-o, --outputdir] :: outputs the templates as individual files to a directory
@@ -130,6 +129,8 @@ function wrap(file: string, name: string, openedFile: string): string {
130129
// If we have a template per file the export will expose the template directly
131130
return options.outputdir ? `global.${objectStmt};\nmodule.exports = ${objectAccessor};` : `global.${objectStmt}`;
132131

132+
case "ts":
133+
return `// @ts-ignore\n${objectStmt}`;
133134
default:
134135
return objectStmt;
135136
}
@@ -141,19 +142,18 @@ function prepareOutput(content: string): string {
141142
case "amd":
142143
return content;
143144
case "node":
144-
return (
145-
"(function() {\n" +
146-
"if (!!!global." +
147-
variableName +
148-
") global." +
149-
variableName +
150-
" = {};\n" +
151-
'var Hogan = require("hogan.js");' +
152-
content +
153-
"\n" +
154-
(!options.outputdir ? "module.exports = global." + variableName + ";\n" : "") +
155-
"})();"
156-
);
145+
return `(function() {
146+
if (!!!global.${variableName}) global.${variableName} = {};
147+
var Hogan = require("hogan.js");
148+
${content}
149+
${!options.outputdir ? `module.exports = global.${variableName};\n` : ""})();`;
150+
151+
case "ts":
152+
return `import * as Hogan from "hogan.js";
153+
type CompiledTemplates = { [name: string]: Hogan.Template };
154+
export const ${variableName}: CompiledTemplates = {};
155+
${content}`;
156+
157157
default:
158158
return "if (!!!" + variableName + ") var " + variableName + " = {};\n" + content;
159159
}
@@ -181,7 +181,9 @@ const templates = extractFiles(options.argv.remain)
181181

182182
if (!options.outputdir) return cleanFileContents;
183183

184-
return fs.writeFileSync(path.join(options.outputdir, `${name}.js`), prepareOutput(cleanFileContents));
184+
const fileExtension = options.wrapper === "ts" ? "ts" : "js";
185+
186+
return fs.writeFileSync(path.join(options.outputdir, `${name}.${fileExtension}`), prepareOutput(cleanFileContents));
185187
})
186188
.filter(templateContents => typeof templateContents !== "undefined");
187189

0 commit comments

Comments
 (0)