Skip to content

Commit eb334df

Browse files
Merge pull request #834 from NativeScript/fatme/work-correctly-with-ios-runtme
Work correctly if iOS runtime version is lower than 1.3
2 parents 191a7a5 + 3488c61 commit eb334df

File tree

9 files changed

+46
-21
lines changed

9 files changed

+46
-21
lines changed

lib/definitions/platform.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ interface IPlatformData {
2525
projectRoot: string;
2626
normalizedPlatformName: string;
2727
appDestinationDirectoryPath: string;
28-
appResourcesDestinationDirectoryPath: string;
2928
deviceBuildOutputPath: string;
3029
emulatorBuildOutputPath?: string;
3130
validPackageNamesForDevice: string[];

lib/definitions/project.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ interface IPlatformProjectService {
4646
preparePluginNativeCode(pluginData: IPluginData): IFuture<void>;
4747
removePluginNativeCode(pluginData: IPluginData): IFuture<void>;
4848
afterPrepareAllPlugins(): IFuture<void>;
49+
getAppResourcesDestinationDirectoryPath(): IFuture<string>;
4950
}
5051

5152
interface IAndroidProjectPropertiesManager {
5253
getProjectReferences(): IFuture<ILibRef[]>;
5354
addProjectReference(referencePath: string): IFuture<void>;
54-
removeProjectReference(referencePath: string): IFuture<void>;
55+
removeProjectReference(referencePath: string): IFuture<void>;
5556
}

lib/services/android-project-service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
4545
frameworkPackageName: "tns-android",
4646
normalizedPlatformName: "Android",
4747
appDestinationDirectoryPath: path.join(projectRoot, "src", "main", "assets"),
48-
appResourcesDestinationDirectoryPath: path.join(projectRoot, "src", "main", "res"),
4948
platformProjectService: this,
5049
emulatorServices: this.$androidEmulatorServices,
5150
projectRoot: projectRoot,
@@ -64,6 +63,12 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
6463
return this._platformData;
6564
}
6665

66+
public getAppResourcesDestinationDirectoryPath(): IFuture<string> {
67+
return (() => {
68+
return path.join(this.platformData.projectRoot, "src", "main", "res");
69+
}).future<string>()();
70+
}
71+
6772
public validate(): IFuture<void> {
6873
return (() => {
6974
this.validatePackageName(this.$projectData.projectId);
@@ -108,7 +113,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
108113
private copyResValues(projectRoot: string, frameworkDir: string, versionNumber: string): IFuture<void> {
109114
return (() => {
110115
let resSourceDir = path.join(frameworkDir, "src", "main", "res");
111-
let resDestinationDir = this.platformData.appResourcesDestinationDirectoryPath;
116+
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath().wait();
112117
this.$fs.createDirectory(resDestinationDir).wait();
113118
let versionDirName = AndroidProjectService.VALUES_VERSION_DIRNAME_PREFIX + versionNumber;
114119
let directoriesToCopy = [AndroidProjectService.VALUES_DIRNAME];
@@ -140,7 +145,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
140145
let manifestPath = this.platformData.configurationFilePath;
141146
shell.sed('-i', /__PACKAGE__/, this.$projectData.projectId, manifestPath);
142147

143-
let stringsFilePath = path.join(this.platformData.appResourcesDestinationDirectoryPath, 'values', 'strings.xml');
148+
let stringsFilePath = path.join(this.getAppResourcesDestinationDirectoryPath().wait(), 'values', 'strings.xml');
144149
shell.sed('-i', /__NAME__/, this.$projectData.projectName, stringsFilePath);
145150
shell.sed('-i', /__TITLE_ACTIVITY__/, this.$projectData.projectName, stringsFilePath);
146151

@@ -239,7 +244,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
239244
let valuesDirRegExp = /^values/;
240245
let resourcesDirs = this.$fs.readDirectory(resourcesDirPath).wait().filter(resDir => !resDir.match(valuesDirRegExp));
241246
_.each(resourcesDirs, resourceDir => {
242-
this.$fs.deleteDirectory(path.join(this.platformData.appResourcesDestinationDirectoryPath, resourceDir)).wait();
247+
this.$fs.deleteDirectory(path.join(this.getAppResourcesDestinationDirectoryPath().wait(), resourceDir)).wait();
243248
});
244249
}).future<void>()();
245250
}

lib/services/ios-project-service.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from "path";
55
import * as shell from "shelljs";
66
import * as util from "util";
77
import * as os from "os";
8+
import * as semver from "semver";
89
import * as xcode from "xcode";
910
import * as constants from "../constants";
1011
import * as helpers from "../common/helpers";
@@ -28,7 +29,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
2829
private $logger: ILogger,
2930
private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices,
3031
private $options: IOptions,
31-
private $injector: IInjector) {
32+
private $injector: IInjector,
33+
private $projectDataService: IProjectDataService) {
3234
super($fs);
3335
}
3436

@@ -39,7 +41,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
3941
frameworkPackageName: "tns-ios",
4042
normalizedPlatformName: "iOS",
4143
appDestinationDirectoryPath: path.join(projectRoot, this.$projectData.projectName),
42-
appResourcesDestinationDirectoryPath: path.join(projectRoot, this.$projectData.projectName, "Resources"),
4344
platformProjectService: this,
4445
emulatorServices: this.$iOSEmulatorServices,
4546
projectRoot: projectRoot,
@@ -61,6 +62,19 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
6162
};
6263
}
6364

