tops-bmad
Version:
CLI tool to install BMAD workflow files into any project with integrated Shai-Hulud 2.0 security scanning
71 lines (59 loc) ⢠2.36 kB
JavaScript
import inquirer from "inquirer";
import fs from "fs-extra";
import path from "path";
import { fileURLToPath } from "url";
import { encryptFile } from "../lib/encrypt.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const PROJECT_ROOT = path.join(__dirname, "..");
const INPUT_ZIP = path.join(PROJECT_ROOT, "bmad-package.zip");
const ENCRYPTED_ZIP = path.join(PROJECT_ROOT, "bmad-package.zip");
console.log("\nš BMAD Package Encryption Tool\n");
(async () => {
try {
// Check if input zip exists
if (!await fs.pathExists(INPUT_ZIP)) {
console.error(`ā Error: Input zip file not found at: ${INPUT_ZIP}`);
process.exit(1);
}
const answers = await inquirer.prompt([
{
name: "password",
type: "password",
message: "Enter a secret key to encrypt the package:",
mask: "*",
validate: v => v.trim() !== "" || "Secret key cannot be empty!"
},
{
name: "confirmPassword",
type: "password",
message: "Confirm the secret key:",
mask: "*",
validate: v => v.trim() !== "" || "Secret key cannot be empty!"
}
]);
if (answers.password !== answers.confirmPassword) {
console.error("ā Error: Secret keys do not match!");
process.exit(1);
}
console.log("\nš Encrypting package...");
// Create a backup of the original file
const BACKUP_ZIP = path.join(PROJECT_ROOT, "bmad-package.zip.backup");
if (await fs.pathExists(INPUT_ZIP)) {
await fs.copy(INPUT_ZIP, BACKUP_ZIP);
console.log(`š Backup created: ${BACKUP_ZIP}`);
}
// Encrypt the file (will overwrite the original)
await encryptFile(INPUT_ZIP, ENCRYPTED_ZIP, answers.password);
console.log("\nā
Encryption complete!");
console.log(`š¦ Encrypted file saved at: ${ENCRYPTED_ZIP}`);
console.log("\nā ļø Important:");
console.log(" 1. Keep the secret key secure and share it only with authorized users");
console.log(" 2. The encrypted file will be decrypted during installation");
console.log(" 3. A backup of the original file is saved as bmad-package.zip.backup");
} catch (error) {
console.error("\nā Error during encryption:", error.message);
process.exit(1);
}
})();