From bbb8d8e4aabe1de83bb01ade4946fb08875f71c0 Mon Sep 17 00:00:00 2001 From: "Angel M. Adames" Date: Fri, 26 Jul 2024 10:45:52 -0400 Subject: [PATCH] chore: Add services paths into project dot env file when monorepo --- src/config/project.config.ts | 36 ++++++++++++++++++++++++------------ src/utils/env.ts | 14 ++++++++++++-- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/config/project.config.ts b/src/config/project.config.ts index 71e3667..64f8a1b 100644 --- a/src/config/project.config.ts +++ b/src/config/project.config.ts @@ -156,20 +156,11 @@ export const projectConfig = { reposPaths() { const paths = [] - const { repositories, projectType } = this.load() + const { repositories } = this.load() const { reposPath } = cliConfig.load() - if (projectType === 'MonoRepo') { - const { monoRepoServices } = this.load() - if (monoRepoServices) { - for (const service of monoRepoServices) { - paths.push(join(reposPath, Object.keys(repositories)[0], service)) - } - } - } else { - for (const repo in repositories) { - paths.push(join(reposPath, repo)) - } + for (const repo in repositories) { + paths.push(join(reposPath, repo)) } return paths @@ -184,4 +175,25 @@ export const projectConfig = { logger.error('Curent project is not a mono repository.') process.exit(1) }, + + repoServicesPaths() { + const paths = [] + const { repositories, projectType } = this.load() + const { reposPath } = cliConfig.load() + + if (projectType === 'MonoRepo') { + const { monoRepoServices } = this.load() + if (monoRepoServices) { + for (const service of monoRepoServices) { + paths.push(join(reposPath, Object.keys(repositories)[0], service)) + } + } + } else { + logger.error('Cannot determine services paths.') + logger.error('Current project is not of type MonoRepo.') + process.exit(1) + } + + return paths + } } diff --git a/src/utils/env.ts b/src/utils/env.ts index a506baa..40a9520 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -13,10 +13,20 @@ export const dotEnv = { const flatConfig = flattenObject(config) for (const repo in config.repositories) { - flatConfig[`${toUpperSnakeCase(repo)}_PATH`] = `${join( + flatConfig[`${toUpperSnakeCase(repo)}_PATH`] = join( configCLI.reposPath, repo, - )}` + ) + } + + if (config.projectType === 'MonoRepo' && config.monoRepoServices) { + for (const service of config.monoRepoServices) { + flatConfig[`${toUpperSnakeCase(config.projectName)}_${toUpperSnakeCase(service)}_PATH`] = join( + configCLI.reposPath, + Object.keys(config.repositories)[0], + service + ) + } } const envContents = Object.entries(flatConfig)