65+
public getAppResourcesDestinationDirectoryPath(): IFuture<string> {
66+
return (() => {
67+
this.$projectDataService.initialize(this.$projectData.projectDir);
68+
let frameworkVersion = this.$projectDataService.getValue(this.platformData.frameworkPackageName).wait()["version"];
69+
70+
if(semver.lt(frameworkVersion, "1.3.0")) {
71+
return path.join(this.platformData.projectRoot, this.$projectData.projectName, "Resources", "icons");
72+
}
73+
74+
return path.join(this.platformData.projectRoot, this.$projectData.projectName, "Resources");
75+
}).future<string>()();
76+
}
77+
6478
public validate(): IFuture<void> {
6579
return (() => {
6680
try {
@@ -258,25 +272,27 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
258272
this.$logger.trace("Images from Xcode project");
259273
this.$logger.trace(xcodeProjectImages);
260274

261-
let appResourcesImages = this.$fs.readDirectory(this.platformData.appResourcesDestinationDirectoryPath).wait();
275+
let appResourcesImages = this.$fs.readDirectory(this.getAppResourcesDestinationDirectoryPath().wait()).wait();
262276
this.$logger.trace("Current images from App_Resources");
263277
this.$logger.trace(appResourcesImages);
264278

265279
let imagesToAdd = _.difference(appResourcesImages, xcodeProjectImages);
266280
this.$logger.trace(`New images to add into xcode project: ${imagesToAdd.join(", ")}`);
267-
_.each(imagesToAdd, image => project.addResourceFile(path.relative(this.platformData.projectRoot, path.join( this.platformData.appResourcesDestinationDirectoryPath, image))));
281+
_.each(imagesToAdd, image => project.addResourceFile(path.relative(this.platformData.projectRoot, path.join(this.getAppResourcesDestinationDirectoryPath().wait(), image))));
268282

269283
let imagesToRemove = _.difference(xcodeProjectImages, appResourcesImages);
270284
this.$logger.trace(`Images to remove from xcode project: ${imagesToRemove.join(", ")}`);
271-
_.each(imagesToRemove, image => project.removeResourceFile(path.join(this.platformData.appResourcesDestinationDirectoryPath, image)));
285+
_.each(imagesToRemove, image => project.removeResourceFile(path.join(this.getAppResourcesDestinationDirectoryPath().wait(), image)));
272286

273287
this.savePbxProj(project).wait();
274288
}
275289
}).future<void>()();
276290
}
277291

