forked from play-co/native-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxcode.js
More file actions
129 lines (115 loc) · 3.94 KB
/
xcode.js
File metadata and controls
129 lines (115 loc) · 3.94 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var path = require('path');
var ff = require('ff');
var exec = require('child_process').exec;
var CONFIG_RELEASE = "Release";
var CONFIG_DEBUG = "Debug";
exports.buildApp = function (builder, appName, targetSDK, configurationName, projectPath, next) {
var f = ff(function() {
var args = [
'-target',
appName,
'-sdk',
targetSDK,
'-configuration',
configurationName,
'-jobs',
8,
];
console.log("Invoking xcodebuild with parameters:", JSON.stringify(args, undefined, 4));
builder.common.spawn('xcodebuild', args, {
cwd: path.resolve(projectPath)
}, f.slotPlain());
}, function(code) {
console.log("xcodebuild exited with code", code);
if (code != 0) {
f.fail("Build failed. Is the manifest.json file properly configured?");
}
}).cb(next);
};
exports.signApp = function (builder, projectPath, appName, outputIPAPath, configurationName, signingIdentity, provisionPath, next) {
var f = ff(function() {
var args = [
'-sdk',
'iphoneos',
'PackageApplication',
'-v',
path.resolve(path.join(projectPath, 'build/'+configurationName+'-iphoneos/'+appName+'.app')),
'-o',
path.resolve(outputIPAPath),
'--sign',
signingIdentity,
'--embed',
path.resolve(provisionPath)
];
console.log("Invoking xcrun with parameters:", JSON.stringify(args, undefined, 4));
builder.common.child('xcrun', args, {
cwd: path.resolve(projectPath)
}, f.slotPlain());
}, function(code) {
console.log("xcrun exited with code", code);
if (code != 0) {
f.fail("Unable to sign the app. Are your provision profile and developer key active?");
}
}).cb(next);
};
// lifted (and edited) from: http://st-on-it.blogspot.com/2011/05/how-to-read-user-input-with-nodejs.html
var ask = function(question, condition, callback) {
var stdin = process.stdin, stdout = process.stdout;
stdin.resume();
stdout.write(question + ": ");
stdin.once('data', function(data) {
data = data.toString().trim();
if (condition(data)) {
callback(data);
} else {
ask(question, condition, callback);
}
});
};
// This function produces an IPA file by calling buildApp and signApp
var buildIPA = function(targetSDK, builder, projectPath, appName, isDebug, provisionPath, signingIdentity, outputIPAPath, next) {
console.log("using sdk:", targetSDK);
var configurationName = isDebug ? CONFIG_DEBUG : CONFIG_RELEASE;
var f = ff(function() {
exports.buildApp(builder, appName, targetSDK, configurationName, projectPath, f());
}, function() {
exports.signApp(builder, projectPath, appName, outputIPAPath, configurationName, signingIdentity, provisionPath, f());
}).error(function(err) {
console.error('ERROR:', err);
process.exit(2);
}).cb(next);
};
// This command figures out which SDKs are available, selects one, and calls buildIPA
exports.buildIPA = function(builder, projectPath, appName, isDebug, provisionPath, signingIdentity, outputIPAPath, chooseSDK, next) {
exec('xcodebuild -version -sdk', function(error, data, stderror) {
var SDKs = [];
if (error) {
console.log("Error building SDK list:", error, stderror);
} else {
var sdkstart = data.indexOf('iphoneos');
while (sdkstart != -1) {
var sdkend = data.indexOf(')', sdkstart);
var sdkstr = data.slice(sdkstart, sdkend);
SDKs.push(sdkstr);
console.log("found sdk:", sdkstr);
sdkstart = data.indexOf('iphoneos', sdkend);
}
SDKs.sort().reverse();
if (chooseSDK && SDKs.length > 1) {
return ask("choose sdk [default: " + SKDs[0] + "]", function(sdk) {
if (sdk != "" && SDKs.indexOf(sdk) == -1) {
console.log(sdk, "is not available");
console.log("options:", SDKs);
return false;
}
return true;
}, function(sdk) {
buildIPA(sdk || SDKS[0], builder, projectPath, appName, isDebug,
provisionPath, signingIdentity, outputIPAPath, next);
});
}
}
buildIPA(SDKs.length ? SDKs[0] : 'iphoneos6.0', builder, projectPath,
appName, isDebug, provisionPath, signingIdentity, outputIPAPath, next);
});
};