UNPKG

@factorialco/shadowdog

Version:

<img src="https://raw.githubusercontent.com/factorialco/shadowdog/refs/heads/main/logo.png" alt="drawing" width="100"/>

122 lines (121 loc) 6.78 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const package_json_1 = __importDefault(require("../package.json")); const path_1 = __importDefault(require("path")); const daemon_1 = require("./daemon"); const generate_1 = require("./generate"); const utils_1 = require("./utils"); const chalk_1 = __importDefault(require("chalk")); const events_1 = require("./events"); const plugins_1 = require("./plugins"); const config_1 = require("./config"); const DEFAULT_CONFIG_FILENAME = 'shadowdog.json'; const cli = new commander_1.Command(); const eventEmitter = new events_1.ShadowdogEventEmitter(); cli .version(package_json_1.default.version) .description('A blazing fast build system with intelligent caching, file watching, and MCP integration'); cli .option('-c, --config <path>', `Config file path (default: ${DEFAULT_CONFIG_FILENAME} in current working directory)`, path_1.default.join(process.cwd(), DEFAULT_CONFIG_FILENAME)) .option('-w, --watch', 'Watch for changes in the configured files and run the tasks automatically') .option('--mcp', 'Start in MCP server mode for external tool integration') .action(async ({ config: configFilePath, watch, mcp }) => { var _a; if (watch) { (0, utils_1.logMessage)(` ███████╗██╗ ██╗ █████╗ ██████╗ ██████╗ ██╗ ██╗██████╗ ██████╗ ██████╗ ██╔════╝██║ ██║██╔══██╗██╔══██╗██╔═══██╗██║ ██║██╔══██╗██╔═══██╗██╔════╝ ███████╗███████║███████║██║ ██║██║ ██║██║ █╗ ██║██║ ██║██║ ██║██║ ███╗ ╚════██║██╔══██║██╔══██║██║ ██║██║ ██║██║███╗██║██║ ██║██║ ██║██║ ██║ ███████║██║ ██║██║ ██║██████╔╝╚██████╔╝╚███╔███╔╝██████╔╝╚██████╔╝╚██████╔╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚═════╝ ╚═════╝ `); } if (mcp) { (0, utils_1.logMessage)(`🔌 ${chalk_1.default.blue('Shadowdog MCP Server')} ${chalk_1.default.blue((0, utils_1.readShadowdogVersion)())} is starting...`); const configRelativePath = path_1.default.relative(process.cwd(), configFilePath); const config = (0, config_1.loadConfig)(configRelativePath); // Only initialize MCP plugin in MCP mode const mcpPlugin = config.plugins.find((p) => p.name === 'shadowdog-mcp'); if (mcpPlugin) { const { default: shadowdogMcp } = await Promise.resolve().then(() => __importStar(require('./plugins/shadowdog-mcp'))); shadowdogMcp.listener(eventEmitter, (_a = mcpPlugin.options) !== null && _a !== void 0 ? _a : {}); } else { (0, utils_1.logMessage)(`⚠️ ${chalk_1.default.yellow('shadowdog-mcp plugin not found in config. Add it to enable MCP server.')}`); return (0, utils_1.exit)(eventEmitter, 1); } // Emit config loaded event for plugins that need access to the full config eventEmitter.emit('configLoaded', { config }); // Initialize MCP server eventEmitter.emit('initialized'); // Keep the process alive for HTTP MCP communication // The HTTP server will keep the process running return; } (0, utils_1.logMessage)(`🚀 Shadowdog ${chalk_1.default.blue((0, utils_1.readShadowdogVersion)())} is booting!`); const configRelativePath = path_1.default.relative(process.cwd(), configFilePath); const config = (0, config_1.loadConfig)(configRelativePath); (0, plugins_1.filterEventListenerPlugins)(config.plugins).forEach(({ fn, options }) => { fn.listener(eventEmitter, options !== null && options !== void 0 ? options : {}); }); // Emit config loaded event for plugins that need access to the full config eventEmitter.emit('configLoaded', { config }); // Emit generate started event eventEmitter.emit('generateStarted'); try { await (0, generate_1.generate)(config, eventEmitter, { continueOnError: watch }); // Emit allTasksComplete event after generate phase completes eventEmitter.emit('allTasksComplete'); } catch (error) { (0, utils_1.logMessage)(`🚫 Unable to perform the initial generation because some command has failed.`); (0, utils_1.logError)(error); return (0, utils_1.exit)(eventEmitter, 1); } if (watch) { (0, daemon_1.runDaemon)(config, configRelativePath, eventEmitter); } else { return (0, utils_1.exit)(eventEmitter, 0); } }); cli.parse(process.argv);