@dotenvx/dotenvx
Advanced tools
Comparing version 1.33.0 to 1.34.0
@@ -5,4 +5,10 @@ # Changelog | ||
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.33.0...main) | ||
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.34.0...main) | ||
## [1.34.0](https://github.com/dotenvx/dotenvx/compare/v1.33.0...v1.34.0) | ||
### Added | ||
* `main.set` method now writes to files ([#517](https://github.com/dotenvx/dotenvx/pull/517)) | ||
## [1.33.0](https://github.com/dotenvx/dotenvx/compare/v1.32.1...v1.33.0) | ||
@@ -9,0 +15,0 @@ |
{ | ||
"version": "1.33.0", | ||
"version": "1.34.0", | ||
"name": "@dotenvx/dotenvx", | ||
@@ -4,0 +4,0 @@ "description": "a better dotenv–from the creator of `dotenv`", |
@@ -18,2 +18,4 @@ // @ts-check | ||
const Parse = require('./helpers/parse') | ||
const fsx = require('./helpers/fsx') | ||
const isIgnoringDotenvKeys = require('./helpers/isIgnoringDotenvKeys') | ||
@@ -173,9 +175,63 @@ /** @type {import('./main').config} */ | ||
// envKeysFile | ||
const envKeysFile = options.envKeysFile | ||
// envs | ||
const envs = buildEnvs(options) | ||
const envKeysFilepath = options.envKeysFile | ||
return new Sets(key, value, envs, encrypt, envKeysFile).run() | ||
const { | ||
processedEnvs, | ||
changedFilepaths, | ||
unchangedFilepaths | ||
} = new Sets(key, value, envs, encrypt, envKeysFilepath).run() | ||
let withEncryption = '' | ||
if (encrypt) { | ||
withEncryption = ' with encryption' | ||
} | ||
for (const processedEnv of processedEnvs) { | ||
logger.verbose(`setting for ${processedEnv.envFilepath}`) | ||
if (processedEnv.error) { | ||
if (processedEnv.error.code === 'MISSING_ENV_FILE') { | ||
logger.warn(processedEnv.error.message) | ||
logger.help(`? add one with [echo "HELLO=World" > ${processedEnv.envFilepath}] and re-run [dotenvx set]`) | ||
} else { | ||
logger.warn(processedEnv.error.message) | ||
if (processedEnv.error.help) { | ||
logger.help(processedEnv.error.help) | ||
} | ||
} | ||
} else { | ||
fsx.writeFileX(processedEnv.filepath, processedEnv.envSrc) | ||
logger.verbose(`${processedEnv.key} set${withEncryption} (${processedEnv.envFilepath})`) | ||
logger.debug(`${processedEnv.key} set${withEncryption} to ${processedEnv.value} (${processedEnv.envFilepath})`) | ||
} | ||
} | ||
if (changedFilepaths.length > 0) { | ||
logger.success(`✔ set ${key}${withEncryption} (${changedFilepaths.join(',')})`) | ||
} else if (unchangedFilepaths.length > 0) { | ||
logger.info(`no changes (${unchangedFilepaths})`) | ||
} else { | ||
// do nothing | ||
} | ||
for (const processedEnv of processedEnvs) { | ||
if (processedEnv.privateKeyAdded) { | ||
logger.success(`✔ key added to ${processedEnv.envKeysFilepath} (${processedEnv.privateKeyName})`) | ||
if (!isIgnoringDotenvKeys()) { | ||
logger.help('⮕ next run [dotenvx ext gitignore --pattern .env.keys] to gitignore .env.keys') | ||
} | ||
logger.help(`⮕ next run [${processedEnv.privateKeyName}='${processedEnv.privateKey}' dotenvx get ${key}] to test decryption locally`) | ||
} | ||
} | ||
return { | ||
processedEnvs, | ||
changedFilepaths, | ||
unchangedFilepaths | ||
} | ||
} | ||
@@ -182,0 +238,0 @@ |
246647
3962