This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implements reading from zip files & prepares base id translatio…
…n helper and supports importing assets with binary files
- Loading branch information
Showing
10 changed files
with
226 additions
and
60 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
import { ValidImportContract, ValidImportModel, IImportItemResult } from './core.models'; | ||
|
||
export class IdTranslateHelper { | ||
public replaceIdReferencesWithNewId( | ||
data: any, | ||
items: IImportItemResult<ValidImportContract, ValidImportModel>[] | ||
): void { | ||
if (data) { | ||
if (Array.isArray(data)) { | ||
for (const arrayItem of data) { | ||
this.replaceIdReferencesWithNewId(arrayItem, items); | ||
} | ||
} else { | ||
for (const key of Object.keys(data)) { | ||
const val = (data as any)[key]; | ||
if (key.toLowerCase() === 'id') { | ||
const id = (data as any).id; | ||
|
||
const newId = this.tryFindNewId(id, items); | ||
|
||
// replace old id with new | ||
if (newId) { | ||
data.id = newId; | ||
} | ||
} | ||
|
||
if (key !== '0') { | ||
this.replaceIdReferencesWithNewId(val, items); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private tryFindNewId( | ||
id: string, | ||
items: IImportItemResult<ValidImportContract, ValidImportModel>[] | ||
): string | undefined { | ||
const item = items.find(m => m.originalId === id); | ||
return item?.importId; | ||
} | ||
} | ||
|
||
export const idTranslateHelper = new IdTranslateHelper(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './core.models'; | ||
export * from './codename-translate-helper'; | ||
export * from './id-translate-helper'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.