Skip to content
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
1 change: 0 additions & 1 deletion lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface IPlatformData {
projectRoot: string;
normalizedPlatformName: string;
appDestinationDirectoryPath: string;
appResourcesDestinationDirectoryPath: string;
deviceBuildOutputPath: string;
emulatorBuildOutputPath?: string;
validPackageNamesForDevice: string[];
Expand Down
3 changes: 2 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ interface IPlatformProjectService {
preparePluginNativeCode(pluginData: IPluginData): IFuture<void>;
removePluginNativeCode(pluginData: IPluginData): IFuture<void>;
afterPrepareAllPlugins(): IFuture<void>;
getAppResourcesDestinationDirectoryPath(): IFuture<string>;
}

interface IAndroidProjectPropertiesManager {
getProjectReferences(): IFuture<ILibRef[]>;
addProjectReference(referencePath: string): IFuture<void>;
removeProjectReference(referencePath: string): IFuture<void>;
removeProjectReference(referencePath: string): IFuture<void>;
}
13 changes: 9 additions & 4 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
frameworkPackageName: "tns-android",
normalizedPlatformName: "Android",
appDestinationDirectoryPath: path.join(projectRoot, "src", "main", "assets"),
appResourcesDestinationDirectoryPath: path.join(projectRoot, "src", "main", "res"),
platformProjectService: this,
emulatorServices: this.$androidEmulatorServices,
projectRoot: projectRoot,
Expand All @@ -64,6 +63,12 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
return this._platformData;
}

public getAppResourcesDestinationDirectoryPath(): IFuture<string> {
return (() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may use future.fromResult here

return path.join(this.platformData.projectRoot, "src", "main", "res");
}).future<string>()();
}

public validate(): IFuture<void> {
return (() => {
this.validatePackageName(this.$projectData.projectId);
Expand Down Expand Up @@ -108,7 +113,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
private copyResValues(projectRoot: string, frameworkDir: string, versionNumber: string): IFuture<void> {
return (() => {
let resSourceDir = path.join(frameworkDir, "src", "main", "res");
let resDestinationDir = this.platformData.appResourcesDestinationDirectoryPath;
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath().wait();
this.$fs.createDirectory(resDestinationDir).wait();
let versionDirName = AndroidProjectService.VALUES_VERSION_DIRNAME_PREFIX + versionNumber;
let directoriesToCopy = [AndroidProjectService.VALUES_DIRNAME];
Expand Down Expand Up @@ -140,7 +145,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
let manifestPath = this.platformData.configurationFilePath;
shell.sed('-i', /__PACKAGE__/, this.$projectData.projectId, manifestPath);

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

Expand Down Expand Up @@ -239,7 +244,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
let valuesDirRegExp = /^values/;
let resourcesDirs = this.$fs.readDirectory(resourcesDirPath).wait().filter(resDir => !resDir.match(valuesDirRegExp));
_.each(resourcesDirs, resourceDir => {
this.$fs.deleteDirectory(path.join(this.platformData.appResourcesDestinationDirectoryPath, resourceDir)).wait();
this.$fs.deleteDirectory(path.join(this.getAppResourcesDestinationDirectoryPath().wait(), resourceDir)).wait();
});
}).future<void>()();
}
Expand Down
28 changes: 22 additions & 6 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as path from "path";
import * as shell from "shelljs";
import * as util from "util";
import * as os from "os";
import * as semver from "semver";
import * as xcode from "xcode";
import * as constants from "../constants";
import * as helpers from "../common/helpers";
Expand All @@ -28,7 +29,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
private $logger: ILogger,
private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices,
private $options: IOptions,
private $injector: IInjector) {
private $injector: IInjector,
private $projectDataService: IProjectDataService) {
super($fs);
}

Expand All @@ -39,7 +41,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
frameworkPackageName: "tns-ios",
normalizedPlatformName: "iOS",
appDestinationDirectoryPath: path.join(projectRoot, this.$projectData.projectName),
appResourcesDestinationDirectoryPath: path.join(projectRoot, this.$projectData.projectName, "Resources"),
platformProjectService: this,
emulatorServices: this.$iOSEmulatorServices,
projectRoot: projectRoot,
Expand All @@ -61,6 +62,19 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
};
}

