From 482f841c3e8b8a2d330461e05a86112415689dce Mon Sep 17 00:00:00 2001 From: Matt Meigs Date: Thu, 30 Nov 2023 09:28:33 -0500 Subject: [PATCH] log build deps --- .../src/helpers/dependency-helpers.ts | 9 ++-- src/commands/src/helpers/index.ts | 49 ++++++++++++------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 3d87b7fd7..37ed24946 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -42,6 +42,7 @@ async function createEnvProdFile( ); } catch (e) { console.error(`ERROR! Could not write to .env.production`); + logger(`ERROR! Could not write to .env.production: ${e}`); throw e; } } @@ -62,9 +63,9 @@ export async function prepareBuildAndGetDependencies( // doing these in parallel const commandPromises = [ - getCommitHash(repoDir), - getCommitBranch(repoDir), - getPatchId(repoDir), + getCommitHash(repoDir, preppedLogger), + getCommitBranch(repoDir, preppedLogger), + getPatchId(repoDir, preppedLogger), existsAsync(path.join(process.cwd(), 'config/redirects')), createEnvProdFile(repoDir, projectName, baseUrl, preppedLogger), ]; @@ -83,7 +84,7 @@ export async function prepareBuildAndGetDependencies( }; } catch (error) { console.error('ERROR! Could not get build dependencies'); - preppedLogger(`error, could not get build deps`); + preppedLogger(`error, could not get build deps: ${error}`); throw error; } } diff --git a/src/commands/src/helpers/index.ts b/src/commands/src/helpers/index.ts index ca9ceebc3..b05236d99 100644 --- a/src/commands/src/helpers/index.ts +++ b/src/commands/src/helpers/index.ts @@ -255,38 +255,49 @@ export async function readFileAndExec({ return response; } -export async function getPatchId(repoDir: string): Promise { +export async function getPatchId(repoDir: string, logger: (msg: string) => void): Promise { const filePath = path.join(repoDir, 'myPatch.patch'); try { const { outputText: gitPatchId } = await readFileAndExec({ command: 'git', filePath, args: ['patch-id'] }); return gitPatchId.slice(0, 7); } catch (err) { - console.warn('No patch ID found'); + console.warn('No patch ID found: ', +filePath); + logger('No patch ID found: ' + filePath + ' ' + err); } } -export async function getCommitBranch(repoDir: string): Promise { - // equivalent to git rev-parse --abbrev-ref HEAD - const response = await executeCliCommand({ - command: 'git', - args: ['rev-parse', '--abbrev-ref', 'HEAD'], - options: { cwd: repoDir }, - }); +export async function getCommitBranch(repoDir: string, logger: (msg: string) => void): Promise { + try { + // equivalent to git rev-parse --abbrev-ref HEAD + const response = await executeCliCommand({ + command: 'git', + args: ['rev-parse', '--abbrev-ref', 'HEAD'], + options: { cwd: repoDir }, + }); - return response.outputText; + return response.outputText; + } catch (err) { + logger(`commit branch fail: ${err}`); + throw Error; + } } -export async function getCommitHash(repoDir: string): Promise { - // equivalent to git rev-parse --short HEAD - const response = await executeCliCommand({ - command: 'git', - args: ['rev-parse', '--short', 'HEAD'], - options: { cwd: repoDir }, - }); - console.log('commit hash ', response); +export async function getCommitHash(repoDir: string, logger: (msg: string) => void): Promise { + try { + // equivalent to git rev-parse --short HEAD + const response = await executeCliCommand({ + command: 'git', + args: ['rev-parse', '--short', 'HEAD'], + options: { cwd: repoDir }, + }); + console.log('commit hash ', response); - return response.outputText; + return response.outputText; + } catch (err) { + logger(`commit hash fail: ${err}`); + throw Error; + } } export const checkIfPatched = async (repoDir: string) => !existsAsync(path.join(repoDir, 'myPatch.patch'));