feat: add library list parser to handle libraries.txt content
This commit is contained in:
parent
02774b383f
commit
3afdc0de9e
|
|
@ -132,6 +132,24 @@ function metadataIdToWokwiType(metadataId: string): string {
|
||||||
return `wokwi-${metadataId}`;
|
return `wokwi-${metadataId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Library list parser ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the contents of a Wokwi libraries.txt file.
|
||||||
|
* - Strips blank lines and # comments
|
||||||
|
* - Excludes Wokwi-hosted entries in the form name@wokwi:hash
|
||||||
|
* (they have no arduino-cli installable equivalent)
|
||||||
|
*/
|
||||||
|
export function parseLibrariesTxt(content: string): string[] {
|
||||||
|
const libs: string[] = [];
|
||||||
|
for (const raw of content.split('\n')) {
|
||||||
|
const line = raw.trim();
|
||||||
|
if (!line || line.startsWith('#') || line.includes('@wokwi:')) continue;
|
||||||
|
libs.push(line);
|
||||||
|
}
|
||||||
|
return libs;
|
||||||
|
}
|
||||||
|
|
||||||
// ── Export ────────────────────────────────────────────────────────────────────
|
// ── Export ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export async function exportToWokwiZip(
|
export async function exportToWokwiZip(
|
||||||
|
|
@ -305,16 +323,11 @@ export async function importFromWokwiZip(file: File): Promise<ImportResult> {
|
||||||
return a.name.localeCompare(b.name);
|
return a.name.localeCompare(b.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Parse libraries.txt — skip blank lines, comments (#), and Wokwi-only entries (name@wokwi:hash)
|
// Parse libraries.txt
|
||||||
const libraries: string[] = [];
|
const libraries: string[] = [];
|
||||||
const libEntry = zip.file('libraries.txt');
|
const libEntry = zip.file('libraries.txt');
|
||||||
if (libEntry) {
|
if (libEntry) {
|
||||||
const libText = await libEntry.async('string');
|
libraries.push(...parseLibrariesTxt(await libEntry.async('string')));
|
||||||
for (const raw of libText.split('\n')) {
|
|
||||||
const line = raw.trim();
|
|
||||||
if (!line || line.startsWith('#') || line.includes('@wokwi:')) continue;
|
|
||||||
libraries.push(line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { boardType, boardPosition, components, wires, files, libraries };
|
return { boardType, boardPosition, components, wires, files, libraries };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue