Skip to content

Commit

Permalink
refactor: defineEnvVariables with omitFromExample
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Apr 29, 2024
1 parent 5a1a4e9 commit 9cd7183
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion commands/env/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
)

/**
Expand Down
8 changes: 4 additions & 4 deletions modules/ace/codemods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ export class Codemods extends EventEmitter {
/**
* Define one or more environment variables
*/
async defineEnvVariables(
environmentVariables: Record<string, number | string | boolean>,
options?: { withEmptyExampleValue?: boolean }
async defineEnvVariables<T extends Record<string, number | string | boolean>>(
environmentVariables: T,
options?: { omitFromExample?: Array<keyof T> }
) {
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()
Expand Down
5 changes: 4 additions & 1 deletion tests/ace/codemods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=')
})
Expand Down

0 comments on commit 9cd7183

Please sign in to comment.