UNPKG

@aminya/dotenv-vault

Version:

A secrets manager for .env files – from the same people that pioneered dotenv.

112 lines (111 loc) 3.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbortService = void 0; const tslib_1 = require("tslib"); const chalk_1 = tslib_1.__importDefault(require("chalk")); const vars_1 = require("../vars"); const log_service_1 = require("../services/log-service"); class AbortService { constructor(attrs = {}) { this.cmd = attrs.cmd; this.log = new log_service_1.LogService({ cmd: attrs.cmd }); } error(msg, obj) { this.log.plain(`${chalk_1.default.red('x')} Aborted.`); if (obj.code) { this.code(obj.code); } if (obj.suggestions[0]) { this.suggestion(obj.suggestions[0]); } this.cmd.error(msg); } code(code) { this.log.plain(`Code: ${code}`); } suggestion(suggestion) { this.log.plain(`Suggestion: ${suggestion}`); } quit() { this.log.plain(`${chalk_1.default.red('x')} Aborted.`); this.cmd.exit(); } missingEnvVault() { this.error(`Missing ${vars_1.vars.vaultFilename} (${vars_1.vars.vaultKey}).`, { code: 'MISSING_DOTENV_VAULT', ref: '', suggestions: [`Run, ${chalk_1.default.bold(`${vars_1.vars.cli} new`)}`], }); } emptyEnvVault() { this.error(`Empty ${vars_1.vars.vaultFilename} (${vars_1.vars.vaultKey}).`, { code: 'EMPTY_DOTENV_VAULT', ref: '', suggestions: [`Run, ${chalk_1.default.bold(`${vars_1.vars.cli} new`)}`], }); } invalidEnvVault() { this.error(`Invalid ${vars_1.vars.vaultFilename} (${vars_1.vars.vaultKey}).`, { code: 'INVALID_DOTENV_VAULT', ref: '', suggestions: [`Run, ${chalk_1.default.bold(`${vars_1.vars.cli} new`)}`], }); } existingEnvVault() { this.error(`Existing ${vars_1.vars.vaultFilename} (${vars_1.vars.vaultKey}).`, { code: 'EXISTING_DOTENV_VAULT', ref: '', suggestions: [`Delete ${vars_1.vars.vaultFilename} and then run, ${chalk_1.default.bold(`${vars_1.vars.cli} new`)}`], }); } invalidEnvMe() { this.error('Invalid .env.me (DOTENV_ME).', { code: 'INVALID_DOTENV_ME', ref: '', suggestions: [`Run, ${chalk_1.default.bold(`${vars_1.vars.cli} login`)}`], }); } missingEnvMe() { this.error('Missing .env.me (DOTENV_ME).', { code: 'MISSING_DOTENV_ME', ref: '', suggestions: [`Run, ${chalk_1.default.bold(`${vars_1.vars.cli} login`)}`], }); } emptyEnvMe() { this.error('Empty .env.me (DOTENV_ME).', { code: 'EMPTY_DOTENV_ME', ref: '', suggestions: [`Run, ${chalk_1.default.bold(`${vars_1.vars.cli} login`)}`], }); } missingEnv(filename = '.env') { this.error(`Missing ${filename}.`, { code: 'MISSING_ENV_FILE', ref: '', suggestions: [`Create it (touch ${filename}) and then try again. Or run, ${chalk_1.default.bold(`${vars_1.vars.cli} pull`)}`], }); } emptyEnv(filename = '.env') { this.error(`Empty ${filename}.`, { code: 'EMPTY_ENV_FILE', ref: '', suggestions: [`Populate ${filename} with values and then try again. Or run, ${chalk_1.default.bold(`${vars_1.vars.cli} pull`)}`], }); } missingEnvKeys() { this.error('Missing .env.keys file', { code: 'MISSING_DOTENV_KEYS', ref: '', suggestions: [`Run, ${chalk_1.default.bold(`${vars_1.vars.cli} local build`)}`], }); } emptyEnvKeys() { this.error('Empty .env.keys file.', { code: 'EMPTY_DOTENV_KEYS', ref: '', suggestions: [`Run, ${chalk_1.default.bold(`${vars_1.vars.cli} local build`)}`], }); } } exports.AbortService = AbortService;