-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(assets-generation): Do not fail in case some App_Resources are missing #3557
Conversation
…ssing In case you delete `App_Resources/iOS` directory, the `getAssetsStructure` method fails as it tries to read `Content.json` files from the deleted directory. Instead of failing, just return empty arrays for the images. This is already working this way for Android. Add test for the case
@@ -125,7 +125,7 @@ export class ProjectDataService implements IProjectDataService { | |||
|
|||
private async getIOSAssetSubGroup(dirPath: string): Promise<IAssetSubGroup> { | |||
const pathToContentJson = path.join(dirPath, AssetConstants.iOSResourcesFileName); | |||
const content = <IAssetSubGroup>this.$fs.readJson(pathToContentJson); | |||
const content = this.$fs.exists(pathToContentJson) && <IAssetSubGroup>this.$fs.readJson(pathToContentJson) || { images: [] }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen in case when pathToContentJson
exists but the file is not a valid json? I'm expecting to throw an error in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I prefer to throw the error in this case as it is not expected to have a non-json file here.
const fs = testInjector.resolve<IFileSystem>("fs"); | ||
fs.readJson = (filePath: string): any => { | ||
if (basename(filePath) === AssetConstants.imageDefinitionsFileName) { | ||
return { android: {}, ios: {} }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case when imageDefinitionsFileName
file does not exist, an error will be thrown. I'm wondering if we should check this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is part of CLI resources, so in case it does not exist, something terrible happened 😸
In case you delete
App_Resources/iOS
directory, thegetAssetsStructure
method fails as it tries to readContent.json
files from the deleted directory. Instead of failing, just return empty arrays for the images. This is already working this way for Android.Add test for the case
PR Checklist
What is the current behavior?
Trying to generate/get assets structure fails when App_Resources/iOS is deleted
What is the new behavior?
The generation of assets will work for Android in this case.
Fixes ProgressNS/sidekick-feedback#168 .