-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
399 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/@sanity/cli/src/actions/init-project/bootstrapRemoteTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
|
||
import {debug} from '../../debug' | ||
import {type CliCommandContext} from '../../types' | ||
import { | ||
applyEnvVariables, | ||
downloadAndExtractRepo, | ||
getGihubRepoInfo, | ||
isNextJsTemplate, | ||
validateRemoteTemplate, | ||
} from '../../util/remoteTemplate' | ||
import {type GenerateConfigOptions} from './createStudioConfig' | ||
|
||
export interface BootstrapOptions { | ||
packageName: string | ||
templateName: string | ||
outputPath: string | ||
variables: GenerateConfigOptions['variables'] | ||
} | ||
|
||
export async function bootstrapRemoteTemplate( | ||
opts: BootstrapOptions, | ||
context: CliCommandContext, | ||
): Promise<void> { | ||
const {apiClient, cliRoot, output} = context | ||
|
||
const templatesDir = path.join(cliRoot, 'templates') | ||
const {outputPath, templateName, packageName, variables} = opts | ||
const {projectId, dataset} = variables | ||
const sourceDir = path.join(templatesDir, templateName) | ||
const sharedDir = path.join(templatesDir, 'shared') | ||
|
||
debug('Getting Github repo info for "%s"', templateName) | ||
const repoInfo = await getGihubRepoInfo(templateName) | ||
|
||
// Validate repo here | ||
await validateRemoteTemplate(repoInfo) | ||
|
||
debug('Create new directory "%s"', outputPath) | ||
await fs.mkdir(outputPath, {recursive: true}) | ||
|
||
await downloadAndExtractRepo(outputPath, repoInfo) | ||
|
||
const isNext = await isNextJsTemplate(outputPath) | ||
const envName = isNext ? '.env.local' : '.env' | ||
await applyEnvVariables(outputPath, variables, envName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {type SanityUser} from '../types' | ||
|
||
export function getProviderName(provider: SanityUser['provider']) { | ||
if (provider === 'google') return 'Google' | ||
if (provider === 'github') return 'GitHub' | ||
if (provider === 'sanity') return 'Email' | ||
if (provider.startsWith('saml-')) return 'SAML' | ||
return provider | ||
} |
Oops, something went wrong.