diff --git a/src/commands/dependencies/copy.ts b/src/commands/dependencies/copy.ts index e72c9fd..7f79ced 100644 --- a/src/commands/dependencies/copy.ts +++ b/src/commands/dependencies/copy.ts @@ -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() @@ -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({ diff --git a/src/commands/project/create.ts b/src/commands/project/create.ts index c2105ef..a12255a 100644 --- a/src/commands/project/create.ts +++ b/src/commands/project/create.ts @@ -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 { @@ -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 { diff --git a/src/commands/setup/index.ts b/src/commands/setup/index.ts index b5b84a6..34e3c49 100644 --- a/src/commands/setup/index.ts +++ b/src/commands/setup/index.ts @@ -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() @@ -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 \n') + logger.info('✅ Your DEMS project was been successfully initialized!') + logger.info('🚀 Happy coding!') }) } diff --git a/src/config/project.config.ts b/src/config/project.config.ts index 8aae658..034ac31 100644 --- a/src/config/project.config.ts +++ b/src/config/project.config.ts @@ -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) }, diff --git a/src/utils/git.ts b/src/utils/git.ts index 038b02d..35e03aa 100644 --- a/src/utils/git.ts +++ b/src/utils/git.ts @@ -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!`)