Skip to content

Commit

Permalink
chore: Add monoRepoServicesList to projectConfig interface
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Jul 25, 2024
1 parent 704152d commit 163603b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
21 changes: 10 additions & 11 deletions src/commands/project/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ export function createProjectCommand() {
}
} else {
switch (newProject.projectType) {
case 'Single' || 'MonoRepo': {
const repo = await input({
message: 'What is the name of the repository?',
})
newProject.repositories[repo] =
`[email protected]:${newProject.git.org}/${repo}.git`
break
}
case 'MultiRepo': {
do {
const repo = await input({
Expand All @@ -105,16 +97,24 @@ export function createProjectCommand() {
} while (await confirm({ message: 'Add another one?' }))
break
}
default: {
const repo = await input({
message: 'What is the name of the repository?',
})
newProject.repositories[repo] =
`[email protected]:${newProject.git.org}/${repo}.git`
break
}
}
}

if (newProject.projectType === 'MonoRepo') {
newProject.monoRepoProjects = []
newProject.monoRepoServices = []
do {
const newMonoRepoProject = await input({
message: 'What is the name of the mono-repo project or service?',
})
newProject.monoRepoProjects.push(newMonoRepoProject)
newProject.monoRepoServices.push(newMonoRepoProject)
} while (await confirm({ message: 'Add another mono-repo service?' }))
}

Expand All @@ -137,7 +137,6 @@ export function createProjectCommand() {
})
) {
createPath({ path: newProject.projectRootPath })

projectConfig.save(newProject)
logger.info('New project created successfully.')
}
Expand Down
64 changes: 41 additions & 23 deletions src/config/project.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export interface ProjectConfigSpec {

// Individual projects inside a MonoRepo project type. For example,
// if a mono repo has two projects, backend & frontend, then, the
// monoRepoProjects will be like (relative to the path of the main repo):
// monoRepoProjects: {
// monoRepoServices will be like (relative to the path of the main repo):
// monoRepoServices: {
// backend: "path/to/backend",
// frontend: "path/to/frontend"
// }
// 'projectType' must be set to 'MonoRepo' for this directive to work.
monoRepoProjects?: Array<string>
monoRepoServices?: Array<string>

// The `git` object contains all configuration values for Git resources.
git: {
Expand Down Expand Up @@ -117,31 +117,12 @@ export const projectConfig = {
return JSON.parse(fs.readFileSync(configFile).toString())
},

repoList() {
return Object.keys(this.load().repositories)
},

repoURLs() {
return Object.values(this.load().repositories)
},

reposPaths() {
const paths = []
const { repositories } = this.load()
const { reposPath } = cliConfig.load()

for (const repo in repositories) {
paths.push(join(reposPath, repo))
}

return paths
},

save(config: ProjectConfigSpec) {
createPath({ path: config.projectRootPath })
createFile({
file: `${config.projectRootPath}/config.json`,
content: JSON.stringify(config, null, 2),
overwrite: true,
})
},

Expand All @@ -163,4 +144,41 @@ export const projectConfig = {
logger.warn("Run 'dems setup' to create it.")
process.exit(1)
},

repoList() {
return Object.keys(this.load().repositories)
},

repoURLs() {
return Object.values(this.load().repositories)
},

reposPaths() {
const paths = []
const { repositories, projectType } = this.load()
const { reposPath } = cliConfig.load()

if (projectType === 'MonoRepo') {
const { monoRepoServices } = this.load()
for (const service in monoRepoServices) {
paths.push(join(reposPath, Object.keys(repositories)[0], service))
}
} else {
for (const repo in repositories) {
paths.push(join(reposPath, repo))
}
}

return paths
},

repoServicesList() {
const { projectType, monoRepoServices } = this.load()
if (projectType === 'MonoRepo') {
return monoRepoServices
}

logger.error('Curent project is not a mono repository.')
process.exit(1)
}
}

0 comments on commit 163603b

Please sign in to comment.