mirror of
https://github.com/plebbit/seedit.git
synced 2026-04-19 06:39:18 -04:00
fixes conflicts between ES Modules used by Vite and CommonJS modules needed by Electron in packaged applications
59 lines
1.6 KiB
JavaScript
Executable File
59 lines
1.6 KiB
JavaScript
Executable File
// require this file to log to file in case there's a crash
|
|
|
|
// Convert all external module imports to CommonJS require
|
|
const util = require('util');
|
|
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const EnvPaths = require('env-paths');
|
|
const envPaths = EnvPaths('plebbit', { suffix: false });
|
|
|
|
// previous version created a file instead of folder
|
|
// we should remove this at some point
|
|
try {
|
|
if (fs.lstatSync(envPaths.log).isFile()) {
|
|
fs.removeSync(envPaths.log);
|
|
}
|
|
} catch (e) {}
|
|
|
|
const logFilePath = path.join(envPaths.log, new Date().toISOString().substring(0, 7));
|
|
fs.ensureFileSync(logFilePath);
|
|
const logFile = fs.createWriteStream(logFilePath, { flags: 'a' });
|
|
const writeLog = (...args) => {
|
|
logFile.write(new Date().toISOString() + ' ');
|
|
for (const arg of args) {
|
|
logFile.write(util.format(arg) + ' ');
|
|
}
|
|
logFile.write('\r\n');
|
|
};
|
|
|
|
const consoleLog = console.log;
|
|
console.log = (...args) => {
|
|
writeLog(...args);
|
|
consoleLog(...args);
|
|
};
|
|
const consoleError = console.error;
|
|
console.error = (...args) => {
|
|
writeLog(...args);
|
|
consoleError(...args);
|
|
};
|
|
const consoleWarn = console.warn;
|
|
console.warn = (...args) => {
|
|
writeLog(...args);
|
|
consoleWarn(...args);
|
|
};
|
|
const consoleDebug = console.debug;
|
|
console.debug = (...args) => {
|
|
// don't add date for debug because it's usually already included
|
|
for (const arg of args) {
|
|
logFile.write(util.format(arg) + ' ');
|
|
}
|
|
logFile.write('\r\n');
|
|
consoleDebug(...args);
|
|
};
|
|
|
|
// errors aren't console logged
|
|
process.on('uncaughtException', console.error);
|
|
process.on('unhandledRejection', console.error);
|
|
|
|
console.log(envPaths);
|