Add TypeScript test, use .eslintignore

This commit is contained in:
Rodrigo Fernandes 2016-08-27 12:46:22 +01:00
parent 3d0927a857
commit 5ad783ae3d
5 changed files with 40 additions and 22 deletions

6
.eslintignore Normal file
View file

@ -0,0 +1,6 @@
src/**
!src/*.js
!src/ui/js/*.js
coverage/**
dist/**
test/**

View file

@ -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",

View file

View file

@ -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);

View file

@ -0,0 +1,26 @@
/// <reference path="./diff2html.d.ts" />
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);