-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstallios.js
More file actions
executable file
·338 lines (301 loc) · 13.4 KB
/
installios.js
File metadata and controls
executable file
·338 lines (301 loc) · 13.4 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/usr/bin/env node
var packageJson = require('./package.json');
var execSync = require('child_process').execSync;
var path = require('path');
var fs = require('fs');
var interactiveOAuth = require('./scripts/interactive-oauth');
var bootconfig = require('./scripts/update-bootconfig');
// ============================================================================
// Validation Functions
// ============================================================================
function validateEnvironment() {
console.log('🔍 Validating environment...\n');
var errors = [];
var warnings = [];
// Check xcodegen
try {
execSync('which xcodegen', { stdio: 'pipe' });
console.log(' ✅ xcodegen found');
} catch (e) {
errors.push('xcodegen not found. Install: brew install xcodegen');
}
// Check pod
try {
execSync('which pod', { stdio: 'pipe' });
console.log(' ✅ CocoaPods found');
} catch (e) {
errors.push('CocoaPods not found. Install: sudo gem install cocoapods');
}
// Check Boost
try {
execSync('brew --prefix boost', { stdio: 'pipe' });
console.log(' ✅ Boost found');
} catch (e) {
errors.push('Boost not found. Install: brew install boost');
}
// Check Node version
var nodeVersion = process.versions.node.split('.')[0];
if (parseInt(nodeVersion) < 18) {
warnings.push('Node version ' + nodeVersion + ' detected. Node 18+ recommended.');
} else {
console.log(' ✅ Node.js ' + process.versions.node);
}
// Report errors
if (errors.length > 0) {
console.error('\n❌ Environment validation failed:\n');
errors.forEach(function (err) {
console.error(' • ' + err);
});
process.exit(1);
}
// Report warnings
if (warnings.length > 0) {
console.warn('\n⚠️ Warnings:\n');
warnings.forEach(function (warn) {
console.warn(' • ' + warn);
});
}
console.log('\n✅ Environment validation passed\n');
}
// ============================================================================
// Main Installation Flow
// ============================================================================
// Check for help flag
if (process.argv.includes('--help') || process.argv.includes('-h')) {
console.log('\n╔═══════════════════════════════════════════════════════════════╗');
console.log('║ iOS Multi-App Installation - AgentforceSDK ║');
console.log('╚═══════════════════════════════════════════════════════════════╝\n');
console.log('Usage:');
console.log(' node installios.js [target]\n');
console.log('Target:');
console.log(' service Install Service Agent only (no Mobile SDK)');
console.log(' employee Install Employee Agent only (with Mobile SDK)');
console.log(' all Install both apps (default)\n');
console.log('Examples:');
console.log(' node installios.js service # Service Agent only');
console.log(' node installios.js employee # Employee Agent only');
console.log(' node installios.js all # Both apps');
console.log(' node installios.js # Same as "all"\n');
console.log('OAuth Configuration:');
console.log(' When installing Employee Agent, you will be prompted to configure');
console.log(' OAuth credentials interactively during installation.\n');
process.exit(0);
}
// Parse target argument: service, employee, all (default: all)
var target = process.argv[2] || 'all';
if (!['service', 'employee', 'all'].includes(target)) {
console.error('❌ Invalid target: ' + target);
console.error(' Usage: node installios.js [service|employee|all]');
console.error(' Examples:');
console.error(' node installios.js service # Service Agent only (no Mobile SDK)');
console.error(' node installios.js employee # Employee Agent only (with Mobile SDK)');
console.error(' node installios.js all # Both apps (with Mobile SDK)');
console.error(' node installios.js # Same as "all" (backward compatible)');
process.exit(1);
}
console.log('\n╔═══════════════════════════════════════════════════════════════╗');
console.log('║ iOS Multi-App Installation - AgentforceSDK ║');
console.log('╚═══════════════════════════════════════════════════════════════╝\n');
// Validate environment before starting
validateEnvironment();
// Display installation plan
console.log('📋 Installation Plan:');
console.log(' Target: ' + target);
console.log(' Mobile SDK: ' + (target === 'service' ? '❌ Not included' : '✅ Included'));
console.log(
' Apps to build: ' +
(target === 'all'
? 'ServiceAgent + EmployeeAgent'
: target === 'service'
? 'ServiceAgent'
: 'EmployeeAgent'),
);
console.log('\n🔧 Steps:');
console.log(' 1. Install npm dependencies');
console.log(' 2. Apply patches (patch-package)');
if (target !== 'service') {
console.log(' 2.5. Configure OAuth (Employee Agent)');
console.log(' 3. Build react-native-force (Mobile SDK bridge)');
}
console.log(' 4. Configure Node.js path');
console.log(' 5. Generate Xcode project (xcodegen)');
console.log(' 6. Install CocoaPods');
console.log(' 7. Add Pods target dependencies');
console.log(' 8. Save lock files');
console.log('\n▶️ Starting installation...\n');
console.log('═══════════════════════════════════════════════════════════════\n');
// Step 1: Install npm dependencies
console.log('📦 Step 1/8: Installing npm dependencies...');
try {
execSync('npm install --legacy-peer-deps --ignore-scripts', { stdio: [0, 1, 2] });
console.log('✅ Step 1/8: npm dependencies installed\n');
} catch (e) {
console.error('❌ npm install failed. Try: npm install --legacy-peer-deps --ignore-scripts');
process.exit(1);
}
// Step 2: Apply patches
console.log('📦 Step 2/8: Applying patches (e.g. cli-platform-apple for multi-scheme iOS)...');
try {
execSync('npx patch-package', { stdio: [0, 1, 2] });
console.log('✅ Step 2/8: Patches applied\n');
} catch (e) {
console.warn('⚠️ patch-package failed (optional if no patches)\n');
}
// Step 2.5: Configure OAuth for Employee Agent (async)
async function configureOAuthStep() {
if (target === 'employee' || target === 'all') {
console.log('🔐 Step 2.5/8: Configuring OAuth (Employee Agent only)...\n');
try {
var oauthConfig = await interactiveOAuth.promptOAuthConfig();
if (oauthConfig) {
var bootconfigPath = path.join(__dirname, 'ios/EmployeeAgent/bootconfig.plist');
console.log(' 📝 Updating bootconfig.plist...');
bootconfig.backupBootconfig(bootconfigPath);
var result = bootconfig.updateIOSBootconfig(bootconfigPath, oauthConfig);
if (result.modified) {
console.log(' ✅ OAuth configuration updated successfully\n');
}
if (result.warnings.length > 0) {
console.warn(' ⚠️ Warnings during configuration:');
result.warnings.forEach(function (warn) {
console.warn(' • ' + warn);
});
console.log('');
}
bootconfig.printSecurityWarning();
}
} catch (err) {
console.error('❌ Failed to configure OAuth: ' + err.message);
process.exit(1);
}
}
}
// Run OAuth configuration (async)
(async function () {
await configureOAuthStep();
// Continue with remaining steps
continueInstallation();
})();
function continueInstallation() {
// Step 3: Build react-native-force for Employee Agent (provides Mobile SDK React Native bridge)
if (target === 'employee' || target === 'all') {
console.log('📦 Step 3/8: Building react-native-force (Mobile SDK React Native bridge)...');
try {
execSync('npm run build:force', { stdio: [0, 1, 2] });
console.log('✅ Step 3/8: react-native-force built\n');
} catch (e) {
console.warn('⚠️ build:force failed (optional if already built)\n');
}
} else {
console.log('⏭️ Step 3/8: Skipped (Service Agent does not need Mobile SDK bridge)\n');
}
// Step 4: Configure Node.js path
console.log('🔧 Step 4/8: Configuring Node.js path for Xcode...');
var nodePath = process.execPath;
if (!nodePath || !fs.existsSync(nodePath)) {
try {
nodePath = execSync('which node', { encoding: 'utf-8' }).trim();
} catch (e) {
try {
nodePath = execSync('command -v node', { encoding: 'utf-8' }).trim();
} catch (e2) {
console.error('❌ Could not find Node.js path. Set NODE_BINARY in ios/.xcode.env');
process.exit(1);
}
}
}
if (!fs.existsSync(nodePath)) {
console.error(
'❌ Node path ' + nodePath + ' does not exist. Set NODE_BINARY in ios/.xcode.env',
);
process.exit(1);
}
console.log(' NODE_BINARY=' + nodePath);
execSync('echo export NODE_BINARY=' + nodePath + ' > .xcode.env', { stdio: 'pipe', cwd: 'ios' });
console.log('✅ Step 4/8: Node.js path configured (ios/.xcode.env)\n');
// Use separate Podfiles: service = subset, employee/all = full (employee Podfile)
var podfileName = target === 'service' ? 'Podfile.service' : 'Podfile.employee';
var lockFileName = target === 'service' ? 'Podfile.service.lock' : 'Podfile.employee.lock';
var iosDir = path.join(__dirname, 'ios');
var sourcePodfile = path.join(iosDir, podfileName);
var activePodfile = path.join(iosDir, 'Podfile');
var activeLock = path.join(iosDir, 'Podfile.lock');
var sourceLock = path.join(iosDir, lockFileName);
console.log('📋 Preparing Podfile for target: ' + target);
console.log(
' Using: ' +
podfileName +
' (' +
(target === 'service' ? 'Service Agent only' : 'Employee Agent / both apps') +
')',
);
fs.copyFileSync(sourcePodfile, activePodfile);
if (fs.existsSync(sourceLock)) {
fs.copyFileSync(sourceLock, activeLock);
console.log(' Restored: ' + lockFileName);
} else {
if (fs.existsSync(activeLock)) {
fs.unlinkSync(activeLock);
}
console.log(' No existing lock file found (will generate new one)');
}
console.log('');
// Step 5: Generate Xcode project
console.log('📝 Step 5/8: Generating Xcode project with xcodegen...');
try {
execSync('xcodegen generate', { stdio: [0, 1, 2], cwd: 'ios' });
console.log('✅ Step 5/8: Xcode project generated\n');
} catch (e) {
console.error(
'❌ xcodegen generation failed. Ensure xcodegen is installed: brew install xcodegen',
);
process.exit(1);
}
// Step 6: Install CocoaPods
console.log('🍎 Step 6/8: Installing CocoaPods dependencies...');
console.log(' This may take a few minutes...\n');
try {
var env = { ...process.env };
delete env.NODE_EXTRA_CA_CERTS;
env.NODE_NO_WARNINGS = '1';
execSync('pod install', { stdio: [0, 1, 2], cwd: 'ios', env: env });
console.log('\n✅ Step 6/8: CocoaPods installed\n');
} catch (e) {
console.error('\n❌ pod install failed. Try: cd ios && pod install --repo-update');
process.exit(1);
}
// Step 7: Pods target dependencies added automatically via Podfile.common.rb post_install hook
console.log('✅ Step 7/8: Pods target dependencies added (via post_install hook)\n');
// Step 8: Save lock file
console.log('💾 Step 8/8: Managing lock files...');
if (fs.existsSync(activeLock)) {
fs.copyFileSync(activeLock, sourceLock);
console.log(' ✅ Saved ' + lockFileName);
} else {
console.warn(' ⚠️ No Podfile.lock generated (unexpected)');
}
console.log('\n═══════════════════════════════════════════════════════════════\n');
console.log('✅ iOS setup complete!');
console.log('\n📱 Next steps:\n');
if (target === 'service') {
console.log(' 🚀 Run Service Agent:');
console.log(' npm run ios:service\n');
console.log(' 📂 Or open in Xcode:');
console.log(' open ios/ReactAgentforce.xcworkspace');
console.log(' Select scheme: ServiceAgent');
} else if (target === 'employee') {
console.log(' 🚀 Run Employee Agent:');
console.log(' npm run ios:employee\n');
console.log(' 📂 Or open in Xcode:');
console.log(' open ios/ReactAgentforce.xcworkspace');
console.log(' Select scheme: EmployeeAgent');
} else {
console.log(' 🚀 Run either app:');
console.log(' npm run ios:service (Service Agent)');
console.log(' npm run ios:employee (Employee Agent)\n');
console.log(' 📂 Or open in Xcode:');
console.log(' open ios/ReactAgentforce.xcworkspace');
console.log(' Select scheme: ServiceAgent or EmployeeAgent');
}
console.log('\n═══════════════════════════════════════════════════════════════\n');
} // End of continueInstallation()