Skip to content

Commit 0768fa4

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #597 from NativeScript/fatme/fix-broken-android-prepare
Fix broken android prepare
2 parents 9395362 + d8affae commit 0768fa4

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

lib/definitions/project.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface IPlatformProjectService {
2828
afterCreateProject(projectRoot: string): IFuture<void>;
2929
buildProject(projectRoot: string): IFuture<void>;
3030
prepareProject(): IFuture<void>;
31+
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void>;
3132
isPlatformPrepared(projectRoot: string): IFuture<boolean>;
3233
addLibrary(platformData: IPlatformData, libraryPath: string): IFuture<void>;
3334
canUpdatePlatform(currentVersion: string, newVersion: string): IFuture<boolean>;

lib/services/android-project-service.ts

+10
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ class AndroidProjectService implements IPlatformProjectService {
181181
public isPlatformPrepared(projectRoot: string): IFuture<boolean> {
182182
return this.$fs.exists(path.join(projectRoot, "assets", constants.APP_FOLDER_NAME));
183183
}
184+
185+
public prepareAppResources(appResourcesDirectoryPath: string): IFuture<void> {
186+
return (() => {
187+
let resourcesDirPath = path.join(appResourcesDirectoryPath, this.platformData.normalizedPlatformName);
188+
let resourcesDirs = this.$fs.readDirectory(resourcesDirPath).wait();
189+
_.each(resourcesDirs, resourceDir => {
190+
this.$fs.deleteDirectory(path.join(this.platformData.appResourcesDestinationDirectoryPath, resourceDir)).wait();
191+
});
192+
}).future<void>()();
193+
}
184194

185195
private parseProjectProperties(projDir: string, destDir: string): void {
186196
let projProp = path.join(projDir, "project.properties");

lib/services/ios-project-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ class IOSProjectService implements IPlatformProjectService {
254254
}).future<void>()();
255255
}
256256

257+
public prepareAppResources(appResourcesDirectoryPath: string): IFuture<void> {
258+
return this.$fs.deleteDirectory(this.platformData.appResourcesDestinationDirectoryPath);
259+
}
260+
257261
private replace(name: string): string {
258262
if(_.startsWith(name, '"')) {
259263
name = name.substr(1, name.length-2);

lib/services/platform-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ export class PlatformService implements IPlatformService {
158158
shell.cp("-R", appSourceDirectoryPath, platformData.appDestinationDirectoryPath);
159159

160160
// Copy App_Resources to project root folder
161-
this.$fs.ensureDirectoryExists(platformData.appResourcesDestinationDirectoryPath).wait(); // Should be deleted
162161
var appResourcesDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
162+
this.$fs.ensureDirectoryExists(platformData.appResourcesDestinationDirectoryPath).wait();
163163
if (this.$fs.exists(appResourcesDirectoryPath).wait()) {
164-
this.$fs.deleteDirectory(platformData.appResourcesDestinationDirectoryPath).wait(); // Respect removed files
164+
platformData.platformProjectService.prepareAppResources(appResourcesDirectoryPath).wait();
165165
shell.cp("-R", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), platformData.appResourcesDestinationDirectoryPath);
166166
this.$fs.deleteDirectory(appResourcesDirectoryPath).wait();
167167
}

test/npm-support.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ describe("Npm support tests", () => {
123123
frameworkPackageName: "tns-android",
124124
normalizedPlatformName: "Android",
125125
platformProjectService: {
126-
prepareProject: () => Future.fromResult()
126+
prepareProject: () => Future.fromResult(),
127+
prepareAppResources: () => Future.fromResult()
127128
}
128129
}
129130
};

test/stubs.ts

+3
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
297297
updatePlatform(currentVersion: string, newVersion: string): IFuture<void> {
298298
return Future.fromResult();
299299
}
300+
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void> {
301+
return Future.fromResult();
302+
}
300303
}
301304

302305
export class ProjectDataService implements IProjectDataService {

0 commit comments

Comments
 (0)