Skip to content

Commit

Permalink
chore: Update setup command to add final messages at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Jul 30, 2024
1 parent 2286385 commit b2326f8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/commands/dependencies/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Command } from 'commander'
import { cliConfig } from '../../config/cli.config'
import { projectConfig } from '../../config/project.config'
import { composeExec } from '../../utils/compose'
import logger from '../../utils/log'

export function depsCopyCommand() {
return new Command()
Expand All @@ -13,6 +14,7 @@ export function depsCopyCommand() {
projectConfig.load()
const { reposPath } = cliConfig.load()

logger.info('Copying dependencies from Docker containers to local repos.')
if (projectType === 'MonoRepo' && monoRepoServices) {
for (const path of projectConfig.repoServicesPaths()) {
composeExec({
Expand Down
20 changes: 16 additions & 4 deletions src/commands/project/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export function createProjectCommand() {
})
}

newProject.projectRootPath = join(CONFIG_PATH, newProject.projectName)
newProject.configFile = join(newProject.projectRootPath, 'config.json')
newProject.envFile = join(newProject.projectRootPath, '.env')

if (projectConfig.confirmExists(newProject.configFile)) {
if (
await confirm({
message: 'Project config will be overwritten. Continue?',
})
) {
logger.warn('Modiying existing project config...')
} else {
return
}
}

if (options.filesPath) {
newProject.filesPath = options.filesPath
} else {
Expand All @@ -37,10 +53,6 @@ export function createProjectCommand() {
})
}

newProject.projectRootPath = join(CONFIG_PATH, newProject.projectName)
newProject.configFile = join(newProject.projectRootPath, 'config.json')
newProject.envFile = join(newProject.projectRootPath, '.env')

if (options.projectType) {
newProject.projectType = options.projectType
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/commands/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { copyExampleFilesCommand } from '../environment/copy-example-files'
import { generateDotEnvCommand } from '../environment/generate-dot-env'
import { gitCloneCommand } from '../git/clone'
import { createProjectCommand } from '../project/create'
import logger from '../../utils/log'

export function setupCommand() {
return new Command()
Expand All @@ -18,9 +19,17 @@ export function setupCommand() {
copyExampleFilesCommand().parse()
generateDotEnvCommand().parse()

logger.info('Building services images using Docker Compose.')
composeCommand().parse(['build'], { from: 'user' })

logger.info('Provisioning services using Docker Compose.')
composeCommand().parse(['up -d'], { from: 'user' })

depsCopyCommand().parse()

logger.info('To manage your newly created DEMS project, use:')
logger.info('> dems compose <COMMAND>\n')
logger.info('✅ Your DEMS project was been successfully initialized!')
logger.info('🚀 Happy coding!')
})
}
9 changes: 9 additions & 0 deletions src/config/project.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export const projectConfig = {
process.exit(1)
},

confirmExists(configFile = PROJECT_CONFIG_FILE) {
if (isFile(configFile)) {
logger.warn('Project has been already initialized.')
return true
}

return false
},

repoList() {
return Object.keys(this.load().repositories)
},
Expand Down
5 changes: 4 additions & 1 deletion src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import logger from './log'
export const git = {
async clone({ path, repo, ref }: GitParams) {
createPath({ path })
checkLocalRepo(join(path, getRepoNameFromURL(repo)))

if (checkLocalRepo(join(path, getRepoNameFromURL(repo)))) {
return
}

await $`git -C ${path} clone ${repo} -b ${ref}`
logger.info(`Repo '${repo}' was cloned successfully!`)
Expand Down

0 comments on commit b2326f8

Please sign in to comment.