feat: use 0.2 as the default schema (#145)
This commit is contained in:
parent
ce8a5aec4a
commit
98126b777e
1 changed files with 74 additions and 33 deletions
|
|
@ -7,9 +7,10 @@ import prettyBytes from "pretty-bytes";
|
|||
|
||||
import { unpackExtension } from "../cli/unpack.js";
|
||||
import {
|
||||
LATEST_MANIFEST_SCHEMA,
|
||||
LATEST_MANIFEST_SCHEMA_LOOSE,
|
||||
MANIFEST_SCHEMAS,
|
||||
MANIFEST_SCHEMAS_LOOSE,
|
||||
} from "../shared/constants.js";
|
||||
import { getManifestVersionFromRawData } from "../shared/manifestVersionResolve.js";
|
||||
|
||||
/**
|
||||
* Check if a buffer contains a valid PNG file signature
|
||||
|
|
@ -119,8 +120,13 @@ export function validateManifest(inputPath: string): boolean {
|
|||
|
||||
const manifestContent = readFileSync(manifestPath, "utf-8");
|
||||
const manifestData = JSON.parse(manifestContent);
|
||||
const manifestVersion = getManifestVersionFromRawData(manifestData);
|
||||
if (!manifestVersion) {
|
||||
console.log("Unrecognized or unsupported manifest version");
|
||||
return false;
|
||||
}
|
||||
|
||||
const result = LATEST_MANIFEST_SCHEMA.safeParse(manifestData);
|
||||
const result = MANIFEST_SCHEMAS[manifestVersion].safeParse(manifestData);
|
||||
|
||||
if (result.success) {
|
||||
console.log("Manifest schema validation passes!");
|
||||
|
|
@ -192,7 +198,12 @@ export async function cleanMcpb(inputPath: string) {
|
|||
const manifestPath = resolve(unpackPath, "manifest.json");
|
||||
const originalManifest = await fs.readFile(manifestPath, "utf-8");
|
||||
const manifestData = JSON.parse(originalManifest);
|
||||
const result = LATEST_MANIFEST_SCHEMA_LOOSE.safeParse(manifestData);
|
||||
const manifestVersion = getManifestVersionFromRawData(manifestData);
|
||||
if (!manifestVersion) {
|
||||
throw new Error("Unrecognized or unsupported manifest version");
|
||||
}
|
||||
const result =
|
||||
MANIFEST_SCHEMAS_LOOSE[manifestVersion].safeParse(manifestData);
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error(
|
||||
|
|
|
|||
Loading…
Reference in a new issue