Skip to content

Commit

Permalink
chore: Add services paths into project dot env file when monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Jul 26, 2024
1 parent dec24fc commit bbb8d8e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
36 changes: 24 additions & 12 deletions src/config/project.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
14 changes: 12 additions & 2 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bbb8d8e

Please sign in to comment.