-
Notifications
You must be signed in to change notification settings - Fork 106
feat: production setup #378
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
Draft
userquin
wants to merge
13
commits into
npmx-dev:main
Choose a base branch
from
userquin:feat-production-setup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+311
−21
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5a86e64
feat: production setup
userquin a9963b6
Merge branch 'main' into feat-production-setup
userquin 2e26137
[autofix.ci] apply automated fixes
autofix-ci[bot] 763c542
chore: add vite-plugin-pwa to dev dependencies to fix `test:types`
userquin 8051c37
Merge remote-tracking branch 'origin/feat-production-setup' into feat…
userquin 57e15f5
fix: add `text=auto` to `.gitattributes` to avoid breaking png files
userquin b50306b
chore: add pwa icons
userquin 0b7dc94
chore: don't use `std-env` to resolve `isDevelopment`
userquin a36e440
Merge branch 'main' into feat-production-setup
userquin bd0930d
chore: add logo.svg
userquin dc0f778
chore: update lock file
userquin 723dcad
chore: use Vercel environment variables
userquin db1e9b2
chore: add aria-hidden to logo img
userquin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| * text eol=lf | ||
| * text=auto eol=lf |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,86 @@ | ||
| import Git from 'simple-git' | ||
| import * as process from 'node:process' | ||
|
|
||
| export { version } from '../package.json' | ||
|
|
||
| /** | ||
| * Environment variable `PULL_REQUEST` provided by Netlify. | ||
| * @see {@link https://docs.netlify.com/build/configure-builds/environment-variables/#git-metadata} | ||
| * | ||
| * Environment variable `VERCEL_GIT_PULL_REQUEST_ID` provided by Vercel. | ||
| * @see {@link https://vercel.com/docs/environment-variables/system-environment-variables#VERCEL_GIT_PULL_REQUEST_ID} | ||
| * | ||
| * Whether triggered by a GitHub PR | ||
| */ | ||
| export const isPR = process.env.PULL_REQUEST === 'true' || !!process.env.VERCEL_GIT_PULL_REQUEST_ID | ||
|
|
||
| /** | ||
| * Environment variable `BRANCH` provided by Netlify. | ||
| * @see {@link https://docs.netlify.com/build/configure-builds/environment-variables/#git-metadata} | ||
| * | ||
| * Environment variable `VERCEL_GIT_COMMIT_REF` provided by Vercel. | ||
| * @see {@link https://vercel.com/docs/environment-variables/system-environment-variables#VERCEL_GIT_COMMIT_REF} | ||
| * | ||
| * Git branch | ||
| */ | ||
| export const gitBranch = process.env.BRANCH || process.env.VERCEL_GIT_COMMIT_REF | ||
|
|
||
| /** | ||
| * Environment variable `CONTEXT` provided by Netlify. | ||
| * @see {@link https://docs.netlify.com/build/configure-builds/environment-variables/#build-metadata} | ||
| * | ||
| * Environment variable `VERCEL_ENV` provided by Vercel. | ||
| * @see {@link https://vercel.com/docs/environment-variables/system-environment-variables#VERCEL_ENV} | ||
| * | ||
| * Whether triggered by PR, `deploy-preview` or `dev`. | ||
| */ | ||
| export const isPreview = | ||
| isPR || | ||
| process.env.CONTEXT === 'deploy-preview' || | ||
| process.env.CONTEXT === 'dev' || | ||
| process.env.VERCEL_ENV === 'preview' || | ||
| process.env.VERCEL_ENV === 'development' | ||
|
|
||
| const git = Git() | ||
| export async function getGitInfo() { | ||
| let branch | ||
| try { | ||
| branch = gitBranch || (await git.revparse(['--abbrev-ref', 'HEAD'])) | ||
| } catch { | ||
| branch = 'unknown' | ||
| } | ||
|
|
||
| let commit | ||
| try { | ||
| // Netlify: COMMIT_REF, Vercel: VERCEL_GIT_COMMIT_SHA | ||
| commit = | ||
| process.env.COMMIT_REF || process.env.VERCEL_GIT_COMMIT_SHA || (await git.revparse(['HEAD'])) | ||
| } catch { | ||
| commit = 'unknown' | ||
| } | ||
|
|
||
| let shortCommit | ||
| try { | ||
| if (commit && commit !== 'unknown') { | ||
| shortCommit = commit.slice(0, 7) | ||
| } else { | ||
| shortCommit = await git.revparse(['--short=7', 'HEAD']) | ||
| } | ||
| } catch { | ||
| shortCommit = 'unknown' | ||
| } | ||
|
|
||
| return { branch, commit, shortCommit } | ||
| } | ||
|
|
||
| export async function getEnv(isDevelopment: boolean) { | ||
| const { commit, shortCommit, branch } = await getGitInfo() | ||
| const env = isDevelopment | ||
| ? 'dev' | ||
| : isPreview | ||
| ? 'preview' | ||
| : branch === 'main' | ||
| ? 'canary' | ||
| : 'release' | ||
| return { commit, shortCommit, branch, env } as const | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,35 @@ | ||
| import type { BuildInfo } from '../shared/types' | ||
| import { createResolver, defineNuxtModule } from 'nuxt/kit' | ||
| import { isCI } from 'std-env' | ||
| import { getEnv, version } from '../config/env' | ||
|
|
||
| const { resolve } = createResolver(import.meta.url) | ||
|
|
||
| export default defineNuxtModule({ | ||
| meta: { | ||
| name: 'npmx:build-env', | ||
| }, | ||
| async setup(_options, nuxt) { | ||
| const { env, commit, shortCommit, branch } = await getEnv(nuxt.options.dev) | ||
| const buildInfo: BuildInfo = { | ||
| version, | ||
| time: +Date.now(), | ||
| commit, | ||
| shortCommit, | ||
| branch, | ||
| env, | ||
| } | ||
|
|
||
| nuxt.options.appConfig = nuxt.options.appConfig || {} | ||
| nuxt.options.appConfig.env = env | ||
| nuxt.options.appConfig.buildInfo = buildInfo | ||
|
|
||
| nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {} | ||
| nuxt.options.nitro.virtual['#build-info'] = `export const env = ${JSON.stringify(env)}` | ||
|
|
||
| nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || [] | ||
| if (env === 'dev') nuxt.options.nitro.publicAssets.unshift({ dir: resolve('../public-dev') }) | ||
| else if (env === 'canary' || env === 'preview' || !isCI) | ||
| nuxt.options.nitro.publicAssets.unshift({ dir: resolve('../public-staging') }) | ||
| }, | ||
| }) |
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I cleanup netlify entries?