Skip to content

Commit 9aabb6c

Browse files
ivanovitrosen-vladimirov
authored andcommitted
Fixes after review
1 parent 6143320 commit 9aabb6c

9 files changed

+401
-60
lines changed

.vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
// "args": [ "debug", "android", "--path", "cliapp"]
2424
// "args": [ "livesync", "android", "--path", "cliapp"]
2525
// "args": [ "livesync", "android", "--watch", "--path", "cliapp"],
26-
// "args": [ "generate-icons", "./test/image-generation-test.png", "--path", "cliapp" ],
27-
// "args": [ "generate-splashscreens", "./test/image-generation-test.png", "--path", "cliapp", "--background", "black" ],
26+
// "args": [ "resources", "generate", "icons", "./test/image-generation-test.png", "--path", "cliapp" ],
27+
// "args": [ "resources", "generate", "splashes", "./test/image-generation-test.png", "--path", "cliapp", "--background", "#8000ff" ],
2828
},
2929
{
3030
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`

lib/bootstrap.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,6 @@ $injector.require('playgroundService', './services/playground-service');
162162
$injector.require("platformEnvironmentRequirements", "./services/platform-environment-requirements");
163163
$injector.require("nativescriptCloudExtensionService", "./services/nativescript-cloud-extension-service");
164164

165-
$injector.requireCommand("generate-icons", "./commands/generate-assets")
166-
$injector.requireCommand("generate-splashscreens", "./commands/generate-assets")
167-
$injector.requirePublic("assetsGenerationService", "./services/assets-generation/assets-generation-service");
165+
$injector.requireCommand("resources|generate|icons", "./commands/generate-assets")
166+
$injector.requireCommand("resources|generate|splashes", "./commands/generate-assets")
167+
$injector.requirePublic("assetsGenerationService", "./services/assets-generation/assets-generation-service");

lib/commands/generate-assets.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export abstract class GenerateCommandBase implements ICommand {
1313
public async execute(args: string[]): Promise<void> {
1414
const [ imagePath ] = args;
1515
const resourcesPath = this.$projectData.getAppResourcesDirectoryPath();
16-
await this.generate(imagePath, resourcesPath, this.$options.background)
16+
await this.generate(imagePath, resourcesPath, this.$options.background);
1717
}
1818

19-
protected abstract generate(imagePath: string, resourcesPath: string, background?: string): Promise<void>
19+
protected abstract generate(imagePath: string, resourcesPath: string, background?: string): Promise<void>;
2020
}
2121

2222
export class GenerateIconsCommand extends GenerateCommandBase implements ICommand {
@@ -28,11 +28,11 @@ export class GenerateIconsCommand extends GenerateCommandBase implements IComman
2828
}
2929

3030
protected async generate(imagePath: string, resourcesPath: string, background?: string): Promise<void> {
31-
await this.$assetsGenerationService.generateIcons(imagePath, resourcesPath);
31+
await this.$assetsGenerationService.generateIcons({ imagePath, resourcesPath });
3232
}
3333
}
3434

35-
$injector.registerCommand("generate-icons", GenerateIconsCommand);
35+
$injector.registerCommand("resources|generate|icons", GenerateIconsCommand);
3636

3737
export class GenerateSplashScreensCommand extends GenerateCommandBase implements ICommand {
3838
constructor(protected $options: IOptions,
@@ -43,8 +43,8 @@ export class GenerateSplashScreensCommand extends GenerateCommandBase implements
4343
}
4444

4545
protected async generate(imagePath: string, resourcesPath: string, background?: string): Promise<void> {
46-
await this.$assetsGenerationService.generateSplashScreens(imagePath, resourcesPath, background);
46+
await this.$assetsGenerationService.generateSplashScreens({ imagePath, resourcesPath, background });
4747
}
4848
}
4949

50-
$injector.registerCommand("generate-splashscreens", GenerateSplashScreensCommand);
50+
$injector.registerCommand("resources|generate|splashes", GenerateSplashScreensCommand);

lib/declarations.d.ts

+28-7
Original file line numberDiff line numberDiff line change
@@ -796,25 +796,46 @@ interface INativescriptCloudExtensionService {
796796
install(): Promise<IExtensionData>;
797797
}
798798

799+
/**
800+
* Describes the basic data needed for resource generation
801+
*/
802+
interface IResourceGenerationData {
803+
/**
804+
* @param {string} imagePath Path to the image that will be used for generation
805+
*/
806+
imagePath: string,
807+
/**
808+
* @param {string} resourcesPath Path to the app resources
809+
*/
810+
resourcesPath: string
811+
}
812+
813+
/**
814+
* Describes the data needed for splash screens generation
815+
*/
816+
interface ISplashesGenerationData extends IResourceGenerationData {
817+
/**
818+
* @param {string} background Background color that will be used for background. Defaults to #FFFFFF
819+
*/
820+
background?: string
821+
}
822+
799823

800824
/**
801825
* Describes service used for assets generation
802826
*/
803827
interface IAssetsGenerationService {
804828
/**
805829
* Generate icons for iOS and Android
806-
* @param {string} imagePath Path to the image that will be used for generation
807-
* @param {string} resourcesPath Path to the app resources
830+
* @param {IResourceGenerationData} iconsGenerationData Provides the data needed for icons generation
808831
* @returns {Promise<void>}
809832
*/
810-
generateIcons(imagePath: string, resourcesPath: string): Promise<void>;
833+
generateIcons(iconsGenerationData: IResourceGenerationData): Promise<void>;
811834

812835
/**
813836
* Generate splash screens for iOS and Android
814-
* @param {string} imagePath Path to the image that will be used for generation
815-
* @param {string} resourcesPath Path to the app resources
816-
* @param {string} background Background color that will be used for background. Defaults to #FFFFFF
837+
* @param {ISplashesGenerationData} splashesGenerationData Provides the data needed for splash screens generation
817838
* @returns {Promise<void>}
818839
*/
819-
generateSplashScreens(imagePath: string, resourcesPath: string, background?: string): Promise<void>;
840+
generateSplashScreens(splashesGenerationData: ISplashesGenerationData): Promise<void>;
820841
}

lib/services/assets-generation/assets-generation-service.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,32 @@ import { Icons, SplashScreens, Operations } from "./image-definitions"
55
import { exported } from "../../common/decorators";
66

77
export class AssetsGenerationService implements IAssetsGenerationService {
8-
constructor(private $logger: ILogger) {
8+
constructor(private $logger: ILogger,
9+
private $androidResourcesMigrationService: IAndroidResourcesMigrationService) {
910
}
1011

1112
@exported("assetsGenerationService")
12-
public async generateIcons(imagePath: string, resourcesPath: string): Promise<void> {
13+
public async generateIcons(resourceGenerationData: IResourceGenerationData): Promise<void> {
1314
this.$logger.info("Generating icons ...");
14-
await this.generateImagesForDefinitions(imagePath, resourcesPath, Icons)
15+
await this.generateImagesForDefinitions(resourceGenerationData.imagePath, resourceGenerationData.resourcesPath, Icons)
1516
this.$logger.info("Icons generation completed.");
1617
}
1718

1819
@exported("assetsGenerationService")
19-
public async generateSplashScreens(imagePath: string, resourcesPath: string, background?: string): Promise<void> {
20+
public async generateSplashScreens(splashesGenerationData: ISplashesGenerationData): Promise<void> {
2021
this.$logger.info("Generating splash screens ...");
21-
await this.generateImagesForDefinitions(imagePath, resourcesPath, SplashScreens, background)
22+
await this.generateImagesForDefinitions(splashesGenerationData.imagePath, splashesGenerationData.resourcesPath, SplashScreens, splashesGenerationData.background)
2223
this.$logger.info("Splash screens generation completed.");
2324
}
2425

2526
private async generateImagesForDefinitions(imagePath: string, resourcesPath: string, definitions: any[], background: string = "white") : Promise<void> {
27+
const hasMigrated = this.$androidResourcesMigrationService.hasMigrated(resourcesPath);
28+
2629
for (let definition of definitions) {
2730
const operation = definition.operation || Operations.Resize;
2831
const scale = definition.scale || 0.8;
29-
const outputPath = this.convertToAbsolutePath(resourcesPath, definition.path);
32+
const path = hasMigrated ? definition.path : (definition.pathBeforeMigration || definition.path)
33+
const outputPath = this.convertToAbsolutePath(resourcesPath, path);
3034

3135
switch (operation) {
3236
case Operations.OverlayWith:
@@ -47,14 +51,14 @@ export class AssetsGenerationService implements IAssetsGenerationService {
4751
}
4852
}
4953

50-
private async resize(imagePath: string, width: number, height: number) {
54+
private async resize(imagePath: string, width: number, height: number) : Promise<Jimp> {
5155
const image = await Jimp.read(imagePath);
5256
return image.scaleToFit(width, height);
5357
}
5458

55-
private generateImage(background: string, width: number, height: number, outputPath: string, overlayImage?: Jimp) {
59+
private generateImage(background: string, width: number, height: number, outputPath: string, overlayImage?: Jimp): void {
5660
//Typescript declarations for Jimp are not updated to define the constructor with backgroundColor so we workaround it by casting it to <any> for this case only.
57-
let J = <any>Jimp;
61+
const J = <any>Jimp;
5862
const backgroundColor = this.getRgbaNumber(background);
5963
let image = new J(width, height, backgroundColor);
6064

lib/services/assets-generation/image-definitions.ts

+41-18
Original file line numberDiff line numberDiff line change
@@ -94,35 +94,46 @@ export const Icons = [
9494
"height":114,
9595
"path":"iOS/Assets.xcassets/AppIcon.appiconset/[email protected]"
9696
},
97+
{
98+
"width":1024,
99+
"height":1024,
100+
"path":"iOS/Assets.xcassets/AppIcon.appiconset/icon-1024.png"
101+
},
97102
{
98103
"width":72,
99104
"height":72,
100-
"path":"Android/drawable-hdpi/icon.png"
105+
"path":"Android/src/main/res/drawable-hdpi/icon.png",
106+
"pathBeforeMigration":"Android/drawable-hdpi/icon.png"
101107
},
102108
{
103109
"width":36,
104110
"height":36,
105-
"path":"Android/drawable-ldpi/icon.png"
111+
"path":"Android/src/main/res/drawable-ldpi/icon.png",
112+
"pathBeforeMigration":"Android/drawable-ldpi/icon.png"
106113
},
107114
{
108115
"width":48,
109116
"height":48,
110-
"path":"Android/drawable-mdpi/icon.png"
117+
"path":"Android/src/main/res/drawable-mdpi/icon.png",
118+
"pathBeforeMigration":"Android/drawable-mdpi/icon.png"
111119
},
112120
{
113121
"width":96,
114122
"height":96,
115-
"path":"Android/drawable-xhdpi/icon.png"
123+
"path":"Android/src/main/res/drawable-xhdpi/icon.png",
124+
"pathBeforeMigration":"Android/drawable-xhdpi/icon.png"
116125
},
117126
{
118127
"width":144,
119128
"height":144,
120-
"path":"Android/drawable-xxhdpi/icon.png"
129+
"path":"Android/src/main/res/drawable-xxhdpi/icon.png",
130+
"pathBeforeMigration":"Android/drawable-xxhdpi/icon.png"
121131
},
122132
{
123133
"width":345,
124134
"height":345,
125-
"path":"Android/drawable-xxxhdpi/icon.png"
135+
"path":"Android/src/main/res/drawable-xxxhdpi/icon.png",
136+
"pathBeforeMigration":"Android/drawable-xxxhdpi/icon.png"
126137
}
127138
]
128139

@@ -238,68 +249,80 @@ export const SplashScreens = [
238249
{
239250
"width":576,
240251
"height":768,
241-
"path":"Android/drawable-hdpi/background.png",
252+
"path":"Android/src/main/res/drawable-hdpi/background.png",
253+
"pathBeforeMigration":"Android/drawable-hdpi/background.png",
242254
"operation": "blank"
243255
},
244256
{
245257
"width":288,
246258
"height":384,
247-
"path":"Android/drawable-ldpi/background.png",
259+
"path":"Android/src/main/res/drawable-ldpi/background.png",
260+
"pathBeforeMigration":"Android/drawable-ldpi/background.png",
248261
"operation": "blank"
249262
},
250263
{
251264
"width":384,
252265
"height":512,
253-
"path":"Android/drawable-mdpi/background.png",
266+
"path":"Android/src/main/res/drawable-mdpi/background.png",
267+
"pathBeforeMigration":"Android/drawable-mdpi/background.png",
254268
"operation": "blank"
255269
},
256270
{
257271
"width":768,
258272
"height":1024,
259-
"path":"Android/drawable-xhdpi/background.png",
273+
"path":"Android/src/main/res/drawable-xhdpi/background.png",
274+
"pathBeforeMigration":"Android/drawable-xhdpi/background.png",
260275
"operation": "blank"
261276
},
262277
{
263278
"width":1154,
264279
"height":1536,
265-
"path":"Android/drawable-xxhdpi/background.png",
280+
"path":"Android/src/main/res/drawable-xxhdpi/background.png",
281+
"pathBeforeMigration":"Android/drawable-xxhdpi/background.png",
266282
"operation": "blank"
267283
},
268284
{
269285
"width":1536,
270286
"height":2048,
271-
"path":"Android/drawable-xxxhdpi/background.png",
287+
"path":"Android/src/main/res/drawable-xxxhdpi/background.png",
288+
"pathBeforeMigration":"Android/drawable-xxxhdpi/background.png",
272289
"operation": "blank"
273290
},
274291
{
275292
"width":476,
276293
"height":476,
277-
"path":"Android/drawable-hdpi/logo.png"
294+
"path":"Android/src/main/res/drawable-hdpi/logo.png",
295+
"pathBeforeMigration":"Android/drawable-hdpi/logo.png"
278296
},
279297
{
280298
"width":188,
281299
"height":188,
282-
"path":"Android/drawable-ldpi/logo.png"
300+
"path":"Android/src/main/res/drawable-ldpi/logo.png",
301+
"pathBeforeMigration":"Android/drawable-ldpi/logo.png"
283302
},
284303
{
285304
"width":284,
286305
"height":284,
287-
"path":"Android/drawable-mdpi/logo.png"
306+
"path":"Android/src/main/res/drawable-mdpi/logo.png",
307+
"pathBeforeMigration":"Android/drawable-mdpi/logo.png"
288308
},
289309
{
290310
"width":668,
291311
"height":668,
292-
"path":"Android/drawable-xhdpi/logo.png"
312+
"path":"Android/src/main/res/drawable-xhdpi/logo.png",
313+
"pathBeforeMigration":"Android/drawable-xhdpi/logo.png"
293314
},
294315
{
295316
"width":1024,
296317
"height":1024,
297-
"path":"Android/drawable-xxhdpi/logo.png"
318+
"path":"Android/src/main/res/drawable-xxhdpi/logo.png",
319+
"pathBeforeMigration":"Android/drawable-xxhdpi/logo.png"
298320
},
299321
{
300322
"width":1024,
301323
"height":1024,
302-
"path":"Android/drawable-xxxhdpi/logo.png"
324+
"path":"Android/src/main/res/drawable-xxxhdpi/logo.png",
325+
"pathBeforeMigration":"Android/drawable-xxxhdpi/logo.png"
303326
}
304327
]
305328

0 commit comments

Comments
 (0)