Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jan 16, 2025
1 parent 76cf00b commit b5c9270
Showing 1 changed file with 80 additions and 82 deletions.
162 changes: 80 additions & 82 deletions src/lib/qdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit b5c9270

Please sign in to comment.