UNPKG

microfox

Version:

Universal CLI tool for creating modern TypeScript packages with npm availability checking

126 lines (123 loc) 5.42 kB
#!/usr/bin/env node "use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/commands/add.ts var add_exports = {}; __export(add_exports, { addCommand: () => addCommand }); module.exports = __toCommonJS(add_exports); var import_commander = require("commander"); var import_fs = __toESM(require("fs")); var import_path = __toESM(require("path")); var import_chalk = __toESM(require("chalk")); var import_inquirer = __toESM(require("inquirer")); var import_readline_sync = __toESM(require("readline-sync")); // src/utils/getProjectRoot.ts var getWorkingDirectory = () => { return process.cwd(); }; // src/commands/add.ts async function addBackgroundAgentFunctions(name) { const workingDir = getWorkingDirectory(); const functionsDir = import_path.default.join(workingDir, "src", "functions", name); console.log( import_chalk.default.blue( `\u{1F680} Adding background agent functions ${import_chalk.default.bold(name)} at ${functionsDir} ` ) ); import_fs.default.mkdirSync(functionsDir, { recursive: true }); const templateDir = import_path.default.resolve(__dirname, "background-agent", "src", "functions"); const entries = import_fs.default.readdirSync(templateDir, { withFileTypes: true }); for (const entry of entries) { const srcPath = import_path.default.join(templateDir, entry.name); const destPath = import_path.default.join(functionsDir, entry.name.replace(/\.txt$/, "")); if (!entry.isDirectory() && entry.name.endsWith(".txt")) { const templateContent = import_fs.default.readFileSync(srcPath, "utf-8"); const content = templateContent.replace(/<%= agentName %>/g, name); import_fs.default.writeFileSync(destPath, content); console.log(import_chalk.default.green(`\u2705 Created ${import_path.default.relative(workingDir, destPath)}`)); } } } async function addAction() { console.log(import_chalk.default.cyan("\u2728 Add new features to your project!\n")); const workingDir = getWorkingDirectory(); const microfoxConfigPath = import_path.default.join(workingDir, "microfox.json"); if (!import_fs.default.existsSync(microfoxConfigPath)) { console.log(import_chalk.default.red("Error: `microfox.json` not found in the current directory.")); console.log(import_chalk.default.red("Please run this command from the root of a Microfox project.")); return; } const { featureType } = await import_inquirer.default.prompt([ { type: "list", name: "featureType", message: "Select what you want to add:", choices: ["background_agent_functions"] } ]); if (!featureType) { console.log(import_chalk.default.yellow("Operation cancelled.")); return; } if (featureType === "background_agent_functions") { const functionName = import_readline_sync.default.question( import_chalk.default.yellow("\u{1F4E6} Enter a name for the new functions: ") ); if (!functionName.trim()) { throw new Error("Function name cannot be empty"); } await addBackgroundAgentFunctions(functionName.trim()); console.log( import_chalk.default.green( ` \u{1F389} Successfully added background agent functions ${import_chalk.default.bold(functionName)}!` ) ); console.log(import_chalk.default.gray(`\u{1F4CD} Located at src/functions/${functionName.trim()}`)); console.log(import_chalk.default.yellow("\n\u{1F4A1} Next steps:")); console.log(import_chalk.default.yellow(" 1. Check the new files in src/functions/")); console.log(import_chalk.default.yellow(" 2. Update your agent logic to use the new functions.")); } } var addCommand = new import_commander.Command("add").description("Add features to a Microfox project").action(async () => { try { await addAction(); } catch (error) { console.error(import_chalk.default.red("\u274C Error:"), error instanceof Error ? error.message : String(error)); process.exit(1); } }); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { addCommand }); //# sourceMappingURL=add.js.map