UNPKG

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
#!/usr/bin/env node 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); } })();