diff --git a/src/main/main.ts b/src/main/main.ts index caa3aca1b76d78300f14e098e744c8c710a32375..10f8b949434dee9820b2b4f7ce20e9de39af2be8 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -10,15 +10,7 @@ * `./src/main.js` using webpack. This gives us some performance wins. */ import path from 'path'; -import { - app, - BrowserWindow, - shell, - ipcMain, - utilityProcess, - Menu, - dialog, -} from 'electron'; +import { app, BrowserWindow, shell, ipcMain, dialog } from 'electron'; import { autoUpdater } from 'electron-updater'; import log from 'electron-log'; import Store from 'electron-store'; @@ -35,9 +27,10 @@ import { checkIfCondaEnvironmentExists, checkDependencies, checkIfCondaBinExists, - getTransformerLabCodeDir, + getLogFilePath, } from './util'; +const fs = require('fs'); const Tail = require('tail').Tail; // //////////// @@ -133,8 +126,16 @@ console.log('setting up listening to log file'); const startListeningToServerLog = async () => { // Now listen to the log file and send updates to the renderer - const server_dir = await getTransformerLabCodeDir(); - const logFile = path.join(server_dir, 'local_server.log'); + const logFile = await getLogFilePath(); + //create the file if it doesn't exist: + if (!fs.existsSync(logFile)) { + // first make the directory: + const logDir = path.dirname(logFile); + if (!fs.existsSync(logDir)) { + fs.mkdirSync(logDir, { recursive: true }); + } + fs.writeFileSync(logFile, ''); + } let tail = new Tail(logFile); let currentlySubscribed = false; diff --git a/src/main/util.ts b/src/main/util.ts index d6e18a3c548a142d606fe0ee4430bfe660ab5904..0963bc190f4991457a47bf025fa40974e23f54c8 100644 --- a/src/main/util.ts +++ b/src/main/util.ts @@ -1,6 +1,7 @@ /* eslint import/prefer-default-export: off */ import { URL } from 'url'; import path from 'path'; +import { log } from 'console'; const fs = require('fs'); const os = require('os'); const { spawn, exec, ChildProcess } = require('child_process'); @@ -42,6 +43,10 @@ export async function getTransformerLabCodeDir() { : transformerLabDir; } +export async function getLogFilePath() { + return path.join(await getTransformerLabCodeDir(), 'local_server.log'); +} + export function resolveHtmlPath(htmlFileName: string) { if (process.env.NODE_ENV === 'development') { const port = process.env.PORT || 1212; @@ -106,7 +111,7 @@ export async function checkLocalServerVersion() { export async function startLocalServer() { const server_dir = await getTransformerLabCodeDir(); - const logFilePath = path.join(server_dir, 'local_server.log'); + const logFilePath = await getLogFilePath(); const out = fs.openSync(logFilePath, 'a'); const err = fs.openSync(logFilePath, 'a'); @@ -363,7 +368,7 @@ function truncate(str: string, max: number) { */ export async function executeInstallStep(argument: string) { const server_dir = await getTransformerLabCodeDir(); - const logFilePath = path.join(server_dir, 'local_server.log'); + const logFilePath = await getLogFilePath(); const out = fs.openSync(logFilePath, 'a'); const err = fs.openSync(logFilePath, 'a');