public getAppResourcesDestinationDirectoryPath(): IFuture<string> {
return (() => {
this.$projectDataService.initialize(this.$projectData.projectDir);
let frameworkVersion = this.$projectDataService.getValue(this.platformData.frameworkPackageName).wait()["version"];

if(semver.lt(frameworkVersion, "1.3.0")) {
return path.join(this.platformData.projectRoot, this.$projectData.projectName, "Resources", "icons");
}

return path.join(this.platformData.projectRoot, this.$projectData.projectName, "Resources");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both return statements build the same path - is this expected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paths are different - path.join(this.platformData.projectRoot, this.$projectData.projectName, "Resources", "icons"); and path.join(this.platformData.projectRoot, this.$projectData.projectName, "Resources");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh dear, the last part ("icons") went on another line on my monitor and I missed it completely. I am so sorry.

}).future<string>()();
}

public validate(): IFuture<void> {
return (() => {
try {
Expand Down Expand Up @@ -258,25 +272,27 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
this.$logger.trace("Images from Xcode project");
this.$logger.trace(xcodeProjectImages);

let appResourcesImages = this.$fs.readDirectory(this.platformData.appResourcesDestinationDirectoryPath).wait();
let appResourcesImages = this.$fs.readDirectory(this.getAppResourcesDestinationDirectoryPath().wait()).wait();
this.$logger.trace("Current images from App_Resources");
this.$logger.trace(appResourcesImages);

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

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

this.savePbxProj(project).wait();
}
}).future<void>()();
}

public prepareAppResources(appResourcesDirectoryPath: string): IFuture<void> {
return this.$fs.deleteDirectory(this.platformData.appResourcesDestinationDirectoryPath);
return (() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can unwrap the return -> wait -> future chain

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have .wait inside the function

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I feel stupid :(

this.$fs.deleteDirectory(this.getAppResourcesDestinationDirectoryPath().wait()).wait();
}).future<void>()();
}

private get projectPodFilePath(): string {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ export class PlatformService implements IPlatformService {
shell.cp("-Rf", appSourceDirectoryPath, platformData.appDestinationDirectoryPath);

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

Expand Down
3 changes: 2 additions & 1 deletion test/npm-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ function setupProject(): IFuture<any> {
platformProjectService: {
prepareProject: () => Future.fromResult(),
prepareAppResources: () => Future.fromResult(),
afterPrepareAllPlugins: () => Future.fromResult()
afterPrepareAllPlugins: () => Future.fromResult(),
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
}
};
};
Expand Down
6 changes: 4 additions & 2 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ describe('Platform Service Tests', () => {
validate: () => Future.fromResult(),
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
interpolateData: (projectRoot: string) => Future.fromResult(),
afterCreateProject: (projectRoot: string) => Future.fromResult()
afterCreateProject: (projectRoot: string) => Future.fromResult(),
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
}
};
};
Expand Down Expand Up @@ -276,7 +277,8 @@ describe('Platform Service Tests', () => {
validate: () => Future.fromResult(),
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
interpolateData: (projectRoot: string) => Future.fromResult(),
afterCreateProject: (projectRoot: string) => Future.fromResult()
afterCreateProject: (projectRoot: string) => Future.fromResult(),
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
}
};
};
Expand Down
7 changes: 4 additions & 3 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ export class PlatformsDataStub implements IPlatformsData {
validPackageNamesForDevice: [],
frameworkFilesExtensions: [],
appDestinationDirectoryPath: "",
appResourcesDestinationDirectoryPath: "",
preparePluginNativeCode: () => Future.fromResult(),
removePluginNativeCode: () => Future.fromResult(),
afterPrepareAllPlugins: () => Future.fromResult()
Expand All @@ -273,10 +272,12 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
deviceBuildOutputPath: "",
validPackageNamesForDevice: [],
frameworkFilesExtensions: [],
appDestinationDirectoryPath: "",
appResourcesDestinationDirectoryPath: "",
appDestinationDirectoryPath: ""
};
}
getAppResourcesDestinationDirectoryPath(): IFuture<string>{
return Future.fromResult("");
}
validate(): IFuture<void> {
return Future.fromResult();
}
Expand Down