UNPKG

create-mcp-i-app

Version:

Bootstrap MCP applications with identity features (temporary - use create-mcpi-app after Oct 7)

54 lines 2.15 kB
import { execSync } from "child_process"; import fs from "fs-extra"; import path from "path"; import os from "os"; import chalk from "chalk"; /** * Scaffold XMCP project using upstream create-xmcp-app tool */ export async function fetchXMCPTemplate(projectPath, options = {}) { const { xmcpChannel = "latest", packageManager = "npm" } = options; const projectName = path.basename(projectPath); // Create temporary directory for scaffolding const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "xmcp-scaffold-")); try { console.log(chalk.blue("📦 Scaffolding XMCP project with upstream tool...")); // Build the create-xmcp-app command const createCommand = xmcpChannel === "next" ? "npx create-xmcp-app@next" : "npx create-xmcp-app@latest"; // Scaffold the project using upstream create-xmcp-app const scaffoldArgs = [ projectName, "--yes", // Skip prompts `--use-${packageManager}`, // Use specified package manager "--skip-install", // We'll handle installation later ]; execSync(`${createCommand} ${scaffoldArgs.join(" ")}`, { cwd: tempDir, stdio: "inherit", // Show output to user }); const scaffoldedPath = path.join(tempDir, projectName); if (!fs.existsSync(scaffoldedPath)) { throw new Error("Upstream scaffolding failed - project directory not created"); } // Copy scaffolded project to target location fs.copySync(scaffoldedPath, projectPath, { filter: (src) => { const basename = path.basename(src); // Skip node_modules if it exists return basename !== "node_modules"; }, }); console.log(chalk.green("✅ XMCP project scaffolded successfully")); } catch (error) { console.error(chalk.red("Failed to scaffold XMCP project:"), error); throw error; } finally { // Clean up temp directory fs.removeSync(tempDir); } } //# sourceMappingURL=fetch-xmcp-template.js.map