UNPKG

create-eliza

Version:

Initialize an Eliza project

950 lines (938 loc) 31.7 kB
import { createRequire } from 'module'; const require = createRequire(import.meta.url); import { copyTemplate, getConfig, installPlugin, runBunCommand } from "./chunk-D7QPC2K7.js"; import { branchExists, createBranch, createPullRequest, execa, forkExists, forkRepository, getFileContent, getGitHubCredentials, getGitHubToken, getPluginRepository, getRegistryIndex, getRegistrySettings, initializeDataDir, saveRegistrySettings, updateFile, validateDataDir } from "./chunk-BFN357Z4.js"; import { handleError } from "./chunk-KVRKBU4Y.js"; import { require_main } from "./chunk-ZMJ3QLUC.js"; import { source_default } from "./chunk-BY3DNMXE.js"; import { logger } from "./chunk-FGGK5AA5.js"; import { require_prompts } from "./chunk-OGSHIQ3J.js"; import { Command } from "./chunk-S757QXWN.js"; import { __toESM } from "./chunk-WCMDOJQK.js"; // src/commands/plugins.ts import { promises as fs3, existsSync as existsSync2 } from "node:fs"; import path3 from "node:path"; // src/utils/plugin-env.ts import { promises as fs, existsSync } from "node:fs"; import os from "node:os"; import path from "node:path"; var import_dotenv = __toESM(require_main(), 1); var PLUGIN_ENV_REQUIREMENTS = { "@elizaos/plugin-openai": [ { name: "OPENAI_API_KEY", description: "OpenAI API key", required: true }, { name: "OPENAI_ORG_ID", description: "OpenAI organization ID", required: false } ], "@elizaos/plugin-anthropic": [ { name: "ANTHROPIC_API_KEY", description: "Anthropic API key", required: true }, { name: "ANTHROPIC_SMALL_MODEL", description: "Anthropic small model name", required: false, default: "claude-3-haiku-20240307" }, { name: "ANTHROPIC_LARGE_MODEL", description: "Anthropic large model name", required: false, default: "claude-3-opus-20240229" } ], "@elizaos/plugin-telegram": [ { name: "TELEGRAM_BOT_TOKEN", description: "Telegram bot token", required: true } ], "@elizaos/plugin-twitter": [ { name: "TWITTER_USERNAME", description: "Twitter username", required: true }, { name: "TWITTER_PASSWORD", description: "Twitter password", required: true }, { name: "TWITTER_EMAIL", description: "Twitter email", required: false }, { name: "TWITTER_2FA_SECRET", description: "Twitter 2FA secret", required: false } ] }; var ENV_LOCATIONS = [ ".env", // Current directory path.join(os.homedir(), ".env"), // Home directory path.join(os.homedir(), ".eliza", ".env") // Global Eliza config ]; function isEnvSet(name) { return process.env[name] !== void 0; } async function loadAllEnvFiles() { for (const location of ENV_LOCATIONS) { try { await fs.stat(location); import_dotenv.default.config({ path: location }); logger.info(`Loaded environment variables from ${location}`); } catch (error) { } } } function getPluginEnvRequirements(pluginName) { return PLUGIN_ENV_REQUIREMENTS[pluginName] || []; } function checkPluginEnvRequirements(pluginName) { const requirements = getPluginEnvRequirements(pluginName); const missing = requirements.filter( (req) => req.required && !isEnvSet(req.name) ); return { missing, all: requirements }; } async function ensurePluginEnvRequirements(pluginName, interactive = true, envFile = path.join(os.homedir(), ".eliza", ".env")) { await loadAllEnvFiles(); const { missing, all } = checkPluginEnvRequirements(pluginName); all.forEach((req) => { if (req.default && !isEnvSet(req.name)) { process.env[req.name] = req.default; logger.info(`Using default value for ${req.name}: ${req.default}`); } }); const { missing: stillMissing } = checkPluginEnvRequirements(pluginName); if (stillMissing.length === 0) { return true; } if (!interactive) { logger.warn(`Missing required environment variables for ${pluginName}:`); stillMissing.forEach((req) => { logger.warn(` - ${req.name}: ${req.description}`); }); return false; } const envDir = path.dirname(envFile); await fs.mkdir(envDir, { recursive: true }); let envContent = ""; try { envContent = await fs.readFile(envFile, "utf-8"); if (!envContent.endsWith("\n")) { envContent += "\n"; } } catch (error) { envContent = "# Environment variables for Eliza\n\n"; } const prompt = await import("./prompts-AYEGBXQG.js"); logger.info(`Setting up environment variables for ${pluginName}...`); for (const req of stillMissing) { const { value } = await prompt.default({ type: "text", name: "value", message: `Enter ${req.name} (${req.description})`, validate: (value2) => req.required && !value2 ? "This field is required" : true }); if (value) { process.env[req.name] = value; envContent += `${req.name}=${value} `; } } await fs.writeFile(envFile, envContent); logger.success(`Environment variables for ${pluginName} saved to ${envFile}`); return true; } // src/commands/plugins.ts var import_prompts = __toESM(require_prompts(), 1); // src/utils/plugin-publisher.ts import { promises as fs2 } from "node:fs"; import path2 from "node:path"; async function testPublishToNpm(cwd) { try { await execa("npm", ["whoami"]); logger.info("\u2713 Logged in to npm"); logger.info("Testing build..."); await execa("npm", ["run", "build", "--dry-run"], { cwd }); logger.info("\u2713 Build test successful"); const pkgJson = JSON.parse(await fs2.readFile(path2.join(cwd, "package.json"), "utf-8")); await execa("npm", ["access", "ls-packages"], { cwd }); logger.info("\u2713 Have publish permissions"); return true; } catch (error) { logger.error("Test failed:", error); if (error instanceof Error) { logger.error(`Error message: ${error.message}`); logger.error(`Error stack: ${error.stack}`); } return false; } } async function testPublishToGitHub(cwd, packageJson, username) { try { const token = await getGitHubToken(); if (!token) { logger.error("GitHub token not found"); return false; } logger.info("\u2713 GitHub token found"); const response = await fetch("https://api.github.com/user", { headers: { Authorization: `token ${token}` } }); if (!response.ok) { logger.error("Invalid GitHub token or insufficient permissions"); return false; } logger.info("\u2713 GitHub token is valid"); const settings = await getRegistrySettings(); const [registryOwner, registryRepo] = settings.defaultRegistry.split("/"); const hasFork = await forkExists(token, registryOwner, registryRepo, username); logger.info(hasFork ? "\u2713 Fork exists" : "\u2713 Can create fork"); if (!hasFork) { logger.info("Creating fork..."); const forkCreated = await forkRepository(token, registryOwner, registryRepo); if (!forkCreated) { logger.error("Failed to create fork"); return false; } logger.info("\u2713 Fork created"); await new Promise((resolve) => setTimeout(resolve, 3e3)); } const branchName = `test-${packageJson.name.replace(/^@elizaos\//, "")}-${packageJson.version}`; const hasBranch = await branchExists(token, username, registryRepo, branchName); logger.info(hasBranch ? "\u2713 Test branch exists" : "\u2713 Can create branch"); if (!hasBranch) { logger.info("Creating branch..."); const branchCreated = await createBranch(token, username, registryRepo, branchName, "main"); if (!branchCreated) { logger.error("Failed to create branch"); return false; } logger.info("\u2713 Branch created"); } const simpleName = packageJson.name.replace(/^@elizaos\//, "").replace(/[^a-zA-Z0-9-]/g, "-"); const testPath = `${simpleName}-test.json`; logger.info(`Attempting to create test file: ${testPath} in branch: ${branchName}`); const canUpdate = await updateFile( token, username, registryRepo, testPath, JSON.stringify({ test: true, timestamp: (/* @__PURE__ */ new Date()).toISOString() }), "Test file update", branchName // Use the test branch instead of main ); if (!canUpdate) { logger.error("Cannot update files in repository"); return false; } logger.info("\u2713 Can update files"); return true; } catch (error) { logger.error("Test failed:", error); if (error instanceof Error) { logger.error(`Error message: ${error.message}`); logger.error(`Error stack: ${error.stack}`); } return false; } } async function publishToNpm(cwd) { try { await execa("npm", ["whoami"]); logger.info("Building package..."); await execa("npm", ["run", "build"], { cwd, stdio: "inherit" }); logger.info("Publishing to npm..."); await execa("npm", ["publish"], { cwd, stdio: "inherit" }); return true; } catch (error) { logger.error("Failed to publish to npm:", error); return false; } } async function publishToGitHub(cwd, packageJson, cliVersion, username, isTest = false) { const token = await getGitHubToken(); if (!token) { logger.error("GitHub token not found. Please set it using the login command."); return false; } if (isTest) { logger.info("Running in test mode - no actual changes will be made"); } const settings = await getRegistrySettings(); const [registryOwner, registryRepo] = settings.defaultRegistry.split("/"); const hasFork = await forkExists(token, registryOwner, registryRepo, username); let forkFullName; if (!hasFork && !isTest) { logger.info(`Creating fork of ${settings.defaultRegistry}...`); const fork = await forkRepository(token, registryOwner, registryRepo); if (!fork) { logger.error("Failed to fork registry repository."); return false; } forkFullName = fork; } else { forkFullName = `${username}/${registryRepo}`; logger.info(`Using existing fork: ${forkFullName}`); } const branchName = `plugin-${packageJson.name.replace(/^@elizaos\//, "")}-${packageJson.version}`; const hasBranch = await branchExists(token, username, registryRepo, branchName); if (!hasBranch && !isTest) { logger.info(`Creating branch ${branchName}...`); const created = await createBranch(token, username, registryRepo, branchName); if (!created) { logger.error("Failed to create branch."); return false; } } const packagePath = `packages/${packageJson.name.replace(/^@elizaos\//, "")}.json`; const existingContent = await getFileContent(token, registryOwner, registryRepo, packagePath); let metadata; if (existingContent) { metadata = JSON.parse(existingContent); if (metadata.versions.includes(packageJson.version)) { logger.error(`Version ${packageJson.version} already exists in registry.`); return false; } metadata.versions.push(packageJson.version); metadata.latestVersion = packageJson.version; metadata.runtimeVersion = cliVersion; } else { metadata = { name: packageJson.name, description: packageJson.description || "", author: packageJson.author || "", repository: packageJson.repository?.url || "", versions: [packageJson.version], latestVersion: packageJson.version, runtimeVersion: cliVersion, maintainer: username, tags: [], categories: [] }; } if (!isTest) { const updated = await updateFile( token, username, registryRepo, packagePath, JSON.stringify(metadata, null, 2), `Update ${packageJson.name} to version ${packageJson.version}`, branchName ); if (!updated) { logger.error("Failed to update package metadata."); return false; } const prCreated = await createPullRequest( token, registryOwner, registryRepo, `Add ${packageJson.name}@${packageJson.version} to registry`, `This PR adds ${packageJson.name} version ${packageJson.version} to the registry. - Package name: ${packageJson.name} - Version: ${packageJson.version} - Runtime version: ${cliVersion} - Description: ${packageJson.description || "No description provided"} - Repository: ${metadata.repository} Submitted by: @${username}`, `${username}:${branchName}`, "main" ); if (!prCreated) { logger.error("Failed to create pull request."); return false; } logger.success(`Pull request created: ${prCreated}`); } else { logger.info("Test successful - all checks passed"); logger.info("Would create:"); logger.info(`- Branch: ${branchName}`); logger.info(`- Package file: ${packagePath}`); logger.info(`- Pull request: Add ${packageJson.name}@${packageJson.version} to registry`); } return true; } // src/commands/plugins.ts import { fileURLToPath } from "node:url"; var plugins = new Command().name("plugins").description("manage ElizaOS plugins"); plugins.command("list").description("list available plugins").option("-t, --type <type>", "filter by type (adapter, client, plugin)").action(async (opts) => { try { const registry = await getRegistryIndex(); const plugins2 = Object.keys(registry).filter((name) => !opts.type || name.includes(opts.type)).sort(); logger.info("\nAvailable plugins:"); for (const plugin of plugins2) { logger.info(` ${plugin}`); } logger.info(""); } catch (error) { handleError(error); } }); plugins.command("add").description("add a plugin").argument("<plugin>", "plugin name").option("--no-env-prompt", "Skip prompting for environment variables").action(async (plugin, opts) => { try { const cwd = process.cwd(); const config = await getConfig(cwd); if (!config) { logger.error("No project.json found. Please run init first."); process.exit(1); } const repo = await getPluginRepository(plugin); if (!repo) { logger.error(`Plugin ${plugin} not found in registry`); process.exit(1); } if (!config.plugins.installed.includes(plugin)) { config.plugins.installed.push(plugin); } logger.info(`Installing ${plugin}...`); await installPlugin(repo, cwd); if (opts.envPrompt !== false) { await ensurePluginEnvRequirements(plugin, true); } logger.success(`Successfully installed ${plugin}`); } catch (error) { handleError(error); } }); plugins.command("remove").description("remove a plugin").argument("<plugin>", "plugin name").action(async (plugin, _opts) => { try { const cwd = process.cwd(); const config = await getConfig(cwd); if (!config) { logger.error("No project.json found. Please run init first."); process.exit(1); } config.plugins.installed = config.plugins.installed.filter( (p) => p !== plugin ); logger.info(`Removing ${plugin}...`); await execa("bun", ["remove", plugin], { cwd, stdio: "inherit" }); logger.success(`Successfully removed ${plugin}`); } catch (error) { handleError(error); } }); plugins.command("update").description("update plugins").option("-p, --plugin <plugin>", "specific plugin to update").action(async (opts) => { try { const cwd = process.cwd(); const config = await getConfig(cwd); if (!config) { logger.error("No project.json found. Please run init first."); process.exit(1); } const _registry = await getRegistryIndex(); const plugins2 = opts.plugin ? [opts.plugin] : config.plugins.installed; for (const plugin of plugins2) { const repo = await getPluginRepository(plugin); if (!repo) { logger.warn(`Plugin ${plugin} not found in registry, skipping`); continue; } logger.info(`Updating ${plugin}...`); await execa("bun", ["update", plugin], { cwd, stdio: "inherit" }); } logger.success("Plugins updated successfully"); } catch (error) { handleError(error); } }); plugins.command("create").description("create a new plugin").option("-d, --dir <dir>", "installation directory", ".").action(async (opts) => { try { const { name } = await (0, import_prompts.default)({ type: "text", name: "name", message: "What would you like to name your plugin?", validate: (value) => value.length > 0 || "Plugin name is required" }); if (!name) { process.exit(0); } const targetDir = opts.dir === "." ? path3.resolve(name) : path3.resolve(opts.dir); if (!existsSync2(targetDir)) { await fs3.mkdir(targetDir, { recursive: true }); } else { const files = await fs3.readdir(targetDir); const isEmpty = files.length === 0 || files.every((f) => f.startsWith(".")); if (!isEmpty) { const { proceed } = await (0, import_prompts.default)({ type: "confirm", name: "proceed", message: "Directory is not empty. Continue anyway?", initial: false }); if (!proceed) { process.exit(0); } } } const pluginName = name.startsWith("@elizaos/plugin-") ? name : `@elizaos/plugin-${name}`; await copyTemplate("plugin", targetDir, pluginName); logger.info("Installing dependencies..."); try { await runBunCommand(["install"], targetDir); logger.success("Dependencies installed successfully!"); } catch (_error) { logger.warn( "Failed to install dependencies automatically. Please run 'bun install' manually." ); } logger.success("Plugin created successfully!"); logger.info(` Next steps: 1. ${source_default.cyan(`cd ${name}`)} to navigate to your plugin directory 2. Update the plugin code in ${source_default.cyan("src/index.ts")} 3. Run ${source_default.cyan("bun dev")} to start development 4. Run ${source_default.cyan("bun build")} to build your plugin`); } catch (error) { handleError(error); } }); plugins.command("deploy").description("deploy a plugin to GitHub").option( "-r, --registry <registry>", "target registry", "elizaos-plugins/registry" ).option("-n, --npm", "publish to npm instead of GitHub", false).action(async (opts) => { try { const cwd = process.cwd(); const packageJsonPath = path3.join(cwd, "package.json"); if (!existsSync2(packageJsonPath)) { logger.error("No package.json found in current directory."); process.exit(1); } const packageJsonContent = await fs3.readFile(packageJsonPath, "utf-8"); const packageJson = JSON.parse(packageJsonContent); if (!packageJson.name || !packageJson.version) { logger.error("Invalid package.json: missing name or version."); process.exit(1); } if (!packageJson.name.includes("plugin-")) { logger.warn( "This doesn't appear to be an ElizaOS plugin. Package name should include 'plugin-'." ); const { proceed } = await (0, import_prompts.default)({ type: "confirm", name: "proceed", message: "Proceed anyway?", initial: false }); if (!proceed) { process.exit(0); } } const cliPackageJsonPath = path3.resolve( path3.dirname(fileURLToPath(import.meta.url)), "../package.json" ); let cliVersion = "0.0.0"; try { const cliPackageJsonContent = await fs3.readFile( cliPackageJsonPath, "utf-8" ); const cliPackageJson = JSON.parse(cliPackageJsonContent); cliVersion = cliPackageJson.version || "0.0.0"; } catch (error) { logger.warn("Could not determine CLI version, using 0.0.0"); } if (opts.npm) { logger.info("Publishing to npm..."); try { await execa("npm", ["whoami"], { stdio: "inherit" }); } catch (error) { logger.error("Not logged in to npm. Please run 'npm login' first."); process.exit(1); } logger.info("Building package..."); await execa("npm", ["run", "build"], { cwd, stdio: "inherit" }); logger.info("Publishing to npm..."); await execa("npm", ["publish"], { cwd, stdio: "inherit" }); logger.success( `Successfully published ${packageJson.name}@${packageJson.version} to npm` ); return; } logger.info("Deploying to GitHub..."); let credentials = await getGitHubCredentials(); if (!credentials) { logger.info("\nGitHub credentials required for publishing."); logger.info("Please enter your GitHub credentials:\n"); await new Promise((resolve) => setTimeout(resolve, 10)); const newCredentials = await getGitHubCredentials(); if (!newCredentials) { process.exit(1); } credentials = newCredentials; } const [registryOwner, registryRepo] = opts.registry.split("/"); if (!registryOwner || !registryRepo) { logger.error("Invalid registry format. Expected 'owner/repo'."); process.exit(1); } const registryFullName = `${registryOwner}/${registryRepo}`; logger.info(`Checking for fork of ${registryFullName}...`); const hasFork = await forkExists( credentials.token, registryOwner, registryRepo, credentials.username ); let forkFullName; if (!hasFork) { logger.info(`Creating fork of ${registryFullName}...`); const fork = await forkRepository( credentials.token, registryOwner, registryRepo ); if (!fork) { logger.error("Failed to fork registry repository."); process.exit(1); } forkFullName = fork; } else { forkFullName = `${credentials.username}/${registryRepo}`; logger.info(`Using existing fork: ${forkFullName}`); } const branchName = `plugin-${packageJson.name.replace(/^@elizaos\//, "")}-${packageJson.version}`; const branchAlreadyExists = await branchExists( credentials.token, credentials.username, registryRepo, branchName ); if (branchAlreadyExists) { logger.warn(`Branch ${branchName} already exists.`); const { proceed } = await (0, import_prompts.default)({ type: "confirm", name: "proceed", message: "Use existing branch? This might overwrite previous changes.", initial: false }); if (!proceed) { process.exit(0); } } else { logger.info(`Creating branch ${branchName}...`); const branchCreated = await createBranch( credentials.token, credentials.username, registryRepo, branchName ); if (!branchCreated) { logger.error("Failed to create branch."); process.exit(1); } } const packageIndexPath = `packages/${packageJson.name.replace(/^@elizaos\//, "")}.json`; const existingPackageContent = await getFileContent( credentials.token, registryOwner, registryRepo, packageIndexPath ); let packageData; if (existingPackageContent) { packageData = JSON.parse(existingPackageContent); logger.info(`Found existing package data: ${packageJson.name}`); if (packageData.versions?.includes(packageJson.version)) { logger.error( `Version ${packageJson.version} already exists in registry.` ); logger.error( "Please increment your package version before deploying." ); process.exit(1); } packageData.versions = packageData.versions || []; packageData.versions.push(packageJson.version); packageData.latestVersion = packageJson.version; packageData.runtimeVersion = cliVersion; } else { logger.info(`Creating new package entry for ${packageJson.name}`); packageData = { name: packageJson.name, description: packageJson.description || "", author: packageJson.author || "", repository: packageJson.repository?.url || "", versions: [packageJson.version], latestVersion: packageJson.version, runtimeVersion: cliVersion, maintainer: credentials.username }; } logger.info(`Updating package index for ${packageJson.name}...`); const packageIndexUpdated = await updateFile( credentials.token, credentials.username, registryRepo, packageIndexPath, JSON.stringify(packageData, null, 2), `Update ${packageJson.name} to version ${packageJson.version}`, branchName ); if (!packageIndexUpdated) { logger.error("Failed to update package index."); process.exit(1); } const registryIndexPath = "index.json"; const existingRegistryContent = await getFileContent( credentials.token, credentials.username, registryRepo, registryIndexPath, branchName ) || await getFileContent( credentials.token, registryOwner, registryRepo, registryIndexPath ); let registryData = {}; if (existingRegistryContent) { registryData = JSON.parse(existingRegistryContent); } let repoUrl = packageJson.repository?.url || ""; if (repoUrl.startsWith("git+")) { repoUrl = repoUrl.substring(4); } if (repoUrl.endsWith(".git")) { repoUrl = repoUrl.slice(0, -4); } if (!repoUrl) { repoUrl = `https://github.com/${registryOwner}/${packageJson.name.replace(/^@elizaos\//, "")}`; } registryData[packageJson.name] = repoUrl; const sortedRegistryData = {}; Object.keys(registryData).sort().forEach((key) => { sortedRegistryData[key] = registryData[key]; }); logger.info("Updating registry index..."); const registryIndexUpdated = await updateFile( credentials.token, credentials.username, registryRepo, registryIndexPath, JSON.stringify(sortedRegistryData, null, 2), `Add ${packageJson.name}@${packageJson.version} to registry`, branchName ); if (!registryIndexUpdated) { logger.error("Failed to update registry index."); process.exit(1); } logger.info("Creating pull request..."); const pullRequestCreated = await createPullRequest( credentials.token, registryOwner, registryRepo, `Add ${packageJson.name}@${packageJson.version} to registry`, `This PR adds ${packageJson.name} version ${packageJson.version} to the registry. - Package name: ${packageJson.name} - Version: ${packageJson.version} - Runtime version: ${cliVersion} - Description: ${packageJson.description || "No description provided"} - Repository: ${repoUrl} Submitted by: @${credentials.username}`, `${credentials.username}:${branchName}`, "main" ); if (!pullRequestCreated) { logger.error("Failed to create pull request."); process.exit(1); } logger.success( `Successfully created pull request for ${packageJson.name}@${packageJson.version}` ); logger.info( `Your plugin will be available in the registry after the PR is merged: ${pullRequestCreated}` ); } catch (error) { handleError(error); } }); plugins.command("publish").description("publish a plugin to the registry").option("-r, --registry <registry>", "target registry", "elizaos/registry").option("-n, --npm", "publish to npm", false).option("-t, --test", "test publish process without making changes", false).action(async (opts) => { try { const cwd = process.cwd(); const isValid = await validateDataDir(); if (!isValid) { logger.info("\nGitHub credentials required for publishing."); logger.info("You'll need a GitHub Personal Access Token with these scopes:"); logger.info(" * repo (for repository access)"); logger.info(" * read:org (for organization access)"); logger.info(" * workflow (for workflow access)\n"); await initializeDataDir(); const credentials2 = await getGitHubCredentials(); if (!credentials2) { logger.error("GitHub credentials setup cancelled."); process.exit(1); } const revalidated = await validateDataDir(); if (!revalidated) { logger.error("Failed to validate credentials after saving."); process.exit(1); } } const packageJsonPath = path3.join(cwd, "package.json"); if (!existsSync2(packageJsonPath)) { logger.error("No package.json found in current directory."); process.exit(1); } const packageJsonContent = await fs3.readFile(packageJsonPath, "utf-8"); const packageJson = JSON.parse(packageJsonContent); if (!packageJson.name || !packageJson.version) { logger.error("Invalid package.json: missing name or version."); process.exit(1); } if (!packageJson.name.includes("plugin-")) { logger.warn( "This doesn't appear to be an ElizaOS plugin. Package name should include 'plugin-'." ); const { proceed } = await (0, import_prompts.default)({ type: "confirm", name: "proceed", message: "Proceed anyway?", initial: false }); if (!proceed) { process.exit(0); } } const cliPackageJsonPath = path3.resolve( path3.dirname(fileURLToPath(import.meta.url)), "../package.json" ); let cliVersion = "0.0.0"; try { const cliPackageJsonContent = await fs3.readFile( cliPackageJsonPath, "utf-8" ); const cliPackageJson = JSON.parse(cliPackageJsonContent); cliVersion = cliPackageJson.version || "0.0.0"; } catch (error) { logger.warn("Could not determine CLI version, using 0.0.0"); } let credentials = await getGitHubCredentials(); if (!credentials) { logger.info("\nGitHub credentials required for publishing."); logger.info("Please enter your GitHub credentials:\n"); await new Promise((resolve) => setTimeout(resolve, 10)); const newCredentials = await getGitHubCredentials(); if (!newCredentials) { process.exit(1); } credentials = newCredentials; } const settings = await getRegistrySettings(); settings.defaultRegistry = opts.registry; settings.publishConfig = { registry: opts.registry, username: credentials.username, useNpm: opts.npm }; await saveRegistrySettings(settings); if (opts.test) { logger.info("Running publish tests..."); if (opts.npm) { logger.info("\nTesting npm publishing:"); const npmTestSuccess = await testPublishToNpm(cwd); if (!npmTestSuccess) { logger.error("npm publishing test failed"); process.exit(1); } } logger.info("\nTesting GitHub publishing:"); const githubTestSuccess = await testPublishToGitHub( cwd, packageJson, credentials.username ); if (!githubTestSuccess) { logger.error("GitHub publishing test failed"); process.exit(1); } logger.success("All tests passed successfully!"); return; } if (opts.npm) { const success2 = await publishToNpm(cwd); if (!success2) { process.exit(1); } } const success = await publishToGitHub( cwd, packageJson, cliVersion, credentials.username, false ); if (!success) { process.exit(1); } logger.success( `Successfully published ${packageJson.name}@${packageJson.version}` ); } catch (error) { handleError(error); } }); export { plugins }; //# sourceMappingURL=chunk-KVFP67RD.js.map