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.
This commit is contained in:
		
							parent
							
								
									83eb405f2f
								
							
						
					
					
						commit
						2ffd3ae1c7
					
				
							
								
								
									
										25
									
								
								external/crlfchecker/crlfchecker.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								external/crlfchecker/crlfchecker.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -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
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								make.js
									
									
									
									
									
								
							@ -1,6 +1,7 @@
 | 
				
			|||||||
#!/usr/bin/env node
 | 
					#!/usr/bin/env node
 | 
				
			||||||
require('./external/shelljs/make');
 | 
					require('./external/shelljs/make');
 | 
				
			||||||
var builder = require('./external/builder/builder.js');
 | 
					var builder = require('./external/builder/builder.js');
 | 
				
			||||||
 | 
					var crlfchecker = require('./external/crlfchecker/crlfchecker.js');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var ROOT_DIR = __dirname + '/', // absolute path to project's root
 | 
					var ROOT_DIR = __dirname + '/', // absolute path to project's root
 | 
				
			||||||
    BUILD_DIR = 'build/',
 | 
					    BUILD_DIR = 'build/',
 | 
				
			||||||
@ -27,32 +28,6 @@ var DEFINES = {
 | 
				
			|||||||
  CHROME: false
 | 
					  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
 | 
					// make all
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
@ -245,7 +220,7 @@ target.bundle = function() {
 | 
				
			|||||||
        {silent: true}).output.replace('\n', '');
 | 
					        {silent: true}).output.replace('\n', '');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Handle only src/*.js for now.
 | 
					  // 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
 | 
					  // This just preprocesses the empty pdf.js file, we don't actually want to
 | 
				
			||||||
  // preprocess everything yet since other build targets use this file.
 | 
					  // preprocess everything yet since other build targets use this file.
 | 
				
			||||||
@ -711,7 +686,7 @@ target.lint = function() {
 | 
				
			|||||||
  exec('gjslint --nojsdoc ' + LINT_FILES.join(' '));
 | 
					  exec('gjslint --nojsdoc ' + LINT_FILES.join(' '));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Handle only src/*.js for now.
 | 
					  // Handle only src/*.js for now.
 | 
				
			||||||
  warnIfCarriageReturnsArePresent(cat('src/*.js'));
 | 
					  crlfchecker.checkIfCrlfIsPresent(['src/*.js']);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user