1- import { entries , join , map , pipe } from "@fxts/core" ;
1+ import { concat , entries , join , map , pipe , when } from "@fxts/core" ;
22import { toMerged } from "es-toolkit" ;
3- import { replace } from "../utils.ts" ;
43import { readTemplate } from "../lib.ts" ;
54import type { InitCommandData , PackageManager } from "../types.ts" ;
5+ import { replace } from "../utils.ts" ;
6+ import { needsDenoDotenv } from "./utils.ts" ;
67
78/**
89 * Loads the federation configuration file content from template.
9- * Reads the default federation template and replaces placeholders with actual configuration values.
10+ * Reads the default federation template and replaces placeholders with actual
11+ * configuration values.
1012 *
11- * @param param0 - Configuration object containing imports, project name, KV store, message queue, and package manager
13+ * @param param0 - Configuration object containing imports, project name,
14+ * KV store, message queue, and package manager
1215 * @returns The complete federation configuration file content as a string
1316 */
1417export const loadFederation = async (
@@ -43,12 +46,19 @@ export const loadLogging = async ({ projectName }: InitCommandData) =>
4346
4447/**
4548 * Generates import statements for KV store and message queue dependencies.
46- * Merges imports from both KV and MQ configurations and creates proper ES module import syntax.
49+ * Merges imports from both KV and MQ configurations and creates proper
50+ * ES module import syntax.
4751 *
48- * @param param0 - Destructured object containing kv and mq configurations
52+ * Destructured parameters:
53+ * - kv: KV store configuration, including module import mappings
54+ * - mq: Message queue configuration, including module import mappings
55+ * - packageManager: Package manager used for environment-specific handling
56+ * - env: Environment variable setup used to determine loading requirements
57+ *
58+ * @param param0 - InitCommandData containing kv, mq, packageManager, and env
4959 * @returns A multi-line string containing all necessary import statements
5060 */
51- export const getImports = ( { kv, mq } : InitCommandData ) =>
61+ export const getImports = ( { kv, mq, packageManager , env } : InitCommandData ) =>
5262 pipe (
5363 toMerged ( kv . imports , mq . imports ) ,
5464 entries ,
@@ -61,12 +71,17 @@ export const getImports = ({ kv, mq }: InitCommandData) =>
6171 . join ( ", " )
6272 } from ${ JSON . stringify ( module ) } ;`
6373 ) ,
74+ when (
75+ ( ) => needsDenoDotenv ( { packageManager, env } ) ,
76+ concat ( [ 'import "@std/dotenv/load";' ] ) ,
77+ ) ,
6478 join ( "\n" ) ,
6579 ) ;
6680
6781/**
6882 * Converts import mappings to named import string with aliases.
69- * Creates proper ES module named import syntax, using aliases when the import name differs from the local name.
83+ * Creates proper ES module named import syntax, using aliases when the import
84+ * name differs from the local name.
7085 *
7186 * @param imports - A record mapping import names to their local aliases
7287 * @returns A comma-separated string of named imports with aliases where needed
@@ -81,12 +96,16 @@ export const getAlias = (imports: Record<string, string>) =>
8196
8297const ENV_REG_EXP = / p r o c e s s \. e n v \. ( \w + ) / g;
8398/**
84- * Converts Node.js environment variable access to Deno-compatible syntax when needed.
85- * Transforms `process.env.VAR_NAME` to `Deno.env.get("VAR_NAME")` for Deno projects.
99+ * Converts Node.js environment variable access to Deno-compatible syntax when
100+ * needed.
101+ * Transforms `process.env.VAR_NAME` to `Deno.env.get("VAR_NAME")` for Deno
102+ * projects.
86103 *
87- * @param obj - The object string containing potential environment variable references
104+ * @param obj - The object string containing potential environment variable
105+ * references
88106 * @param pm - The package manager (runtime) being used
89- * @returns The converted object string with appropriate environment variable access syntax
107+ * @returns The converted object string with appropriate environment variable
108+ * access syntax
90109 */
91110export const convertEnv = ( obj : string , pm : PackageManager ) =>
92111 pm === "deno" && ENV_REG_EXP . test ( obj )
0 commit comments