From b5c92709d5bb353486056978f7940fbd00298304 Mon Sep 17 00:00:00 2001 From: keeramis Date: Wed, 15 Jan 2025 22:00:50 -0800 Subject: [PATCH] Lint fix --- src/lib/qdl.js | 162 ++++++++++++++++++++++++------------------------- 1 file changed, 80 insertions(+), 82 deletions(-) diff --git a/src/lib/qdl.js b/src/lib/qdl.js index 5db4b547f..387ed2fc2 100644 --- a/src/lib/qdl.js +++ b/src/lib/qdl.js @@ -25,90 +25,88 @@ async function getExecutable() { } async function run({ files, includeDir, updateFolder, zip, ui, outputLogFile }) { - const qdlPath = '/Users/keerthyamisagadda/code/tachyon-qdl/qdl'; - await fs.chmod(qdlPath, 0o755); - - const qdlArguments = [ - '--storage', TACHYON_STORAGE_TYPE, - ...(zip ? ['--zip', zip] : []), - ...(includeDir ? ['--include', includeDir] : []), - ...files - ]; - - const progressBar = ui.createProgressBar(); - let currentModuleName = '', currentModuleSectors = 0; - let totalSectorsInAllFiles = 0, totalSectorsFlashed = 0, progressBarInitialized = false; - - const handleError = (process, message) => { - progressBar.stop(); - ui.stdout.write(message); - process.kill(); - }; - - const processLogLine = (line, process) => { - fs.appendFileSync(outputLogFile, `${line}\n`); - - if (line.includes('Waiting for EDL device')) { - handleError(process, `Device is not in EDL mode${os.EOL}`); - } else if (line.includes('[ERROR]')) { - handleError(process, `${os.EOL}Error detected: ${line}${os.EOL}`); - } else if (line.includes('status=getProgramInfo')) { - const match = line.match(/sectors_total=(\d+)/); - if (match) { + const qdlPath = '/Users/keerthyamisagadda/code/tachyon-qdl/qdl'; + await fs.chmod(qdlPath, 0o755); + + const qdlArguments = [ + '--storage', TACHYON_STORAGE_TYPE, + ...(zip ? ['--zip', zip] : []), + ...(includeDir ? ['--include', includeDir] : []), + ...files + ]; + + const progressBar = ui.createProgressBar(); + let currentModuleName = '', currentModuleSectors = 0; + let totalSectorsInAllFiles = 0, totalSectorsFlashed = 0, progressBarInitialized = false; + + const handleError = (process, message) => { + progressBar.stop(); + ui.stdout.write(message); + process.kill(); + }; + + const processLogLine = (line, process) => { + fs.appendFileSync(outputLogFile, `${line}\n`); + + if (line.includes('Waiting for EDL device')) { + handleError(process, `Device is not in EDL mode${os.EOL}`); + } else if (line.includes('[ERROR]')) { + handleError(process, `${os.EOL}Error detected: ${line}${os.EOL}`); + } else if (line.includes('status=getProgramInfo')) { + const match = line.match(/sectors_total=(\d+)/); + if (match) { totalSectorsInAllFiles += parseInt(match[1], 10); } - } else if (line.includes('status=Start flashing module')) { - const moduleNameMatch = line.match(/module=(.*?),/); - const sectorsTotalMatch = line.match(/sectors_total=(\d+)/); - if (moduleNameMatch && sectorsTotalMatch) { - currentModuleName = moduleNameMatch[1]; - currentModuleSectors = parseInt(sectorsTotalMatch[1], 10); - - if (!progressBarInitialized) { - progressBarInitialized = true; - progressBar.start(totalSectorsInAllFiles, totalSectorsFlashed, { description: `Flashing ${currentModuleName}` }); - } else { - progressBar.update(totalSectorsFlashed, { description: `Flashing ${currentModuleName}` }); - } - } - } else if (line.includes('status=Flashing module')) { - const sectorsFlashedMatch = line.match(/sectors_done=(\d+)/); - if (sectorsFlashedMatch) { - const sectorsFlashed = parseInt(sectorsFlashedMatch[1], 10); - progressBar.update(totalSectorsFlashed + sectorsFlashed, { description: `Flashing module: ${currentModuleName} (${sectorsFlashed}/${currentModuleSectors} sectors)` }); - - if (sectorsFlashed === currentModuleSectors) { - totalSectorsFlashed += currentModuleSectors; - progressBar.update({ description: `Flashed ${currentModuleName}` }); - } - - if (totalSectorsFlashed === totalSectorsInAllFiles) { - progressBar.update({ description: 'Flashing complete' }); - progressBar.stop(); - } - } - } - }; - - try { - const qdlProcess = execa(qdlPath, qdlArguments, { cwd: updateFolder || process.cwd(), stdio: 'pipe' }); - - const handleStream = (stream) => { - stream.on('data', chunk => { - chunk.toString().split('\n').map(line => line.trim()).filter(Boolean).forEach(line => { - processLogLine(line, qdlProcess); - }); - }); - }; - - handleStream(qdlProcess.stdout, 'stdout'); - handleStream(qdlProcess.stderr, 'stderr'); - - await qdlProcess; - return; - } catch (error) { - throw error; - } finally { + } else if (line.includes('status=Start flashing module')) { + const moduleNameMatch = line.match(/module=(.*?),/); + const sectorsTotalMatch = line.match(/sectors_total=(\d+)/); + if (moduleNameMatch && sectorsTotalMatch) { + currentModuleName = moduleNameMatch[1]; + currentModuleSectors = parseInt(sectorsTotalMatch[1], 10); + + if (!progressBarInitialized) { + progressBarInitialized = true; + progressBar.start(totalSectorsInAllFiles, totalSectorsFlashed, { description: `Flashing ${currentModuleName}` }); + } else { + progressBar.update(totalSectorsFlashed, { description: `Flashing ${currentModuleName}` }); + } + } + } else if (line.includes('status=Flashing module')) { + const sectorsFlashedMatch = line.match(/sectors_done=(\d+)/); + if (sectorsFlashedMatch) { + const sectorsFlashed = parseInt(sectorsFlashedMatch[1], 10); + progressBar.update(totalSectorsFlashed + sectorsFlashed, { description: `Flashing module: ${currentModuleName} (${sectorsFlashed}/${currentModuleSectors} sectors)` }); + + if (sectorsFlashed === currentModuleSectors) { + totalSectorsFlashed += currentModuleSectors; + progressBar.update({ description: `Flashed ${currentModuleName}` }); + } + + if (totalSectorsFlashed === totalSectorsInAllFiles) { + progressBar.update({ description: 'Flashing complete' }); + progressBar.stop(); + } + } + } + }; + + try { + const qdlProcess = execa(qdlPath, qdlArguments, { cwd: updateFolder || process.cwd(), stdio: 'pipe' }); + + const handleStream = (stream) => { + stream.on('data', chunk => { + chunk.toString().split('\n').map(line => line.trim()).filter(Boolean).forEach(line => { + processLogLine(line, qdlProcess); + }); + }); + }; + + handleStream(qdlProcess.stdout, 'stdout'); + handleStream(qdlProcess.stderr, 'stderr'); + + await qdlProcess; + return; + } finally { progressBar.stop(); } }