Add TypeScript test, use .eslintignore
This commit is contained in:
parent
3d0927a857
commit
5ad783ae3d
5 changed files with 40 additions and 22 deletions
6
.eslintignore
Normal file
6
.eslintignore
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
src/**
|
||||||
|
!src/*.js
|
||||||
|
!src/ui/js/*.js
|
||||||
|
coverage/**
|
||||||
|
dist/**
|
||||||
|
test/**
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
"release-website": "node ./scripts/release-website.js",
|
"release-website": "node ./scripts/release-website.js",
|
||||||
"release-bower": "./scripts/update-bower-version.sh",
|
"release-bower": "./scripts/update-bower-version.sh",
|
||||||
"templates": "./scripts/hulk.js --wrapper node --variable 'browserTemplates' ./src/templates/*.mustache > ./src/templates/diff2html-templates.js",
|
"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/**/*",
|
"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",
|
"check-coverage": "istanbul check-coverage --statements 90 --functions 90 --branches 85 --lines 90 ./coverage/coverage.json",
|
||||||
"test": "npm run coverage && npm run check-coverage",
|
"test": "npm run coverage && npm run check-coverage",
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// dependencies
|
// dependencies
|
||||||
var hogan = require('hogan.js');
|
var hogan = require('hogan.js');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
@ -23,7 +22,6 @@ var nopt = require('nopt');
|
||||||
var mkderp = require('mkdirp');
|
var mkderp = require('mkdirp');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
|
|
||||||
// locals
|
// locals
|
||||||
var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];
|
var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];
|
||||||
var specialsRegExp = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
|
var specialsRegExp = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
|
||||||
|
|
@ -45,23 +43,19 @@ var shortHand = {
|
||||||
};
|
};
|
||||||
var templates;
|
var templates;
|
||||||
|
|
||||||
|
|
||||||
// options
|
// options
|
||||||
options = nopt(options, shortHand);
|
options = nopt(options, shortHand);
|
||||||
|
|
||||||
|
|
||||||
// escape special regexp characters
|
// escape special regexp characters
|
||||||
function esc(text) {
|
function esc(text) {
|
||||||
return text.replace(specialsRegExp, '\\$1');
|
return text.replace(specialsRegExp, '\\$1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// cyan function for rob
|
// cyan function for rob
|
||||||
function cyan(text) {
|
function cyan(text) {
|
||||||
return '\033[36m' + text + '\033[39m';
|
return '\x1B[36m' + text + '\x1B[39m';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// check for dirs and correct ext (<3 for windows)
|
// check for dirs and correct ext (<3 for windows)
|
||||||
function extractFiles(args) {
|
function extractFiles(args) {
|
||||||
var usage = '\n' +
|
var usage = '\n' +
|
||||||
|
|
@ -86,10 +80,9 @@ function extractFiles(args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
args.forEach(function(arg) {
|
args.forEach(function(arg) {
|
||||||
|
|
||||||
if (/\*/.test(arg)) {
|
if (/\*/.test(arg)) {
|
||||||
arg = arg.split('*');
|
arg = arg.split('*');
|
||||||
return files = files.concat(
|
files = files.concat(
|
||||||
fs.readdirSync(arg[0] || '.')
|
fs.readdirSync(arg[0] || '.')
|
||||||
.map(function(f) {
|
.map(function(f) {
|
||||||
var file = path.join(arg[0], f);
|
var file = path.join(arg[0], f);
|
||||||
|
|
@ -99,16 +92,15 @@ function extractFiles(args) {
|
||||||
return f;
|
return f;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.statSync(arg).isFile()) files.push(arg);
|
if (fs.statSync(arg).isFile()) files.push(arg);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// remove utf-8 byte order mark, http://en.wikipedia.org/wiki/Byte_order_mark
|
// remove utf-8 byte order mark, http://en.wikipedia.org/wiki/Byte_order_mark
|
||||||
function removeByteOrderMark(text) {
|
function removeByteOrderMark(text) {
|
||||||
if (text.charCodeAt(0) === 0xfeff) {
|
if (text.charCodeAt(0) === 0xfeff) {
|
||||||
|
|
@ -117,16 +109,15 @@ function removeByteOrderMark(text) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// wrap templates
|
// wrap templates
|
||||||
function wrap(file, name, openedFile) {
|
function wrap(file, name, openedFile) {
|
||||||
switch (options.wrapper) {
|
switch (options.wrapper) {
|
||||||
case "amd":
|
case 'amd':
|
||||||
return 'define(' + (!options.outputdir ? '"' + path.join(path.dirname(file), name) + '", ' : '') +
|
return 'define(' + (!options.outputdir ? '"' + path.join(path.dirname(file), name) + '", ' : '') +
|
||||||
'[ "hogan.js" ], function(Hogan){ return new Hogan.Template(' +
|
'[ "hogan.js" ], function(Hogan){ return new Hogan.Template(' +
|
||||||
hogan.compile(openedFile, {asString: 1}) +
|
hogan.compile(openedFile, {asString: 1}) +
|
||||||
');});';
|
');});';
|
||||||
case "node":
|
case 'node':
|
||||||
var globalObj = 'global.' + (options.variable || 'templates') + '["' + name + '"]';
|
var globalObj = 'global.' + (options.variable || 'templates') + '["' + name + '"]';
|
||||||
var globalStmt = globalObj + ' = new Hogan.Template(' + hogan.compile(openedFile, {asString: 1}) + ');';
|
var globalStmt = globalObj + ' = new Hogan.Template(' + hogan.compile(openedFile, {asString: 1}) + ');';
|
||||||
var nodeOutput = globalStmt;
|
var nodeOutput = globalStmt;
|
||||||
|
|
@ -145,13 +136,12 @@ function wrap(file, name, openedFile) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function prepareOutput(content) {
|
function prepareOutput(content) {
|
||||||
var variableName = options.variable || 'templates';
|
var variableName = options.variable || 'templates';
|
||||||
switch (options.wrapper) {
|
switch (options.wrapper) {
|
||||||
case "amd":
|
case 'amd':
|
||||||
return content;
|
return content;
|
||||||
case "node":
|
case 'node':
|
||||||
var nodeExport = '';
|
var nodeExport = '';
|
||||||
|
|
||||||
// if we have aggregated templates the export will expose the template map
|
// if we have aggregated templates the export will expose the template map
|
||||||
|
|
@ -170,19 +160,16 @@ function prepareOutput(content) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// write the directory
|
// write the directory
|
||||||
if (options.outputdir) {
|
if (options.outputdir) {
|
||||||
mkderp.sync(options.outputdir);
|
mkderp.sync(options.outputdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Prepend namespace to template name
|
// Prepend namespace to template name
|
||||||
function namespace(name) {
|
function namespace(name) {
|
||||||
return (options.namespace || '') + name;
|
return (options.namespace || '') + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// write a template foreach file that matches template extension
|
// write a template foreach file that matches template extension
|
||||||
templates = extractFiles(options.argv.remain)
|
templates = extractFiles(options.argv.remain)
|
||||||
.map(function(file) {
|
.map(function(file) {
|
||||||
|
|
@ -200,7 +187,6 @@ templates = extractFiles(options.argv.remain)
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// output templates
|
// output templates
|
||||||
if (!templates.length || options.outputdir) process.exit(0);
|
if (!templates.length || options.outputdir) process.exit(0);
|
||||||
|
|
||||||
|
|
|
||||||
26
typescript/diff2html-tests.ts
Normal file
26
typescript/diff2html-tests.ts
Normal 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);
|
||||||
Loading…
Reference in a new issue