@commutatus/cm-env
Advanced tools
Comparing version 1.0.2 to 1.1.0-0
34
index.js
@@ -13,4 +13,4 @@ #!/usr/bin/env node | ||
var program = new Command(); | ||
var envList = ['dev', 'staging', 'prod']; | ||
var envToFileName = { | ||
// This is to allow easier integration for Next.js projects | ||
var nextJsEnvToFileName = { | ||
dev: 'development', | ||
@@ -20,7 +20,19 @@ staging: 'staging', | ||
}; | ||
var isNextJsEnvType = function (env) { | ||
return env in nextJsEnvToFileName; | ||
}; | ||
var getEncOrKeyFileNameFromEnv = function (env) { | ||
var fileName = env; | ||
if (isNextJsEnvType(env)) { | ||
fileName = nextJsEnvToFileName[env]; | ||
} | ||
return fileName; | ||
}; | ||
var getEncryptedFilePath = function (env) { | ||
return "keys/".concat(envToFileName[env], ".enc"); | ||
var fileName = getEncOrKeyFileNameFromEnv(env); | ||
return "keys/".concat(fileName, ".enc"); | ||
}; | ||
var getKeyFilePath = function (env) { | ||
return ".".concat(envToFileName[env], ".key"); | ||
var fileName = getEncOrKeyFileNameFromEnv(env); | ||
return ".".concat(fileName, ".key"); | ||
}; | ||
@@ -37,2 +49,5 @@ var getCryptoKey = function (env) { | ||
}; | ||
var getEnvNameArgument = function () { | ||
return new commander_1.default.Argument('<env>', 'Name of the environment. For example: "prod", "dev", "staging"'); | ||
}; | ||
var encryptFile = function (env, envFile) { | ||
@@ -73,3 +88,3 @@ var fileData = fs_1.default.readFileSync(envFile, 'utf8'); | ||
.description('Encrypt env file') | ||
.addArgument(new commander_1.default.Argument('<env>', 'Name of the environment').choices(envList)) | ||
.addArgument(getEnvNameArgument()) | ||
.option('--env-file <file>', 'Path to env file', '.env.local') | ||
@@ -83,3 +98,3 @@ .action(function (env, _a) { | ||
.description('Decrypt env file') | ||
.addArgument(new commander_1.default.Argument('<env>', 'Name of the environment').choices(envList)) | ||
.addArgument(getEnvNameArgument()) | ||
.option('--env-file <file>', 'Path to env file', '.env.local') | ||
@@ -93,6 +108,11 @@ .action(function (env, _a) { | ||
.description('Setup keys directory and generate keys') | ||
.argument('[env]', 'Name of the environment. For example: prod, dev, staging') | ||
.option('-f, --force', 'Force overwrite of existing keys') | ||
.action(function (_a) { | ||
.action(function (env, _a) { | ||
var force = _a.force; | ||
setupKeysDirectory(); | ||
var envList = Object.keys(nextJsEnvToFileName); | ||
if (typeof env === 'string') { | ||
envList = [env]; | ||
} | ||
envList.forEach(function (env) { | ||
@@ -99,0 +119,0 @@ var keyFilePath = getKeyFilePath(env); |
{ | ||
"name": "@commutatus/cm-env", | ||
"version": "1.0.2", | ||
"version": "1.1.0-0", | ||
"description": "Utilities for encrypting and decrypting env files", | ||
@@ -5,0 +5,0 @@ "main": "index.ts", |
@@ -66,2 +66,4 @@ # cm-env | ||
Custom environment names are supported | ||
This will create a file under `keys/[env name].enc` which is the encrypted version of `.env.local` | ||
@@ -68,0 +70,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7444
122
82
2