/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
scripts/docs-deploy/deploy-to-site.mts
84 строки
3 KB
Kristiyan Kostadinov
build: ensure deployment key is deleted (#33338)
03 июн 2026, 20:50
Не верифицирован
03 июн 2026, 20:50
120c2b9
Код
Авторство
О чём код?
import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; import {$} from 'zx'; import {SiteTarget} from './utils.mjs'; interface Deployment { projectId: string; site: SiteTarget; } /** Interface describing a production deployment. */ export interface ProductionDeployment extends Deployment { description: string; } /** Interface describing a temporary preview deployment. */ export interface PreviewDeployment extends Deployment { channelId: string; expires: string; } /** Type describing a Firebase deployment. */ export type DeploymentInfo = ProductionDeployment | PreviewDeployment; /** * Deploys the docs site at the specified directory to Firebase with respect * to the deployment information provided. * * The deployment info either describes the production deployment information, * or a preview temporary deployment that will expire automatically. */ export async function deployToSite( projectPath: string, firebaseServiceKey: string, info: DeploymentInfo, ) { const firebase = async (...cmd: string[]) => $`pnpm --dir=${projectPath}/docs firebase --non-interactive ${cmd}`; const gcpServiceKeyTmpFile = path.join(os.tmpdir(), 'mat-docs-deploy-gcp-key.json'); // Setup GCP service key for the docs-app deployment. // https://firebase.google.com/docs/admin/setup. await fs.promises.writeFile(gcpServiceKeyTmpFile, firebaseServiceKey); try { process.env['GOOGLE_APPLICATION_CREDENTIALS'] = gcpServiceKeyTmpFile; await firebase('use', info.projectId, '--debug'); await firebase('target:clear', 'hosting', 'mat-aio'); await firebase('target:apply', 'hosting', 'mat-aio', info.site.firebaseSiteId); if (isPreviewDeployment(info)) { const channelId = info.channelId; const expires = info.expires; await firebase( 'hosting:channel:deploy', channelId, '--only', 'mat-aio', '--expires', expires, ); } else { await firebase('deploy', '--only', 'hosting:mat-aio', '--message', info.description); } } finally { process.env['GOOGLE_APPLICATION_CREDENTIALS'] = undefined; await fs.promises.rm(gcpServiceKeyTmpFile, {force: true}); } } /** Whether the given deployment info corresponds to a preview deployment. */ export function isPreviewDeployment(info: DeploymentInfo): info is PreviewDeployment { return (info as Partial<PreviewDeployment>).channelId !== undefined; } /** Whether the given deployment info corresponds to a production deployment. */ export function isProductionDeployment(info: DeploymentInfo): info is ProductionDeployment { return !isPreviewDeployment(info); }