From 9cd71839a0be0b4198f050e8e11c3e4a93c82cd7 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Mon, 29 Apr 2024 12:12:43 +0200 Subject: [PATCH] refactor: defineEnvVariables with omitFromExample --- commands/env/add.ts | 2 +- modules/ace/codemods.ts | 8 ++++---- tests/ace/codemods.spec.ts | 5 ++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/commands/env/add.ts b/commands/env/add.ts index 840d7da4..c70d60c2 100644 --- a/commands/env/add.ts +++ b/commands/env/add.ts @@ -100,7 +100,7 @@ export default class EnvAdd extends BaseCommand { const transformedName = stringHelpers.snakeCase(this.name).toUpperCase() await codemods.defineEnvVariables( { [transformedName]: this.value }, - { withEmptyExampleValue: true } + { omitFromExample: [transformedName] } ) /** diff --git a/modules/ace/codemods.ts b/modules/ace/codemods.ts index f07ea6d9..08b83164 100644 --- a/modules/ace/codemods.ts +++ b/modules/ace/codemods.ts @@ -101,16 +101,16 @@ export class Codemods extends EventEmitter { /** * Define one or more environment variables */ - async defineEnvVariables( - environmentVariables: Record, - options?: { withEmptyExampleValue?: boolean } + async defineEnvVariables>( + environmentVariables: T, + options?: { omitFromExample?: Array } ) { const editor = new EnvEditor(this.#app.appRoot) await editor.load() Object.keys(environmentVariables).forEach((key) => { const value = environmentVariables[key] - editor.add(key, value, options?.withEmptyExampleValue) + editor.add(key, value, options?.omitFromExample?.includes(key)) }) await editor.save() diff --git a/tests/ace/codemods.spec.ts b/tests/ace/codemods.spec.ts index 6ed79431..1aae37d9 100644 --- a/tests/ace/codemods.spec.ts +++ b/tests/ace/codemods.spec.ts @@ -78,7 +78,10 @@ test.group('Codemods | environment variables', (group) => { await fs.create('.env.example', '') const codemods = new Codemods(ace.app, ace.ui.logger) - await codemods.defineEnvVariables({ SECRET_VALUE: 'secret' }, { withEmptyExampleValue: true }) + await codemods.defineEnvVariables( + { SECRET_VALUE: 'secret' }, + { omitFromExample: ['SECRET_VALUE'] } + ) await assert.fileContains('.env', 'SECRET_VALUE=secret') await assert.fileContains('.env.example', 'SECRET_VALUE=') })