From ac809fc67684ce06b294bf0836c4e592cd87ec25 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Fri, 4 Jun 2021 14:44:33 +0200 Subject: [PATCH] fix(cli): dont error on init when log has been written --- packages/cdktf-cli/bin/cmds/init.ts | 4 ++-- packages/cdktf-cli/lib/logging.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/cdktf-cli/bin/cmds/init.ts b/packages/cdktf-cli/bin/cmds/init.ts index 9b7060c2c2..12c52b163d 100644 --- a/packages/cdktf-cli/bin/cmds/init.ts +++ b/packages/cdktf-cli/bin/cmds/init.ts @@ -12,7 +12,7 @@ import { terraformCheck } from './terraform-check'; import { displayVersionMessage } from './version-check' import { FUTURE_FLAGS } from 'cdktf/lib/features'; import { downloadFile, HttpError } from '../../lib/util'; -import { logger } from '../../lib/logging'; +import { logFileName, logger } from '../../lib/logging'; const chalkColour = new chalk.Instance(); @@ -44,7 +44,7 @@ class Command implements yargs.CommandModule { await terraformCheck() await displayVersionMessage() - if (fs.readdirSync('.').filter(f => !f.startsWith('.')).length > 0) { + if (fs.readdirSync('.').filter(f => !f.startsWith('.') && f !== logFileName).length > 0) { console.error(chalkColour`{redBright ERROR: Cannot initialize a project in a non-empty directory}`); process.exit(1); } diff --git a/packages/cdktf-cli/lib/logging.ts b/packages/cdktf-cli/lib/logging.ts index b136efc7a2..57e6c3486b 100644 --- a/packages/cdktf-cli/lib/logging.ts +++ b/packages/cdktf-cli/lib/logging.ts @@ -4,9 +4,10 @@ const logger = getLogger(); logger.level = process.env.CDKTF_LOG_LEVEL || 'INFO'; +const logFileName = "cdktf.log"; if (process.env.CDKTF_DISABLE_LOGGING === 'false') { configure({ - appenders: { cdktf: { type: "file", filename: "./cdktf.log" } }, + appenders: { cdktf: { type: "file", filename: "./" + logFileName } }, categories: { default: { appenders: ["cdktf"], level: "debug" } } }); } @@ -18,5 +19,6 @@ const processLogger = (chunk: Buffer | string | Uint8Array) => { export { logger, getLogger, - processLogger + processLogger, + logFileName }