UNPKG

envilder

Version:

A CLI that securely centralizes your environment variables from AWS SSM as a single source of truth

55 lines 2.78 kB
#!/usr/bin/env node var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { Command } from 'commander'; import { EnvilderBuilder } from './cli/domain/EnvilderBuilder.js'; import { PackageJsonFinder } from './cli/infrastructure/PackageJsonFinder.js'; /** * Parses CLI arguments and runs the environment file generator. * * Expects `--map` and `--envfile` options to be provided, with an optional `--profile` for AWS CLI profile selection. Invokes the main process to generate a `.env` file from AWS SSM parameters based on the provided mapping. * * @throws {Error} If either `--map` or `--envfile` arguments are missing. */ export function main() { return __awaiter(this, void 0, void 0, function* () { const program = new Command(); const version = yield getVersion(); program .name('envilder') .description('A CLI tool to generate .env files from AWS SSM parameters') .version(version) .requiredOption('--map <path>', 'Path to the JSON file with environment variable mapping') .requiredOption('--envfile <path>', 'Path to the .env file to be generated') .option('--profile <name>', 'AWS CLI profile to use'); yield program.parseAsync(process.argv); const options = program.opts(); if (!options.map || !options.envfile) { throw new Error('Missing required arguments: --map and --envfile'); } const envilder = EnvilderBuilder.build() .withDefaultFileManager() .withAwsProvider(options.profile) .create(); yield envilder.run(options.map, options.envfile); }); } function getVersion() { const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); return new PackageJsonFinder().readPackageJsonVersion(join(__dirname, '../package.json')); } main().catch((error) => { console.error('🚨 Uh-oh! Looks like Mario fell into the wrong pipe! 🍄💥'); console.error(error); }); //# sourceMappingURL=Cli.js.map