diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..576c5e5d --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +# Google OAuth Client Secret (base64 encoded) +# For development, use your own Google Cloud Console credentials +# See: https://developers.google.com/identity/protocols/oauth2/native-app +GOOGLE_CLIENT_SECRET_B64= + +# GitHub token for releases (optional, for release-it) +GITHUB_TOKEN= diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 3bd7575b..4371693d 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -3,10 +3,14 @@ import process from "process"; import builtins from "builtin-modules"; import fs from "fs"; import path from "path"; +import dotenv from "dotenv"; import inlineWorkerPlugin from "esbuild-plugin-inline-worker"; import { sassPlugin } from "esbuild-sass-plugin"; +// Load environment variables from .env file +dotenv.config(); + // Respect release-it dry-run: skip writing build artifacts entirely const __D_RY__ = process.env.RELEASE_IT_DRY_RUN === "1" || process.env.RELEASE_IT === "1"; @@ -94,6 +98,12 @@ const buildOptions = { banner: { js: banner, }, + define: { + // Inject base64-encoded secrets at build time (decoded at runtime) + "process.env.GOOGLE_CLIENT_SECRET_B64": JSON.stringify( + process.env.GOOGLE_CLIENT_SECRET_B64 || "", + ), + }, minify: prod ? true : false, entryPoints: ["src/index.ts"], plugins: [ diff --git a/src/types/env.d.ts b/src/types/env.d.ts new file mode 100644 index 00000000..28569fa4 --- /dev/null +++ b/src/types/env.d.ts @@ -0,0 +1,10 @@ +/** + * Environment variable type declarations + * These values are injected at build time via esbuild's define option + */ +declare namespace NodeJS { + interface ProcessEnv { + /** Base64-encoded Google OAuth client secret */ + GOOGLE_CLIENT_SECRET_B64?: string; + } +}