Skip to content

Commit 75d6bbc

Browse files
authored
chore: change env filename used by generate-i18n and improve error message (#3222)
## What's the purpose of this pull request? The `generate-i18n` CLI command was loading credentials from `.env` instead of `vtex.env`, which is the FastStore-specific environment file. Additionally, the error message shown when credentials are missing was too vague, not telling developers where to look or what to do next. ## How to test it? Running `node packages/cli/bin/run generate-i18n ./packages/core`, test with and without the variables on `vtex.env`. Or through a test account, running the build command: <img width="700" alt="Screenshot 2026-02-25 at 10 07 40" src="https://github.com/user-attachments/assets/12d1209d-dfc6-406e-8786-4dfb3e51fccf" /> ### Starters Deploy Preview PR: vtex-sites/brandless.store#148 Even without the `vtex.env` it worked on production since those variables were set in Webops Settings: <img width="500" alt="Screenshot 2026-02-25 at 10 08 35" src="https://github.com/user-attachments/assets/86550e20-39c4-4998-a973-c4c7509471c5" /> ## References - [Jira task](https://vtex-dev.atlassian.net/browse/SFS-3048) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved credentials validation for the i18n command with clearer error messaging and earlier checks to fail fast. * Environment file loading now occurs conditionally at runtime, improving detection and configuration behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 5da1a3c commit 75d6bbc

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

packages/cli/src/commands/generate-i18n.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,16 @@ import { FastStoreSDK } from '@vtex/faststore-sdk'
33
import chalk from 'chalk'
44
import dotenv from 'dotenv'
55
import fsExtra from 'fs-extra'
6+
import { existsSync } from 'node:fs'
67
import path from 'node:path'
78
import { format } from 'prettier'
89
import { checkAndValidateLocalization } from '../utils/config'
910
import { getBasePath, withBasePath } from '../utils/directory'
1011
import { saveFile } from '../utils/file'
1112
import { logger } from '../utils/logger'
12-
dotenv.config({
13-
path: [path.resolve(process.cwd(), '.env')],
14-
})
1513

1614
const configFileName = 'discovery.config.default.js'
1715

18-
const { VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY, FS_DISCOVERY_APP_TOKEN } =
19-
process.env
20-
21-
const hasCredentials =
22-
VTEX_ACCOUNT && FS_DISCOVERY_APP_KEY && FS_DISCOVERY_APP_TOKEN
23-
2416
export default class GenerateI18n extends Command {
2517
static hidden = true
2618

@@ -89,6 +81,26 @@ export default class GenerateI18n extends Command {
8981
return
9082
}
9183

84+
const vtexEnvPath = path.join(argPath, 'vtex.env')
85+
if (existsSync(vtexEnvPath)) {
86+
dotenv.config({ path: vtexEnvPath })
87+
}
88+
89+
const { VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY, FS_DISCOVERY_APP_TOKEN } =
90+
process.env
91+
const hasCredentials =
92+
VTEX_ACCOUNT && FS_DISCOVERY_APP_KEY && FS_DISCOVERY_APP_TOKEN
93+
94+
if (!hasCredentials) {
95+
logger.error(`${chalk.red('[Error]')} - Missing VTEX credentials.\n
96+
${chalk.cyan('Required Action:')}\n
97+
Check your FastStore WebOps Settings page - to work in production, it should contain the following variables: ${chalk.cyan('VTEX_ACCOUNT')}, ${chalk.cyan('FS_DISCOVERY_APP_KEY')}, ${chalk.cyan('FS_DISCOVERY_APP_TOKEN')}.\n
98+
If running locally, please check your ${chalk.bold('vtex.env')} file, it should also contain those variables.
99+
`)
100+
101+
process.exit(1)
102+
}
103+
92104
const { tmpDir } = withBasePath(argPath)
93105
const configPath =
94106
this.getConfigFile(flags.config && path.resolve(argPath, flags.config)) ||
@@ -110,12 +122,6 @@ export default class GenerateI18n extends Command {
110122
logger.info(`${chalk.blue('[Info]')} - Config file location: ${configPath}`)
111123
const discoveryConfig = await import(configPath)
112124

113-
if (!hasCredentials) {
114-
logger.info(`${chalk.red('error')} - Missing VTEX credentials.`)
115-
116-
return
117-
}
118-
119125
const faststore = new FastStoreSDK({
120126
account: VTEX_ACCOUNT,
121127
appKey: FS_DISCOVERY_APP_KEY,

0 commit comments

Comments
 (0)