Skip to content

Commit

Permalink
changing maps persistance deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Nov 15, 2022
1 parent ee5fc25 commit 1714407
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/model/AssetMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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));
}
}

0 comments on commit 1714407

Please sign in to comment.