Skip to content

Commit

Permalink
chore: Improve error handling when copying example files
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Jul 31, 2024
1 parent b2326f8 commit e8a7e57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/commands/environment/copy-example-files.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Command } from 'commander'
import { projectConfig } from '../../config/project.config'
import { copyFile, readPathMatchingFiles } from '../../utils/file-system'
import { copyFile, isDirectory, readPathMatchingFiles } from '../../utils/file-system'
import logger from '../../utils/log'

export function copyExampleFilesCommand() {
return new Command()
.name('copy-example-files')
.summary('Copy example dotenv files on each repo path')
.summary('Copy example dotenv (.env.example) files on each repo path')
.action(() => {
for (const path of projectConfig.reposPaths()) {
if (!isDirectory(path)) {
logger.error(`The repository path '${path}' does not yet exist.`)
logger.error('Did you run `dems setup` or `dems git clone`?')
process.exit(1);
}

const exampleEnvFiles = readPathMatchingFiles(path, '.env.example')

if (exampleEnvFiles.length > 0) {
Expand All @@ -17,6 +24,10 @@ export function copyExampleFilesCommand() {
target: file.replace('.example', ''),
})
}
} else {
logger.error(`No example env files were found in path: '${path}'`)
logger.error('Current example files in scope: [.env.example]')
process.exit(1)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/commands/setup/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Command } from 'commander'
import logger from '../../utils/log'
import { composeCommand } from '../compose'
import { depsCopyCommand } from '../dependencies/copy'
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 Down

0 comments on commit e8a7e57

Please sign in to comment.