init-xmcp 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/README.md +44 -0
- package/build-and-link.sh +73 -0
- package/dist/helpers/create-handler.d.ts +7 -0
- package/dist/helpers/create-handler.js +29 -0
- package/dist/helpers/create-tool.d.ts +6 -0
- package/dist/helpers/create-tool.js +53 -0
- package/dist/helpers/detect-framework.d.ts +3 -0
- package/dist/helpers/detect-framework.js +33 -0
- package/dist/helpers/generate-config.d.ts +7 -0
- package/dist/helpers/generate-config.js +29 -0
- package/dist/helpers/init.d.ts +10 -0
- package/dist/helpers/init.js +21 -0
- package/dist/helpers/install.d.ts +11 -0
- package/dist/helpers/install.js +44 -0
- package/dist/helpers/update-gitignore.d.ts +6 -0
- package/dist/helpers/update-gitignore.js +18 -0
- package/dist/helpers/update-package.d.ts +6 -0
- package/dist/helpers/update-package.js +28 -0
- package/dist/helpers/update-tsconfig.d.ts +6 -0
- package/dist/helpers/update-tsconfig.js +35 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +239 -0
- package/dist/utils/check-node.d.ts +4 -0
- package/dist/utils/check-node.js +15 -0
- package/index.js +23 -0
- package/package.json +57 -0
- package/src/helpers/create-handler.ts +35 -0
- package/src/helpers/create-tool.ts +57 -0
- package/src/helpers/detect-framework.ts +62 -0
- package/src/helpers/generate-config.ts +37 -0
- package/src/helpers/init.ts +40 -0
- package/src/helpers/install.ts +59 -0
- package/src/helpers/update-gitignore.ts +23 -0
- package/src/helpers/update-package.ts +31 -0
- package/src/helpers/update-tsconfig.ts +45 -0
- package/src/index.ts +312 -0
- package/src/utils/check-node.ts +23 -0
- package/tsconfig.json +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://xmcp.dev">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://assets.basehub.com/bf7c3bb1/303b8a62053c9d86ca3b972b5597ab5c/x.png">
|
|
5
|
+
<img alt="xmcp logo" src="https://assets.basehub.com/bf7c3bb1/303b8a62053c9d86ca3b972b5597ab5c/x.png" height="128">
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
<h1>xmcp</h1>
|
|
9
|
+
|
|
10
|
+
<a href="https://basement.studio"><img alt="xmcp logo" src="https://img.shields.io/badge/MADE%20BY%20basement.studio-000000.svg?style=for-the-badge&labelColor=000"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/init-xmcp"><img alt="NPM version" src="https://img.shields.io/npm/v/xmcp.svg?style=for-the-badge&labelColor=000000"></a>
|
|
12
|
+
<a href="https://github.com/basementstudio/xmcp/blob/main/license.md"><img alt="License" src="https://img.shields.io/npm/l/xmcp.svg?style=for-the-badge&labelColor=000000"></a>
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
# init-xmcp
|
|
17
|
+
|
|
18
|
+
Initialize `xmcp` applications with one command on top of Next.js and Express projects. Unlock the power of `xmcp` discovery and integration with your existing codebase.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx init-xmcp
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
- `-v, --version`: Output the current version of init-xmcp.
|
|
29
|
+
- `-y, --yes`: Skip confirmation prompts (default: false)
|
|
30
|
+
- `--package-manager <manager>`: Specify package manager (npm, yarn, pnpm) (default: "")
|
|
31
|
+
- `--tools-path <path>`: Specify custom tools path (default: "")
|
|
32
|
+
- `--route-path <path>`: Specify custom route path (default: "")
|
|
33
|
+
- `--skip-tools`: Skip tool creation (default: false)
|
|
34
|
+
- `--skip-route`: Skip route creation (default: false)
|
|
35
|
+
- `-h, --help`: Display help message.
|
|
36
|
+
|
|
37
|
+
## Getting Started
|
|
38
|
+
|
|
39
|
+
- Visit [xmcp.dev](https://xmcp.dev) to learn more about the project.
|
|
40
|
+
- Visit [xmcp.dev/docs](https://xmcp.dev/docs) to view the full documentation.
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
This project is licensed under the MIT License - see the [LICENSE](<[LICENSE](https://github.com/basementstudio/xmcp/blob/main/license.md)>) file for details.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Colors for output
|
|
4
|
+
RED='\033[0;31m'
|
|
5
|
+
GREEN='\033[0;32m'
|
|
6
|
+
YELLOW='\033[1;33m'
|
|
7
|
+
BLUE='\033[0;34m'
|
|
8
|
+
NC='\033[0m' # No Color
|
|
9
|
+
|
|
10
|
+
echo -e "${BLUE}🔨 Building and linking init-xmcp CLI...${NC}\n"
|
|
11
|
+
|
|
12
|
+
# Check if we're in the right directory
|
|
13
|
+
if [ ! -f "package.json" ] || [ ! -d "src" ]; then
|
|
14
|
+
echo -e "${RED}❌ Error: This script must be run from the init-xmcp directory${NC}"
|
|
15
|
+
echo -e "${YELLOW}Please navigate to packages/init-xmcp and run this script${NC}"
|
|
16
|
+
exit 1
|
|
17
|
+
fi
|
|
18
|
+
|
|
19
|
+
# Install dependencies if node_modules doesn't exist
|
|
20
|
+
if [ ! -d "node_modules" ]; then
|
|
21
|
+
echo -e "${YELLOW}📦 Installing dependencies...${NC}"
|
|
22
|
+
npm install
|
|
23
|
+
if [ $? -ne 0 ]; then
|
|
24
|
+
echo -e "${RED}❌ Failed to install dependencies${NC}"
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
echo -e "${GREEN}✅ Dependencies installed${NC}\n"
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
# Clean previous build
|
|
31
|
+
echo -e "${YELLOW}🧹 Cleaning previous build...${NC}"
|
|
32
|
+
rm -rf dist/
|
|
33
|
+
echo -e "${GREEN}✅ Cleaned${NC}\n"
|
|
34
|
+
|
|
35
|
+
# Build TypeScript
|
|
36
|
+
echo -e "${YELLOW}🔨 Building TypeScript...${NC}"
|
|
37
|
+
npm run build
|
|
38
|
+
if [ $? -ne 0 ]; then
|
|
39
|
+
echo -e "${RED}❌ Build failed${NC}"
|
|
40
|
+
exit 1
|
|
41
|
+
fi
|
|
42
|
+
echo -e "${GREEN}✅ Build successful${NC}\n"
|
|
43
|
+
|
|
44
|
+
# Check if already linked and unlink if necessary
|
|
45
|
+
echo -e "${YELLOW}🔗 Checking for existing global link...${NC}"
|
|
46
|
+
if npm list -g init-xmcp > /dev/null 2>&1; then
|
|
47
|
+
echo -e "${YELLOW}Found existing global link, unlinking...${NC}"
|
|
48
|
+
npm unlink -g init-xmcp
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
# Link the package globally
|
|
52
|
+
echo -e "${YELLOW}🔗 Linking package globally...${NC}"
|
|
53
|
+
npm link
|
|
54
|
+
if [ $? -ne 0 ]; then
|
|
55
|
+
echo -e "${RED}❌ Failed to link package${NC}"
|
|
56
|
+
exit 1
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
echo -e "${GREEN}✅ Package linked successfully!${NC}\n"
|
|
60
|
+
|
|
61
|
+
# Test the CLI
|
|
62
|
+
echo -e "${BLUE}🧪 Testing the CLI...${NC}"
|
|
63
|
+
if command -v init-xmcp > /dev/null 2>&1; then
|
|
64
|
+
init-xmcp --help
|
|
65
|
+
echo -e "\n${GREEN}🎉 Success! You can now use 'init-xmcp' globally${NC}"
|
|
66
|
+
echo -e "${BLUE}💡 Try: init-xmcp --help${NC}"
|
|
67
|
+
echo -e "${BLUE}💡 Try: init-xmcp --nextjs --yes${NC}"
|
|
68
|
+
echo -e "${BLUE}💡 Try: init-xmcp --express --tools-path lib/tools --yes${NC}"
|
|
69
|
+
else
|
|
70
|
+
echo -e "${RED}❌ CLI not found in PATH. You may need to restart your terminal.${NC}"
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
echo -e "\n${YELLOW}📝 To unlink later, run: npm unlink -g init-xmcp${NC}"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create mcp route folder and file with handler
|
|
3
|
+
* only on Next.js projects
|
|
4
|
+
* @param projectRoot - Project root directory
|
|
5
|
+
* @param handlerPath - Path for route folder (relative to project root)
|
|
6
|
+
*/
|
|
7
|
+
export declare function createRoute(projectRoot: string, handlerPath: string): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Create mcp route folder and file with handler
|
|
6
|
+
* only on Next.js projects
|
|
7
|
+
* @param projectRoot - Project root directory
|
|
8
|
+
* @param handlerPath - Path for route folder (relative to project root)
|
|
9
|
+
*/
|
|
10
|
+
export function createRoute(projectRoot, handlerPath) {
|
|
11
|
+
// normalize the path to handle any path separators correctly
|
|
12
|
+
const normalizedHandlerPath = path.normalize(handlerPath);
|
|
13
|
+
const handlerDirPath = path.join(projectRoot, normalizedHandlerPath);
|
|
14
|
+
try {
|
|
15
|
+
// create route folder and all parent directories
|
|
16
|
+
fs.ensureDirSync(handlerDirPath);
|
|
17
|
+
const routeFilePath = path.join(handlerDirPath, "route.ts");
|
|
18
|
+
fs.writeFileSync(routeFilePath, handlerTemplate);
|
|
19
|
+
console.log(chalk.green(`Created route: ${normalizedHandlerPath}/route.ts`));
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error(chalk.red(`Failed to create route: ${error}`));
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const handlerTemplate = `import { xmcpHandler } from '@xmcp/adapter';
|
|
27
|
+
|
|
28
|
+
export { xmcpHandler as GET, xmcpHandler as POST };
|
|
29
|
+
`;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Create tools directory and tool file
|
|
6
|
+
* @param projectRoot - Project root directory
|
|
7
|
+
* @param toolsPath - Path for tools directory (relative to project root)
|
|
8
|
+
*/
|
|
9
|
+
export function createTool(projectRoot, toolsPath) {
|
|
10
|
+
// normalize the path to handle any path separators correctly
|
|
11
|
+
const normalizedToolsPath = path.normalize(toolsPath);
|
|
12
|
+
const toolsDirPath = path.join(projectRoot, normalizedToolsPath);
|
|
13
|
+
try {
|
|
14
|
+
// create tools directory and all parent directories
|
|
15
|
+
fs.ensureDirSync(toolsDirPath);
|
|
16
|
+
const toolFilePath = path.join(toolsDirPath, "greet.ts");
|
|
17
|
+
fs.writeFileSync(toolFilePath, toolTemplate);
|
|
18
|
+
console.log(chalk.green(`Created tool: ${normalizedToolsPath}/greet.ts`));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(chalk.red(`Failed to create tool: ${error}`));
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const toolTemplate = `import { z } from "zod";
|
|
26
|
+
import { type InferSchema } from "xmcp";
|
|
27
|
+
|
|
28
|
+
// Define the schema for tool parameters
|
|
29
|
+
export const schema = {
|
|
30
|
+
name: z.string().describe("The name of the user to greet"),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Define tool metadata
|
|
34
|
+
export const metadata = {
|
|
35
|
+
name: "greet",
|
|
36
|
+
description: "Greet the user",
|
|
37
|
+
annotations: {
|
|
38
|
+
title: "Greet the user",
|
|
39
|
+
readOnlyHint: true,
|
|
40
|
+
destructiveHint: false,
|
|
41
|
+
idempotentHint: true,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Tool implementation
|
|
46
|
+
export default async function greet({ name }: InferSchema<typeof schema>) {
|
|
47
|
+
const result = \`Hello, \${name}!\`;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
content: [{ type: "text", text: result }],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "path";
|
|
4
|
+
export function detectFramework(projectRoot) {
|
|
5
|
+
// check if project has been initialized with nextjs or default to express
|
|
6
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf-8"));
|
|
7
|
+
if (!packageJson.dependencies?.next && !packageJson.devDependencies?.next) {
|
|
8
|
+
return "express";
|
|
9
|
+
}
|
|
10
|
+
return "nextjs";
|
|
11
|
+
}
|
|
12
|
+
export function detectTypeScript(projectRoot) {
|
|
13
|
+
// check if project has been initialized with typescript or default to javascript
|
|
14
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf-8"));
|
|
15
|
+
if (!packageJson.devDependencies?.typescript &&
|
|
16
|
+
!packageJson.dependencies?.typescript) {
|
|
17
|
+
console.log(chalk.yellow("Please initialize xmcp within a TypeScript project. Missing dependency: typescript"));
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// if typescript is in the dependencies, check for tsconfig.json and validate it
|
|
21
|
+
if (fs.existsSync(path.join(projectRoot, "tsconfig.json"))) {
|
|
22
|
+
try {
|
|
23
|
+
const tsconfigContent = fs.readJsonSync(path.join(projectRoot, "tsconfig.json"));
|
|
24
|
+
return typeof tsconfigContent === "object" && tsconfigContent !== null;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
console.log(chalk.yellow("Please initialize xmcp within a TypeScript project. Invalid tsconfig.json file"));
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
console.log(chalk.yellow("Please initialize xmcp within a TypeScript project. Missing file: tsconfig.json"));
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate xmcp.config.ts based on selected framework adapter
|
|
3
|
+
* @param projectPath - Project directory path
|
|
4
|
+
* @param frameworkAdapter - Selected framework adapter
|
|
5
|
+
* @param toolsPath - Optional path for tools directory
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateConfig(projectPath: string, frameworkAdapter: string, toolsPath?: string): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
/**
|
|
4
|
+
* Generate xmcp.config.ts based on selected framework adapter
|
|
5
|
+
* @param projectPath - Project directory path
|
|
6
|
+
* @param frameworkAdapter - Selected framework adapter
|
|
7
|
+
* @param toolsPath - Optional path for tools directory
|
|
8
|
+
*/
|
|
9
|
+
export function generateConfig(projectPath, frameworkAdapter, toolsPath) {
|
|
10
|
+
let configContent = `import { type XmcpConfig } from "xmcp";
|
|
11
|
+
|
|
12
|
+
const config: XmcpConfig = {
|
|
13
|
+
http: true,
|
|
14
|
+
experimental: {
|
|
15
|
+
adapter: "${frameworkAdapter}",
|
|
16
|
+
},`;
|
|
17
|
+
if (toolsPath) {
|
|
18
|
+
configContent += `
|
|
19
|
+
paths: {
|
|
20
|
+
tools: "${toolsPath}",
|
|
21
|
+
},`;
|
|
22
|
+
}
|
|
23
|
+
configContent += `
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default config;`;
|
|
27
|
+
const configPath = path.join(projectPath, "xmcp.config.ts");
|
|
28
|
+
fs.writeFileSync(configPath, configContent);
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Framework } from "./detect-framework.js";
|
|
2
|
+
interface InitOptions {
|
|
3
|
+
projectRoot: string;
|
|
4
|
+
framework: Framework;
|
|
5
|
+
toolsPath: string | undefined;
|
|
6
|
+
routePath: string | undefined;
|
|
7
|
+
packageManager: "npm" | "yarn" | "pnpm";
|
|
8
|
+
}
|
|
9
|
+
export declare function init(options: InitOptions): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { generateConfig } from "./generate-config.js";
|
|
2
|
+
import { install } from "./install.js";
|
|
3
|
+
import { updatePackageJson } from "./update-package.js";
|
|
4
|
+
import { updateTsConfig } from "./update-tsconfig.js";
|
|
5
|
+
import { updateGitignore } from "./update-gitignore.js";
|
|
6
|
+
import { createTool } from "./create-tool.js";
|
|
7
|
+
import { createRoute } from "./create-handler.js";
|
|
8
|
+
export async function init(options) {
|
|
9
|
+
const { projectRoot, framework, toolsPath, routePath, packageManager } = options;
|
|
10
|
+
generateConfig(projectRoot, framework, toolsPath);
|
|
11
|
+
await install(projectRoot, packageManager);
|
|
12
|
+
updatePackageJson(projectRoot);
|
|
13
|
+
updateTsConfig(projectRoot);
|
|
14
|
+
updateGitignore(projectRoot);
|
|
15
|
+
if (toolsPath) {
|
|
16
|
+
createTool(projectRoot, toolsPath);
|
|
17
|
+
}
|
|
18
|
+
if (framework === "nextjs" && routePath) {
|
|
19
|
+
createRoute(projectRoot, routePath);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect which package manager is being used in the project
|
|
3
|
+
* @param projectPath - Project directory path
|
|
4
|
+
* @returns Package manager name (npm, yarn, or pnpm)
|
|
5
|
+
*/
|
|
6
|
+
export declare function detectPackageManager(projectPath: string): "npm" | "yarn" | "pnpm" | null;
|
|
7
|
+
/**
|
|
8
|
+
* Install xmcp dependencies using the specified package manager
|
|
9
|
+
* @param packageManager - Package manager to use (npm, yarn, pnpm, or bun)
|
|
10
|
+
*/
|
|
11
|
+
export declare function install(projectPath: string, packageManager: "npm" | "pnpm" | "yarn"): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
// based on create-xmcp-app CLI
|
|
6
|
+
/**
|
|
7
|
+
* Detect which package manager is being used in the project
|
|
8
|
+
* @param projectPath - Project directory path
|
|
9
|
+
* @returns Package manager name (npm, yarn, or pnpm)
|
|
10
|
+
*/
|
|
11
|
+
export function detectPackageManager(projectPath) {
|
|
12
|
+
if (fs.existsSync(path.join(projectPath, "yarn.lock"))) {
|
|
13
|
+
return "yarn";
|
|
14
|
+
}
|
|
15
|
+
if (fs.existsSync(path.join(projectPath, "pnpm-lock.yaml"))) {
|
|
16
|
+
return "pnpm";
|
|
17
|
+
}
|
|
18
|
+
if (fs.existsSync(path.join(projectPath, "package-lock.json"))) {
|
|
19
|
+
return "npm";
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Install xmcp dependencies using the specified package manager
|
|
25
|
+
* @param packageManager - Package manager to use (npm, yarn, pnpm, or bun)
|
|
26
|
+
*/
|
|
27
|
+
export async function install(projectPath, packageManager) {
|
|
28
|
+
const dependencies = ["xmcp", "zod"];
|
|
29
|
+
const devDependencies = ["swc-loader"];
|
|
30
|
+
const commands = {
|
|
31
|
+
npm: `npm install ${dependencies.join(" ")} && npm install --save-dev ${devDependencies.join(" ")}`,
|
|
32
|
+
pnpm: `pnpm add ${dependencies.join(" ")} && pnpm add --save-dev ${devDependencies.join(" ")}`,
|
|
33
|
+
yarn: `yarn add ${dependencies.join(" ")} && yarn add --dev ${devDependencies.join(" ")}`,
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
console.log(chalk.blue(`\nInstalling dependencies using ${packageManager}...`));
|
|
37
|
+
execSync(commands[packageManager], { cwd: projectPath, stdio: "inherit" });
|
|
38
|
+
console.log(chalk.green("\nDependencies installed successfully!"));
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(chalk.red("\nFailed to install dependencies. You can install them manually:"));
|
|
42
|
+
console.log(chalk.yellow(`\n${commands[packageManager]}`));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
/**
|
|
4
|
+
* Update .gitignore to include xmcp and xmcp-env.d.ts entries
|
|
5
|
+
* @param projectPath - The root directory of the project
|
|
6
|
+
* @returns void
|
|
7
|
+
*/
|
|
8
|
+
export function updateGitignore(projectPath) {
|
|
9
|
+
const gitignorePath = path.join(projectPath, ".gitignore");
|
|
10
|
+
// xmcp entries to add
|
|
11
|
+
const xmcpEntries = ["", "# xmcp", ".xmcp", "xmcp-env.d.ts"];
|
|
12
|
+
let gitignoreContent = "";
|
|
13
|
+
if (fs.existsSync(gitignorePath)) {
|
|
14
|
+
gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
|
|
15
|
+
}
|
|
16
|
+
const updatedContent = gitignoreContent + xmcpEntries.join("\n");
|
|
17
|
+
fs.writeFileSync(gitignorePath, updatedContent);
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
/**
|
|
4
|
+
* update package.json scripts to include xmcp build and dev commands
|
|
5
|
+
* @param projectPath - The root directory of the project
|
|
6
|
+
* @returns void
|
|
7
|
+
*/
|
|
8
|
+
export function updatePackageJson(projectPath) {
|
|
9
|
+
const packageJsonPath = path.join(projectPath, "package.json");
|
|
10
|
+
const packageJson = fs.readJsonSync(packageJsonPath);
|
|
11
|
+
if (!packageJson.scripts) {
|
|
12
|
+
packageJson.scripts = {};
|
|
13
|
+
}
|
|
14
|
+
// prepend commands to existing scripts - prevent overwriting
|
|
15
|
+
if (packageJson.scripts.build) {
|
|
16
|
+
packageJson.scripts.build = `xmcp build && ${packageJson.scripts.build}`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
packageJson.scripts.build = "xmcp build";
|
|
20
|
+
}
|
|
21
|
+
if (packageJson.scripts.dev) {
|
|
22
|
+
packageJson.scripts.dev = `xmcp dev & ${packageJson.scripts.dev}`;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
packageJson.scripts.dev = "xmcp dev";
|
|
26
|
+
}
|
|
27
|
+
fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 });
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* updates the tsconfig.json file to include the @xmcp/* alias for accessing the handler
|
|
6
|
+
* @param projectRoot - The root directory of the project
|
|
7
|
+
* @returns void
|
|
8
|
+
*/
|
|
9
|
+
export function updateTsConfig(projectRoot) {
|
|
10
|
+
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
11
|
+
const tsconfig = fs.readJsonSync(tsconfigPath);
|
|
12
|
+
if (!tsconfig) {
|
|
13
|
+
console.log(chalk.yellow("No tsconfig.json file found - skipping alias configuration"));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// there's a file, but it's empty - we can add the compiler options and paths
|
|
17
|
+
if (!tsconfig.compilerOptions) {
|
|
18
|
+
tsconfig.compilerOptions = {};
|
|
19
|
+
}
|
|
20
|
+
if (!tsconfig.compilerOptions.paths) {
|
|
21
|
+
tsconfig.compilerOptions.paths = {};
|
|
22
|
+
}
|
|
23
|
+
// alias for accessing the handler, otherwise should be pointing to .xmcp/adapter when importing it
|
|
24
|
+
if (!tsconfig.compilerOptions.paths["@xmcp/*"]) {
|
|
25
|
+
tsconfig.compilerOptions.paths["@xmcp/*"] = ["./.xmcp/*"];
|
|
26
|
+
}
|
|
27
|
+
if (!tsconfig.include) {
|
|
28
|
+
tsconfig.include = [];
|
|
29
|
+
}
|
|
30
|
+
if (!tsconfig.include.includes("xmcp.d.ts")) {
|
|
31
|
+
// include xmcp.d.ts in the build
|
|
32
|
+
tsconfig.include.push("xmcp.d.ts");
|
|
33
|
+
}
|
|
34
|
+
fs.writeJsonSync(tsconfigPath, tsconfig, { spaces: 2 });
|
|
35
|
+
}
|
package/dist/index.d.ts
ADDED