278292
public prepareAppResources(appResourcesDirectoryPath: string): IFuture<void> {
279-
return this.$fs.deleteDirectory(this.platformData.appResourcesDestinationDirectoryPath);
293+
return (() => {
294+
this.$fs.deleteDirectory(this.getAppResourcesDestinationDirectoryPath().wait()).wait();
295+
}).future<void>()();
280296
}
281297

282298
private get projectPodFilePath(): string {

lib/services/platform-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ export class PlatformService implements IPlatformService {
163163
shell.cp("-Rf", appSourceDirectoryPath, platformData.appDestinationDirectoryPath);
164164

165165
// Copy App_Resources to project root folder
166-
this.$fs.ensureDirectoryExists(platformData.appResourcesDestinationDirectoryPath).wait(); // Should be deleted
166+
this.$fs.ensureDirectoryExists(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait()).wait(); // Should be deleted
167167
let appResourcesDirectoryPath = path.join(appDestinationDirectoryPath, constants.APP_RESOURCES_FOLDER_NAME);
168168
if (this.$fs.exists(appResourcesDirectoryPath).wait()) {
169169
platformData.platformProjectService.prepareAppResources(appResourcesDirectoryPath).wait();
170-
shell.cp("-Rf", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), platformData.appResourcesDestinationDirectoryPath);
170+
shell.cp("-Rf", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait());
171171
this.$fs.deleteDirectory(appResourcesDirectoryPath).wait();
172172
}
173173

test/npm-support.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ function setupProject(): IFuture<any> {
120120
platformProjectService: {
121121
prepareProject: () => Future.fromResult(),
122122
prepareAppResources: () => Future.fromResult(),
123-
afterPrepareAllPlugins: () => Future.fromResult()
123+
afterPrepareAllPlugins: () => Future.fromResult(),
124+
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
124125
}
125126
};
126127
};

test/platform-service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ describe('Platform Service Tests', () => {
218218
validate: () => Future.fromResult(),
219219
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
220220
interpolateData: (projectRoot: string) => Future.fromResult(),
221-
afterCreateProject: (projectRoot: string) => Future.fromResult()
221+
afterCreateProject: (projectRoot: string) => Future.fromResult(),
222+
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
222223
}
223224
};
224225
};
@@ -276,7 +277,8 @@ describe('Platform Service Tests', () => {
276277
validate: () => Future.fromResult(),
277278
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
278279
interpolateData: (projectRoot: string) => Future.fromResult(),
279-
afterCreateProject: (projectRoot: string) => Future.fromResult()
280+
afterCreateProject: (projectRoot: string) => Future.fromResult(),
281+
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
280282
}
281283
};
282284
};

test/stubs.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ export class PlatformsDataStub implements IPlatformsData {
250250
validPackageNamesForDevice: [],
251251
frameworkFilesExtensions: [],
252252
appDestinationDirectoryPath: "",
253-
appResourcesDestinationDirectoryPath: "",
254253
preparePluginNativeCode: () => Future.fromResult(),
255254
removePluginNativeCode: () => Future.fromResult(),
256255
afterPrepareAllPlugins: () => Future.fromResult()
@@ -273,10 +272,12 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
273272
deviceBuildOutputPath: "",
274273
validPackageNamesForDevice: [],
275274
frameworkFilesExtensions: [],
276-
appDestinationDirectoryPath: "",
277-
appResourcesDestinationDirectoryPath: "",
275+
appDestinationDirectoryPath: ""
278276
};
279277
}
278+
getAppResourcesDestinationDirectoryPath(): IFuture<string>{
279+
return Future.fromResult("");
280+
}
280281
validate(): IFuture<void> {
281282
return Future.fromResult();
282283
}

0 commit comments

Comments
 (0)