@microfox/cli
Version:
Universal CLI tool for creating modern TypeScript packages with npm availability checking
128 lines (127 loc) • 5.5 kB
JavaScript
;
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/push.ts
var push_exports = {};
__export(push_exports, {
pushCommand: () => pushCommand
});
module.exports = __toCommonJS(push_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_chalk = __toESM(require("chalk"));
var import_axios = __toESM(require("axios"));
var import_micromatch = __toESM(require("micromatch"));
var API_ENDPOINT = "https://staging-cicd.microfox.app/api/deployments/new-agent-cli";
var getDirectoryFiles = (dir, basePath = "", ignorePatterns) => {
const structure = [];
const items = import_fs.default.readdirSync(dir, { withFileTypes: true });
for (const item of items) {
const relativePath = import_path.default.join(basePath, item.name);
if (import_micromatch.default.isMatch(relativePath, ignorePatterns)) {
continue;
}
if (item.isDirectory()) {
structure.push(...getDirectoryFiles(import_path.default.join(dir, item.name), relativePath, ignorePatterns));
} else {
structure.push({
type: "file",
name: item.name,
path: relativePath.replace(/\\/g, "/"),
content: import_fs.default.readFileSync(import_path.default.join(dir, item.name), "utf-8")
});
}
}
return structure;
};
async function pushCommand() {
const cwd = process.cwd();
const microfoxConfigPath = import_path.default.join(cwd, "microfox.json");
if (!import_fs.default.existsSync(microfoxConfigPath)) {
console.error(import_chalk.default.red("\u274C Error: `microfox.json` not found in the current directory."));
console.log(import_chalk.default.yellow("This command must be run from the root of an agent project."));
process.exit(1);
}
console.log(import_chalk.default.cyan("\u{1F680} Pushing your agent to Microfox..."));
const microfoxConfig = JSON.parse(import_fs.default.readFileSync(microfoxConfigPath, "utf-8"));
let agentApiKey;
const envPath = import_path.default.join(cwd, "env.json");
if (import_fs.default.existsSync(envPath)) {
try {
const envConfig = JSON.parse(import_fs.default.readFileSync(envPath, "utf-8"));
agentApiKey = envConfig.AGENT_API_KEY;
} catch (e) {
console.warn(import_chalk.default.yellow("\u26A0\uFE0F Could not read or parse `env.json`. The AGENT_API_KEY will not be sent."));
}
}
const stage = microfoxConfig.stage || "prod";
const ignored = microfoxConfig.ignored || [];
const defaultIgnore = ["node_modules/**", ".git/**", "dist/**", ".build/**", ".serverless/**", ".DS_Store", "package-lock.json", "pnpm-lock.yaml"];
const allIgnored = [...defaultIgnore, ...ignored];
const files = getDirectoryFiles(cwd, "", allIgnored);
try {
console.log(import_chalk.default.blue("\u{1F4E6} Bundling and deploying your agent..."));
const response = await import_axios.default.post(
API_ENDPOINT,
{
stage,
isLocal: false,
dir: files
},
{
headers: {
"x-agent-api-key": agentApiKey
}
}
);
if (response.status === 200) {
console.log(import_chalk.default.green("\u2705 Deployment successful!"));
console.log(import_chalk.default.green(` Run ID: ${response.data.runId}`));
console.log(import_chalk.default.green(` Message: ${response.data.message}`));
} else {
console.error(import_chalk.default.red(`\u274C Deployment failed with status: ${response.status}`));
console.error(response.data);
process.exit(1);
}
} catch (error) {
console.error(import_chalk.default.red("\u274C An error occurred during deployment:"));
if (import_axios.default.isAxiosError(error) && error.response) {
console.error(import_chalk.default.red(` Status: ${error.response.status}`));
console.error(import_chalk.default.red(` Data: ${JSON.stringify(error.response.data, null, 2)}`));
} else {
console.error(error);
}
process.exit(1);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
pushCommand
});
//# sourceMappingURL=push.js.map