Skip to content

Commit

Permalink
fix init prepareManifest env been override ProjectSpecBase
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 committed Jun 11, 2024
1 parent 4f4bf67 commit d5dc903
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/cli/src/controller/init-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,22 @@ export async function prepareManifest(projectPath: string, project: ProjectSpecB
if (isTs) {
const tsManifest = (await fs.promises.readFile(tsPath, 'utf8')).toString();
//adding env config for endpoint.
const formattedEndpoint = `process.env.ENDPOINT!?.split(',') as string[] | string`;
const endpointUpdatedManifestData = findReplace(tsManifest, ENDPOINT_REG, `endpoint: ${formattedEndpoint}`);
const chainIdUpdatedManifestData = findReplace(
endpointUpdatedManifestData,
CHAIN_ID_REG,
`chainId: process.env.CHAIN_ID!`
);
const formattedEnvEndpoint = `process.env.ENDPOINT!?.split(',') as string[] | string`;
const formatEndpoint = (endpoint: string | string[]) => {
if (Array.isArray(endpoint)) {
return JSON.stringify(endpoint);
}
return `"${endpoint}"`;
};
const endpoint = project.endpoint ? formatEndpoint(project.endpoint) : formattedEnvEndpoint;
const endpointOutput = `endpoint: ${endpoint}`;
const endpointUpdatedManifestData = findReplace(tsManifest, ENDPOINT_REG, endpointOutput);
const specChainId = isProjectSpecV1_0_0(project) ? project.chainId : undefined;

const chainId = specChainId ? `"${specChainId}"` : `process.env.CHAIN_ID!`;
const chainIdOutput = `chainId: ${chainId}`;

const chainIdUpdatedManifestData = findReplace(endpointUpdatedManifestData, CHAIN_ID_REG, chainIdOutput);
manifestData = addDotEnvConfigCode(chainIdUpdatedManifestData);
} else {
//load and write manifest(project.yaml)
Expand Down

0 comments on commit d5dc903

Please sign in to comment.