From 5ad783ae3d36652004c495f94942ff2a54fada11 Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Sat, 27 Aug 2016 12:46:22 +0100 Subject: [PATCH] Add TypeScript test, use .eslintignore --- .eslintignore | 6 ++++++ package.json | 2 +- scripts/.ignore | 0 scripts/hulk.js | 28 +++++++--------------------- typescript/diff2html-tests.ts | 26 ++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 22 deletions(-) create mode 100644 .eslintignore delete mode 100644 scripts/.ignore create mode 100644 typescript/diff2html-tests.ts diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..ded904e --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +src/** +!src/*.js +!src/ui/js/*.js +coverage/** +dist/** +test/** diff --git a/package.json b/package.json index 8361445..4faf81e 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "release-website": "node ./scripts/release-website.js", "release-bower": "./scripts/update-bower-version.sh", "templates": "./scripts/hulk.js --wrapper node --variable 'browserTemplates' ./src/templates/*.mustache > ./src/templates/diff2html-templates.js", - "style": "eslint src/*.js src/ui/js/*.js", + "style": "eslint .", "coverage": "istanbul cover _mocha -- -u exports -R spec ./test/**/*", "check-coverage": "istanbul check-coverage --statements 90 --functions 90 --branches 85 --lines 90 ./coverage/coverage.json", "test": "npm run coverage && npm run check-coverage", diff --git a/scripts/.ignore b/scripts/.ignore deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/hulk.js b/scripts/hulk.js index 4ce8203..5a793c1 100755 --- a/scripts/hulk.js +++ b/scripts/hulk.js @@ -15,7 +15,6 @@ * limitations under the License. */ - // dependencies var hogan = require('hogan.js'); var path = require('path'); @@ -23,7 +22,6 @@ var nopt = require('nopt'); var mkderp = require('mkdirp'); var fs = require('fs'); - // locals var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; var specialsRegExp = new RegExp('(\\' + specials.join('|\\') + ')', 'g'); @@ -45,23 +43,19 @@ var shortHand = { }; var templates; - // options options = nopt(options, shortHand); - // escape special regexp characters function esc(text) { return text.replace(specialsRegExp, '\\$1'); } - // cyan function for rob function cyan(text) { - return '\033[36m' + text + '\033[39m'; + return '\x1B[36m' + text + '\x1B[39m'; } - // check for dirs and correct ext (<3 for windows) function extractFiles(args) { var usage = '\n' + @@ -86,10 +80,9 @@ function extractFiles(args) { } args.forEach(function(arg) { - if (/\*/.test(arg)) { arg = arg.split('*'); - return files = files.concat( + files = files.concat( fs.readdirSync(arg[0] || '.') .map(function(f) { var file = path.join(arg[0], f); @@ -99,16 +92,15 @@ function extractFiles(args) { return f; }) ); + return files; } if (fs.statSync(arg).isFile()) files.push(arg); - }); return files; } - // remove utf-8 byte order mark, http://en.wikipedia.org/wiki/Byte_order_mark function removeByteOrderMark(text) { if (text.charCodeAt(0) === 0xfeff) { @@ -117,16 +109,15 @@ function removeByteOrderMark(text) { return text; } - // wrap templates function wrap(file, name, openedFile) { switch (options.wrapper) { - case "amd": + case 'amd': return 'define(' + (!options.outputdir ? '"' + path.join(path.dirname(file), name) + '", ' : '') + '[ "hogan.js" ], function(Hogan){ return new Hogan.Template(' + hogan.compile(openedFile, {asString: 1}) + ');});'; - case "node": + case 'node': var globalObj = 'global.' + (options.variable || 'templates') + '["' + name + '"]'; var globalStmt = globalObj + ' = new Hogan.Template(' + hogan.compile(openedFile, {asString: 1}) + ');'; var nodeOutput = globalStmt; @@ -145,13 +136,12 @@ function wrap(file, name, openedFile) { } } - function prepareOutput(content) { var variableName = options.variable || 'templates'; switch (options.wrapper) { - case "amd": + case 'amd': return content; - case "node": + case 'node': var nodeExport = ''; // if we have aggregated templates the export will expose the template map @@ -170,19 +160,16 @@ function prepareOutput(content) { } } - // write the directory if (options.outputdir) { mkderp.sync(options.outputdir); } - // Prepend namespace to template name function namespace(name) { return (options.namespace || '') + name; } - // write a template foreach file that matches template extension templates = extractFiles(options.argv.remain) .map(function(file) { @@ -200,7 +187,6 @@ templates = extractFiles(options.argv.remain) return t; }); - // output templates if (!templates.length || options.outputdir) process.exit(0); diff --git a/typescript/diff2html-tests.ts b/typescript/diff2html-tests.ts new file mode 100644 index 0000000..2fe6b3d --- /dev/null +++ b/typescript/diff2html-tests.ts @@ -0,0 +1,26 @@ +/// + +import Diff2Html = require('diff2html'); + +let d2h = Diff2Html.Diff2Html; + +class Diff2HtmlOptionsImpl implements Diff2Html.Options { + constructor(public inputFormat: string) { + } +} + +let strInput = + 'diff --git a/sample b/sample\n' + + 'index 0000001..0ddf2ba\n' + + '--- a/sample\n' + + '+++ b/sample\n' + + '@@ -1 +1 @@\n' + + '-test\n' + + '+test1r\n'; + +let strConfiguration = new Diff2HtmlOptionsImpl('diff'); +let diffInput = d2h.getJsonFromDiff(strInput, strConfiguration); + +let diffConfiguration = new Diff2HtmlOptionsImpl('json'); +let htmlString = d2h.getPrettyHtml(diffInput, diffConfiguration); +console.log(htmlString);