MCPcopy
hub / github.com/subquery/subql / prepareEnv

Function prepareEnv

packages/cli/src/controller/init-controller.ts:301–329  ·  view source on GitHub ↗
(projectPath: string, project: ProjectSpecBase)

Source from the content-addressed store, hash-verified

299}
300
301export async function prepareEnv(projectPath: string, project: ProjectSpecBase): Promise<void> {
302 //load and write manifest(project.ts/project.yaml)
303 const envPath = defaultEnvPath(projectPath);
304 const envDevelopPath = defaultEnvDevelopPath(projectPath);
305 const envLocalPath = defaultEnvLocalPath(projectPath);
306 const envDevelopLocalPath = defaultEnvDevelopLocalPath(projectPath);
307
308 let chainId;
309 if (isProjectSpecV1_0_0(project)) {
310 chainId = project.chainId;
311 } else {
312 const tsPath = defaultTSManifestPath(projectPath);
313 const tsManifest = (await fs.promises.readFile(tsPath, 'utf8')).toString();
314
315 const match = tsManifest.match(CAPTURE_CHAIN_ID_REG);
316 if (match) {
317 chainId = match[2];
318 }
319 }
320
321 //adding env configs
322 const endpointStr = Array.isArray(project.endpoint) ? project.endpoint.join(',') : JSON.stringify(project.endpoint);
323
324 const envData = `ENDPOINT=${endpointStr}\nCHAIN_ID=${chainId}`;
325 await fs.promises.writeFile(envPath, envData, 'utf8');
326 await fs.promises.writeFile(envDevelopPath, envData, 'utf8');
327 await fs.promises.writeFile(envLocalPath, envData, 'utf8');
328 await fs.promises.writeFile(envDevelopLocalPath, envData, 'utf8');
329}
330
331export async function prepareGitIgnore(projectPath: string): Promise<void> {
332 //load and write .gitignore

Callers 1

prepareFunction · 0.85

Calls 6

defaultEnvPathFunction · 0.90
defaultEnvDevelopPathFunction · 0.90
defaultEnvLocalPathFunction · 0.90
isProjectSpecV1_0_0Function · 0.90
defaultTSManifestPathFunction · 0.90

Tested by

no test coverage detected