Skip to content

Commit 7eabb6d

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Create and build for iOS
1 parent 3f42363 commit 7eabb6d

File tree

3 files changed

+67
-17
lines changed

3 files changed

+67
-17
lines changed

lib/definitions/project.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface IPlatformSpecificProjectService {
2525
validate(): void;
2626
checkRequirements(): IFuture<void>;
2727
createProject(projectRoot: string, frameworkDir: string): IFuture<void>;
28-
interpolateData(projectRoot: string): void;
28+
interpolateData(projectRoot: string): IFuture<void>;
2929
executePlatformSpecificAction(projectRoot: string, frameworkDir: string): void;
3030
buildProject(projectRoot: string): IFuture<void>;
3131
}

lib/services/platform-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PlatformsData implements IPlatformsData {
2222
};
2323

2424
constructor($projectData: IProjectData) {
25-
this.platformsData["ios"].projectRoot = "";
25+
this.platformsData["ios"].projectRoot = path.join($projectData.platformsDir, "ios", $projectData.projectName);
2626
this.platformsData["android"].projectRoot = path.join($projectData.platformsDir, "android");
2727
}
2828

lib/services/project-service.ts

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,15 @@ class AndroidProjectService implements IPlatformSpecificProjectService {
290290
}).future<any>()();
291291
}
292292

293-
public interpolateData(projectRoot: string): void {
294-
// Interpolate the activity name and package
295-
var stringsFilePath = path.join(projectRoot, 'res', 'values', 'strings.xml');
296-
shell.sed('-i', /__NAME__/, this.$projectData.projectName, stringsFilePath);
297-
shell.sed('-i', /__TITLE_ACTIVITY__/, this.$projectData.projectName, stringsFilePath);
298-
shell.sed('-i', /__NAME__/, this.$projectData.projectName, path.join(projectRoot, '.project'));
299-
shell.sed('-i', /__PACKAGE__/, this.$projectData.projectId, path.join(projectRoot, "AndroidManifest.xml"));
293+
public interpolateData(projectRoot: string): IFuture<void> {
294+
return (() => {
295+
// Interpolate the activity name and package
296+
var stringsFilePath = path.join(projectRoot, 'res', 'values', 'strings.xml');
297+
shell.sed('-i', /__NAME__/, this.$projectData.projectName, stringsFilePath);
298+
shell.sed('-i', /__TITLE_ACTIVITY__/, this.$projectData.projectName, stringsFilePath);
299+
shell.sed('-i', /__NAME__/, this.$projectData.projectName, path.join(projectRoot, '.project'));
300+
shell.sed('-i', /__PACKAGE__/, this.$projectData.projectId, path.join(projectRoot, "AndroidManifest.xml"));
301+
}).future<void>()();
300302
}
301303

302304
public executePlatformSpecificAction(projectRoot: string, frameworkDir: string) {
@@ -420,32 +422,80 @@ class AndroidProjectService implements IPlatformSpecificProjectService {
420422
$injector.register("androidProjectService", AndroidProjectService);
421423

422424
class IOSProjectService implements IPlatformSpecificProjectService {
423-
public validate(): void {
425+
private static PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__";
424426

425-
}
427+
constructor(private $childProcess: IChildProcess,
428+
private $projectData: IProjectData,
429+
private $fs: IFileSystem,
430+
private $errors: IErrors) { }
431+
432+
public validate(): void { }
426433

427434
public checkRequirements(): IFuture<void> {
428435
return (() => {
436+
try {
437+
this.$childProcess.exec("which xcodebuild").wait();
438+
} catch(error) {
439+
this.$errors.fail("The command 'which xcodebuild' failed. Make sure you have the Xcode installed");
440+
}
429441
}).future<void>()();
430442
}
431443

432-
public interpolateData(): void {
444+
public interpolateData(projectRoot: string): IFuture<void> {
445+
return (() => {
446+
this.replaceFileName("-Info.plist", projectRoot).wait();
447+
this.replaceFileName("-Prefix.pch", projectRoot).wait();
448+
this.replaceFileName(".xcodeproj", this.$projectData.platformsDir).wait();
433449

434-
}
450+
/* this.$fs.rename(path.join(this.$projectData.platformsDir, IOSProjectService.PROJECT_NAME_PLACEHOLDER + ".xcodeproj"),
451+
path.join(this.$projectData.platformsDir, this.$projectData.projectName + ".xcodeproj")).wait(); */
435452

436-
public executePlatformSpecificAction(): void {
453+
var pbxprojFilePath = path.join(this.$projectData.platformsDir, this.$projectData.projectName + ".xcodeproj", "project.pbxproj");
454+
this.replaceFileContent(pbxprojFilePath).wait();
455+
}).future<void>()();
456+
}
437457

458+
public createProject(projectRoot: string, frameworkDir: string): IFuture<void> {
459+
return (() => {
460+
shell.cp("-r", path.join(frameworkDir, "*"), this.$projectData.platformsDir);
461+
this.$fs.rename(path.join(this.$projectData.platformsDir, IOSProjectService.PROJECT_NAME_PLACEHOLDER), projectRoot).wait();
462+
}).future<void>()();
438463
}
439464

440-
public createProject(): IFuture<void> {
465+
public buildProject(projectRoot: string): IFuture<void> {
441466
return (() => {
467+
var args = [
468+
"-project", path.join(this.$projectData.platformsDir, "ios", this.$projectData.projectName + ".xcodeproj"),
469+
"-target", this.$projectData.projectName,
470+
"-configuration", options.release || "Debug",
471+
"-sdk", "iphonesimulator",
472+
"build",
473+
"ARCHS=\"armv7 armv7s arm64\"",
474+
"VALID_ARCHS=\"armv7 armv7s arm64\"",
475+
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build") + ""
476+
];
477+
this.$childProcess.spawn("xcodebuild", args, {cwd: options, stdio: 'inherit'});
478+
}).future<void>()();
479+
}
442480

443-
}).future<any>()();
481+
public executePlatformSpecificAction(projectRoot: string, frameworkDir: string): void {
482+
483+
}
484+
485+
private replaceFileContent(file: string): IFuture<void> {
486+
return (() => {
487+
var fileContent = this.$fs.readText(file).wait();
488+
var replacedContent = helpers.stringReplaceAll(fileContent, IOSProjectService.PROJECT_NAME_PLACEHOLDER, this.$projectData.projectName);
489+
this.$fs.writeFile(file, replacedContent).wait();
490+
}).future<void>()();
444491
}
445492

446-
public buildProject(): IFuture<void> {
493+
private replaceFileName(fileNamePart: string, projectRoot: string): IFuture<void> {
447494
return (() => {
495+
var oldFileName = IOSProjectService.PROJECT_NAME_PLACEHOLDER + fileNamePart;
496+
var newFileName = this.$projectData.projectName + fileNamePart;
448497

498+
this.$fs.rename(path.join(projectRoot, oldFileName), path.join(projectRoot, newFileName)).wait();
449499
}).future<void>()();
450500
}
451501
}

0 commit comments

Comments
 (0)