feat: add --manifest-version option to init command
Allow developers to specify which manifest version to use when initializing a new manifest.json file. Usage: mcpb init --manifest-version 0.3 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
3635e20ca8
commit
761e834ba8
2 changed files with 43 additions and 20 deletions
|
|
@ -51,19 +51,29 @@ program
|
||||||
.command("init [directory]")
|
.command("init [directory]")
|
||||||
.description("Create a new MCPB extension manifest")
|
.description("Create a new MCPB extension manifest")
|
||||||
.option("-y, --yes", "Accept all defaults (non-interactive mode)")
|
.option("-y, --yes", "Accept all defaults (non-interactive mode)")
|
||||||
.action((directory?: string, options?: { yes?: boolean }) => {
|
.option(
|
||||||
void (async () => {
|
"--manifest-version <version>",
|
||||||
try {
|
"Manifest version to use in the generated manifest",
|
||||||
const success = await initExtension(directory, options?.yes);
|
)
|
||||||
process.exit(success ? 0 : 1);
|
.action(
|
||||||
} catch (error) {
|
(directory?: string, options?: { yes?: boolean; manifestVersion?: string }) => {
|
||||||
console.error(
|
void (async () => {
|
||||||
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
|
try {
|
||||||
);
|
const success = await initExtension(
|
||||||
process.exit(1);
|
directory,
|
||||||
}
|
options?.yes,
|
||||||
})();
|
options?.manifestVersion,
|
||||||
});
|
);
|
||||||
|
process.exit(success ? 0 : 1);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Validate command
|
// Validate command
|
||||||
program
|
program
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { confirm, input, select } from "@inquirer/prompts";
|
import { confirm, input, select } from "@inquirer/prompts";
|
||||||
import { existsSync, readFileSync, writeFileSync } from "fs";
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||||
import { basename, join, resolve } from "path";
|
import { basename, join, resolve } from "path";
|
||||||
import type { z } from "zod";
|
|
||||||
|
|
||||||
// Import the schema for DEFAULT_MANIFEST_VERSION
|
import {
|
||||||
// TODO: Allow dynamic manifest version choice
|
DEFAULT_MANIFEST_VERSION,
|
||||||
import type { McpbManifestSchema } from "../schemas/0.2.js";
|
MANIFEST_SCHEMAS,
|
||||||
import { DEFAULT_MANIFEST_VERSION } from "../shared/constants.js";
|
} from "../shared/constants.js";
|
||||||
|
import type { McpbManifestAny } from "../types.js";
|
||||||
|
|
||||||
interface PackageJson {
|
interface PackageJson {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
|
@ -877,18 +877,19 @@ export function buildManifest(
|
||||||
license: string;
|
license: string;
|
||||||
repository?: { type: string; url: string };
|
repository?: { type: string; url: string };
|
||||||
},
|
},
|
||||||
|
manifestVersion: keyof typeof MANIFEST_SCHEMAS = DEFAULT_MANIFEST_VERSION,
|
||||||
// localization?: {
|
// localization?: {
|
||||||
// resources: string;
|
// resources: string;
|
||||||
// default_locale: string;
|
// default_locale: string;
|
||||||
// },
|
// },
|
||||||
): z.infer<typeof McpbManifestSchema> {
|
): McpbManifestAny {
|
||||||
const { name, displayName, version, description, authorName } = basicInfo;
|
const { name, displayName, version, description, authorName } = basicInfo;
|
||||||
const { authorEmail, authorUrl } = authorInfo;
|
const { authorEmail, authorUrl } = authorInfo;
|
||||||
const { serverType, entryPoint, mcp_config } = serverConfig;
|
const { serverType, entryPoint, mcp_config } = serverConfig;
|
||||||
const { keywords, license, repository } = optionalFields;
|
const { keywords, license, repository } = optionalFields;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
manifest_version: DEFAULT_MANIFEST_VERSION,
|
manifest_version: manifestVersion,
|
||||||
name,
|
name,
|
||||||
...(displayName && displayName !== name
|
...(displayName && displayName !== name
|
||||||
? { display_name: displayName }
|
? { display_name: displayName }
|
||||||
|
|
@ -945,10 +946,21 @@ export function printNextSteps() {
|
||||||
export async function initExtension(
|
export async function initExtension(
|
||||||
targetPath: string = process.cwd(),
|
targetPath: string = process.cwd(),
|
||||||
nonInteractive = false,
|
nonInteractive = false,
|
||||||
|
manifestVersion?: string,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const resolvedPath = resolve(targetPath);
|
const resolvedPath = resolve(targetPath);
|
||||||
const manifestPath = join(resolvedPath, "manifest.json");
|
const manifestPath = join(resolvedPath, "manifest.json");
|
||||||
|
|
||||||
|
// Validate manifest version if provided
|
||||||
|
if (manifestVersion && !(manifestVersion in MANIFEST_SCHEMAS)) {
|
||||||
|
console.error(
|
||||||
|
`ERROR: Invalid manifest version "${manifestVersion}". Supported versions: ${Object.keys(MANIFEST_SCHEMAS).join(", ")}`,
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const effectiveManifestVersion = (manifestVersion ||
|
||||||
|
DEFAULT_MANIFEST_VERSION) as keyof typeof MANIFEST_SCHEMAS;
|
||||||
|
|
||||||
if (existsSync(manifestPath)) {
|
if (existsSync(manifestPath)) {
|
||||||
if (nonInteractive) {
|
if (nonInteractive) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|
@ -1029,6 +1041,7 @@ export async function initExtension(
|
||||||
compatibility,
|
compatibility,
|
||||||
userConfig,
|
userConfig,
|
||||||
optionalFields,
|
optionalFields,
|
||||||
|
effectiveManifestVersion,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Write manifest
|
// Write manifest
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue