diff --git a/index.js b/index.js index 0995459..d197652 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ const path = require('path'); const fs = require('fs'); -const { sleep } = require('./util'); +const { sleep, saveLargeObject } = require('./util'); const { getAllWorkflows } = require('./workflow'); const { getAllProcesses, getProcessPaths, getProcessPathsSubFlow } = require('./process'); @@ -106,7 +106,8 @@ require(path.join(process.cwd(), "..", "server", "dist", "database.js")); } // console.log("allWorkFlowInfo", JSON.stringify(allWorkFlowInfo, null, 2)); - fs.writeFileSync("./result-pretty.json", JSON.stringify(allWorkFlowInfo, null, 2)); + // fs.writeFileSync("./result-pretty.json", JSON.stringify(allWorkFlowInfo, null, 2)); + saveLargeObject(allWorkFlowInfo,"./result-pretty.json") fs.writeFileSync("./result.json", JSON.stringify(allWorkFlowInfo)); console.timeEnd("WorkflowTester"); console.log("DONE"); diff --git a/util.js b/util.js index 3c3da41..0ff367f 100644 --- a/util.js +++ b/util.js @@ -1,3 +1,5 @@ +const fs = require('fs'); + const sleep = (ms) => { return new Promise(resolve => { console.log(`${(ms / 1000).toFixed(2)}s SHOULD WAIT`); @@ -383,6 +385,36 @@ function isValidRegex(str) { return false; } } + +async function saveLargeObject(obj, filename) { + const ws = fs.createWriteStream(filename, { encoding: 'utf8' }); + ws.write('{\n'); + + const entries = Object.entries(obj); + for (let i = 0; i < entries.length; i++) { + const [key, value] = entries[i]; + // stringify مقدار + const chunk = JSON.stringify(value, null, 2) + .split('\n') + .map((line, idx) => idx === 0 + ? ` "${key}": ${line}` + : ` ${line}`) + .join('\n'); + // اگر اولین نیست، قبلش کاما بگذار + ws.write((i > 0 ? ',\n' : '') + chunk); + } + + ws.write('\n}\n'); + ws.end(); + + await new Promise((res, rej) => { + ws.on('finish', res); + ws.on('error', rej); + }); + console.log(`فایل ${filename} ذخیره شد.`); +} + + module.exports = { sleep, convertStringToJson, @@ -396,5 +428,6 @@ module.exports = { isBoolean, checkingConditionTypes, checkingOptions, - checkCondition + checkCondition, + saveLargeObject } \ No newline at end of file