Skip to content

fix: generate iOS images when we have their sizes #5139

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

Merged
merged 2 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/services/project-data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,15 @@ export class ProjectDataService implements IProjectDataService {
}
});

if (!foundMatchingDefinition && image.filename) {
this.$logger.warn(`Didn't find a matching image definition for file ${path.join(path.basename(dirPath), image.filename)}. This file will be skipped from reources generation.`);
if (!foundMatchingDefinition) {
if (image.height && image.width) {
this.$logger.trace("Missing data for image", image, " in CLI's resource file, but we will try to generate images based on the size from Contents.json");
finalContent.images.push(image);
} else if (image.filename) {
this.$logger.warn(`Didn't find a matching image definition for file ${path.join(path.basename(dirPath), image.filename)}. This file will be skipped from resources generation.`);
} else {
this.$logger.trace(`Unable to detect data for image generation of image`, image);
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nativescript",
"preferGlobal": true,
"version": "6.2.1",
"version": "6.2.2",
"author": "Telerik <[email protected]>",
"description": "Command-line interface for building NativeScript projects",
"bin": {
Expand Down
21 changes: 21 additions & 0 deletions resources/assets/image-definitions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
{
"ios": {
"icons": [
{
"width": 20,
"height": 20,
"directory": "Assets.xcassets/AppIcon.appiconset",
"filename": "[email protected]",
"scale": "3x"
},
{
"width": 20,
"height": 20,
"directory": "Assets.xcassets/AppIcon.appiconset",
"filename": "[email protected]",
"scale": "2x"
},
{
"width": 20,
"height": 20,
"directory": "Assets.xcassets/AppIcon.appiconset",
"filename": "icon-20.png",
"scale": "1x"
},
{
"width": 60,
"height": 60,
Expand Down
97 changes: 97 additions & 0 deletions test/services/project-data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,103 @@ describe("projectDataService", () => {

assert.deepEqual(assetStructure, { ios: emptyAssetStructure, android: _.merge(_.cloneDeep(emptyAssetStructure), { splashImages: null }) });
});

it("generates iOS resources for files, which are not declared in image-definitions.json, but we have their size from resource's Contents.json", async () => {
const defaultEmptyData: any = {};
defaultEmptyData[CLIENT_NAME_KEY_IN_PROJECT_FILE] = {};
const testInjector = createTestInjector(JSON.stringify(defaultEmptyData));
const fs = testInjector.resolve<IFileSystem>("fs");
fs.exists = () => true;
fs.readJson = (filePath: string): any => {
if (basename(filePath) === AssetConstants.imageDefinitionsFileName) {
return {
android: {},
ios: {
"icons": [
{
"width": 20,
"height": 20,
"directory": "Assets.xcassets/AppIcon.appiconset",
"filename": "[email protected]",
"scale": "3x"
}]
}
};
}

if (basename(filePath) === AssetConstants.iOSResourcesFileName && filePath.indexOf(AssetConstants.iOSIconsDirName) !== -1) {
return {
"images": [
{
"size": "20x20",
"idiom": "iphone",
"filename": "[email protected]",
"scale": "2x"
},
{
"size": "20x20",
"idiom": "iphone",
"filename": "[email protected]",
"scale": "3x"
}
]
};
}
};

const projectDataService = testInjector.resolve<IProjectDataService>("projectDataService");
const assetStructure = await projectDataService.getAssetsStructure({ projectDir: "." });
const emptyAssetStructure: IAssetGroup = {
icons: {
images: []
},
splashBackgrounds: {
images: []
},
splashCenterImages: {
images: []
},
splashImages: {
images: []
}
};

const expectedIOSStructure = _.merge({}, emptyAssetStructure, {
icons: {
"images": [
{
"filename": "[email protected]",
"height": 20,
"idiom": "iphone",
"scale": "2x",
"size": "20x20",
"width": 20
},
{
"filename": "[email protected]",
"height": 20,
"idiom": "iphone",
"overlayImageScale": undefined,
"resizeOperation": undefined,
"rgba": undefined,
"scale": "3x",
"size": "20x20",
"width": 20
}
]
}
});

_.each(assetStructure.ios.icons.images, icon => {
// as path is generated from the current directory, skip it from the validation
delete icon.path;
});

assert.deepEqual(assetStructure, {
ios: expectedIOSStructure,
android: _.merge(_.cloneDeep(emptyAssetStructure), { splashImages: null })
});
});
});

describe("getAppExecutableFiles", () => {
Expand Down