@blotch/angular-lynx-native 22.2.20 → 22.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/android/icon.d.ts +29 -0
- package/dist/android/icon.d.ts.map +1 -0
- package/dist/android/icon.js +142 -0
- package/dist/android/project.d.ts +2 -1
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +5 -2
- package/dist/generate.d.ts +2 -2
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +11 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -4
- package/dist/ios/build.d.ts +55 -12
- package/dist/ios/build.d.ts.map +1 -1
- package/dist/ios/build.js +203 -42
- package/dist/ios/iphone.d.ts +99 -0
- package/dist/ios/iphone.d.ts.map +1 -0
- package/dist/ios/iphone.js +204 -0
- package/dist/ios/project.d.ts +2 -0
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +10 -1
- package/dist/ios/run.d.ts +17 -2
- package/dist/ios/run.d.ts.map +1 -1
- package/dist/ios/run.js +30 -4
- package/dist/options.d.ts +49 -3
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +33 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +6 -0
- package/dist/png.d.ts +38 -0
- package/dist/png.d.ts.map +1 -1
- package/dist/png.js +167 -0
- package/dist/run.d.ts +12 -4
- package/dist/run.d.ts.map +1 -1
- package/package.json +5 -1
- package/templates/android/README.md +5 -1
- package/templates/android/app/src/main/AndroidManifest.xml +16 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +16 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareModule.kt +274 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +57 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +95 -0
- package/templates/android/app/src/main/res/mipmap/ic_launcher_round.xml +6 -0
- package/templates/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
- package/templates/android/app/src/main/res/xml/share_paths.xml +8 -0
- package/templates/ios/App/AngularLynxWebGL.h +7 -0
- package/templates/ios/App/AngularLynxWebGL.m +27 -0
- package/templates/ios/App/AngularLynxWebGLContext.m +139 -0
- package/templates/ios/App/LynxViewController.swift +2 -0
- package/templates/ios/App/ShareModule.swift +215 -0
package/dist/ios/build.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import { cpSync, existsSync, lstatSync, mkdirSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { X509Certificate } from 'node:crypto';
|
|
3
|
+
import os from 'node:os';
|
|
2
4
|
import path from 'node:path';
|
|
3
|
-
import { run } from "../process.js";
|
|
5
|
+
import { NativeBuildError, capture, run } from "../process.js";
|
|
4
6
|
import { escapeXml } from "../xml.js";
|
|
5
7
|
/**
|
|
6
|
-
* Reads the App Store Connect API key from the
|
|
7
|
-
*
|
|
8
|
-
* build without credentials still produces the
|
|
9
|
-
* it's configured halfway, which is always a
|
|
8
|
+
* Reads the signing options, and the App Store Connect API key from the
|
|
9
|
+
* environment variables they name. Returns undefined when signing isn't
|
|
10
|
+
* configured at all, so a build without credentials still produces the
|
|
11
|
+
* simulator app, and throws when it's configured halfway, which is always a
|
|
12
|
+
* mistake.
|
|
13
|
+
*
|
|
14
|
+
* `teamId` alone signs only the development builds `--run` installs on a
|
|
15
|
+
* phone: an `.ipa` takes `signing` (an API key) or `export`, so a Personal
|
|
16
|
+
* Team, which can't export one, never fails a plain build.
|
|
10
17
|
*/
|
|
11
18
|
export const resolveIosSigning = (app, env = process.env) => {
|
|
12
|
-
const signing = app.ios
|
|
13
|
-
if (!signing && !
|
|
19
|
+
const { signing, teamId, export: exportMethod } = app.ios;
|
|
20
|
+
if (!signing && !teamId && !exportMethod) {
|
|
14
21
|
return undefined;
|
|
15
22
|
}
|
|
23
|
+
if (!teamId) {
|
|
24
|
+
throw new Error(`ios.${signing ? 'signing' : 'export'} is set, but ios.teamId is not.`);
|
|
25
|
+
}
|
|
26
|
+
if (!signing) {
|
|
27
|
+
return { teamId, ...(exportMethod && { export: exportMethod }) };
|
|
28
|
+
}
|
|
16
29
|
const read = (option, name) => {
|
|
17
30
|
if (!name) {
|
|
18
31
|
throw new Error(`ios.signing.${option} must name the environment variable that holds it.`);
|
|
@@ -23,30 +36,81 @@ export const resolveIosSigning = (app, env = process.env) => {
|
|
|
23
36
|
}
|
|
24
37
|
return value;
|
|
25
38
|
};
|
|
26
|
-
|
|
27
|
-
throw new Error('ios.signing is set, but ios.teamId is not.');
|
|
28
|
-
}
|
|
29
|
-
const keyPath = read('keyPathEnv', signing?.keyPathEnv);
|
|
39
|
+
const keyPath = read('keyPathEnv', signing.keyPathEnv);
|
|
30
40
|
if (!existsSync(keyPath)) {
|
|
31
41
|
throw new Error(`The App Store Connect key ${keyPath} doesn't exist.`);
|
|
32
42
|
}
|
|
33
43
|
return {
|
|
34
|
-
teamId
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
teamId,
|
|
45
|
+
apiKey: {
|
|
46
|
+
keyPath,
|
|
47
|
+
keyId: read('keyIdEnv', signing.keyIdEnv),
|
|
48
|
+
issuerId: read('issuerIdEnv', signing.issuerIdEnv),
|
|
49
|
+
},
|
|
50
|
+
export: exportMethod ?? 'app-store-connect',
|
|
38
51
|
};
|
|
39
52
|
};
|
|
40
53
|
/**
|
|
41
|
-
* Builds the iOS shell:
|
|
42
|
-
*
|
|
54
|
+
* Builds the iOS shell: a simulator `.app`, plus an `.ipa` when signing
|
|
55
|
+
* says how to export one. With `device`, only a development-signed `.app` for
|
|
56
|
+
* that iPhone instead, which is all `--run` installs there: the simulator app
|
|
57
|
+
* would be thrown away, and archiving the `.ipa` takes minutes a Personal
|
|
58
|
+
* Team's run would spend failing. Returns the artifacts' paths.
|
|
43
59
|
*/
|
|
44
|
-
export const buildIos = async ({ project, app, frameworksDir, buildDir, outputDir, logFile, log, signing, }) => {
|
|
60
|
+
export const buildIos = async ({ project, app, frameworksDir, buildDir, outputDir, logFile, log, signing, device, }) => {
|
|
45
61
|
linkFrameworks(project.dir, frameworksDir);
|
|
46
62
|
const xcodebuild = (args) => run('xcodebuild', args, { cwd: project.dir, logFile });
|
|
47
63
|
const common = ['-project', 'App.xcodeproj', '-scheme', 'App'];
|
|
48
|
-
const artifacts = [];
|
|
49
64
|
mkdirSync(outputDir, { recursive: true });
|
|
65
|
+
/**
|
|
66
|
+
* -allowProvisioningUpdates lets xcodebuild create the certificate and the
|
|
67
|
+
* provisioning profile itself, so nobody opens Xcode: with the API key
|
|
68
|
+
* when there is one, else with the Apple ID signed in to Xcode.
|
|
69
|
+
*/
|
|
70
|
+
const auth = (apiKey) => [
|
|
71
|
+
'-allowProvisioningUpdates',
|
|
72
|
+
...(apiKey
|
|
73
|
+
? [
|
|
74
|
+
'-authenticationKeyPath',
|
|
75
|
+
apiKey.keyPath,
|
|
76
|
+
'-authenticationKeyID',
|
|
77
|
+
apiKey.keyId,
|
|
78
|
+
'-authenticationKeyIssuerID',
|
|
79
|
+
apiKey.issuerId,
|
|
80
|
+
]
|
|
81
|
+
: []),
|
|
82
|
+
];
|
|
83
|
+
if (device) {
|
|
84
|
+
if (!signing) {
|
|
85
|
+
throw new NativeBuildError(await missingTeamMessage(device.name));
|
|
86
|
+
}
|
|
87
|
+
log(`Building the iOS app for ${device.name}`);
|
|
88
|
+
await xcodebuild([
|
|
89
|
+
'build',
|
|
90
|
+
...common,
|
|
91
|
+
'-configuration',
|
|
92
|
+
'Release',
|
|
93
|
+
'-sdk',
|
|
94
|
+
'iphoneos',
|
|
95
|
+
// The phone itself rather than generic/platform=iOS, so automatic
|
|
96
|
+
// signing knows which device the development profile must list, and
|
|
97
|
+
// -allowProvisioningDeviceRegistration adds it to the team if it's new.
|
|
98
|
+
'-destination',
|
|
99
|
+
`id=${device.udid}`,
|
|
100
|
+
'-derivedDataPath',
|
|
101
|
+
buildDir,
|
|
102
|
+
...auth(signing.apiKey),
|
|
103
|
+
'-allowProvisioningDeviceRegistration',
|
|
104
|
+
`DEVELOPMENT_TEAM=${signing.teamId}`,
|
|
105
|
+
]).catch((error) => {
|
|
106
|
+
throw explainDeviceBuildFailure(error, device.name, signing.teamId);
|
|
107
|
+
});
|
|
108
|
+
const deviceApp = path.join(outputDir, `${app.productName}-device.app`);
|
|
109
|
+
rmSync(deviceApp, { recursive: true, force: true });
|
|
110
|
+
cpSync(path.join(buildDir, 'Build/Products/Release-iphoneos', `${app.productName}.app`), deviceApp, { recursive: true, verbatimSymlinks: true });
|
|
111
|
+
return [deviceApp];
|
|
112
|
+
}
|
|
113
|
+
const artifacts = [];
|
|
50
114
|
log('Building the iOS Simulator app');
|
|
51
115
|
await xcodebuild([
|
|
52
116
|
'build',
|
|
@@ -64,23 +128,16 @@ export const buildIos = async ({ project, app, frameworksDir, buildDir, outputDi
|
|
|
64
128
|
rmSync(simulatorApp, { recursive: true, force: true });
|
|
65
129
|
cpSync(path.join(buildDir, 'Build/Products/Release-iphonesimulator', `${app.productName}.app`), simulatorApp, { recursive: true, verbatimSymlinks: true });
|
|
66
130
|
artifacts.push(simulatorApp);
|
|
67
|
-
if (!signing) {
|
|
68
|
-
log(
|
|
131
|
+
if (!signing?.export) {
|
|
132
|
+
log(signing
|
|
133
|
+
? 'Skipping the .ipa: set ios.signing (an App Store Connect API key) or ios.export in angular.json to build one.'
|
|
134
|
+
: 'Skipping the .ipa: set ios.teamId and ios.signing in angular.json to build one.');
|
|
69
135
|
return artifacts;
|
|
70
136
|
}
|
|
71
|
-
// Headless signing: the API key lets xcodebuild create and download the
|
|
72
|
-
// certificate and provisioning profile itself, so nobody opens Xcode.
|
|
73
|
-
const auth = [
|
|
74
|
-
'-allowProvisioningUpdates',
|
|
75
|
-
'-authenticationKeyPath',
|
|
76
|
-
signing.keyPath,
|
|
77
|
-
'-authenticationKeyID',
|
|
78
|
-
signing.keyId,
|
|
79
|
-
'-authenticationKeyIssuerID',
|
|
80
|
-
signing.issuerId,
|
|
81
|
-
];
|
|
82
137
|
const archive = path.join(buildDir, `${app.productName}.xcarchive`);
|
|
83
|
-
log(
|
|
138
|
+
log(signing.export === 'release-testing'
|
|
139
|
+
? "Archiving the iOS app for the team's registered iPhones"
|
|
140
|
+
: 'Archiving the iOS app for the App Store');
|
|
84
141
|
await xcodebuild([
|
|
85
142
|
'archive',
|
|
86
143
|
...common,
|
|
@@ -92,14 +149,16 @@ export const buildIos = async ({ project, app, frameworksDir, buildDir, outputDi
|
|
|
92
149
|
archive,
|
|
93
150
|
'-derivedDataPath',
|
|
94
151
|
buildDir,
|
|
95
|
-
...auth,
|
|
152
|
+
...auth(signing.apiKey),
|
|
96
153
|
`DEVELOPMENT_TEAM=${signing.teamId}`,
|
|
97
|
-
])
|
|
154
|
+
]).catch((error) => {
|
|
155
|
+
throw explainSigningFailure(error, signing.teamId);
|
|
156
|
+
});
|
|
98
157
|
const exportOptions = path.join(buildDir, 'ExportOptions.plist');
|
|
99
|
-
writeFileSync(exportOptions, exportOptionsPlist(signing.teamId));
|
|
158
|
+
writeFileSync(exportOptions, exportOptionsPlist(signing.teamId, signing.export));
|
|
100
159
|
const exportDir = path.join(buildDir, 'export');
|
|
101
160
|
rmSync(exportDir, { recursive: true, force: true });
|
|
102
|
-
log(
|
|
161
|
+
log(`Exporting the .ipa (${signing.export})`);
|
|
103
162
|
await xcodebuild([
|
|
104
163
|
'-exportArchive',
|
|
105
164
|
'-archivePath',
|
|
@@ -108,13 +167,111 @@ export const buildIos = async ({ project, app, frameworksDir, buildDir, outputDi
|
|
|
108
167
|
exportDir,
|
|
109
168
|
'-exportOptionsPlist',
|
|
110
169
|
exportOptions,
|
|
111
|
-
...auth,
|
|
170
|
+
...auth(signing.apiKey),
|
|
112
171
|
]);
|
|
113
172
|
const ipa = path.join(outputDir, `${app.productName}.ipa`);
|
|
114
173
|
cpSync(path.join(exportDir, `${app.productName}.ipa`), ipa);
|
|
115
174
|
artifacts.push(ipa);
|
|
116
175
|
return artifacts;
|
|
117
176
|
};
|
|
177
|
+
/**
|
|
178
|
+
* What to do when `--run` targets an iPhone but nothing says who signs the
|
|
179
|
+
* app. iOS runs only signed apps, and a free Apple ID is enough for one's
|
|
180
|
+
* own phone, so the message says so rather than pointing at the paid program.
|
|
181
|
+
* Xcode doesn't show a team's ID anywhere obvious, so the message lists the
|
|
182
|
+
* teams it can find on this Mac.
|
|
183
|
+
*/
|
|
184
|
+
export const missingTeamMessage = async (deviceName) => {
|
|
185
|
+
const teams = await signingTeams();
|
|
186
|
+
return (`Running the app on ${deviceName} needs ios.teamId in angular.json: iOS only runs apps signed by an Apple Developer team. ` +
|
|
187
|
+
(teams.length > 0
|
|
188
|
+
? `Set it to one of your teams: ${teams.map((team) => `${team.id} (${team.name})`).join(', ')}.`
|
|
189
|
+
: 'Sign in to Xcode with your Apple ID (Xcode → Settings → Accounts) and build again, and this message lists your teams.') +
|
|
190
|
+
" A free Apple ID's Personal Team works, but its apps stop opening after 7 days; the paid Apple Developer Program's team keeps them working for a year.");
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* The teams this Mac can sign for: those of the accounts signed in to Xcode,
|
|
194
|
+
* which Xcode keeps in its preferences, and those of the Apple Development
|
|
195
|
+
* certificates in the keychain, whose subject holds the team's ID as OU and
|
|
196
|
+
* its name as O.
|
|
197
|
+
*/
|
|
198
|
+
export const signingTeams = async ({ preferences = path.join(os.homedir(), 'Library/Preferences/com.apple.dt.Xcode.plist'), } = {}) => {
|
|
199
|
+
const teams = new Map();
|
|
200
|
+
// IDEProvisioningTeamByIdentifier in Xcode 15 and later,
|
|
201
|
+
// IDEProvisioningTeams before: each maps an account to its teams.
|
|
202
|
+
for (const key of [
|
|
203
|
+
'IDEProvisioningTeamByIdentifier',
|
|
204
|
+
'IDEProvisioningTeams',
|
|
205
|
+
]) {
|
|
206
|
+
const json = await capture('plutil', [
|
|
207
|
+
'-extract',
|
|
208
|
+
key,
|
|
209
|
+
'json',
|
|
210
|
+
'-o',
|
|
211
|
+
'-',
|
|
212
|
+
preferences,
|
|
213
|
+
]);
|
|
214
|
+
try {
|
|
215
|
+
const accounts = JSON.parse(json ?? '{}');
|
|
216
|
+
for (const team of Object.values(accounts).flat()) {
|
|
217
|
+
if (team.teamID) {
|
|
218
|
+
teams.set(team.teamID, `${team.teamName ?? team.teamID}${team.isFreeProvisioningTeam ? ', Personal Team' : ''}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// Preferences in a shape this doesn't know suggest no team.
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const certificates = (await capture('security', [
|
|
227
|
+
'find-certificate',
|
|
228
|
+
'-a',
|
|
229
|
+
'-c',
|
|
230
|
+
'Apple Development',
|
|
231
|
+
'-p',
|
|
232
|
+
])) ?? '';
|
|
233
|
+
for (const pem of certificates.match(/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/g) ?? []) {
|
|
234
|
+
try {
|
|
235
|
+
const subject = new X509Certificate(pem).subject;
|
|
236
|
+
const id = /^OU=(.+)$/m.exec(subject)?.[1];
|
|
237
|
+
if (id && !teams.has(id)) {
|
|
238
|
+
teams.set(id, /^O=(.+)$/m.exec(subject)?.[1] ?? id);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
// A certificate Node can't parse names no team to suggest.
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return [...teams].map(([id, name]) => ({ id, name }));
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Building for a particular iPhone needs the phone itself: xcodebuild asks
|
|
249
|
+
* it for its development services before compiling, waits a minute for a
|
|
250
|
+
* locked or unreachable phone, then fails with the reason at the end of a
|
|
251
|
+
* long log. This puts the reason first, as the install step's does.
|
|
252
|
+
*/
|
|
253
|
+
const explainDeviceBuildFailure = (error, deviceName, teamId) => {
|
|
254
|
+
if (/needs to be unlocked/i.test(error.message)) {
|
|
255
|
+
return new NativeBuildError(`${deviceName} is locked. Unlock it, keep it unlocked until the app opens, and build again.\n\n${error.message}`);
|
|
256
|
+
}
|
|
257
|
+
if (/Timed out waiting for all destinations/i.test(error.message)) {
|
|
258
|
+
return new NativeBuildError(`xcodebuild couldn't reach ${deviceName}. Connect it with a USB cable, or put it on this Mac's Wi-Fi network, unlock it, and build again.\n\n${error.message}`);
|
|
259
|
+
}
|
|
260
|
+
return explainSigningFailure(error, teamId);
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Adds what to do to xcodebuild's signing errors, which name the missing
|
|
264
|
+
* account or profile but not where to fix it. Other failures pass through.
|
|
265
|
+
*/
|
|
266
|
+
const explainSigningFailure = (error, teamId) => {
|
|
267
|
+
if (/No Accounts?\b|No account for team/i.test(error.message)) {
|
|
268
|
+
return new NativeBuildError(`Xcode has no signed-in account for team ${teamId}. Sign in to Xcode with the Apple ID of that team (Xcode → Settings → Accounts), or set ios.signing to an App Store Connect API key, then build again.\n\n${error.message}`);
|
|
269
|
+
}
|
|
270
|
+
if (/requires a development team|No profiles for/i.test(error.message)) {
|
|
271
|
+
return new NativeBuildError(`Xcode couldn't make a provisioning profile for team ${teamId}. Check that ios.teamId is a team your Apple ID in Xcode → Settings → Accounts belongs to, and for an .ipa that the team is in the paid Apple Developer Program.\n\n${error.message}`);
|
|
272
|
+
}
|
|
273
|
+
return error;
|
|
274
|
+
};
|
|
118
275
|
/**
|
|
119
276
|
* Points the project's `Frameworks` folder at the cached XCFrameworks. A
|
|
120
277
|
* symlink, so the ~100 MB of frameworks aren't copied into every project. An
|
|
@@ -128,22 +285,26 @@ const linkFrameworks = (projectDir, frameworksDir) => {
|
|
|
128
285
|
rmSync(link, { force: true });
|
|
129
286
|
symlinkSync(frameworksDir, link, 'dir');
|
|
130
287
|
};
|
|
131
|
-
export const exportOptionsPlist = (teamId) => `<?xml version="1.0" encoding="UTF-8"?>
|
|
288
|
+
export const exportOptionsPlist = (teamId, method) => `<?xml version="1.0" encoding="UTF-8"?>
|
|
132
289
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
133
290
|
<plist version="1.0">
|
|
134
291
|
<dict>
|
|
135
292
|
<key>method</key>
|
|
136
|
-
<string
|
|
293
|
+
<string>${method}</string>
|
|
137
294
|
<key>destination</key>
|
|
138
295
|
<string>export</string>
|
|
139
296
|
<key>signingStyle</key>
|
|
140
297
|
<string>automatic</string>
|
|
141
298
|
<key>teamID</key>
|
|
142
299
|
<string>${escapeXml(teamId)}</string>
|
|
143
|
-
|
|
300
|
+
${
|
|
301
|
+
// App Store Connect's own settings, which ad hoc exports don't take.
|
|
302
|
+
method === 'app-store-connect'
|
|
303
|
+
? ` <key>uploadSymbols</key>
|
|
144
304
|
<true/>
|
|
145
305
|
<key>manageAppVersionAndBuildNumber</key>
|
|
146
306
|
<false/>
|
|
147
|
-
|
|
307
|
+
`
|
|
308
|
+
: ''}</dict>
|
|
148
309
|
</plist>
|
|
149
310
|
`;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { RunTarget } from '../run.ts';
|
|
2
|
+
/**
|
|
3
|
+
* A device in `xcrun devicectl list devices --json-output -`, as far as it's
|
|
4
|
+
* read here. Xcode 27's devicectl moved everything into `properties` and
|
|
5
|
+
* marks the older `deviceProperties` and friends deprecated, so both are
|
|
6
|
+
* read, the new ones first.
|
|
7
|
+
*/
|
|
8
|
+
export type DevicectlDevice = {
|
|
9
|
+
/** CoreDevice's own ID for the device, not its UDID. */
|
|
10
|
+
readonly identifier: string;
|
|
11
|
+
readonly properties?: {
|
|
12
|
+
readonly hardware?: {
|
|
13
|
+
readonly udid?: string;
|
|
14
|
+
readonly platform?: string;
|
|
15
|
+
/** `physical` for a real device, `simulated` for a simulator. */
|
|
16
|
+
readonly reality?: string;
|
|
17
|
+
readonly marketingName?: string;
|
|
18
|
+
};
|
|
19
|
+
readonly connection?: {
|
|
20
|
+
readonly pairingState?: string;
|
|
21
|
+
};
|
|
22
|
+
readonly state?: {
|
|
23
|
+
readonly name?: string;
|
|
24
|
+
/** e.g. `{ "enabled": { "mode": 1 } }`. */
|
|
25
|
+
readonly developerModeStatus?: unknown;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
readonly hardwareProperties?: {
|
|
29
|
+
readonly udid?: string;
|
|
30
|
+
readonly platform?: string;
|
|
31
|
+
readonly reality?: string;
|
|
32
|
+
readonly marketingName?: string;
|
|
33
|
+
};
|
|
34
|
+
readonly connectionProperties?: {
|
|
35
|
+
readonly pairingState?: string;
|
|
36
|
+
};
|
|
37
|
+
readonly deviceProperties?: {
|
|
38
|
+
readonly name?: string;
|
|
39
|
+
/** `enabled` or `disabled`. */
|
|
40
|
+
readonly developerModeStatus?: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/** A real iPhone (or iPad) devicectl knows, from {@link parseIPhones}. */
|
|
44
|
+
export type IPhone = {
|
|
45
|
+
readonly udid: string;
|
|
46
|
+
/** The name set on the phone, e.g. `Dolan’s iPhone`. */
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly identifier: string;
|
|
49
|
+
readonly model?: string;
|
|
50
|
+
readonly paired: boolean;
|
|
51
|
+
/** Undefined when devicectl doesn't say, e.g. before it's connected once. */
|
|
52
|
+
readonly developerMode?: 'enabled' | 'disabled';
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The real iOS devices in devicectl's list. devicectl lists the simulators
|
|
56
|
+
* too, which `simctl` already covers, so only physical ones are kept.
|
|
57
|
+
*/
|
|
58
|
+
export declare const parseIPhones: (output: string) => IPhone[];
|
|
59
|
+
/**
|
|
60
|
+
* The iPhone `--device` names, by its name, UDID or CoreDevice identifier,
|
|
61
|
+
* or undefined when it names none (it may name a simulator). Throws when the
|
|
62
|
+
* phone can't take an app yet, before minutes of building.
|
|
63
|
+
*/
|
|
64
|
+
export declare const pickIPhone: (phones: readonly IPhone[], device: string) => IPhone | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* The paired iPhones, or none when devicectl isn't there (Xcode 14 and
|
|
67
|
+
* earlier) or fails, so `--device` still reaches the simulators.
|
|
68
|
+
*/
|
|
69
|
+
export declare const listIPhones: () => Promise<IPhone[]>;
|
|
70
|
+
/**
|
|
71
|
+
* The target for an iPhone `--device` named. The build signs the app for it
|
|
72
|
+
* (see buildIos), then this installs it and opens it with devicectl, which
|
|
73
|
+
* reaches the phone by USB or, once it has been paired, over Wi-Fi.
|
|
74
|
+
*/
|
|
75
|
+
export declare const startIPhone: ({ phone, logFile, log, }: {
|
|
76
|
+
readonly phone: IPhone;
|
|
77
|
+
readonly logFile: string;
|
|
78
|
+
readonly log: (message: string) => void;
|
|
79
|
+
}) => RunTarget;
|
|
80
|
+
/** One error in devicectl's chain of underlying errors. */
|
|
81
|
+
export type DevicectlReason = {
|
|
82
|
+
readonly domain?: string;
|
|
83
|
+
readonly code?: number;
|
|
84
|
+
/** The description, failure reason and recovery suggestion, in that order. */
|
|
85
|
+
readonly messages: readonly string[];
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Flattens the error in devicectl's JSON output: the outermost error says
|
|
89
|
+
* what failed ("The developer disk image could not be mounted"), and the
|
|
90
|
+
* innermost usually why ("the device was still locked").
|
|
91
|
+
*/
|
|
92
|
+
export declare const devicectlErrors: (json: string) => DevicectlReason[];
|
|
93
|
+
/**
|
|
94
|
+
* Says what to do on the phone for the failures that need it, as the
|
|
95
|
+
* Android run does for USB debugging, and passes devicectl's own words on
|
|
96
|
+
* for the rest.
|
|
97
|
+
*/
|
|
98
|
+
export declare const explainDevicectlFailure: (reasons: readonly DevicectlReason[], name: string, action: string, logFile: string) => string;
|
|
99
|
+
//# sourceMappingURL=iphone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iphone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G;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,eAAe,EAsB7D,CAAC;AAKF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,SAAS,eAAe,EAAE,EACnC,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,SAAS,MAAM,KACd,MA2BF,CAAC"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { existsSync, readFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { NativeBuildError, capture, run } from "../process.js";
|
|
4
|
+
/**
|
|
5
|
+
* The real iOS devices in devicectl's list. devicectl lists the simulators
|
|
6
|
+
* too, which `simctl` already covers, so only physical ones are kept.
|
|
7
|
+
*/
|
|
8
|
+
export const parseIPhones = (output) => {
|
|
9
|
+
const devices = JSON.parse(output).result?.devices ?? [];
|
|
10
|
+
return devices.flatMap((device) => {
|
|
11
|
+
const hardware = {
|
|
12
|
+
...device.hardwareProperties,
|
|
13
|
+
...device.properties?.hardware,
|
|
14
|
+
};
|
|
15
|
+
const name = device.properties?.state?.name ?? device.deviceProperties?.name;
|
|
16
|
+
if (hardware.reality !== 'physical' ||
|
|
17
|
+
hardware.platform !== 'iOS' ||
|
|
18
|
+
!hardware.udid ||
|
|
19
|
+
!name) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const pairingState = device.properties?.connection?.pairingState ??
|
|
23
|
+
device.connectionProperties?.pairingState;
|
|
24
|
+
const developerMode = developerModeOf(device);
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
udid: hardware.udid,
|
|
28
|
+
name,
|
|
29
|
+
identifier: device.identifier,
|
|
30
|
+
...(hardware.marketingName && { model: hardware.marketingName }),
|
|
31
|
+
paired: pairingState === 'paired',
|
|
32
|
+
...(developerMode && { developerMode }),
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* `properties.state.developerModeStatus` is an enum encoded as an object
|
|
39
|
+
* with one key (`{ "enabled": { "mode": 1 } }`); the deprecated field is
|
|
40
|
+
* that key as a string.
|
|
41
|
+
*/
|
|
42
|
+
const developerModeOf = (device) => {
|
|
43
|
+
const status = device.properties?.state?.developerModeStatus;
|
|
44
|
+
const key = status && typeof status === 'object'
|
|
45
|
+
? Object.keys(status)[0]
|
|
46
|
+
: typeof status === 'string'
|
|
47
|
+
? status
|
|
48
|
+
: device.deviceProperties?.developerModeStatus;
|
|
49
|
+
return key === 'enabled' || key === 'disabled' ? key : undefined;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Phone names come from the phone's settings, where iOS types a curly
|
|
53
|
+
* apostrophe (`Dolan’s iPhone`) that a terminal rarely does, so names are
|
|
54
|
+
* compared with straight quotes and without case.
|
|
55
|
+
*/
|
|
56
|
+
const normalizeName = (name) => name.toLowerCase().replace(/[‘’]/g, "'").replace(/[“”]/g, '"');
|
|
57
|
+
/**
|
|
58
|
+
* The iPhone `--device` names, by its name, UDID or CoreDevice identifier,
|
|
59
|
+
* or undefined when it names none (it may name a simulator). Throws when the
|
|
60
|
+
* phone can't take an app yet, before minutes of building.
|
|
61
|
+
*/
|
|
62
|
+
export const pickIPhone = (phones, device) => {
|
|
63
|
+
const wanted = normalizeName(device);
|
|
64
|
+
const phone = phones.find((candidate) => candidate.udid.toLowerCase() === wanted ||
|
|
65
|
+
candidate.identifier.toLowerCase() === wanted ||
|
|
66
|
+
normalizeName(candidate.name) === wanted);
|
|
67
|
+
if (!phone) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
if (!phone.paired) {
|
|
71
|
+
throw new NativeBuildError(`${phone.name} isn't paired with this Mac. Connect it with a USB cable, unlock it and tap Trust, then build again.`);
|
|
72
|
+
}
|
|
73
|
+
if (phone.developerMode === 'disabled') {
|
|
74
|
+
throw new NativeBuildError(developerModeMessage(phone.name));
|
|
75
|
+
}
|
|
76
|
+
return phone;
|
|
77
|
+
};
|
|
78
|
+
const developerModeMessage = (name) => `Developer Mode is off on ${name}, and iOS only runs apps from Xcode with it on. On the phone, open Settings → Privacy & Security → Developer Mode, turn it on and let the phone restart, then build again. The setting shows up once the phone has been connected to this Mac.`;
|
|
79
|
+
/**
|
|
80
|
+
* The paired iPhones, or none when devicectl isn't there (Xcode 14 and
|
|
81
|
+
* earlier) or fails, so `--device` still reaches the simulators.
|
|
82
|
+
*/
|
|
83
|
+
export const listIPhones = async () => {
|
|
84
|
+
const output = await capture('xcrun', [
|
|
85
|
+
'devicectl',
|
|
86
|
+
'list',
|
|
87
|
+
'devices',
|
|
88
|
+
'--quiet',
|
|
89
|
+
'--json-output',
|
|
90
|
+
'-',
|
|
91
|
+
]);
|
|
92
|
+
if (output === undefined) {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return parseIPhones(output);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The target for an iPhone `--device` named. The build signs the app for it
|
|
104
|
+
* (see buildIos), then this installs it and opens it with devicectl, which
|
|
105
|
+
* reaches the phone by USB or, once it has been paired, over Wi-Fi.
|
|
106
|
+
*/
|
|
107
|
+
export const startIPhone = ({ phone, logFile, log, }) => {
|
|
108
|
+
log(`Running the app on ${phone.name}${phone.model ? ` (${phone.model})` : ''}`);
|
|
109
|
+
return {
|
|
110
|
+
iPhone: { udid: phone.udid, name: phone.name },
|
|
111
|
+
launch: async (binary, app) => {
|
|
112
|
+
log(`Installing the app on ${phone.name}`);
|
|
113
|
+
await devicectl(['device', 'install', 'app', '--device', phone.udid, binary], { phone, action: 'install the app', logFile });
|
|
114
|
+
// Replaces the copy a previous `--run` left open, which would otherwise
|
|
115
|
+
// stay in front, still running the old build.
|
|
116
|
+
await devicectl([
|
|
117
|
+
'device',
|
|
118
|
+
'process',
|
|
119
|
+
'launch',
|
|
120
|
+
'--device',
|
|
121
|
+
phone.udid,
|
|
122
|
+
'--terminate-existing',
|
|
123
|
+
app.id,
|
|
124
|
+
], { phone, action: 'open the app', logFile });
|
|
125
|
+
log(`Opened ${app.name} on ${phone.name}`);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Runs a devicectl command with its result written as JSON, so a failure is
|
|
131
|
+
* read from the structured error rather than its indented text, and
|
|
132
|
+
* explained when it's something the developer fixes on the phone.
|
|
133
|
+
*/
|
|
134
|
+
const devicectl = async (args, { phone, action, logFile, }) => {
|
|
135
|
+
const json = path.join(path.dirname(logFile), 'devicectl.json');
|
|
136
|
+
rmSync(json, { force: true });
|
|
137
|
+
try {
|
|
138
|
+
await run('xcrun', ['devicectl', ...args, '--json-output', json], {
|
|
139
|
+
cwd: process.cwd(),
|
|
140
|
+
logFile,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
const reasons = existsSync(json)
|
|
145
|
+
? devicectlErrors(readFileSync(json, 'utf8'))
|
|
146
|
+
: [];
|
|
147
|
+
throw reasons.length > 0
|
|
148
|
+
? new NativeBuildError(explainDevicectlFailure(reasons, phone.name, action, logFile))
|
|
149
|
+
: error;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Flattens the error in devicectl's JSON output: the outermost error says
|
|
154
|
+
* what failed ("The developer disk image could not be mounted"), and the
|
|
155
|
+
* innermost usually why ("the device was still locked").
|
|
156
|
+
*/
|
|
157
|
+
export const devicectlErrors = (json) => {
|
|
158
|
+
let error;
|
|
159
|
+
try {
|
|
160
|
+
error = JSON.parse(json).error;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
const reasons = [];
|
|
166
|
+
while (error) {
|
|
167
|
+
const info = error.userInfo ?? {};
|
|
168
|
+
reasons.push({
|
|
169
|
+
domain: error.domain,
|
|
170
|
+
code: error.code,
|
|
171
|
+
messages: [
|
|
172
|
+
'NSLocalizedDescription',
|
|
173
|
+
'NSLocalizedFailureReason',
|
|
174
|
+
'NSLocalizedRecoverySuggestion',
|
|
175
|
+
].flatMap((key) => info[key]?.string ?? []),
|
|
176
|
+
});
|
|
177
|
+
error = info['NSUnderlyingError']?.error;
|
|
178
|
+
}
|
|
179
|
+
return reasons;
|
|
180
|
+
};
|
|
181
|
+
/** CoreDevice's error code for a phone that's locked. */
|
|
182
|
+
const DEVICE_LOCKED = 10003;
|
|
183
|
+
/**
|
|
184
|
+
* Says what to do on the phone for the failures that need it, as the
|
|
185
|
+
* Android run does for USB debugging, and passes devicectl's own words on
|
|
186
|
+
* for the rest.
|
|
187
|
+
*/
|
|
188
|
+
export const explainDevicectlFailure = (reasons, name, action, logFile) => {
|
|
189
|
+
const text = reasons.flatMap((reason) => reason.messages).join(' ');
|
|
190
|
+
if (reasons.some((reason) => reason.domain === 'com.apple.dt.CoreDeviceError' &&
|
|
191
|
+
reason.code === DEVICE_LOCKED) ||
|
|
192
|
+
/\blocked\b/i.test(text)) {
|
|
193
|
+
return `${name} is locked. Unlock it, keep it unlocked until the app opens, and build again.`;
|
|
194
|
+
}
|
|
195
|
+
if (/developer mode/i.test(text)) {
|
|
196
|
+
return developerModeMessage(name);
|
|
197
|
+
}
|
|
198
|
+
// A free Apple ID's apps don't open until the phone trusts their developer.
|
|
199
|
+
if (/explicitly trusted|untrusted developer|invalid code signature|inadequate entitlements/i.test(text)) {
|
|
200
|
+
return `${name} doesn't trust the app's developer yet, which iOS asks once for apps signed with a free Apple ID. On the phone, open Settings → General → VPN & Device Management, tap your Apple ID under Developer App, then Trust, and build again.`;
|
|
201
|
+
}
|
|
202
|
+
const said = [...new Set(reasons.flatMap((reason) => reason.messages))].join(' ');
|
|
203
|
+
return `Couldn't ${action} on ${name}. devicectl says: ${said} The full log is ${logFile}.`;
|
|
204
|
+
};
|
package/dist/ios/project.d.ts
CHANGED
|
@@ -7,5 +7,7 @@ import type { ResolvedApp } from '../options.ts';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const iosGenerator: PlatformGenerator;
|
|
9
9
|
export declare const xcconfig: (app: ResolvedApp) => string;
|
|
10
|
+
/** What iOS shows the first time someone taps Save Image, without `savePhotos`. */
|
|
11
|
+
export declare const DEFAULT_SAVE_PHOTOS_REASON = "Saves the images you choose to your photo library.";
|
|
10
12
|
export declare const infoPlistEntries: (app: ResolvedApp) => string;
|
|
11
13
|
//# sourceMappingURL=project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/ios/project.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AAiB9D;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,iBA6B1B,CAAC;AAQF,eAAO,MAAM,QAAQ,GAAI,KAAK,WAAW,KAAG,MAY9B,CAAC;AAEf,eAAO,MAAM,gBAAgB,GAAI,KAAK,WAAW,KAAG,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/ios/project.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AAiB9D;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,iBA6B1B,CAAC;AAQF,eAAO,MAAM,QAAQ,GAAI,KAAK,WAAW,KAAG,MAY9B,CAAC;AAEf,mFAAmF;AACnF,eAAO,MAAM,0BAA0B,uDACe,CAAC;AAEvD,eAAO,MAAM,gBAAgB,GAAI,KAAK,WAAW,KAAG,MAsDnD,CAAC"}
|