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 #1315 in the future.
  • Loading branch information
Adam Comella committed Aug 17, 2015
1 parent cf7098f commit 13c7189
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
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);
});

};
})();
30 changes: 30 additions & 0 deletions tasks/options/check-bom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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";

var config = require("../../config.js");

function searchDirectory(directoryPath) {
return {
cwd: directoryPath,
src: "**/*.+(js|css|htm|html)",
expand: true,
nocase: true
};
}

module.exports = {
publishWinJs: {
files: [
searchDirectory(config.winjsPublishRoot),
searchDirectory(config.winjsBowerRepo)
]
},
publishLocalization: {
files: [
searchDirectory(config.localizationPublishRoot),
searchDirectory(config.localizationBowerRepo)
]
}
};
})();
4 changes: 3 additions & 1 deletion tasks/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
// winjs
'gitreset:publishWinJsBower', 'gitclean:publishWinJsBower', 'gitpull:publishWinJsBower', // Make the local bower repo match the one on GitHub
'clean:publishWinJs', 'copy:publishWinJs', 'compress:publishWinJs', 'gitadd:publishWinJsBower', 'nugetpack:publishWinJs',
'check-bom:publishWinJs', // BOM verification should be the last task in the group

// winjs-localization
'gitreset:publishLocalizationBower', 'gitclean:publishLocalizationBower', 'gitpull:publishLocalizationBower', // Make the local bower repo match the one on GitHub
'clean:publishLocalization', 'copy:publishLocalization', 'compress:publishLocalization', 'gitadd:publishLocalizationBower', 'nugetpack:publishLocalization'
'clean:publishLocalization', 'copy:publishLocalization', 'compress:publishLocalization', 'gitadd:publishLocalizationBower', 'nugetpack:publishLocalization',
'check-bom:publishLocalization' // BOM verification should be the last task in the group
]);

// Populates the 'dist' folder and then uses it to:
Expand Down

0 comments on commit 13c7189

Please sign in to comment.