Skip to content

Commit

Permalink
Verify files have BOM during publish task
Browse files Browse the repository at this point in the history
This verification is designed to simulate part of the Windows App
Certification Kit test.

Protects us from regressing winjs/winjs#1315 in the future.
  • Loading branch information
Adam Comella committed Aug 10, 2015
1 parent 3b0fb38 commit a38b403
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = function(grunt) {

var currentGitCommitHash = execSync('git rev-parse HEAD').toString().trim();

var bomGlob = "**/*.+(js|css|htm|html)";

// Project configuration.
grunt.initConfig({
pkg: pkg,
Expand Down Expand Up @@ -58,6 +60,22 @@ module.exports = function(grunt) {
}
},

"check-bom": {
publish: {
files: [{
cwd: "js",
src: bomGlob,
expand: true,
nocase: true
}, {
cwd: publishRoot,
src: bomGlob,
expand: true,
nocase: true
}]
}
},

nugetpack: {
publish: {
src: 'Knockout.WinJS.nuspec',
Expand Down Expand Up @@ -104,6 +122,8 @@ module.exports = function(grunt) {
}
});

grunt.loadTasks('tasks/');

var plugins = [
'grunt-contrib-clean',
'grunt-contrib-compress',
Expand Down Expand Up @@ -135,6 +155,7 @@ module.exports = function(grunt) {
'copy:publish',
'compress:publish',
'nugetpack:publish',
'check-bom:publish',
]);

grunt.registerTask('finished-publish', function (mode) {
Expand Down
26 changes: 26 additions & 0 deletions tasks/check-bom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information.
(function () {
"use strict";

module.exports = function (grunt) {

// Verifies that files begin with a UTF8 BOM. Files without one will not be able to pass the
// Windows App Certification Kit test.

grunt.registerMultiTask("check-bom", function () {
function checkBom(filePath) {
if (grunt.file.exists(filePath)) {
var content = grunt.file.read(filePath, { encoding: null });
if (content.length < 3 || content[0] !== 0xef || content[1] !== 0xbb || content[2] !== 0xbf) {
grunt.fail.fatal("check-bom File is missing BOM: " + filePath);
}
} else {
grunt.log.warn("check-bom No such file: " + filePath);
}
}

this.filesSrc.forEach(checkBom);
});

};
})();

0 comments on commit a38b403

Please sign in to comment.