Open SreakMan opened 2 months ago
const fs = require("fs");
const path = require("path");
const YAML = require("yaml");
const Ajv = require("ajv");
const AjvFormats = require("ajv-formats");
const ajv = new Ajv();
AjvFormats(ajv);
ajv.addFormat("long", {
type: "number",
validate: function (value) {
return (
Number.isInteger(value) &&
value <= Number.MAX_SAFE_INTEGER &&
value >= Number.MIN_SAFE_INTEGER
);
},
});
const lib = {};
const schemaDir = `./schema`;
for (let filename of fs.readdirSync(schemaDir)) {
const [_, type, __, version] = filename.split(".");
lib[`1.${version}.0-${type}`] = JSON.parse(
fs.readFileSync(path.resolve(schemaDir, filename), "utf8")
);
}
const outFile = `./log`;
const pre = "https://github.com/microsoft/winget-pkgs/tree/master/manifests/";
const loadManifest = (dir) => {
for (const filename of fs.readdirSync(dir)) {
const subDir = path.resolve(dir, filename);
const subStat = fs.statSync(subDir);
if (subStat.isDirectory()) {
loadManifest(subDir);
} else if (subStat.isFile()) {
if (filename.endsWith(".yaml") || filename.endsWith(".yml")) {
const data = YAML.parse(fs.readFileSync(subDir, "utf8"));
const schema = lib[`${data.ManifestVersion}-${data.ManifestType}`];
if (!ajv.validate(schema, data)) {
const relativePath = path
.relative(manifestDir, subDir)
.split(path.sep)
.join("/");
const log = `<a href="${pre}${relativePath}">${relativePath}</a>\n`;
fs.appendFileSync(outFile, log);
}
}
}
}
};
const manifestDir = `./winget-pkgs/manifests`;
loadManifest(manifestDir);
Description of the new feature/enhancement
Some fields in the repository's manifest files do not actually comply with the constraints. example
Proposed technical implementation details (optional)
No response