mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-14 04:49:59 +00:00
3c43a1cdd1
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import Git from 'simple-git'
|
|
import { isDevelopment } from 'std-env'
|
|
|
|
export { version } from '../package.json'
|
|
|
|
/**
|
|
* Environment variable `PULL_REQUEST` provided by Netlify.
|
|
* @see {@link https://docs.netlify.com/configure-builds/environment-variables/#git-metadata}
|
|
*
|
|
* Whether triggered by a GitHub PR
|
|
*/
|
|
export const isPR = process.env.PULL_REQUEST === 'true'
|
|
|
|
/**
|
|
* Environment variable `BRANCH` provided by Netlify.
|
|
* @see {@link https://docs.netlify.com/configure-builds/environment-variables/#git-metadata}
|
|
*
|
|
* Git branch
|
|
*/
|
|
export const gitBranch = process.env.BRANCH
|
|
|
|
/**
|
|
* Environment variable `CONTEXT` provided by Netlify.
|
|
* @see {@link https://docs.netlify.com/configure-builds/environment-variables/#build-metadata}
|
|
*
|
|
* Whether triggered by PR, `deploy-preview` or `dev`.
|
|
*/
|
|
export const isPreview = isPR || process.env.CONTEXT === 'deploy-preview' || process.env.CONTEXT === 'dev'
|
|
|
|
const git = Git()
|
|
export async function getGitInfo() {
|
|
const branch = gitBranch || await git.revparse(['--abbrev-ref', 'HEAD'])
|
|
const commit = await git.revparse(['HEAD'])
|
|
const shortCommit = await git.revparse(['--short=7', 'HEAD'])
|
|
return { branch, commit, shortCommit }
|
|
}
|
|
|
|
export async function getEnv() {
|
|
const { commit, shortCommit, branch } = await getGitInfo()
|
|
const env = isDevelopment
|
|
? 'dev'
|
|
: isPreview
|
|
? 'preview'
|
|
: branch === 'main'
|
|
? 'canary'
|
|
: 'release'
|
|
return { commit, shortCommit, branch, env } as const
|
|
}
|