From f3171a8ed63b681118aa729f4876e619d25306b3 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 15 Nov 2019 18:45:04 +0200 Subject: [PATCH 1/2] fix: generate iOS images when we have their sizes In case we do not have some of iOS Resource images in our image-definitions.json file, we do not generate images for them. This was not the case prior 6.2.0 release, so fix the behavior by getting back the old logic - get the image size from the Contents.json and generate image for it. Also add the images from the templates that are currently missing from our `image-definitions.json` file. --- lib/services/project-data-service.ts | 11 ++- resources/assets/image-definitions.json | 21 ++++++ test/services/project-data-service.ts | 97 +++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 2 deletions(-) diff --git a/lib/services/project-data-service.ts b/lib/services/project-data-service.ts index db02f78245..30dc8b0cd3 100644 --- a/lib/services/project-data-service.ts +++ b/lib/services/project-data-service.ts @@ -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); + } } }); diff --git a/resources/assets/image-definitions.json b/resources/assets/image-definitions.json index 7777b0ec04..78e1e7eb5b 100644 --- a/resources/assets/image-definitions.json +++ b/resources/assets/image-definitions.json @@ -1,6 +1,27 @@ { "ios": { "icons": [ + { + "width": 20, + "height": 20, + "directory": "Assets.xcassets/AppIcon.appiconset", + "filename": "icon-20@3x.png", + "scale": "3x" + }, + { + "width": 20, + "height": 20, + "directory": "Assets.xcassets/AppIcon.appiconset", + "filename": "icon-20@2x.png", + "scale": "2x" + }, + { + "width": 20, + "height": 20, + "directory": "Assets.xcassets/AppIcon.appiconset", + "filename": "icon-20.png", + "scale": "1x" + }, { "width": 60, "height": 60, diff --git a/test/services/project-data-service.ts b/test/services/project-data-service.ts index 35c4c919c2..9b4da40ea7 100644 --- a/test/services/project-data-service.ts +++ b/test/services/project-data-service.ts @@ -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("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": "icon-20@3x.png", + "scale": "3x" + }] + } + }; + } + + if (basename(filePath) === AssetConstants.iOSResourcesFileName && filePath.indexOf(AssetConstants.iOSIconsDirName) !== -1) { + return { + "images": [ + { + "size": "20x20", + "idiom": "iphone", + "filename": "icon-20@2x.png", + "scale": "2x" + }, + { + "size": "20x20", + "idiom": "iphone", + "filename": "icon-20@3x.png", + "scale": "3x" + } + ] + }; + } + }; + + const projectDataService = testInjector.resolve("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": "icon-20@2x.png", + "height": 20, + "idiom": "iphone", + "scale": "2x", + "size": "20x20", + "width": 20 + }, + { + "filename": "icon-20@3x.png", + "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", () => { From 60fc024a45778f3c7d750595e75eb0d466416e50 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Mon, 18 Nov 2019 12:05:44 +0200 Subject: [PATCH 2/2] chore: set version to 6.2.2 --- npm-shrinkwrap.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index f51552202e..969d5d63d6 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "nativescript", - "version": "6.2.1", + "version": "6.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 06cd007e91..4f1bd0f4b4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nativescript", "preferGlobal": true, - "version": "6.2.1", + "version": "6.2.2", "author": "Telerik ", "description": "Command-line interface for building NativeScript projects", "bin": {