From 7eabb6da240cf0ea55c25b100dbdd3f3a0517431 Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Mon, 21 Jul 2014 10:10:19 +0300 Subject: [PATCH] Create and build for iOS --- lib/definitions/project.d.ts | 2 +- lib/services/platform-service.ts | 2 +- lib/services/project-service.ts | 80 ++++++++++++++++++++++++++------ 3 files changed, 67 insertions(+), 17 deletions(-) diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 7b6b80be7d..c68a9b6924 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -25,7 +25,7 @@ interface IPlatformSpecificProjectService { validate(): void; checkRequirements(): IFuture; createProject(projectRoot: string, frameworkDir: string): IFuture; - interpolateData(projectRoot: string): void; + interpolateData(projectRoot: string): IFuture; executePlatformSpecificAction(projectRoot: string, frameworkDir: string): void; buildProject(projectRoot: string): IFuture; } \ No newline at end of file diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 0168e7d7a9..d8fdf23622 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -22,7 +22,7 @@ class PlatformsData implements IPlatformsData { }; constructor($projectData: IProjectData) { - this.platformsData["ios"].projectRoot = ""; + this.platformsData["ios"].projectRoot = path.join($projectData.platformsDir, "ios", $projectData.projectName); this.platformsData["android"].projectRoot = path.join($projectData.platformsDir, "android"); } diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index 764e624518..5590789f6c 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -290,13 +290,15 @@ class AndroidProjectService implements IPlatformSpecificProjectService { }).future()(); } - public interpolateData(projectRoot: string): void { - // Interpolate the activity name and package - var stringsFilePath = path.join(projectRoot, 'res', 'values', 'strings.xml'); - shell.sed('-i', /__NAME__/, this.$projectData.projectName, stringsFilePath); - shell.sed('-i', /__TITLE_ACTIVITY__/, this.$projectData.projectName, stringsFilePath); - shell.sed('-i', /__NAME__/, this.$projectData.projectName, path.join(projectRoot, '.project')); - shell.sed('-i', /__PACKAGE__/, this.$projectData.projectId, path.join(projectRoot, "AndroidManifest.xml")); + public interpolateData(projectRoot: string): IFuture { + return (() => { + // Interpolate the activity name and package + var stringsFilePath = path.join(projectRoot, 'res', 'values', 'strings.xml'); + shell.sed('-i', /__NAME__/, this.$projectData.projectName, stringsFilePath); + shell.sed('-i', /__TITLE_ACTIVITY__/, this.$projectData.projectName, stringsFilePath); + shell.sed('-i', /__NAME__/, this.$projectData.projectName, path.join(projectRoot, '.project')); + shell.sed('-i', /__PACKAGE__/, this.$projectData.projectId, path.join(projectRoot, "AndroidManifest.xml")); + }).future()(); } public executePlatformSpecificAction(projectRoot: string, frameworkDir: string) { @@ -420,32 +422,80 @@ class AndroidProjectService implements IPlatformSpecificProjectService { $injector.register("androidProjectService", AndroidProjectService); class IOSProjectService implements IPlatformSpecificProjectService { - public validate(): void { + private static PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__"; - } + constructor(private $childProcess: IChildProcess, + private $projectData: IProjectData, + private $fs: IFileSystem, + private $errors: IErrors) { } + + public validate(): void { } public checkRequirements(): IFuture { return (() => { + try { + this.$childProcess.exec("which xcodebuild").wait(); + } catch(error) { + this.$errors.fail("The command 'which xcodebuild' failed. Make sure you have the Xcode installed"); + } }).future()(); } - public interpolateData(): void { + public interpolateData(projectRoot: string): IFuture { + return (() => { + this.replaceFileName("-Info.plist", projectRoot).wait(); + this.replaceFileName("-Prefix.pch", projectRoot).wait(); + this.replaceFileName(".xcodeproj", this.$projectData.platformsDir).wait(); - } + /* this.$fs.rename(path.join(this.$projectData.platformsDir, IOSProjectService.PROJECT_NAME_PLACEHOLDER + ".xcodeproj"), + path.join(this.$projectData.platformsDir, this.$projectData.projectName + ".xcodeproj")).wait(); */ - public executePlatformSpecificAction(): void { + var pbxprojFilePath = path.join(this.$projectData.platformsDir, this.$projectData.projectName + ".xcodeproj", "project.pbxproj"); + this.replaceFileContent(pbxprojFilePath).wait(); + }).future()(); + } + public createProject(projectRoot: string, frameworkDir: string): IFuture { + return (() => { + shell.cp("-r", path.join(frameworkDir, "*"), this.$projectData.platformsDir); + this.$fs.rename(path.join(this.$projectData.platformsDir, IOSProjectService.PROJECT_NAME_PLACEHOLDER), projectRoot).wait(); + }).future()(); } - public createProject(): IFuture { + public buildProject(projectRoot: string): IFuture { return (() => { + var args = [ + "-project", path.join(this.$projectData.platformsDir, "ios", this.$projectData.projectName + ".xcodeproj"), + "-target", this.$projectData.projectName, + "-configuration", options.release || "Debug", + "-sdk", "iphonesimulator", + "build", + "ARCHS=\"armv7 armv7s arm64\"", + "VALID_ARCHS=\"armv7 armv7s arm64\"", + "CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build") + "" + ]; + this.$childProcess.spawn("xcodebuild", args, {cwd: options, stdio: 'inherit'}); + }).future()(); + } - }).future()(); + public executePlatformSpecificAction(projectRoot: string, frameworkDir: string): void { + + } + + private replaceFileContent(file: string): IFuture { + return (() => { + var fileContent = this.$fs.readText(file).wait(); + var replacedContent = helpers.stringReplaceAll(fileContent, IOSProjectService.PROJECT_NAME_PLACEHOLDER, this.$projectData.projectName); + this.$fs.writeFile(file, replacedContent).wait(); + }).future()(); } - public buildProject(): IFuture { + private replaceFileName(fileNamePart: string, projectRoot: string): IFuture { return (() => { + var oldFileName = IOSProjectService.PROJECT_NAME_PLACEHOLDER + fileNamePart; + var newFileName = this.$projectData.projectName + fileNamePart; + this.$fs.rename(path.join(projectRoot, oldFileName), path.join(projectRoot, newFileName)).wait(); }).future()(); } }