From 171440737e36f68c9da0c9e505cbdf8b80b7e12e Mon Sep 17 00:00:00 2001 From: Amadeo Pellicce Date: Tue, 15 Nov 2022 11:04:53 -0500 Subject: [PATCH] changing maps persistance deserialization --- src/model/AssetMap.ts | 6 +++++- src/repo/index.ts | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/model/AssetMap.ts b/src/model/AssetMap.ts index b91d601..fbe174d 100644 --- a/src/model/AssetMap.ts +++ b/src/model/AssetMap.ts @@ -18,9 +18,13 @@ this.type = i.type; } - deserialise(): string { + deserialise(array = false): string { let parsed = JSON.parse(JSON.stringify(this)); parsed = sortObjectKeys(parsed); + + if(array) { + parsed = [parsed]; + } return JSON.stringify(parsed, undefined, 2); } } diff --git a/src/repo/index.ts b/src/repo/index.ts index 46594cb..a4f3924 100644 --- a/src/repo/index.ts +++ b/src/repo/index.ts @@ -131,7 +131,7 @@ export function addAssetMap(map: AssetMap, repoPath: string = DEFAULT_REPO_DISK_ } if(!fs.existsSync(assetMapInfoFile)) { - fs.writeFileSync(assetMapInfoFile, JSON.stringify([map.deserialise()], null, 2)); + fs.writeFileSync(assetMapInfoFile, map.deserialise(true)); return; } @@ -146,6 +146,6 @@ export function addAssetMap(map: AssetMap, repoPath: string = DEFAULT_REPO_DISK_ if(!existingMap) { assetMaps.push(map); - fs.writeFileSync(assetMapInfoFile, JSON.stringify(assetMaps.map(m => m.deserialise()), null, 2)); + fs.writeFileSync(assetMapInfoFile, JSON.stringify(assetMaps, null, 2)); } } \ No newline at end of file