MCPcopy Index your code
hub / github.com/subquery/subql / addDotEnvConfigCode

Function addDotEnvConfigCode

packages/cli/src/controller/init-controller.ts:268–299  ·  view source on GitHub ↗
(manifestData: string)

Source from the content-addressed store, hash-verified

266}
267
268export function addDotEnvConfigCode(manifestData: string): string {
269 // add dotenv config after imports in project.ts file
270 let snippetCodeIndex = -1;
271 const manifestSections = manifestData.split('\n');
272 for (let i = 0; i < manifestSections.length; i++) {
273 if (manifestSections[i].trim() === '') {
274 snippetCodeIndex = i + 1;
275 break;
276 }
277 }
278
279 if (snippetCodeIndex === -1) {
280 snippetCodeIndex = 0;
281 }
282
283 const envConfigCodeSnippet = `
284import * as dotenv from 'dotenv';
285import path from 'path';
286
287const mode = process.env.NODE_ENV || 'production';
288
289// Load the appropriate .env file
290const dotenvPath = path.resolve(__dirname, \`.env\${mode !== 'production' ? \`.$\{mode}\` : ''}\`);
291dotenv.config({ path: dotenvPath, quiet: true });
292`;
293
294 // Inserting the env configuration code in project.ts
295 const updatedTsProject = `${
296 manifestSections.slice(0, snippetCodeIndex).join('\n') + envConfigCodeSnippet
297 }\n${manifestSections.slice(snippetCodeIndex).join('\n')}`;
298 return updatedTsProject;
299}
300
301export async function prepareEnv(projectPath: string, project: ProjectSpecBase): Promise<void> {
302 //load and write manifest(project.ts/project.yaml)

Callers 1

prepareManifestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected