UNPKG

@naturalcycles/nodejs-lib

Version:
52 lines 1.84 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const yargs = require("yargs"); const colors_1 = require("../colors"); const script_1 = require("../script"); const secrets_encrypt_util_1 = require("../secret/secrets-encrypt.util"); script_1.runScript(async () => { const { pattern, encKey, algorithm, del } = getEncryptCLIOptions(); await secrets_encrypt_util_1.secretsEncrypt(pattern, encKey, algorithm, del); }); function getEncryptCLIOptions() { require('dotenv').config(); let { pattern, encKey, encKeyVar, algorithm, del } = yargs.options({ pattern: { type: 'string', array: true, desc: 'Globby pattern for secrets. Can be many.', // demandOption: true, default: './secret/**', }, encKey: { type: 'string', desc: 'Encryption key', }, encKeyVar: { type: 'string', desc: 'Env variable name to get `encKey` from.', default: 'SECRET_ENCRYPTION_KEY', }, algorithm: { type: 'string', default: 'aes-256-cbc', }, del: { type: 'boolean', desc: 'Delete source files after encryption/decryption. Be careful!', }, }).argv; if (!encKey) { encKey = process.env[encKeyVar]; if (encKey) { console.log(`using encKey from process.env.${colors_1.dimGrey(encKeyVar)}`); } else { throw new Error(`encKey is required. Can be provided as --encKey or env.SECRET_ENCRYPTION_KEY (see readme.md)`); } } // `as any` because @types/yargs can't handle string[] type properly return { pattern: pattern, encKey, algorithm, del }; } //# sourceMappingURL=secrets-encrypt.js.map