@pompeii-labs/cli
Version:
Magma CLI
47 lines (46 loc) • 1.48 kB
JavaScript
import { Bundler } from "../bundler.js";
import chalk from "chalk";
import boxen from "boxen";
import path from "path";
import { getOrg, isAuthenticated } from "../auth.js";
async function save(options) {
const projectDir = path.resolve(options.project);
const org = await getOrg();
if (!org) {
console.error(
chalk.red("No organization found. Please run `magma switch` to select an organization.")
);
process.exit(1);
}
console.log(
boxen(chalk.bold(`Saving ${chalk.cyan(path.basename(projectDir))}`), {
padding: 1,
margin: 1,
borderStyle: "round",
borderColor: "cyan"
})
);
const bundler = new Bundler(projectDir, org);
const agent = await bundler.run();
console.log(chalk.green("Agent saved successfully!"));
console.log(chalk.dim(`Agent ID: ${chalk.bold(agent.id)}`));
}
function saveCommand(program) {
program.command("save").description(
"Save/upload the current version of your Magma agent (similar to `git commit` and pushing to a branch)"
).option("-p, --project <path>", "Path to the project directory", ".").action(async (options) => {
if (!isAuthenticated()) {
console.log(chalk.red("Not authenticated with Magma. Please run `magma login`."));
process.exit(1);
}
try {
await save(options);
} catch (error) {
console.error(chalk.red("\n\u2716 Failed to save agent:"), error.message);
process.exit(1);
}
});
}
export {
saveCommand
};