Env Configuration
The primary objective of the env.<mode>.ts file is to provide developers with a type-safe runtime environment, which seamlessly integrates with our router implementation, @brandingbrand/fsapp. This facilitates effortless switching between different runtime environments as necessary. The <mode> parameter can be customized to accurately describe your specific runtime environments, with common examples including dev, staging, prod, etc.
Configure the env.<mode>.ts
Create the env.<mode>.ts in the root of your project directory - and for example purposes we will choose dev. Keep in mind the envPath that as denoted in the flagship-code.config.ts.
touch ./coderc/env/env.dev.tsHere is an example of the runtime environment.
import { defineEnv } from "@brandingbrand/code-cli-kit";
export default defineEnv<Env>({ id: "abc12345", domain: "https://dev.myexampledomain.com",});The options passed to defineEnv are represented by the Env type. This custom type is generated by the developer for their project and is usually located within the src/ directory. A typical declaration file might resemble the following example.
interface Env { id: string; domain: string;}The .d.ts extension enables the type to be utilized throughout the TypeScript project without requiring explicit imports. Specifically, if you’re utilizing the @brandingbrand/fsapp package, you have the opportunity to override the exposed env object to make use of this type, thereby enhancing type safety and ensuring consistency throughout your codebase.
import "@brandingbrand/fsapp";
declare module "@brandingbrand/fsapp" { let env: { app: Env; };}Upon importing env from @brandingbrand/fsapp, it will be automatically fully typed according to the generated type specific to your project. This ensures comprehensive type coverage, aligning seamlessly with your project’s requirements and enhancing overall type safety.