MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / resolveComponentEnv

Function resolveComponentEnv

ts/workflow-cli/cli/deploy/components.ts:127–160  ·  view source on GitHub ↗
(
  dir: string,
  name: string,
  opts: { interactive: boolean },
)

Source from the content-addressed store, hash-verified

125// are taken as-is, empty ones are prompted at a terminal (masked for secrets) or
126// left as a stub otherwise. Returns null when the component ships no example.
127export async function resolveComponentEnv(
128 dir: string,
129 name: string,
130 opts: { interactive: boolean },
131): Promise<string | null> {
132 const file = path.join(dir, `${name}.env.example`);
133 let raw: string;
134 try {
135 raw = await fs.readFile(file, "utf-8");
136 } catch (err) {
137 if ((err as NodeJS.ErrnoException).code === "ENOENT") return null;
138 throw err;
139 }
140
141 const lines: string[] = [];
142 for (const e of parseEnvExample(raw)) {
143 if (e.kind === "comment") {
144 lines.push(e.text);
145 } else if (e.value !== "" || !opts.interactive) {
146 lines.push(`${e.key}=${e.value}`);
147 } else {
148 const value = SECRET_HINT.test(e.key)
149 ? await password({ message: `${name}: ${e.key}`, mask: "*" })
150 : await input({ message: `${name}: ${e.key}` });
151 lines.push(`${e.key}=${value}`);
152 }
153 }
154
155 const header =
156 `# Auto-generated by \`fh-workflow deploy\` from ${name}.env.example.\n` +
157 `# Loaded into the ${name} container via compose env_file; chmod 600 if it holds\n` +
158 `# secrets, and fill any empty values before \`up\`.\n`;
159 return `${header}\n${lines.join("\n")}\n`;
160}
161
162// The interactive custom-components section of the wizard. Components supplied via
163// --component arrive pre-validated and are shown as already added; a yes/no loop

Callers 3

resolveComponentsEnvFunction · 0.90
components.test.tsFile · 0.90
addFunction · 0.85

Calls 2

parseEnvExampleFunction · 0.85
inputStruct · 0.85

Tested by

no test coverage detected