Browse Source

Create crlfchecker module and use it in make.js.

Provide names of the files that contain crlf in the output.
Exit(1) is used instead of throw.
Kalervo Kujala 13 years ago
parent
commit
2ffd3ae1c7
  1. 25
      external/crlfchecker/crlfchecker.js
  2. 31
      make.js

25
external/crlfchecker/crlfchecker.js vendored

@ -0,0 +1,25 @@ @@ -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;

31
make.js

@ -1,6 +1,7 @@ @@ -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 = { @@ -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() { @@ -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() { @@ -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']);
};
//

Loading…
Cancel
Save