merlyn/server/jobs/helpers/index.js
Marcello Fitton 4a4378ed99
chore: add ESLint to /server (#5126)
* add eslint config to server

* add break statements to switch case

* add support for browser globals and turn off empty catch blocks

* disable lines with useless try/catch wrappers

* format

* fix no-undef errors

* disbale lines violating no-unsafe-finally

* ignore syncStaticLists.mjs

* use proper null check for creatorId instead of unreachable nullish coalescing

* remove unneeded typescript eslint comment

* make no-unused-private-class-members a warning

* disable line for no-empty-objects

* add new lint script

* fix no-unused-vars violations

* make no-unsued-vars an error

---------

Co-authored-by: shatfield4 <seanhatfield5@gmail.com>
Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
2026-03-05 16:32:45 -08:00

35 lines
1002 B
JavaScript

const path = require("node:path");
const fs = require("node:fs");
const { parentPort } = require("node:worker_threads");
const documentsPath =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, `../../storage/documents`)
: path.resolve(process.env.STORAGE_DIR, `documents`);
function log(stringContent = "") {
if (parentPort)
parentPort.postMessage(`\x1b[33m[${process.pid}]\x1b[0m: ${stringContent}`); // running as worker
else
process.send(
`\x1b[33m[${process.ppid}:${process.pid}]\x1b[0m: ${stringContent}`
); // running as child_process
}
function conclude() {
if (parentPort) parentPort.postMessage("done");
else process.exit(0);
}
function updateSourceDocument(docPath = null, jsonContent = {}) {
const destinationFilePath = path.resolve(documentsPath, docPath);
fs.writeFileSync(destinationFilePath, JSON.stringify(jsonContent, null, 4), {
encoding: "utf-8",
});
}
module.exports = {
log,
conclude,
updateSourceDocument,
};