diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 1a47178..d1d5530 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -35,6 +35,7 @@ module.exports = { 'import/no-default-export': 'off', 'import/no-duplicates': 'error', 'import/order': 'off', + 'no-console': 'off', }, settings: { 'import/resolver': { diff --git a/app/layout.tsx b/app/layout.tsx index 98d1fd9..76c7667 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -6,7 +6,7 @@ import '@/components/theme-provider/styles.css'; export const metadata: Metadata = { description: 'Welcome, welcome, welcome!', - title: 'pod1612', + title: 'beecast', }; export default function RootLayout({ children }: PropsWithChildren) { diff --git a/app/page.tsx b/app/page.tsx index 669a008..c51ff97 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,3 +1,4 @@ +import { env } from '@/env.mjs'; import { Button, Container, Flex, Heading, Text } from '@radix-ui/themes'; export default function Page() { @@ -8,8 +9,8 @@ export default function Page() { }} > - Hello World - Hello from Radix Themes 🤓 + Hello from Radix Themes 🤓 + Release: {env.GIT_SHA} diff --git a/commitlint.config.js b/commitlint.config.cjs similarity index 100% rename from commitlint.config.js rename to commitlint.config.cjs diff --git a/env.mjs b/env.mjs new file mode 100644 index 0000000..5793354 --- /dev/null +++ b/env.mjs @@ -0,0 +1,29 @@ +// @ts-check + +import { z } from 'zod'; + +const getGitSha = () => { + if (process.env.VERCEL_GIT_COMMIT_SHA) { + return process.env.VERCEL_GIT_COMMIT_SHA; + } + + if (process.env.GITHUB_SHA) { + return process.env.GITHUB_SHA; + } + + return 'dev'; +}; + +const envSchema = z.object({ + GIT_SHA: z.string().min(1).default(getGitSha()), +}); + +const envValidation = envSchema.safeParse(process.env); + +if (!envValidation.success) { + const message = '❌ Invalid environment variables'; + console.error(message, JSON.stringify(envValidation.error.format(), null, 2)); + throw new Error(envValidation.error.message); +} + +export const env = envValidation.data; diff --git a/lint-staged.config.js b/lint-staged.config.cjs similarity index 100% rename from lint-staged.config.js rename to lint-staged.config.cjs diff --git a/next.config.js b/next.config.mjs similarity index 57% rename from next.config.js rename to next.config.mjs index 658404a..8048475 100644 --- a/next.config.js +++ b/next.config.mjs @@ -1,4 +1,6 @@ +import './env.mjs'; + /** @type {import('next').NextConfig} */ const nextConfig = {}; -module.exports = nextConfig; +export default nextConfig; diff --git a/package.json b/package.json index a760ee1..0c21a88 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "next": "14.0.4", "next-themes": "1.0.0-beta.0", "react": "^18", - "react-dom": "^18" + "react-dom": "^18", + "zod": "^3.22.4" }, "devDependencies": { "@commitlint/cli": "^18.4.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index de4f175..dc65a2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ dependencies: react-dom: specifier: ^18 version: 18.2.0(react@18.2.0) + zod: + specifier: ^3.22.4 + version: 3.22.4 devDependencies: '@commitlint/cli': @@ -12672,3 +12675,7 @@ packages: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} dev: true + + /zod@3.22.4: + resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} + dev: false diff --git a/tsconfig.json b/tsconfig.json index bd32522..e44345d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,10 +26,13 @@ "include": [ ".eslintrc.cjs", ".next/types/**/*.ts", - ".storybook/**/*", - "*.config.js", + ".storybook/**/*.ts", + ".storybook/**/*.tsx", + "*.config.cjs", + "*.config.mjs", "**/*.ts", "**/*.tsx", + "env.mjs", "next-env.d.ts" ], "exclude": ["node_modules"]