Skip to content

Commit 2e42aa1

Browse files
authored
Merge pull request #31 from sonicbaume/obf-write-manifest
Write manifest when saving OBZ
2 parents 80beae7 + c4771be commit 2e42aa1

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/processors/obfProcessor.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,15 +733,31 @@ class ObfProcessor extends BaseProcessor {
733733
const obfBoard = this.createObfBoardFromPage(rootPage, 'Exported Board', tree.metadata);
734734
await writeTextToPath(outputPath, JSON.stringify(obfBoard, null, 2));
735735
} else {
736+
const getPageFilename = (id: string): string => (id.endsWith('.obf') ? id : `${id}.obf`);
736737
const files = Object.values(tree.pages).map((page) => {
737738
const obfBoard = this.createObfBoardFromPage(page, 'Board', tree.metadata);
738739
const obfContent = JSON.stringify(obfBoard, null, 2);
739-
const name = page.id.endsWith('.obf') ? page.id : `${page.id}.obf`;
740+
const name = getPageFilename(page.id);
740741
return {
741742
name,
742743
data: new TextEncoder().encode(obfContent),
743744
};
744745
});
746+
const manifest: ObfManifest = {
747+
format: OBF_FORMAT_VERSION,
748+
root: tree.metadata.defaultHomePageId,
749+
paths: {
750+
boards: Object.fromEntries(
751+
Object.entries(tree.pages).map(([id, page]) => [id, getPageFilename(page.id)])
752+
),
753+
images: {}, //TODO Add support for saving images as files
754+
sounds: {}, //TODO Add support for saving sounds as files
755+
},
756+
};
757+
files.push({
758+
name: 'manifest.json',
759+
data: new TextEncoder().encode(JSON.stringify(manifest)),
760+
});
745761
const fileExists = await pathExists(outputPath);
746762
this.zipFile = await this.options.zipAdapter(
747763
fileExists ? outputPath : undefined,

0 commit comments

Comments
 (0)