Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): skip directories without .env.example when bootstrapping remote template #8216

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/@sanity/cli/src/util/remoteTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ export async function applyEnvVariables(
await access(join(root, file))
return file
}),
).catch(() => {
throw new Error('Could not find .env.template, .env.example or .env.local.example file')
})
).catch(() => undefined)

if (!templatePath) {
return // No template .env file found, skip
}

try {
const templateContent = await readFile(join(root, templatePath), 'utf8')
Expand All @@ -231,13 +233,13 @@ export async function applyEnvVariables(
value: string,
useQuotes: boolean,
) => {
const pattern = varRegex instanceof RegExp ? varRegex : new RegExp(`${varRegex}=.*$`, 'm')
const pattern = varRegex instanceof RegExp ? varRegex : new RegExp(`${varRegex}=.*$`, 'gm')
const match = content.match(pattern)
if (!match) return content

const varName = match[0].split('=')[0]
return content.replace(
new RegExp(`${varName}=.*$`, 'm'),
new RegExp(`${varName}=.*$`, 'gm'),
`${varName}=${useQuotes ? `"${value}"` : value}`,
)
}
Expand Down
Loading