From fc9218c348b5070a2f8f73ffecd05664967b3692 Mon Sep 17 00:00:00 2001
From: shmck <shawn.j.mckay@gmail.com>
Date: Sat, 8 Jan 2022 20:18:24 -0800
Subject: [PATCH 1/2] capture error on command failure

Signed-off-by: shmck <shawn.j.mckay@gmail.com>
---
 scripts/build.sh                        | 1 -
 src/services/hooks/utils/runCommands.ts | 6 +++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/build.sh b/scripts/build.sh
index 2bcfc057..347d4136 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -28,7 +28,6 @@ cd web-app
 yarn build
 cd ..
 
-# For Windows build: switch the next 2 lines
 echo "Bundling webapp..."
 if [[ "$OSTYPE" == "msys" ]]; then
     # linux subsystem on windows selected
diff --git a/src/services/hooks/utils/runCommands.ts b/src/services/hooks/utils/runCommands.ts
index f64090dd..0593755a 100644
--- a/src/services/hooks/utils/runCommands.ts
+++ b/src/services/hooks/utils/runCommands.ts
@@ -11,11 +11,15 @@ const runCommands = async (commands: string[] = []): Promise<void> => {
       title: command,
       description: 'Running process...',
     }
+    logger(`Command: ${command}`)
     send({ type: 'COMMAND_START', payload: { process: { ...process, status: 'RUNNING' } } })
     let result: { stdout: string; stderr: string }
     try {
       result = await exec({ command })
-      logger(`Command output: ${JSON.stringify(result)}`)
+      if (result.stderr) {
+        throw new Error(result.stderr)
+      }
+      logger(`Command output: ${result.stdout}`)
     } catch (error: any) {
       logger(`Command failed: ${error.message}`)
       send({ type: '', payload: { process: { ...process, status: 'FAIL' } } })

From 0a545215473af40cc9927616619805430cbc1080 Mon Sep 17 00:00:00 2001
From: shmck <shawn.j.mckay@gmail.com>
Date: Sat, 8 Jan 2022 20:32:24 -0800
Subject: [PATCH 2/2] log all commands and fs actions for debugging

Signed-off-by: shmck <shawn.j.mckay@gmail.com>
---
 src/services/node/index.ts | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/services/node/index.ts b/src/services/node/index.ts
index 822445de..3d4a2bcc 100644
--- a/src/services/node/index.ts
+++ b/src/services/node/index.ts
@@ -17,24 +17,32 @@ interface ExecParams {
 
 // correct paths to be from workspace root rather than extension folder
 const getWorkspacePath = (...paths: string[]) => {
-  return join(WORKSPACE_ROOT, ...paths)
+  const workspacePath = join(WORKSPACE_ROOT, ...paths)
+  logger(`Workspace path: ${workspacePath}`)
+  return workspacePath
 }
 
 export const exec = (params: ExecParams): Promise<{ stdout: string; stderr: string }> | never => {
   const cwd = join(WORKSPACE_ROOT, params.dir || '')
+  logger(`Calling command: ${params.command}`)
   return asyncExec(params.command, { cwd })
 }
 
 export const exists = (...paths: string[]): boolean | never => {
-  return fs.existsSync(getWorkspacePath(...paths))
+  const filePath = getWorkspacePath(...paths)
+  logger(`Check file exists: ${filePath}`)
+  return fs.existsSync(filePath)
 }
 
 export const removeFile = (...paths: string[]) => {
-  return asyncRemoveFile(getWorkspacePath(...paths))
+  const filePath = getWorkspacePath(...paths)
+  logger(`Removing file: ${filePath}`)
+  return asyncRemoveFile(filePath)
 }
 
 export const readFile = (...paths: string[]): Promise<string | void> => {
   const filePath = getWorkspacePath(...paths)
+  logger(`Reading file: ${filePath}`)
   return asyncReadFile(getWorkspacePath(...paths), 'utf8').catch((err) => {
     logger(`Failed to read from ${filePath}: ${err.message}`)
   })
@@ -42,6 +50,7 @@ export const readFile = (...paths: string[]): Promise<string | void> => {
 
 export const writeFile = (data: any, ...paths: string[]): Promise<void> => {
   const filePath = getWorkspacePath(...paths)
+  logger(`Writing file: ${filePath}`)
   return asyncWriteFile(filePath, data).catch((err) => {
     logger(`Failed to write to ${filePath}: ${err.message}`)
   })