-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuilder_ios.ts
114 lines (90 loc) · 4.39 KB
/
builder_ios.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"use strict";
import * as child_process from "child_process";
import * as fse from "fs-extra";
import * as path from "path";
import { AppleBuilder } from "./builder_apple";
import { ICompilation } from "./compilation";
import * as globals from "./globals";
export interface IIOSBuildJSON {
ios: {
release: {
codeSignIdentity: string,
provisioningProfile: string,
},
};
}
export class IOSBuilder extends AppleBuilder {
protected get distributionCodeSigningIdentity(): string {
return "iPhone Distribution";
}
protected get developmentCodeSigningIdentity(): string {
return "iPhone Developer";
}
protected get provisioningExtension(): string {
return ".mobileprovision";
}
protected get platform(): string {
return "ios";
}
protected get getJson(): IIOSBuildJSON {
return {
ios: {
release: {
codeSignIdentity: this.distributionCodeSigningIdentity,
provisioningProfile: this._uuid,
},
},
};
}
protected get packageFormat(): string {
return "ipa";
}
protected get findIdentityCommand(): string {
return "security find-identity -v -p codesigning";
}
public constructor(env: globals.CocoonEnvironment, data: ICompilation, configPath: string, logLevel?: string) {
super(env, data, configPath, logLevel);
this.name = "IOSBuilder";
}
protected getCreateAppCommand(): string {
const provisioningPath = path.join(globals.getHome(), "Library", "MobileDevice", "Provisioning Profiles",
this._uuid + this.provisioningExtension);
const provisionedStrings = child_process.execSync("strings '" + provisioningPath + "'").toString();
const method = (provisionedStrings.includes("ProvisionedDevices")) ? "ad-hoc" : "app-store";
const tmpPath: string = path.join(globals.getCertsPath(this.env, this.data.code, this.data.starttime),
this.data.starttime + "_tmp.plist");
child_process.execSync("openssl smime -inform der -verify -noverify -in '" + provisioningPath
+ "' > '" + tmpPath + "'").toString().trim();
const profileID = child_process.execSync("/usr/libexec/PlistBuddy -c 'Print :UUID' '" + tmpPath + "'")
.toString().trim();
const configParser: any = globals.getConfigParser(this.env, this.data.libVersion);
const cordovaUtil: any = globals.getCordovaUtil(this.env, this.data.libVersion);
const xml = cordovaUtil.projectConfig(globals.getProjectPath(this.env, this.data.code, this.data.starttime));
const cfg = new configParser(xml);
const keychain = this.data.code + ".keychain-db";
const output = child_process.execSync(this.findIdentityCommand + " '" + keychain
+ "' | grep '" + this.distributionCodeSigningIdentity + "'").toString().trim();
const certIdentity = output.match(/\) *(.+) "/)[1];
const teamIdentity = output.match(/"[^"]+\((.+)\)"/)[1];
this.generateExportOptionsPlist(method, cfg.packageName(), certIdentity, teamIdentity, profileID);
return "xcodebuild \
-exportArchive \
-exportOptionsPlist '" +
path.join(globals.getCordovaProjectTmpPath(this.env, this.data.code, this.data.starttime) +
"export_options.plist") + "' \
-archivePath '" + path.join("build", cfg.name() + ".xcarchive") + "' \
-exportPath '" + path.join("build", cfg.name() + "." + this.packageFormat) + "'";
}
private generateExportOptionsPlist(method: string, bundleId: string, certIdentity: string, teamIdentity: string,
profileName: string): void {
const templatePlistFile = fse.readFileSync(path.join(path.dirname(require.main.filename), "..", "assets",
this.platform, "export_options.plist"), {encoding: "UTF8"});
const result = templatePlistFile.replace(/__METHOD__/g, method)
.replace(/__APP_BUNDLE_ID__/g, bundleId)
.replace(/__CERT_ID__/g, certIdentity)
.replace(/__TEAM_ID__/g, teamIdentity)
.replace(/__PROFILE_UUID__/g, profileName);
fse.writeFileSync(path.join(globals.getCordovaProjectTmpPath(this.env, this.data.code, this.data.starttime)
+ "export_options.plist"), result, {encoding: "UTF8"});
}
}