@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
41 lines (40 loc) • 1.86 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const StorageUtilities_1 = __importDefault(require("../../storage/StorageUtilities"));
const IInfoItemData_1 = require("../IInfoItemData");
const ProjectInfoItem_1 = __importDefault(require("../ProjectInfoItem"));
var CheckNoBOMGeneratorTest;
(function (CheckNoBOMGeneratorTest) {
CheckNoBOMGeneratorTest[CheckNoBOMGeneratorTest["NoByteOrderMarkAllowedInJsonFile"] = 101] = "NoByteOrderMarkAllowedInJsonFile";
})(CheckNoBOMGeneratorTest || (CheckNoBOMGeneratorTest = {}));
/**********
* Generator that generates error results if Byte Order Marks are found within .json files
*
* @see {@link ../../../public/data/forms/mctoolsval/nobom.form.json} for topic definitions
*********/
class CheckNoBOMGenerator {
id = "NOBOM";
title = "No Byte Order Mark allowed in json file.";
canAlwaysProcess = true;
severity = IInfoItemData_1.InfoItemType.error;
generate(_project, projectFile) {
const results = [];
if (StorageUtilities_1.default.isJsonFile(projectFile) && this.hasByteOrderMark(projectFile)) {
results.push(this.getNewBOMResult(projectFile));
}
return Promise.resolve(results);
}
summarize() { }
hasByteOrderMark(file) {
const bytes = StorageUtilities_1.default.getContentsAsBinary(file);
const hasBOM = StorageUtilities_1.default.hasUTF8ByteOrderMark(bytes);
return hasBOM;
}
getNewBOMResult(file) {
return new ProjectInfoItem_1.default(this.severity, this.id, CheckNoBOMGeneratorTest.NoByteOrderMarkAllowedInJsonFile, `Byte Order Marks found in file: ${file.name}`);
}
}
exports.default = CheckNoBOMGenerator;