diff --git a/external/crlfchecker/crlfchecker.js b/external/crlfchecker/crlfchecker.js new file mode 100644 index 000000000..50522475e --- /dev/null +++ b/external/crlfchecker/crlfchecker.js @@ -0,0 +1,25 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +function checkIfCrlfIsPresent(files) { + var failed = []; + + (ls(files)).forEach(function checkCrlf(file) { + if ((cat(file)).match(/.*\r.*/)) { + failed.push(file); + } + }); + + if (failed.length) { + var errorMessage = + 'Please remove carriage return\'s from\n' + failed.join('\n') + '\n' + + 'Also check your setting for: git config core.autocrlf.'; + + echo(); + echo(errorMessage); + exit(1); + } +} + +exports.checkIfCrlfIsPresent = checkIfCrlfIsPresent; + diff --git a/make.js b/make.js index bc04e8530..3ff04dedf 100755 --- a/make.js +++ b/make.js @@ -1,6 +1,7 @@ #!/usr/bin/env node require('./external/shelljs/make'); var builder = require('./external/builder/builder.js'); +var crlfchecker = require('./external/crlfchecker/crlfchecker.js'); var ROOT_DIR = __dirname + '/', // absolute path to project's root BUILD_DIR = 'build/', @@ -27,32 +28,6 @@ var DEFINES = { CHROME: false }; -// -// Helper functions -// -function checkIfCarriageReturnsArePresent(string, throwOnError) { - if (string.match(/.*\r.*/)) { - var errorMessage = - 'Carriage Return\'s should not be present. Please remove them.\n' + - 'Also check your setting for: git config core.autocrlf.'; - - if (throwOnError) { - throw(errorMessage); - } else { - echo(); - echo(errorMessage); - } - } -} - -function throwIfCarriageReturnsArePresent(string) { - checkIfCarriageReturnsArePresent(string, true); -} - -function warnIfCarriageReturnsArePresent(string) { - checkIfCarriageReturnsArePresent(string, false); -} - // // make all // @@ -245,7 +220,7 @@ target.bundle = function() { {silent: true}).output.replace('\n', ''); // Handle only src/*.js for now. - throwIfCarriageReturnsArePresent(cat('*.js')); + crlfchecker.checkIfCrlfIsPresent(['*.js']); // This just preprocesses the empty pdf.js file, we don't actually want to // preprocess everything yet since other build targets use this file. @@ -711,7 +686,7 @@ target.lint = function() { exec('gjslint --nojsdoc ' + LINT_FILES.join(' ')); // Handle only src/*.js for now. - warnIfCarriageReturnsArePresent(cat('src/*.js')); + crlfchecker.checkIfCrlfIsPresent(['src/*.js']); }; //