Skip to main content
Glama

npmBuild

Execute npm build commands to compile and prepare projects for deployment, handling dependencies and generating production-ready files.

Instructions

執行npm build命令構建專案

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo
optionsNo

Implementation Reference

  • The static async executeBuild method in NpmBuildTool class that executes the npm build command using child_process.exec after changing to the specified path.
    static async executeBuild(path: string = '.', options: string = ''): Promise<{ stdout: string; stderr: string }> {
      try {
        console.log(`執行 npm build ${options} 在路徑 ${path}`);
        
        // 構建完整指令
        const command = `cd ${path} && npm run build ${options}`;
        
        // 執行指令
        const { stdout, stderr } = await execPromise(command);
        
        if (stdout) {
          console.log('Build輸出:', stdout);
        }
        
        if (stderr && !stderr.includes('npm notice')) {
          console.error('Build錯誤:', stderr);
        }
        
        return { stdout, stderr };
      } catch (error) {
        console.error('Build執行失敗:', error);
        throw error;
      }
    }
  • main.ts:34-48 (registration)
    Registers the 'npmBuild' tool with input schema for optional path and options, wraps the handler execution and formats success/error responses.
    server.tool("npmBuild",
        "執行npm build命令構建專案",
        { path: z.string().optional(), options: z.string().optional() },
        async ({ path = ".", options = "" }) => {
            try {
                const result = await NpmBuildTool.executeBuild(path, options);
                return {
                    content: [{ type: "text", text: `Build completed successfully: ${result.stdout}` }]
                };
            } catch (error) {
                return {
                    content: [{ type: "text", text: `Build failed: ${error instanceof Error ? error.message : "Unknown error"}` }]
                };
            }
        });
  • main.ts:36-36 (schema)
    Zod input schema defining optional path (project directory) and options (additional npm flags) parameters for the npmBuild tool.
    { path: z.string().optional(), options: z.string().optional() },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/GonTwVn/GonMCPtool'

If you have feedback or need assistance with the MCP directory API, please join our Discord server