Skip to content

Commit

Permalink
feat: handle envs
Browse files Browse the repository at this point in the history
  • Loading branch information
RostiMelk committed Nov 26, 2024
1 parent 578e50b commit ce43f61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import fs from 'node:fs/promises'
import {mkdir} from 'node:fs/promises'
import {join} from 'node:path'

import {debug} from '../../debug'
import {type CliCommandContext} from '../../types'
import {
applyEnvVariables,
applyPackageName,
downloadAndExtractRepo,
getMonoRepo,
isNextJsTemplate,
type RepoInfo,
validateRemoteTemplate,
Expand All @@ -31,10 +33,11 @@ export async function bootstrapRemoteTemplate(
const {apiClient} = context

debug('Validating remote template')
await validateRemoteTemplate(repoInfo, bearerToken)
const packages = await getMonoRepo(repoInfo, bearerToken)
await validateRemoteTemplate(repoInfo, packages, bearerToken)

debug('Create new directory "%s"', outputPath)
await fs.mkdir(outputPath, {recursive: true})
await mkdir(outputPath, {recursive: true})

debug('Downloading and extracting repo to %s', outputPath)
await downloadAndExtractRepo(outputPath, repoInfo, bearerToken)
Expand All @@ -44,7 +47,9 @@ export async function bootstrapRemoteTemplate(
const envName = isNext ? '.env.local' : '.env'

debug('Applying environment variables to %s', envName)
await applyEnvVariables(outputPath, variables, envName)
for (const folder of packages ?? ['']) {
await applyEnvVariables(join(outputPath, folder), variables, envName)
}

debug('Setting package name to %s', packageName)
await applyPackageName(outputPath, packageName)
Expand Down
4 changes: 1 addition & 3 deletions packages/@sanity/cli/src/util/remoteTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ async function validatePackage(
*/
export async function validateRemoteTemplate(
repoInfo: RepoInfo,
packages: string[] = [''],
bearerToken?: string,
): Promise<void> {
const {username, name, branch, filePath} = repoInfo
Expand All @@ -383,9 +384,6 @@ export async function validateRemoteTemplate(
headers.Authorization = `Bearer ${bearerToken}`
}

const monorepoPackages = await getMonoRepo(repoInfo, bearerToken)
const packages = monorepoPackages || ['']

const validations = await Promise.all(
packages.map((pkg) => validatePackage(baseUrl, pkg, headers, pkg === '')),
)
Expand Down

0 comments on commit ce43f61

Please sign in to comment.