jetbridge 0.1.0-rc.0
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 +237 -0
- package/dist/cli.d.ts +24 -0
- package/dist/cli.js +3426 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +379 -0
- package/dist/index.js +3268 -0
- package/dist/index.js.map +1 -0
- package/dist/variant-Bh99wLZC.d.ts +327 -0
- package/package.json +84 -0
- package/schema/v1.json +351 -0
- package/templates/index-page.html +165 -0
- package/templates/install-page.html +187 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,3426 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { Command, InvalidArgumentError } from "commander";
|
|
6
|
+
|
|
7
|
+
// src/boundary.ts
|
|
8
|
+
import { execa, execaSync } from "execa";
|
|
9
|
+
import {
|
|
10
|
+
existsSync,
|
|
11
|
+
mkdirSync,
|
|
12
|
+
readFileSync,
|
|
13
|
+
readdirSync,
|
|
14
|
+
rmSync,
|
|
15
|
+
statSync,
|
|
16
|
+
writeFileSync
|
|
17
|
+
} from "fs";
|
|
18
|
+
import { dirname } from "path";
|
|
19
|
+
|
|
20
|
+
// src/errors.ts
|
|
21
|
+
var JetbridgeError = class extends Error {
|
|
22
|
+
name = "JetbridgeError";
|
|
23
|
+
};
|
|
24
|
+
function fail(message) {
|
|
25
|
+
throw new JetbridgeError(message);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/boundary.ts
|
|
29
|
+
var asResult = (r) => ({
|
|
30
|
+
ok: (r.exitCode ?? 0) === 0,
|
|
31
|
+
code: r.exitCode ?? null,
|
|
32
|
+
stdout: typeof r.stdout === "string" ? r.stdout : "",
|
|
33
|
+
stderr: typeof r.stderr === "string" ? r.stderr : ""
|
|
34
|
+
});
|
|
35
|
+
var nodeFileSystem = {
|
|
36
|
+
exists: (path) => existsSync(path),
|
|
37
|
+
read: (path) => readFileSync(path, "utf8"),
|
|
38
|
+
readBytes: (path) => new Uint8Array(readFileSync(path)),
|
|
39
|
+
write: (path, contents) => {
|
|
40
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
41
|
+
writeFileSync(path, contents);
|
|
42
|
+
},
|
|
43
|
+
mkdirp: (path) => {
|
|
44
|
+
mkdirSync(path, { recursive: true });
|
|
45
|
+
},
|
|
46
|
+
readdir: (path) => readdirSync(path),
|
|
47
|
+
rm: (path, opts) => {
|
|
48
|
+
rmSync(path, { recursive: opts?.recursive ?? false, force: true });
|
|
49
|
+
},
|
|
50
|
+
isDirectory: (path) => existsSync(path) && statSync(path).isDirectory(),
|
|
51
|
+
size: (path) => statSync(path).size
|
|
52
|
+
};
|
|
53
|
+
function isInteractive(env = process.env) {
|
|
54
|
+
if (env.CI || env.JETBRIDGE_NON_INTERACTIVE) return false;
|
|
55
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
56
|
+
}
|
|
57
|
+
var HTTP_TIMEOUT_MS = 6e4;
|
|
58
|
+
function childStreams(options, interactive) {
|
|
59
|
+
const output = options.stdio === "inherit" ? "inherit" : "pipe";
|
|
60
|
+
if (options.input !== void 0) return { stdout: output, stderr: output };
|
|
61
|
+
return {
|
|
62
|
+
stdout: output,
|
|
63
|
+
stderr: output,
|
|
64
|
+
stdin: options.stdio === "inherit" && interactive ? "inherit" : "ignore"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function nodeBoundary(options = {}) {
|
|
68
|
+
const interactive = isInteractive() && options.nonInteractive !== true;
|
|
69
|
+
return {
|
|
70
|
+
exec: {
|
|
71
|
+
async run(command, args, runOptions = {}) {
|
|
72
|
+
const result = await execa(command, args, {
|
|
73
|
+
cwd: runOptions.cwd,
|
|
74
|
+
env: runOptions.env,
|
|
75
|
+
extendEnv: true,
|
|
76
|
+
...childStreams(runOptions, interactive),
|
|
77
|
+
...runOptions.input === void 0 ? {} : { input: runOptions.input },
|
|
78
|
+
timeout: runOptions.timeoutMs,
|
|
79
|
+
reject: false
|
|
80
|
+
});
|
|
81
|
+
return asResult(result);
|
|
82
|
+
},
|
|
83
|
+
runSync(command, args, runOptions = {}) {
|
|
84
|
+
const result = execaSync(command, args, {
|
|
85
|
+
cwd: runOptions.cwd,
|
|
86
|
+
env: runOptions.env,
|
|
87
|
+
extendEnv: true,
|
|
88
|
+
...childStreams(runOptions, interactive),
|
|
89
|
+
...runOptions.input === void 0 ? {} : { input: runOptions.input },
|
|
90
|
+
timeout: runOptions.timeoutMs,
|
|
91
|
+
reject: false
|
|
92
|
+
});
|
|
93
|
+
return asResult(result);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
fs: nodeFileSystem,
|
|
97
|
+
async http(request) {
|
|
98
|
+
const timeoutMs = request.timeoutMs ?? HTTP_TIMEOUT_MS;
|
|
99
|
+
let response;
|
|
100
|
+
try {
|
|
101
|
+
response = await fetch(request.url, {
|
|
102
|
+
method: request.method,
|
|
103
|
+
headers: request.headers,
|
|
104
|
+
body: request.body,
|
|
105
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const reason = error?.name === "TimeoutError" ? `timed out after ${timeoutMs}ms` : String(error?.message ?? error);
|
|
109
|
+
return fail(`${request.method} ${request.url} failed \u2014 ${reason}`);
|
|
110
|
+
}
|
|
111
|
+
const headers = {};
|
|
112
|
+
response.headers.forEach((value, key) => {
|
|
113
|
+
headers[key.toLowerCase()] = value;
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
status: response.status,
|
|
117
|
+
ok: response.ok,
|
|
118
|
+
headers,
|
|
119
|
+
text: () => response.text(),
|
|
120
|
+
json: () => response.json()
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
env: (name) => process.env[name],
|
|
124
|
+
now: () => Math.floor(Date.now() / 1e3),
|
|
125
|
+
homedir: () => process.env.HOME ?? "",
|
|
126
|
+
cwd: () => process.cwd(),
|
|
127
|
+
log: {
|
|
128
|
+
info: (m) => console.error(m),
|
|
129
|
+
warn: (m) => console.error(m),
|
|
130
|
+
error: (m) => console.error(m),
|
|
131
|
+
step: (m) => {
|
|
132
|
+
if (interactive) console.error(m);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
interactive
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/asc.ts
|
|
140
|
+
import { createPrivateKey, sign as cryptoSign } from "crypto";
|
|
141
|
+
import { join as join2 } from "path";
|
|
142
|
+
|
|
143
|
+
// src/project.ts
|
|
144
|
+
import { dirname as dirname2, isAbsolute, join, resolve } from "path";
|
|
145
|
+
|
|
146
|
+
// src/config.ts
|
|
147
|
+
import { z } from "zod";
|
|
148
|
+
var CONFIG_FILENAMES = ["jetbridge.config.json", ".jetbridge.json"];
|
|
149
|
+
var CONFIG_VERSION = 1;
|
|
150
|
+
var COMMIT_TYPE_NOISE = [
|
|
151
|
+
"feat",
|
|
152
|
+
"fix",
|
|
153
|
+
"chore",
|
|
154
|
+
"refactor",
|
|
155
|
+
"docs",
|
|
156
|
+
"perf",
|
|
157
|
+
"test",
|
|
158
|
+
"ci",
|
|
159
|
+
"build",
|
|
160
|
+
"style",
|
|
161
|
+
"worktree"
|
|
162
|
+
];
|
|
163
|
+
var identifier = z.string().min(1).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/, "must be a plain identifier");
|
|
164
|
+
var relativePath = z.string().min(1).refine((p) => !p.startsWith("/"), "must be relative to the project root").refine((p) => !p.split("/").includes(".."), "must not escape the project root");
|
|
165
|
+
var targetSchema = z.object({
|
|
166
|
+
/** Xcode target name, as the project spells it. */
|
|
167
|
+
name: z.string().min(1),
|
|
168
|
+
/**
|
|
169
|
+
* Appended to the app's variant bundle id. Omit for the app itself; an
|
|
170
|
+
* extension named `uploadwidget` becomes `<base>.<slug>.uploadwidget`.
|
|
171
|
+
*/
|
|
172
|
+
bundleIdSuffix: z.string().regex(/^[a-z0-9]+$/, "lowercase alphanumerics \u2014 it is one bundle-id segment").optional(),
|
|
173
|
+
/** Shipping entitlements, used by a plain build. */
|
|
174
|
+
entitlements: relativePath.optional(),
|
|
175
|
+
/**
|
|
176
|
+
* Reduced entitlements for a variant. Capabilities the public API cannot
|
|
177
|
+
* grant (app groups, Sign in with Apple) have to be dropped here, or signing
|
|
178
|
+
* fails against a profile that does not carry them.
|
|
179
|
+
*/
|
|
180
|
+
variantEntitlements: relativePath.optional(),
|
|
181
|
+
/**
|
|
182
|
+
* Capabilities to enable on the registered bundle id, e.g.
|
|
183
|
+
* `PUSH_NOTIFICATIONS`. Only what the public API can actually deliver.
|
|
184
|
+
*/
|
|
185
|
+
capabilities: z.array(z.string().regex(/^[A-Z0-9_]+$/, "an App Store Connect capability type")).default([]),
|
|
186
|
+
/**
|
|
187
|
+
* Build setting carrying this target's profile name. The project's xcconfig
|
|
188
|
+
* has to read it — `PROVISIONING_PROFILE_SPECIFIER = $(JETBRIDGE_PROFILE_APP)`.
|
|
189
|
+
*/
|
|
190
|
+
profileSetting: identifier.optional()
|
|
191
|
+
});
|
|
192
|
+
var buildSettingNamesSchema = z.object({
|
|
193
|
+
/** Appended to the bundle id, e.g. `.wave`. */
|
|
194
|
+
bundleSuffix: identifier.default("JETBRIDGE_BUNDLE_SUFFIX"),
|
|
195
|
+
/** The home-screen label. */
|
|
196
|
+
displayName: identifier.default("JETBRIDGE_DISPLAY_NAME"),
|
|
197
|
+
/** Set to `Manual` for a variant, so the build signs against our profiles. */
|
|
198
|
+
signStyle: identifier.default("JETBRIDGE_SIGN_STYLE"),
|
|
199
|
+
/** Optional provenance stamp, e.g. the short commit SHA. */
|
|
200
|
+
gitSha: identifier.default("JETBRIDGE_GIT_SHA")
|
|
201
|
+
});
|
|
202
|
+
var projectSchema = z.object({
|
|
203
|
+
/** Directory holding the Xcode project, relative to the config file. */
|
|
204
|
+
iosDir: relativePath.default("."),
|
|
205
|
+
/** `.xcodeproj` name, relative to `iosDir`. */
|
|
206
|
+
xcodeproj: z.string().min(1).endsWith(".xcodeproj").optional(),
|
|
207
|
+
/** `.xcworkspace` name, relative to `iosDir`. Takes precedence when set. */
|
|
208
|
+
xcworkspace: z.string().min(1).endsWith(".xcworkspace").optional(),
|
|
209
|
+
scheme: z.string().min(1),
|
|
210
|
+
teamId: z.string().regex(/^[A-Z0-9]{10}$/, "an Apple team id is 10 uppercase alphanumerics"),
|
|
211
|
+
baseBundleId: z.string().regex(
|
|
212
|
+
/^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/,
|
|
213
|
+
"a reverse-DNS bundle id, e.g. com.example.app.dev"
|
|
214
|
+
),
|
|
215
|
+
/** XcodeGen spec, relative to `iosDir`. Only set when the project is generated. */
|
|
216
|
+
projectYml: relativePath.optional(),
|
|
217
|
+
/** Re-run XcodeGen before building. Requires `projectYml`. */
|
|
218
|
+
xcodegen: z.boolean().default(false),
|
|
219
|
+
/** Icon shown on the OTA install page, relative to the project root. */
|
|
220
|
+
appIcon: relativePath.optional(),
|
|
221
|
+
/**
|
|
222
|
+
* Device types a cabled install targets. `devicectl` reports an iPad's
|
|
223
|
+
* platform as `iOS` too, so a platform check would sweep a paired iPad into
|
|
224
|
+
* the install set of an iPhone-only app.
|
|
225
|
+
*/
|
|
226
|
+
deviceTypes: z.array(z.enum(["iPhone", "iPad"])).min(1).default(["iPhone"])
|
|
227
|
+
});
|
|
228
|
+
var configurationsSchema = z.object({
|
|
229
|
+
/** Build configurations that exist in the project. Validated before building. */
|
|
230
|
+
available: z.array(z.string().min(1)).min(1).default(["Debug", "Release"]),
|
|
231
|
+
/** Cabled installs default to a debuggable build — it is the inner loop. */
|
|
232
|
+
wired: z.string().min(1).default("Debug"),
|
|
233
|
+
sim: z.string().min(1).default("Debug"),
|
|
234
|
+
/** Archives default to the optimised build, since they go to other people. */
|
|
235
|
+
archive: z.string().min(1).default("Release")
|
|
236
|
+
});
|
|
237
|
+
var variantSchema = z.object({
|
|
238
|
+
/** Home-screen label for a plain build, e.g. what the project already sets. */
|
|
239
|
+
displayName: z.string().min(1),
|
|
240
|
+
/** Prefix for a variant label: `<prefix> Seeded Feed`. Defaults to displayName's first word. */
|
|
241
|
+
labelPrefix: z.string().min(1).optional(),
|
|
242
|
+
/** iOS truncates a home-screen label at roughly this many characters. */
|
|
243
|
+
labelBudget: z.number().int().positive().default(14),
|
|
244
|
+
/**
|
|
245
|
+
* Leading words dropped from a variant name. Defaults to conventional-commit
|
|
246
|
+
* types plus the segments of `baseBundleId`, so pasting the bundle id back in
|
|
247
|
+
* does not produce a name that stutters.
|
|
248
|
+
*/
|
|
249
|
+
noiseWords: z.array(z.string().min(1)).optional(),
|
|
250
|
+
/** Every target that needs its own registered bundle id. */
|
|
251
|
+
targets: z.array(targetSchema).default([]),
|
|
252
|
+
buildSettings: buildSettingNamesSchema.prefault({}),
|
|
253
|
+
/** Name given to generated provisioning profiles. Defaults to the label prefix. */
|
|
254
|
+
profilePrefix: z.string().min(1).optional()
|
|
255
|
+
});
|
|
256
|
+
var xcconfigOverrideSchema = z.object({
|
|
257
|
+
/** Git-ignored xcconfig the build already `#include?`s, relative to the project root. */
|
|
258
|
+
file: relativePath,
|
|
259
|
+
/** Build setting to rewrite, e.g. an API base URL. */
|
|
260
|
+
key: identifier,
|
|
261
|
+
/** Named shortcuts, exposed as `--<name>` on the build commands. */
|
|
262
|
+
presets: z.record(z.string(), z.string()).prefault({})
|
|
263
|
+
});
|
|
264
|
+
var hooksSchema = z.object({
|
|
265
|
+
/**
|
|
266
|
+
* Shell commands run in the project root. JSON cannot hold a function; this
|
|
267
|
+
* is the deliberate cost of a config file a wizard can write and a human can
|
|
268
|
+
* read.
|
|
269
|
+
*/
|
|
270
|
+
preBuild: z.string().min(1).optional(),
|
|
271
|
+
postBuild: z.string().min(1).optional()
|
|
272
|
+
});
|
|
273
|
+
var credentialsSchema = z.object({
|
|
274
|
+
/** Environment variable NAMES. A secret never belongs in this file. */
|
|
275
|
+
ascKeyId: identifier.default("ASC_API_KEY_ID"),
|
|
276
|
+
ascIssuerId: identifier.default("ASC_API_ISSUER_ID"),
|
|
277
|
+
ascKeyPath: identifier.default("ASC_API_KEY_PATH")
|
|
278
|
+
});
|
|
279
|
+
var otaStorageSchema = z.object({
|
|
280
|
+
bucket: z.string().min(1),
|
|
281
|
+
region: z.string().min(1).default("us-east-1"),
|
|
282
|
+
/** Set for S3-compatible hosts (R2, MinIO, Backblaze). Omit for AWS. */
|
|
283
|
+
endpoint: z.string().url().optional(),
|
|
284
|
+
/**
|
|
285
|
+
* Where the uploaded objects are readable from. `itms-services` refuses
|
|
286
|
+
* anything but HTTPS with a valid certificate, so this is checked, not
|
|
287
|
+
* trusted.
|
|
288
|
+
*/
|
|
289
|
+
publicBaseUrl: z.string().url().refine((u) => u.startsWith("https://"), "must be https:// \u2014 iOS refuses to install over http"),
|
|
290
|
+
prefix: z.string().default("builds"),
|
|
291
|
+
accessKeyId: identifier.default("JETBRIDGE_S3_ACCESS_KEY_ID"),
|
|
292
|
+
secretAccessKey: identifier.default("JETBRIDGE_S3_SECRET_ACCESS_KEY")
|
|
293
|
+
});
|
|
294
|
+
var otaSchema = z.object({
|
|
295
|
+
storage: otaStorageSchema,
|
|
296
|
+
exportMethod: z.enum(["ad-hoc", "enterprise"]).default("ad-hoc"),
|
|
297
|
+
/** Builds kept on the index page before the oldest is dropped. */
|
|
298
|
+
maxBuilds: z.number().int().positive().max(500).default(60),
|
|
299
|
+
/** `path` puts an unguessable token in the URL; `none` assumes a private bucket. */
|
|
300
|
+
access: z.enum(["path", "none"]).default("path"),
|
|
301
|
+
branding: z.object({
|
|
302
|
+
title: z.string().min(1).optional(),
|
|
303
|
+
accent: z.string().regex(/^#[0-9a-fA-F]{6}$/, "a six-digit hex colour").optional()
|
|
304
|
+
}).prefault({})
|
|
305
|
+
});
|
|
306
|
+
var gitSchema = z.object({
|
|
307
|
+
/** Repos disagree: main, master, trunk. */
|
|
308
|
+
defaultBranch: z.string().min(1).default("main"),
|
|
309
|
+
/**
|
|
310
|
+
* A plain (non-variant) install overwrites the app every session shares, so
|
|
311
|
+
* its provenance has to be knowable. Off by default — it is a strong
|
|
312
|
+
* convention, not a universal one.
|
|
313
|
+
*/
|
|
314
|
+
requireCleanDefaultBranch: z.boolean().default(false)
|
|
315
|
+
});
|
|
316
|
+
var configSchema = z.object({
|
|
317
|
+
$schema: z.string().optional(),
|
|
318
|
+
configVersion: z.literal(CONFIG_VERSION),
|
|
319
|
+
project: projectSchema,
|
|
320
|
+
configurations: configurationsSchema.prefault({}),
|
|
321
|
+
variant: variantSchema,
|
|
322
|
+
xcconfigOverrides: xcconfigOverrideSchema.optional(),
|
|
323
|
+
hooks: hooksSchema.prefault({}),
|
|
324
|
+
credentials: credentialsSchema.prefault({}),
|
|
325
|
+
ota: otaSchema.optional(),
|
|
326
|
+
git: gitSchema.prefault({})
|
|
327
|
+
}).superRefine((config, ctx) => {
|
|
328
|
+
const { available, wired, sim, archive } = config.configurations;
|
|
329
|
+
for (const [field, value] of Object.entries({ wired, sim, archive })) {
|
|
330
|
+
if (!available.includes(value)) {
|
|
331
|
+
ctx.addIssue({
|
|
332
|
+
code: "custom",
|
|
333
|
+
path: ["configurations", field],
|
|
334
|
+
message: `"${value}" is not in configurations.available (${available.join(", ")})`
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (config.project.xcodegen && !config.project.projectYml) {
|
|
339
|
+
ctx.addIssue({
|
|
340
|
+
code: "custom",
|
|
341
|
+
path: ["project", "projectYml"],
|
|
342
|
+
message: "project.xcodegen is on, so project.projectYml must say which spec to generate from"
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
if (!config.project.xcodeproj && !config.project.xcworkspace) {
|
|
346
|
+
ctx.addIssue({
|
|
347
|
+
code: "custom",
|
|
348
|
+
path: ["project", "xcodeproj"],
|
|
349
|
+
message: "set project.xcodeproj or project.xcworkspace"
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const appTargets = config.variant.targets.filter((t) => !t.bundleIdSuffix);
|
|
353
|
+
if (config.variant.targets.length > 0 && appTargets.length !== 1) {
|
|
354
|
+
ctx.addIssue({
|
|
355
|
+
code: "custom",
|
|
356
|
+
path: ["variant", "targets"],
|
|
357
|
+
message: appTargets.length === 0 ? "one target must be the app itself \u2014 leave its bundleIdSuffix unset" : `only one target can be the app itself; ${appTargets.map((t) => t.name).join(" and ")} both leave bundleIdSuffix unset`
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
const suffixes = config.variant.targets.map((t) => t.bundleIdSuffix ?? "");
|
|
361
|
+
const duplicate = suffixes.find((s, i) => suffixes.indexOf(s) !== i);
|
|
362
|
+
if (duplicate !== void 0) {
|
|
363
|
+
ctx.addIssue({
|
|
364
|
+
code: "custom",
|
|
365
|
+
path: ["variant", "targets"],
|
|
366
|
+
message: `two targets share the bundleIdSuffix "${duplicate}"`
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
function noiseWordsFor(config) {
|
|
371
|
+
const configured = config.variant.noiseWords;
|
|
372
|
+
if (configured) return new Set(configured.map((w) => w.toLowerCase()));
|
|
373
|
+
return /* @__PURE__ */ new Set([
|
|
374
|
+
...COMMIT_TYPE_NOISE,
|
|
375
|
+
...config.project.baseBundleId.split(".").map((s) => s.toLowerCase())
|
|
376
|
+
]);
|
|
377
|
+
}
|
|
378
|
+
function labelPrefixFor(config) {
|
|
379
|
+
return config.variant.labelPrefix ?? config.variant.displayName.split(/\s+/)[0];
|
|
380
|
+
}
|
|
381
|
+
function parseConfig(value) {
|
|
382
|
+
const result = configSchema.safeParse(value);
|
|
383
|
+
if (result.success) return { ok: true, config: result.data };
|
|
384
|
+
return {
|
|
385
|
+
ok: false,
|
|
386
|
+
errors: result.error.issues.map((issue) => ({
|
|
387
|
+
path: issue.path.join(".") || "(root)",
|
|
388
|
+
message: issue.message
|
|
389
|
+
}))
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function formatConfigErrors(errors) {
|
|
393
|
+
return errors.map((e) => ` ${e.path}: ${e.message}`).join("\n");
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/project.ts
|
|
397
|
+
function findConfigFile(boundary, from) {
|
|
398
|
+
let dir = resolve(from);
|
|
399
|
+
for (; ; ) {
|
|
400
|
+
for (const name of CONFIG_FILENAMES) {
|
|
401
|
+
const candidate = join(dir, name);
|
|
402
|
+
if (boundary.fs.exists(candidate)) return candidate;
|
|
403
|
+
}
|
|
404
|
+
const parent = dirname2(dir);
|
|
405
|
+
if (parent === dir) return null;
|
|
406
|
+
dir = parent;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function projectFrom(configPath, config) {
|
|
410
|
+
const root = dirname2(configPath);
|
|
411
|
+
const path = (...segments) => resolve(root, ...segments);
|
|
412
|
+
const iosPath = (...segments) => resolve(root, config.project.iosDir, ...segments);
|
|
413
|
+
return {
|
|
414
|
+
root,
|
|
415
|
+
configPath,
|
|
416
|
+
config,
|
|
417
|
+
path,
|
|
418
|
+
iosPath,
|
|
419
|
+
xcodebuildTarget: () => config.project.xcworkspace ? ["-workspace", iosPath(config.project.xcworkspace)] : ["-project", iosPath(config.project.xcodeproj)]
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function loadProject(boundary, options = {}) {
|
|
423
|
+
const explicit = options.configPath;
|
|
424
|
+
const configPath = explicit ? isAbsolute(explicit) ? explicit : resolve(boundary.cwd(), explicit) : findConfigFile(boundary, options.from ?? boundary.cwd());
|
|
425
|
+
if (!configPath) {
|
|
426
|
+
fail(
|
|
427
|
+
`no ${CONFIG_FILENAMES[0]} found in this directory or any parent.
|
|
428
|
+
Run \`jetbridge init\` to create one.`
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
if (!boundary.fs.exists(configPath)) {
|
|
432
|
+
fail(`config file not found: ${configPath}`);
|
|
433
|
+
}
|
|
434
|
+
let raw;
|
|
435
|
+
try {
|
|
436
|
+
raw = JSON.parse(boundary.fs.read(configPath));
|
|
437
|
+
} catch (e) {
|
|
438
|
+
return fail(`${configPath} is not valid JSON \u2014 ${e.message}`);
|
|
439
|
+
}
|
|
440
|
+
const result = parseConfig(raw);
|
|
441
|
+
if (!result.ok) {
|
|
442
|
+
return fail(
|
|
443
|
+
`${configPath} is not a valid jetbridge config:
|
|
444
|
+
${formatConfigErrors(result.errors)}`
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
return projectFrom(configPath, result.config);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/asc.ts
|
|
451
|
+
var ASC_BASE = "https://api.appstoreconnect.apple.com";
|
|
452
|
+
var TOKEN_TTL_SECONDS = 900;
|
|
453
|
+
function missingCredentialsMessage(config) {
|
|
454
|
+
const { ascKeyId, ascIssuerId, ascKeyPath } = config.credentials;
|
|
455
|
+
return `App Store Connect credentials are not configured.
|
|
456
|
+
Set ${ascKeyId} and ${ascIssuerId} in the environment, and place the private key at
|
|
457
|
+
~/.appstoreconnect/private_keys/AuthKey_<${ascKeyId}>.p8 (or point ${ascKeyPath} at it).`;
|
|
458
|
+
}
|
|
459
|
+
function keySearchDirs(boundary) {
|
|
460
|
+
const home = boundary.homedir();
|
|
461
|
+
return [
|
|
462
|
+
join2(boundary.cwd(), "private_keys"),
|
|
463
|
+
join2(home, "private_keys"),
|
|
464
|
+
join2(home, ".private_keys"),
|
|
465
|
+
join2(home, ".appstoreconnect", "private_keys")
|
|
466
|
+
];
|
|
467
|
+
}
|
|
468
|
+
function localCredentials(boundary, config) {
|
|
469
|
+
const keyId = boundary.env(config.credentials.ascKeyId);
|
|
470
|
+
const issuerId = boundary.env(config.credentials.ascIssuerId);
|
|
471
|
+
if (!keyId || !issuerId) return null;
|
|
472
|
+
const explicit = boundary.env(config.credentials.ascKeyPath);
|
|
473
|
+
const keyPath = explicit ?? keySearchDirs(boundary).map((dir) => join2(dir, `AuthKey_${keyId}.p8`)).find((path) => boundary.fs.exists(path));
|
|
474
|
+
if (!keyPath || !boundary.fs.exists(keyPath)) return null;
|
|
475
|
+
return { keyPath, keyId, issuerId };
|
|
476
|
+
}
|
|
477
|
+
var b64url = (value) => value.toString("base64url");
|
|
478
|
+
function mintToken(boundary, credentials2) {
|
|
479
|
+
const now = boundary.now();
|
|
480
|
+
const header = b64url(
|
|
481
|
+
Buffer.from(JSON.stringify({ alg: "ES256", kid: credentials2.keyId, typ: "JWT" }))
|
|
482
|
+
);
|
|
483
|
+
const payload = b64url(
|
|
484
|
+
Buffer.from(
|
|
485
|
+
JSON.stringify({
|
|
486
|
+
iss: credentials2.issuerId,
|
|
487
|
+
iat: now,
|
|
488
|
+
exp: now + TOKEN_TTL_SECONDS,
|
|
489
|
+
aud: "appstoreconnect-v1"
|
|
490
|
+
})
|
|
491
|
+
)
|
|
492
|
+
);
|
|
493
|
+
const input = `${header}.${payload}`;
|
|
494
|
+
const key = createPrivateKey(boundary.fs.read(credentials2.keyPath));
|
|
495
|
+
const signature = cryptoSign("sha256", Buffer.from(input), { key, dsaEncoding: "ieee-p1363" });
|
|
496
|
+
return `${input}.${b64url(signature)}`;
|
|
497
|
+
}
|
|
498
|
+
function ascClient(boundary, token) {
|
|
499
|
+
return {
|
|
500
|
+
async request(method, path, body) {
|
|
501
|
+
const response = await boundary.http({
|
|
502
|
+
method,
|
|
503
|
+
url: `${ASC_BASE}${path}`,
|
|
504
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
505
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
506
|
+
});
|
|
507
|
+
const text2 = await response.text();
|
|
508
|
+
let parsed = {};
|
|
509
|
+
if (text2) {
|
|
510
|
+
try {
|
|
511
|
+
parsed = JSON.parse(text2);
|
|
512
|
+
} catch {
|
|
513
|
+
parsed = { errors: [{ detail: text2.slice(0, 400) }] };
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return { status: response.status, body: parsed };
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function describeAscError(body) {
|
|
521
|
+
const errors = body?.errors;
|
|
522
|
+
if (!errors?.length) return typeof body === "string" ? body : JSON.stringify(body);
|
|
523
|
+
return errors.map((e) => [e.title, e.detail].filter(Boolean).join(": ")).join("; ");
|
|
524
|
+
}
|
|
525
|
+
function requireCredentials(boundary, config) {
|
|
526
|
+
const credentials2 = localCredentials(boundary, config);
|
|
527
|
+
if (!credentials2) fail(missingCredentialsMessage(config));
|
|
528
|
+
return credentials2;
|
|
529
|
+
}
|
|
530
|
+
function connect(boundary, config) {
|
|
531
|
+
return ascClient(boundary, mintToken(boundary, requireCredentials(boundary, config)));
|
|
532
|
+
}
|
|
533
|
+
var asArray = (data) => Array.isArray(data) ? data : data ? [data] : [];
|
|
534
|
+
|
|
535
|
+
// src/provision.ts
|
|
536
|
+
import { join as join3 } from "path";
|
|
537
|
+
|
|
538
|
+
// src/variant.ts
|
|
539
|
+
function variantWords(raw, noiseWords) {
|
|
540
|
+
const words = raw.split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
541
|
+
while (words.length > 1 && noiseWords.has(words[0].toLowerCase())) words.shift();
|
|
542
|
+
if (words.length === 0) fail("a variant slug must contain letters or digits");
|
|
543
|
+
return words;
|
|
544
|
+
}
|
|
545
|
+
function sanitizeSuffix(raw, config) {
|
|
546
|
+
return variantWords(raw, noiseWordsFor(config)).join("").toLowerCase();
|
|
547
|
+
}
|
|
548
|
+
function variantTitle(raw, config) {
|
|
549
|
+
return variantWords(raw, noiseWordsFor(config)).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
550
|
+
}
|
|
551
|
+
function sanitizeName(raw) {
|
|
552
|
+
const name = raw.replace(/[^A-Za-z0-9 ._-]/g, "");
|
|
553
|
+
if (!name) fail("a display name must contain letters or digits");
|
|
554
|
+
return name;
|
|
555
|
+
}
|
|
556
|
+
function ascEntityName(displayName) {
|
|
557
|
+
const name = displayName.replace(/[^A-Za-z0-9 ]+/g, " ").replace(/\s+/g, " ").trim();
|
|
558
|
+
if (!name) fail(`cannot build an App Store Connect name from "${displayName}"`);
|
|
559
|
+
return name;
|
|
560
|
+
}
|
|
561
|
+
function bundleIdFor(suffix, config) {
|
|
562
|
+
const base = config.project.baseBundleId;
|
|
563
|
+
return suffix ? `${base}.${suffix}` : base;
|
|
564
|
+
}
|
|
565
|
+
function displayNameFor(rawSuffix, explicit, config) {
|
|
566
|
+
if (explicit) return explicit;
|
|
567
|
+
if (!rawSuffix) return config.variant.displayName;
|
|
568
|
+
return `${labelPrefixFor(config)} ${variantTitle(rawSuffix, config)}`;
|
|
569
|
+
}
|
|
570
|
+
function assertSingleSegment(value, config) {
|
|
571
|
+
if (value.includes(".")) {
|
|
572
|
+
fail(
|
|
573
|
+
`a variant slug is just the last segment \u2014 "${config.project.baseBundleId}.<slug>" is built for you (e.g. "wave")`
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
return value;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// src/provision.ts
|
|
580
|
+
var profileDirectory = (boundary) => join3(boundary.homedir(), "Library", "MobileDevice", "Provisioning Profiles");
|
|
581
|
+
var errorText = (status, body) => `${status} ${describeAscError(body)}`;
|
|
582
|
+
async function ensureBundleId(client, identifier2, name) {
|
|
583
|
+
const existing = await client.request(
|
|
584
|
+
"GET",
|
|
585
|
+
`/v1/bundleIds?filter[identifier]=${encodeURIComponent(identifier2)}&limit=5`
|
|
586
|
+
);
|
|
587
|
+
if (existing.status === 200) {
|
|
588
|
+
const match = asArray(existing.body.data).find(
|
|
589
|
+
(row2) => row2.attributes.identifier === identifier2
|
|
590
|
+
);
|
|
591
|
+
if (match) return match.id;
|
|
592
|
+
}
|
|
593
|
+
const created = await client.request("POST", "/v1/bundleIds", {
|
|
594
|
+
data: {
|
|
595
|
+
type: "bundleIds",
|
|
596
|
+
attributes: { identifier: identifier2, name, platform: "IOS" }
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
if (created.status !== 201) {
|
|
600
|
+
fail(
|
|
601
|
+
`could not register the bundle id ${identifier2}: ${errorText(created.status, created.body)}`
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
const row = asArray(created.body.data)[0];
|
|
605
|
+
if (!row) fail(`App Store Connect registered ${identifier2} but returned no id`);
|
|
606
|
+
return row.id;
|
|
607
|
+
}
|
|
608
|
+
async function ensureCapabilities(client, bundleRowId, capabilities) {
|
|
609
|
+
for (const capability of capabilities) {
|
|
610
|
+
const result = await client.request("POST", "/v1/bundleIdCapabilities", {
|
|
611
|
+
data: {
|
|
612
|
+
type: "bundleIdCapabilities",
|
|
613
|
+
attributes: { capabilityType: capability },
|
|
614
|
+
relationships: { bundleId: { data: { type: "bundleIds", id: bundleRowId } } }
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
if (![200, 201, 409].includes(result.status)) {
|
|
618
|
+
fail(`could not enable ${capability}: ${errorText(result.status, result.body)}`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
async function localDevelopmentCertificateId(boundary, client) {
|
|
623
|
+
const identities = boundary.exec.runSync("security", [
|
|
624
|
+
"find-identity",
|
|
625
|
+
"-v",
|
|
626
|
+
"-p",
|
|
627
|
+
"codesigning"
|
|
628
|
+
]);
|
|
629
|
+
const certificates = await client.request(
|
|
630
|
+
"GET",
|
|
631
|
+
"/v1/certificates?filter[certificateType]=DEVELOPMENT&limit=50"
|
|
632
|
+
);
|
|
633
|
+
if (certificates.status !== 200) {
|
|
634
|
+
fail(
|
|
635
|
+
`could not list signing certificates: ${errorText(certificates.status, certificates.body)}`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
const match = asArray(certificates.body.data).find((certificate) => {
|
|
639
|
+
const displayName = certificate.attributes.displayName;
|
|
640
|
+
return typeof displayName === "string" && identities.stdout.includes(displayName);
|
|
641
|
+
});
|
|
642
|
+
if (!match) {
|
|
643
|
+
fail(
|
|
644
|
+
"no App Store Connect development certificate matches a signing identity in this keychain.\n Create one in Xcode once (Settings \u203A Accounts \u203A Manage Certificates), or import the\n existing certificate's private key into this keychain."
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
return match.id;
|
|
648
|
+
}
|
|
649
|
+
async function enabledDeviceIds(client) {
|
|
650
|
+
const devices = await client.request(
|
|
651
|
+
"GET",
|
|
652
|
+
"/v1/devices?filter[platform]=IOS&filter[status]=ENABLED&limit=200"
|
|
653
|
+
);
|
|
654
|
+
if (devices.status !== 200) {
|
|
655
|
+
fail(`could not list registered devices: ${errorText(devices.status, devices.body)}`);
|
|
656
|
+
}
|
|
657
|
+
return asArray(devices.body.data).map((device) => device.id);
|
|
658
|
+
}
|
|
659
|
+
function profileUuid(contents) {
|
|
660
|
+
const text2 = Buffer.from(contents).toString("binary");
|
|
661
|
+
const start = text2.indexOf("<?xml");
|
|
662
|
+
const end = text2.indexOf("</plist>");
|
|
663
|
+
if (start === -1 || end === -1)
|
|
664
|
+
fail("the profile App Store Connect returned has no plist inside");
|
|
665
|
+
const plist = text2.slice(start, end + "</plist>".length);
|
|
666
|
+
const uuid = /<key>UUID<\/key>\s*<string>([^<]+)<\/string>/.exec(plist)?.[1];
|
|
667
|
+
if (!uuid) fail("the profile App Store Connect returned carries no UUID");
|
|
668
|
+
return uuid;
|
|
669
|
+
}
|
|
670
|
+
async function ensureProfile(boundary, client, options) {
|
|
671
|
+
const existing = await client.request(
|
|
672
|
+
"GET",
|
|
673
|
+
`/v1/profiles?filter[name]=${encodeURIComponent(options.name)}&limit=5`
|
|
674
|
+
);
|
|
675
|
+
if (existing.status === 200) {
|
|
676
|
+
for (const row2 of asArray(existing.body.data)) {
|
|
677
|
+
if (row2.attributes.name === options.name) {
|
|
678
|
+
await client.request("DELETE", `/v1/profiles/${row2.id}`);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
const created = await client.request("POST", "/v1/profiles", {
|
|
683
|
+
data: {
|
|
684
|
+
type: "profiles",
|
|
685
|
+
attributes: { name: options.name, profileType: options.profileType },
|
|
686
|
+
relationships: {
|
|
687
|
+
bundleId: { data: { type: "bundleIds", id: options.bundleRowId } },
|
|
688
|
+
certificates: { data: [{ type: "certificates", id: options.certificateId }] },
|
|
689
|
+
devices: { data: options.deviceIds.map((id) => ({ type: "devices", id })) }
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
if (created.status !== 201) {
|
|
694
|
+
fail(
|
|
695
|
+
`could not create the profile "${options.name}": ${errorText(created.status, created.body)}`
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
const row = asArray(created.body.data)[0];
|
|
699
|
+
const encoded = row?.attributes.profileContent;
|
|
700
|
+
if (typeof encoded !== "string") fail(`the profile "${options.name}" came back empty`);
|
|
701
|
+
const contents = Buffer.from(encoded, "base64");
|
|
702
|
+
const uuid = profileUuid(contents);
|
|
703
|
+
const installedAt = join3(profileDirectory(boundary), `${uuid}.mobileprovision`);
|
|
704
|
+
boundary.fs.write(installedAt, new Uint8Array(contents));
|
|
705
|
+
return { uuid, installedAt };
|
|
706
|
+
}
|
|
707
|
+
function targetBundleId(target, suffix, config) {
|
|
708
|
+
const appId = bundleIdFor(suffix, config);
|
|
709
|
+
return target.bundleIdSuffix ? `${appId}.${target.bundleIdSuffix}` : appId;
|
|
710
|
+
}
|
|
711
|
+
function targetEntityName(target, displayName) {
|
|
712
|
+
return ascEntityName(target.bundleIdSuffix ? `${displayName} ${target.name}` : displayName);
|
|
713
|
+
}
|
|
714
|
+
function profileNameFor(target, suffix, config) {
|
|
715
|
+
const prefix = config.variant.profilePrefix ?? labelPrefixFor(config);
|
|
716
|
+
return `${prefix} ${suffix} ${target.bundleIdSuffix ?? "app"}`;
|
|
717
|
+
}
|
|
718
|
+
async function provisionVariant(boundary, project, options) {
|
|
719
|
+
const { config } = project;
|
|
720
|
+
const targets = config.variant.targets;
|
|
721
|
+
if (targets.length === 0) {
|
|
722
|
+
fail(
|
|
723
|
+
"a variant build needs at least one entry in variant.targets \u2014 the app itself, and any extension that ships inside it."
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
if (!options.suffix) fail("provisionVariant needs a variant slug");
|
|
727
|
+
const client = connect(boundary, config);
|
|
728
|
+
const profileType = options.profileType ?? "IOS_APP_DEVELOPMENT";
|
|
729
|
+
const registered = [];
|
|
730
|
+
for (const target of targets) {
|
|
731
|
+
const bundleId = targetBundleId(target, options.suffix, config);
|
|
732
|
+
boundary.log.step(`provisioning ${bundleId}`);
|
|
733
|
+
const rowId = await ensureBundleId(
|
|
734
|
+
client,
|
|
735
|
+
bundleId,
|
|
736
|
+
targetEntityName(target, options.displayName)
|
|
737
|
+
);
|
|
738
|
+
await ensureCapabilities(client, rowId, target.capabilities);
|
|
739
|
+
registered.push({ target, bundleId, rowId });
|
|
740
|
+
}
|
|
741
|
+
const certificateId = await localDevelopmentCertificateId(boundary, client);
|
|
742
|
+
const deviceIds = await enabledDeviceIds(client);
|
|
743
|
+
if (deviceIds.length === 0) {
|
|
744
|
+
fail(
|
|
745
|
+
"no enabled iOS devices are registered on this team, so a profile would install nowhere.\n Register the device once (plug it in and build from Xcode), then re-run."
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
const profiles = [];
|
|
749
|
+
for (const { target, bundleId, rowId } of registered) {
|
|
750
|
+
const profileName = profileNameFor(target, options.suffix, config);
|
|
751
|
+
const { uuid, installedAt } = await ensureProfile(boundary, client, {
|
|
752
|
+
name: profileName,
|
|
753
|
+
bundleRowId: rowId,
|
|
754
|
+
certificateId,
|
|
755
|
+
deviceIds,
|
|
756
|
+
profileType
|
|
757
|
+
});
|
|
758
|
+
profiles.push({ target: target.name, bundleId, profileName, installedAt, uuid });
|
|
759
|
+
}
|
|
760
|
+
return profiles;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// src/bundles.ts
|
|
764
|
+
function protectedBundleIds(config) {
|
|
765
|
+
const base = config.project.baseBundleId;
|
|
766
|
+
return /* @__PURE__ */ new Set([
|
|
767
|
+
base,
|
|
768
|
+
...config.variant.targets.filter((target) => target.bundleIdSuffix).map((target) => `${base}.${target.bundleIdSuffix}`)
|
|
769
|
+
]);
|
|
770
|
+
}
|
|
771
|
+
function assertDeletable(identifier2, config) {
|
|
772
|
+
const base = config.project.baseBundleId;
|
|
773
|
+
if (protectedBundleIds(config).has(identifier2)) {
|
|
774
|
+
fail(
|
|
775
|
+
`refusing to delete ${identifier2} \u2014 it is a core identifier, not a variant.
|
|
776
|
+
This is a bug: it should never have been selected. Nothing further was deleted.`
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
if (!identifier2.startsWith(`${base}.`)) {
|
|
780
|
+
fail(
|
|
781
|
+
`refusing to delete ${identifier2} \u2014 it is not a "${base}.*" variant of this project.
|
|
782
|
+
Remove it from the Apple Developer portal by hand if you really mean to.`
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
async function fetchBundleIds(client) {
|
|
787
|
+
const result = await client.request("GET", "/v1/bundleIds?limit=200");
|
|
788
|
+
if (result.status !== 200) {
|
|
789
|
+
fail(
|
|
790
|
+
`could not list bundle ids (HTTP ${result.status}).
|
|
791
|
+
Check that the App Store Connect key still has access to this team.`
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
return asArray(result.body.data).map((row) => ({
|
|
795
|
+
id: row.id,
|
|
796
|
+
identifier: String(row.attributes.identifier ?? ""),
|
|
797
|
+
name: String(row.attributes.name ?? "")
|
|
798
|
+
}));
|
|
799
|
+
}
|
|
800
|
+
async function fetchProfiles(client) {
|
|
801
|
+
const result = await client.request("GET", "/v1/profiles?limit=200");
|
|
802
|
+
if (result.status !== 200) {
|
|
803
|
+
fail(
|
|
804
|
+
`could not list provisioning profiles (HTTP ${result.status}).
|
|
805
|
+
Check that the App Store Connect key still has access to this team.`
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
return asArray(result.body.data).map((row) => ({
|
|
809
|
+
id: row.id,
|
|
810
|
+
name: String(row.attributes.name ?? ""),
|
|
811
|
+
createdDate: String(row.attributes.createdDate ?? "")
|
|
812
|
+
}));
|
|
813
|
+
}
|
|
814
|
+
function groupVariants(bundleIds, profiles, config) {
|
|
815
|
+
const prefix = `${config.project.baseBundleId}.`;
|
|
816
|
+
const protectedIds = protectedBundleIds(config);
|
|
817
|
+
const profilePrefix = config.variant.profilePrefix ?? labelPrefixFor(config);
|
|
818
|
+
return bundleIds.filter((bundle) => {
|
|
819
|
+
if (protectedIds.has(bundle.identifier)) return false;
|
|
820
|
+
if (!bundle.identifier.startsWith(prefix)) return false;
|
|
821
|
+
const slug = bundle.identifier.slice(prefix.length);
|
|
822
|
+
return slug.length > 0 && !slug.includes(".");
|
|
823
|
+
}).map((app) => {
|
|
824
|
+
const suffix = app.identifier.slice(prefix.length);
|
|
825
|
+
return {
|
|
826
|
+
suffix,
|
|
827
|
+
app,
|
|
828
|
+
extensions: bundleIds.filter(
|
|
829
|
+
(bundle) => bundle.identifier.startsWith(`${app.identifier}.`)
|
|
830
|
+
),
|
|
831
|
+
// Matched on the prefix rather than the exact names `profileNameFor`
|
|
832
|
+
// mints, so a profile for a target that has since left the config is
|
|
833
|
+
// still swept up with its bundle id.
|
|
834
|
+
profiles: profiles.filter(
|
|
835
|
+
(profile) => profile.name.startsWith(`${profilePrefix} ${suffix} `)
|
|
836
|
+
)
|
|
837
|
+
};
|
|
838
|
+
}).sort((a, b) => a.suffix.localeCompare(b.suffix));
|
|
839
|
+
}
|
|
840
|
+
async function readAccount(boundary, project) {
|
|
841
|
+
const client = connect(boundary, project.config);
|
|
842
|
+
boundary.log.step("reading the developer account");
|
|
843
|
+
const [bundleIds, profiles] = await Promise.all([fetchBundleIds(client), fetchProfiles(client)]);
|
|
844
|
+
return { client, variants: groupVariants(bundleIds, profiles, project.config) };
|
|
845
|
+
}
|
|
846
|
+
function firstSeen(variant) {
|
|
847
|
+
const dates = variant.profiles.map((profile) => profile.createdDate).filter(Boolean).sort();
|
|
848
|
+
return dates[0]?.slice(0, 10) ?? "\u2014";
|
|
849
|
+
}
|
|
850
|
+
var toRecords = (variants) => variants.map((variant) => ({
|
|
851
|
+
slug: variant.suffix,
|
|
852
|
+
bundleId: variant.app.identifier,
|
|
853
|
+
name: variant.app.name,
|
|
854
|
+
extensions: variant.extensions.map((extension) => extension.identifier),
|
|
855
|
+
profileCount: variant.profiles.length,
|
|
856
|
+
created: firstSeen(variant) === "\u2014" ? null : firstSeen(variant)
|
|
857
|
+
}));
|
|
858
|
+
var COLUMNS = ["SLUG", "BUNDLE ID", "PROFILES", "CREATED"];
|
|
859
|
+
function renderTable(variants) {
|
|
860
|
+
const rows = variants.map((variant) => [
|
|
861
|
+
variant.suffix,
|
|
862
|
+
variant.app.identifier,
|
|
863
|
+
String(variant.profiles.length),
|
|
864
|
+
firstSeen(variant)
|
|
865
|
+
]);
|
|
866
|
+
const widths = COLUMNS.map(
|
|
867
|
+
(heading, column) => Math.max(heading.length, ...rows.map((row) => row[column].length), 0)
|
|
868
|
+
);
|
|
869
|
+
const line = (cells) => cells.map((cell, column) => column === cells.length - 1 ? cell : cell.padEnd(widths[column])).join(" ");
|
|
870
|
+
return [line(COLUMNS), ...rows.map(line)].join("\n");
|
|
871
|
+
}
|
|
872
|
+
async function listBundles(boundary, project, options = {}) {
|
|
873
|
+
const { variants } = await readAccount(boundary, project);
|
|
874
|
+
if (variants.length === 0 && !options.json) {
|
|
875
|
+
boundary.log.info(`no variants of ${project.config.project.baseBundleId} are registered.`);
|
|
876
|
+
}
|
|
877
|
+
const output = options.json ? JSON.stringify(toRecords(variants), null, 2) : renderTable(variants);
|
|
878
|
+
console.log(output);
|
|
879
|
+
return output;
|
|
880
|
+
}
|
|
881
|
+
function describe(variant, reason) {
|
|
882
|
+
const lines = [
|
|
883
|
+
` ${variant.app.identifier} "${variant.app.name}"${reason ? ` \u2014 ${reason}` : ""}`
|
|
884
|
+
];
|
|
885
|
+
for (const extension of variant.extensions) lines.push(` ${extension.identifier}`);
|
|
886
|
+
for (const profile of variant.profiles) lines.push(` profile: ${profile.name}`);
|
|
887
|
+
if (variant.extensions.length === 0 && variant.profiles.length === 0) {
|
|
888
|
+
lines.push(" (no extensions or profiles)");
|
|
889
|
+
}
|
|
890
|
+
return lines;
|
|
891
|
+
}
|
|
892
|
+
async function deleteVariant(boundary, client, config, variant) {
|
|
893
|
+
assertDeletable(variant.app.identifier, config);
|
|
894
|
+
for (const extension of variant.extensions) assertDeletable(extension.identifier, config);
|
|
895
|
+
for (const profile of variant.profiles) {
|
|
896
|
+
const result2 = await client.request("DELETE", `/v1/profiles/${profile.id}`);
|
|
897
|
+
if (result2.status !== 204) {
|
|
898
|
+
boundary.log.warn(`profile "${profile.name}" was not deleted (HTTP ${result2.status})`);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
for (const extension of variant.extensions) {
|
|
902
|
+
const result2 = await client.request("DELETE", `/v1/bundleIds/${extension.id}`);
|
|
903
|
+
if (result2.status !== 204) {
|
|
904
|
+
fail(
|
|
905
|
+
`${extension.identifier} was not deleted (HTTP ${result2.status}).
|
|
906
|
+
Delete it in the Apple Developer portal, then re-run.`
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
const result = await client.request("DELETE", `/v1/bundleIds/${variant.app.id}`);
|
|
911
|
+
if (result.status !== 204) {
|
|
912
|
+
fail(
|
|
913
|
+
`${variant.app.identifier} was not deleted (HTTP ${result.status}).
|
|
914
|
+
A profile may still reference it \u2014 check the Apple Developer portal.`
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
async function removeSelected(boundary, client, project, selected, yes) {
|
|
919
|
+
boundary.log.info(
|
|
920
|
+
yes ? "deleting from the Apple Developer account:" : "would delete from the Apple Developer account:"
|
|
921
|
+
);
|
|
922
|
+
for (const { variant, reason } of selected) {
|
|
923
|
+
boundary.log.info(describe(variant, reason).join("\n"));
|
|
924
|
+
}
|
|
925
|
+
const slugs = selected.map(({ variant }) => variant.suffix);
|
|
926
|
+
if (!yes) {
|
|
927
|
+
boundary.log.warn(
|
|
928
|
+
`dry run \u2014 nothing was deleted. Re-run with -y to remove ${slugs.length} variant(s).`
|
|
929
|
+
);
|
|
930
|
+
return { slugs, dryRun: true };
|
|
931
|
+
}
|
|
932
|
+
for (const { variant } of selected) {
|
|
933
|
+
boundary.log.step(`deleting ${variant.app.identifier}`);
|
|
934
|
+
await deleteVariant(boundary, client, project.config, variant);
|
|
935
|
+
boundary.log.info(`removed ${variant.app.identifier}`);
|
|
936
|
+
}
|
|
937
|
+
boundary.log.info(`done \u2014 ${slugs.length} variant(s) removed.`);
|
|
938
|
+
return { slugs, dryRun: false };
|
|
939
|
+
}
|
|
940
|
+
async function removeBundles(boundary, project, options) {
|
|
941
|
+
if (options.suffixes.length === 0) {
|
|
942
|
+
fail(
|
|
943
|
+
"name at least one variant to remove.\n `jetbridge bundles ls` shows what is registered; `bundles prune` removes the stale ones."
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
const { client, variants } = await readAccount(boundary, project);
|
|
947
|
+
const selected = options.suffixes.map((slug) => {
|
|
948
|
+
const variant = variants.find((candidate) => candidate.suffix === slug);
|
|
949
|
+
if (!variant) {
|
|
950
|
+
fail(
|
|
951
|
+
`no variant "${slug}" is registered \u2014 nothing was deleted.
|
|
952
|
+
Registered: ${variants.map((candidate) => candidate.suffix).join(", ") || "(none)"}`
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
return { variant };
|
|
956
|
+
});
|
|
957
|
+
return removeSelected(boundary, client, project, selected, Boolean(options.yes));
|
|
958
|
+
}
|
|
959
|
+
async function liveBranchSlugs(boundary, project) {
|
|
960
|
+
const inRepo = await boundary.exec.run("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
961
|
+
cwd: project.root,
|
|
962
|
+
allowFail: true
|
|
963
|
+
});
|
|
964
|
+
if (!inRepo.ok || inRepo.stdout.trim() !== "true") {
|
|
965
|
+
fail(
|
|
966
|
+
"prune decides what is stale from the branches on the remote, and this is not a git checkout.\n Remove them by name instead: `jetbridge bundles rm <slug>`."
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
const remote = await boundary.exec.run("git", ["ls-remote", "--heads", "origin"], {
|
|
970
|
+
cwd: project.root,
|
|
971
|
+
allowFail: true
|
|
972
|
+
});
|
|
973
|
+
if (!remote.ok) {
|
|
974
|
+
fail(
|
|
975
|
+
`could not reach the git remote, so prune cannot tell which branches are gone.
|
|
976
|
+
${(remote.stderr || remote.stdout).trim().split("\n").slice(-3).join("\n ")}
|
|
977
|
+
Nothing was deleted. Reconnect and re-run, or name them with \`bundles rm <slug>\`.`
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
const branches = remote.stdout.split("\n").map((line) => /\srefs\/heads\/(.+)$/.exec(line.trim())?.[1]).filter((branch) => Boolean(branch));
|
|
981
|
+
if (branches.length === 0) {
|
|
982
|
+
fail(
|
|
983
|
+
"the git remote reported no branches at all, which would mark every variant stale.\n Nothing was deleted. Check `git ls-remote --heads origin` by hand."
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
const slugs = /* @__PURE__ */ new Set();
|
|
987
|
+
for (const branch of branches) {
|
|
988
|
+
try {
|
|
989
|
+
slugs.add(sanitizeSuffix(branch, project.config));
|
|
990
|
+
} catch {
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return slugs;
|
|
994
|
+
}
|
|
995
|
+
async function pruneBundles(boundary, project, options = {}) {
|
|
996
|
+
const live = await liveBranchSlugs(boundary, project);
|
|
997
|
+
const { client, variants } = await readAccount(boundary, project);
|
|
998
|
+
const stale = variants.filter((variant) => !live.has(variant.suffix));
|
|
999
|
+
const kept = variants.length - stale.length;
|
|
1000
|
+
boundary.log.info(
|
|
1001
|
+
`${variants.length} variant(s) registered, ${kept} with a branch still on the remote.`
|
|
1002
|
+
);
|
|
1003
|
+
if (stale.length === 0) {
|
|
1004
|
+
boundary.log.info("nothing to prune.");
|
|
1005
|
+
return { slugs: [], dryRun: false };
|
|
1006
|
+
}
|
|
1007
|
+
return removeSelected(
|
|
1008
|
+
boundary,
|
|
1009
|
+
client,
|
|
1010
|
+
project,
|
|
1011
|
+
stale.map((variant) => ({ variant, reason: "no branch on the remote maps to this slug" })),
|
|
1012
|
+
Boolean(options.yes)
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
async function provisionBundles(boundary, project, options) {
|
|
1016
|
+
const { suffix, displayName } = options;
|
|
1017
|
+
if (!suffix) {
|
|
1018
|
+
fail(
|
|
1019
|
+
"name the variant to provision, e.g. `jetbridge bundles provision wave`.\n A plain build signs against the profile the project already has \u2014 there is nothing\n for this command to register."
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
const profiles = await provisionVariant(boundary, project, { suffix, displayName });
|
|
1023
|
+
for (const profile of profiles) {
|
|
1024
|
+
boundary.log.info(`${profile.bundleId} \u2192 "${profile.profileName}" (${profile.installedAt})`);
|
|
1025
|
+
}
|
|
1026
|
+
boundary.log.info(`done \u2014 ${profiles.length} profile(s) installed for "${suffix}".`);
|
|
1027
|
+
return profiles;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// src/init.ts
|
|
1031
|
+
import { join as join5, resolve as resolve3 } from "path";
|
|
1032
|
+
|
|
1033
|
+
// src/detect.ts
|
|
1034
|
+
import { isAbsolute as isAbsolute2, join as join4, relative, resolve as resolve2 } from "path";
|
|
1035
|
+
var isDict = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1036
|
+
var asString = (value) => typeof value === "string" ? value : void 0;
|
|
1037
|
+
function parsePlist(text2) {
|
|
1038
|
+
let at = 0;
|
|
1039
|
+
const skip = () => {
|
|
1040
|
+
for (; ; ) {
|
|
1041
|
+
while (at < text2.length && /\s/.test(text2[at])) at += 1;
|
|
1042
|
+
if (text2.startsWith("//", at)) {
|
|
1043
|
+
const end = text2.indexOf("\n", at);
|
|
1044
|
+
at = end === -1 ? text2.length : end + 1;
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
if (text2.startsWith("/*", at)) {
|
|
1048
|
+
const end = text2.indexOf("*/", at + 2);
|
|
1049
|
+
at = end === -1 ? text2.length : end + 2;
|
|
1050
|
+
continue;
|
|
1051
|
+
}
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
const quoted = () => {
|
|
1056
|
+
at += 1;
|
|
1057
|
+
let out = "";
|
|
1058
|
+
while (at < text2.length && text2[at] !== '"') {
|
|
1059
|
+
if (text2[at] === "\\") {
|
|
1060
|
+
out += text2[at + 1] ?? "";
|
|
1061
|
+
at += 2;
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
out += text2[at];
|
|
1065
|
+
at += 1;
|
|
1066
|
+
}
|
|
1067
|
+
at += 1;
|
|
1068
|
+
return out;
|
|
1069
|
+
};
|
|
1070
|
+
const bare = () => {
|
|
1071
|
+
const start = at;
|
|
1072
|
+
while (at < text2.length && !/[\s;,=(){}]/.test(text2[at])) at += 1;
|
|
1073
|
+
if (at === start) throw new Error(`unexpected "${text2[at]}" at ${at}`);
|
|
1074
|
+
return text2.slice(start, at);
|
|
1075
|
+
};
|
|
1076
|
+
const value = () => {
|
|
1077
|
+
skip();
|
|
1078
|
+
const char = text2[at];
|
|
1079
|
+
if (char === "{") return dict();
|
|
1080
|
+
if (char === "(") return array();
|
|
1081
|
+
if (char === '"') return quoted();
|
|
1082
|
+
return bare();
|
|
1083
|
+
};
|
|
1084
|
+
const dict = () => {
|
|
1085
|
+
at += 1;
|
|
1086
|
+
const out = {};
|
|
1087
|
+
for (; ; ) {
|
|
1088
|
+
skip();
|
|
1089
|
+
if (text2[at] === "}") {
|
|
1090
|
+
at += 1;
|
|
1091
|
+
return out;
|
|
1092
|
+
}
|
|
1093
|
+
if (at >= text2.length) throw new Error("unterminated {");
|
|
1094
|
+
const key = text2[at] === '"' ? quoted() : bare();
|
|
1095
|
+
skip();
|
|
1096
|
+
if (text2[at] !== "=") throw new Error(`expected = after ${key}`);
|
|
1097
|
+
at += 1;
|
|
1098
|
+
out[key] = value();
|
|
1099
|
+
skip();
|
|
1100
|
+
if (text2[at] === ";") at += 1;
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
const array = () => {
|
|
1104
|
+
at += 1;
|
|
1105
|
+
const out = [];
|
|
1106
|
+
for (; ; ) {
|
|
1107
|
+
skip();
|
|
1108
|
+
if (text2[at] === ")") {
|
|
1109
|
+
at += 1;
|
|
1110
|
+
return out;
|
|
1111
|
+
}
|
|
1112
|
+
if (at >= text2.length) throw new Error("unterminated (");
|
|
1113
|
+
out.push(value());
|
|
1114
|
+
skip();
|
|
1115
|
+
if (text2[at] === ",") at += 1;
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
skip();
|
|
1119
|
+
return value();
|
|
1120
|
+
}
|
|
1121
|
+
var emptyFacts = (warnings) => ({
|
|
1122
|
+
projectConfigurations: [],
|
|
1123
|
+
allConfigurations: [],
|
|
1124
|
+
projectSettings: {},
|
|
1125
|
+
targets: [],
|
|
1126
|
+
warnings
|
|
1127
|
+
});
|
|
1128
|
+
function scalarSettings(value) {
|
|
1129
|
+
const out = {};
|
|
1130
|
+
if (!isDict(value)) return out;
|
|
1131
|
+
for (const [key, setting] of Object.entries(value)) {
|
|
1132
|
+
if (typeof setting === "string") out[key] = setting;
|
|
1133
|
+
}
|
|
1134
|
+
return out;
|
|
1135
|
+
}
|
|
1136
|
+
function parsePbxproj(text2) {
|
|
1137
|
+
let root;
|
|
1138
|
+
try {
|
|
1139
|
+
root = parsePlist(text2);
|
|
1140
|
+
} catch (e) {
|
|
1141
|
+
return emptyFacts([`project.pbxproj could not be parsed \u2014 ${e.message}`]);
|
|
1142
|
+
}
|
|
1143
|
+
if (!isDict(root) || !isDict(root.objects)) {
|
|
1144
|
+
return emptyFacts(["project.pbxproj has no objects section"]);
|
|
1145
|
+
}
|
|
1146
|
+
const warnings = [];
|
|
1147
|
+
const objects = root.objects;
|
|
1148
|
+
const object = (id) => {
|
|
1149
|
+
const found = typeof id === "string" ? objects[id] : void 0;
|
|
1150
|
+
return isDict(found) ? found : void 0;
|
|
1151
|
+
};
|
|
1152
|
+
const settingsFor = (listId) => {
|
|
1153
|
+
const out = {};
|
|
1154
|
+
const list = object(listId);
|
|
1155
|
+
const ids = list?.buildConfigurations;
|
|
1156
|
+
if (!Array.isArray(ids)) return out;
|
|
1157
|
+
for (const id of ids) {
|
|
1158
|
+
const configuration = object(id);
|
|
1159
|
+
const name = asString(configuration?.name);
|
|
1160
|
+
if (!name) continue;
|
|
1161
|
+
out[name] = scalarSettings(configuration?.buildSettings);
|
|
1162
|
+
}
|
|
1163
|
+
return out;
|
|
1164
|
+
};
|
|
1165
|
+
const allConfigurations = /* @__PURE__ */ new Set();
|
|
1166
|
+
for (const entry of Object.values(objects)) {
|
|
1167
|
+
if (isDict(entry) && entry.isa === "XCBuildConfiguration") {
|
|
1168
|
+
const name = asString(entry.name);
|
|
1169
|
+
if (name) allConfigurations.add(name);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
const project = object(root.rootObject) ?? Object.values(objects).find((entry) => isDict(entry) && entry.isa === "PBXProject");
|
|
1173
|
+
const projectSettings = settingsFor(isDict(project) ? project.buildConfigurationList : void 0);
|
|
1174
|
+
let projectConfigurations = Object.keys(projectSettings);
|
|
1175
|
+
if (projectConfigurations.length === 0) {
|
|
1176
|
+
projectConfigurations = [...allConfigurations];
|
|
1177
|
+
if (projectConfigurations.length > 0) {
|
|
1178
|
+
warnings.push(
|
|
1179
|
+
"the project-level build configuration list could not be read, so the configuration names come from every target in the file \u2014 check them."
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
const targets = [];
|
|
1184
|
+
const targetIds = isDict(project) && Array.isArray(project.targets) ? project.targets : [];
|
|
1185
|
+
const entries = targetIds.length ? targetIds.map((id) => object(id)) : Object.values(objects).map((entry) => isDict(entry) ? entry : void 0);
|
|
1186
|
+
for (const entry of entries) {
|
|
1187
|
+
if (!entry || entry.isa !== "PBXNativeTarget") continue;
|
|
1188
|
+
const name = asString(entry.name);
|
|
1189
|
+
if (!name) continue;
|
|
1190
|
+
const productType = asString(entry.productType);
|
|
1191
|
+
targets.push({
|
|
1192
|
+
name,
|
|
1193
|
+
...productType ? { productType } : {},
|
|
1194
|
+
settings: settingsFor(entry.buildConfigurationList)
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
if (targets.length === 0) warnings.push("no native targets were found in project.pbxproj");
|
|
1198
|
+
return {
|
|
1199
|
+
projectConfigurations,
|
|
1200
|
+
allConfigurations: [...allConfigurations],
|
|
1201
|
+
projectSettings,
|
|
1202
|
+
targets,
|
|
1203
|
+
warnings
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
var APP_PRODUCT_TYPE = "com.apple.product-type.application";
|
|
1207
|
+
var isExtension = (productType) => Boolean(productType && /app-extension|watchkit2-app|extensionkit-extension/.test(productType));
|
|
1208
|
+
function settingValue(settings, key, preferred) {
|
|
1209
|
+
const found = Object.entries(settings).map(([configuration, values]) => ({ configuration, value: values[key] })).filter((entry) => Boolean(entry.value));
|
|
1210
|
+
if (found.length === 0) return void 0;
|
|
1211
|
+
const chosen = preferred.map((name) => found.find((e) => e.configuration === name)).find(Boolean);
|
|
1212
|
+
const winner = chosen ?? found[0];
|
|
1213
|
+
return {
|
|
1214
|
+
value: winner.value,
|
|
1215
|
+
configuration: winner.configuration,
|
|
1216
|
+
differs: new Set(found.map((e) => e.value)).size > 1
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
function insideRoot(root, base, value) {
|
|
1220
|
+
if (value.includes("$(") || value.includes("${")) return void 0;
|
|
1221
|
+
const absolute = isAbsolute2(value) ? value : resolve2(base, value);
|
|
1222
|
+
const rel = relative(root, absolute);
|
|
1223
|
+
if (!rel || rel.startsWith("..") || isAbsolute2(rel)) return void 0;
|
|
1224
|
+
return rel;
|
|
1225
|
+
}
|
|
1226
|
+
function bundleIdSuffixFrom(value) {
|
|
1227
|
+
const squeezed = value.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1228
|
+
return squeezed.length > 0 ? squeezed : void 0;
|
|
1229
|
+
}
|
|
1230
|
+
var XCODE_PROJECT_SUFFIX = ".xcodeproj";
|
|
1231
|
+
var XCODE_WORKSPACE_SUFFIX = ".xcworkspace";
|
|
1232
|
+
function findProjectDirectory(boundary, root) {
|
|
1233
|
+
const holdsProject = (dir) => {
|
|
1234
|
+
if (!boundary.fs.isDirectory(dir)) return false;
|
|
1235
|
+
return boundary.fs.readdir(dir).some((name) => name.endsWith(XCODE_PROJECT_SUFFIX) || name.endsWith(XCODE_WORKSPACE_SUFFIX));
|
|
1236
|
+
};
|
|
1237
|
+
if (holdsProject(root)) return root;
|
|
1238
|
+
if (!boundary.fs.isDirectory(root)) return void 0;
|
|
1239
|
+
for (const name of boundary.fs.readdir(root)) {
|
|
1240
|
+
if (name.startsWith(".") || name === "node_modules") continue;
|
|
1241
|
+
const candidate = join4(root, name);
|
|
1242
|
+
if (holdsProject(candidate)) return candidate;
|
|
1243
|
+
}
|
|
1244
|
+
return void 0;
|
|
1245
|
+
}
|
|
1246
|
+
function schemeNames(boundary, container) {
|
|
1247
|
+
const directory = join4(container, "xcshareddata", "xcschemes");
|
|
1248
|
+
if (!boundary.fs.isDirectory(directory)) return [];
|
|
1249
|
+
return boundary.fs.readdir(directory).filter((name) => name.endsWith(".xcscheme")).map((name) => name.slice(0, -".xcscheme".length));
|
|
1250
|
+
}
|
|
1251
|
+
function detectProject(boundary, options) {
|
|
1252
|
+
const root = resolve2(options.root);
|
|
1253
|
+
const warnings = [];
|
|
1254
|
+
const explicit = options.iosDir ? resolve2(root, options.iosDir) : void 0;
|
|
1255
|
+
const directory = explicit ?? findProjectDirectory(boundary, root);
|
|
1256
|
+
if (!directory) {
|
|
1257
|
+
return {
|
|
1258
|
+
root,
|
|
1259
|
+
iosDir: { value: options.iosDir ?? ".", source: "." },
|
|
1260
|
+
schemes: [],
|
|
1261
|
+
targets: [],
|
|
1262
|
+
warnings: ["no .xcodeproj or .xcworkspace was found here or one directory below."]
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
const iosDir = relative(root, directory) || ".";
|
|
1266
|
+
const names = boundary.fs.isDirectory(directory) ? boundary.fs.readdir(directory) : [];
|
|
1267
|
+
const projectName = names.find((name) => name.endsWith(XCODE_PROJECT_SUFFIX));
|
|
1268
|
+
const workspaceName = names.find((name) => name.endsWith(XCODE_WORKSPACE_SUFFIX));
|
|
1269
|
+
const specName = names.find((name) => name === "project.yml" || name === "project.yaml");
|
|
1270
|
+
const detection = {
|
|
1271
|
+
root,
|
|
1272
|
+
iosDir: { value: iosDir, source: iosDir },
|
|
1273
|
+
...projectName ? { xcodeproj: { value: projectName, source: iosDir } } : {},
|
|
1274
|
+
...workspaceName ? { xcworkspace: { value: workspaceName, source: iosDir } } : {},
|
|
1275
|
+
...specName ? { projectYml: { value: specName, source: join4(iosDir, specName) } } : {},
|
|
1276
|
+
schemes: [],
|
|
1277
|
+
targets: [],
|
|
1278
|
+
warnings
|
|
1279
|
+
};
|
|
1280
|
+
if (!projectName) {
|
|
1281
|
+
warnings.push(
|
|
1282
|
+
workspaceName ? `${workspaceName} has no .xcodeproj beside it, so nothing could be read out of the project.` : "no .xcodeproj was found, so nothing could be read out of the project."
|
|
1283
|
+
);
|
|
1284
|
+
return detection;
|
|
1285
|
+
}
|
|
1286
|
+
const projectDir = join4(directory, projectName);
|
|
1287
|
+
const pbxprojPath2 = join4(projectDir, "project.pbxproj");
|
|
1288
|
+
const sourceOf = (path) => relative(root, path);
|
|
1289
|
+
detection.schemes = [
|
|
1290
|
+
.../* @__PURE__ */ new Set([
|
|
1291
|
+
...schemeNames(boundary, projectDir),
|
|
1292
|
+
...workspaceName ? schemeNames(boundary, join4(directory, workspaceName)) : []
|
|
1293
|
+
])
|
|
1294
|
+
];
|
|
1295
|
+
if (!boundary.fs.exists(pbxprojPath2)) {
|
|
1296
|
+
warnings.push(`${sourceOf(pbxprojPath2)} is missing, so nothing could be read out of it.`);
|
|
1297
|
+
return detection;
|
|
1298
|
+
}
|
|
1299
|
+
let facts;
|
|
1300
|
+
try {
|
|
1301
|
+
facts = parsePbxproj(boundary.fs.read(pbxprojPath2));
|
|
1302
|
+
} catch (e) {
|
|
1303
|
+
warnings.push(`${sourceOf(pbxprojPath2)} could not be read \u2014 ${e.message}`);
|
|
1304
|
+
return detection;
|
|
1305
|
+
}
|
|
1306
|
+
const pbxSource = sourceOf(pbxprojPath2);
|
|
1307
|
+
warnings.push(...facts.warnings.map((warning) => `${pbxSource}: ${warning}`));
|
|
1308
|
+
if (facts.projectConfigurations.length > 0) {
|
|
1309
|
+
detection.configurations = { value: facts.projectConfigurations, source: pbxSource };
|
|
1310
|
+
}
|
|
1311
|
+
const preferred = [
|
|
1312
|
+
"Debug",
|
|
1313
|
+
...facts.projectConfigurations.filter((name) => name !== "Debug")
|
|
1314
|
+
];
|
|
1315
|
+
const app = facts.targets.find((target) => target.productType === APP_PRODUCT_TYPE);
|
|
1316
|
+
if (!app && facts.targets.length > 0) {
|
|
1317
|
+
warnings.push(`${pbxSource}: no application target was found \u2014 pick one by hand.`);
|
|
1318
|
+
}
|
|
1319
|
+
const readSetting = (target, key) => (target ? settingValue(target.settings, key, preferred) : void 0) ?? settingValue(facts.projectSettings, key, preferred);
|
|
1320
|
+
const teamId = readSetting(app, "DEVELOPMENT_TEAM");
|
|
1321
|
+
if (teamId) {
|
|
1322
|
+
if (/^[A-Z0-9]{10}$/.test(teamId.value)) {
|
|
1323
|
+
detection.teamId = { value: teamId.value, source: pbxSource };
|
|
1324
|
+
} else {
|
|
1325
|
+
warnings.push(
|
|
1326
|
+
`${pbxSource}: DEVELOPMENT_TEAM is "${teamId.value}", which is not a 10-character team id.`
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
const bundleId = app ? settingValue(app.settings, "PRODUCT_BUNDLE_IDENTIFIER", preferred) : void 0;
|
|
1331
|
+
if (bundleId?.value.includes("$(")) {
|
|
1332
|
+
warnings.push(
|
|
1333
|
+
`${pbxSource}: PRODUCT_BUNDLE_IDENTIFIER is built from other build settings ("${bundleId.value}"), so it has to be given by hand.`
|
|
1334
|
+
);
|
|
1335
|
+
} else if (bundleId) {
|
|
1336
|
+
detection.baseBundleId = { value: bundleId.value, source: pbxSource };
|
|
1337
|
+
if (bundleId.differs) {
|
|
1338
|
+
warnings.push(
|
|
1339
|
+
`${pbxSource}: the bundle id differs between configurations \u2014 ${bundleId.configuration} says "${bundleId.value}".`
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
const displayName = app ? settingValue(app.settings, "INFOPLIST_KEY_CFBundleDisplayName", preferred) : void 0;
|
|
1344
|
+
if (displayName && !displayName.value.includes("$(")) {
|
|
1345
|
+
detection.displayName = { value: displayName.value, source: pbxSource };
|
|
1346
|
+
} else if (app) {
|
|
1347
|
+
detection.displayName = { value: app.name, source: pbxSource };
|
|
1348
|
+
}
|
|
1349
|
+
if (app) {
|
|
1350
|
+
const matching = detection.schemes.find((scheme) => scheme === app.name);
|
|
1351
|
+
detection.scheme = matching ? { value: matching, source: sourceOf(join4(projectDir, "xcshareddata", "xcschemes")) } : { value: app.name, source: pbxSource };
|
|
1352
|
+
} else if (detection.schemes.length === 1) {
|
|
1353
|
+
detection.scheme = {
|
|
1354
|
+
value: detection.schemes[0],
|
|
1355
|
+
source: sourceOf(join4(projectDir, "xcshareddata", "xcschemes"))
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
for (const target of facts.targets) {
|
|
1359
|
+
const isApp = target.productType === APP_PRODUCT_TYPE;
|
|
1360
|
+
if (!isApp && !isExtension(target.productType)) continue;
|
|
1361
|
+
const id = settingValue(target.settings, "PRODUCT_BUNDLE_IDENTIFIER", preferred)?.value;
|
|
1362
|
+
const entitlements = settingValue(target.settings, "CODE_SIGN_ENTITLEMENTS", preferred)?.value;
|
|
1363
|
+
const relativeEntitlements = entitlements ? insideRoot(root, directory, entitlements) : void 0;
|
|
1364
|
+
if (entitlements && !relativeEntitlements) {
|
|
1365
|
+
warnings.push(
|
|
1366
|
+
`${pbxSource}: ${target.name}'s entitlements path ("${entitlements}") is outside the project root, so it was left out.`
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
const suffix = isApp ? void 0 : bundleIdSuffixFrom(id?.split(".").pop() ?? target.name.split(".").pop() ?? "");
|
|
1370
|
+
if (!isApp && !suffix) {
|
|
1371
|
+
warnings.push(
|
|
1372
|
+
`${pbxSource}: ${target.name} has no usable bundle-id segment \u2014 add it by hand.`
|
|
1373
|
+
);
|
|
1374
|
+
continue;
|
|
1375
|
+
}
|
|
1376
|
+
detection.targets.push({
|
|
1377
|
+
name: target.name,
|
|
1378
|
+
...target.productType ? { productType: target.productType } : {},
|
|
1379
|
+
isApp,
|
|
1380
|
+
...id && !id.includes("$(") ? { bundleId: id } : {},
|
|
1381
|
+
...suffix ? { bundleIdSuffix: suffix } : {},
|
|
1382
|
+
...relativeEntitlements ? { entitlements: { value: relativeEntitlements, source: pbxSource } } : {}
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
return detection;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
// src/init.ts
|
|
1389
|
+
var SCHEMA_URL = "https://unpkg.com/jetbridge/schema/v1.json";
|
|
1390
|
+
var DEFAULT_CONFIGURATIONS = ["Debug", "Release"];
|
|
1391
|
+
function assembleConfig(input) {
|
|
1392
|
+
return {
|
|
1393
|
+
$schema: SCHEMA_URL,
|
|
1394
|
+
configVersion: CONFIG_VERSION,
|
|
1395
|
+
project: {
|
|
1396
|
+
iosDir: input.iosDir,
|
|
1397
|
+
...input.xcodeproj ? { xcodeproj: input.xcodeproj } : {},
|
|
1398
|
+
...input.xcworkspace ? { xcworkspace: input.xcworkspace } : {},
|
|
1399
|
+
scheme: input.scheme,
|
|
1400
|
+
teamId: input.teamId,
|
|
1401
|
+
baseBundleId: input.baseBundleId,
|
|
1402
|
+
...input.projectYml ? { projectYml: input.projectYml } : {},
|
|
1403
|
+
...input.xcodegen ? { xcodegen: true } : {}
|
|
1404
|
+
},
|
|
1405
|
+
configurations: {
|
|
1406
|
+
available: input.configurations.available,
|
|
1407
|
+
wired: input.configurations.wired,
|
|
1408
|
+
sim: input.configurations.sim,
|
|
1409
|
+
archive: input.configurations.archive
|
|
1410
|
+
},
|
|
1411
|
+
variant: {
|
|
1412
|
+
displayName: input.displayName,
|
|
1413
|
+
targets: input.targets.map((target) => ({
|
|
1414
|
+
name: target.name,
|
|
1415
|
+
...target.bundleIdSuffix ? { bundleIdSuffix: target.bundleIdSuffix } : {},
|
|
1416
|
+
...target.entitlements ? { entitlements: target.entitlements } : {}
|
|
1417
|
+
}))
|
|
1418
|
+
},
|
|
1419
|
+
credentials: {
|
|
1420
|
+
ascKeyId: input.credentials.ascKeyId,
|
|
1421
|
+
ascIssuerId: input.credentials.ascIssuerId
|
|
1422
|
+
},
|
|
1423
|
+
...input.ota ? {
|
|
1424
|
+
ota: {
|
|
1425
|
+
storage: {
|
|
1426
|
+
bucket: input.ota.bucket,
|
|
1427
|
+
region: input.ota.region,
|
|
1428
|
+
...input.ota.endpoint ? { endpoint: input.ota.endpoint } : {},
|
|
1429
|
+
publicBaseUrl: input.ota.publicBaseUrl
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
} : {}
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
var serializeConfig = (value) => `${JSON.stringify(value, null, 2)}
|
|
1436
|
+
`;
|
|
1437
|
+
var quote = (value) => /[\s]/.test(value) ? `'${value}'` : value;
|
|
1438
|
+
function commandPreviews(project) {
|
|
1439
|
+
const { config } = project;
|
|
1440
|
+
const target = project.xcodebuildTarget().map(quote).join(" ");
|
|
1441
|
+
const line = (verb, configuration, destination) => [
|
|
1442
|
+
"xcodebuild",
|
|
1443
|
+
verb,
|
|
1444
|
+
target,
|
|
1445
|
+
"-scheme",
|
|
1446
|
+
quote(config.project.scheme),
|
|
1447
|
+
"-configuration",
|
|
1448
|
+
quote(configuration),
|
|
1449
|
+
"-destination",
|
|
1450
|
+
quote(destination)
|
|
1451
|
+
].join(" ");
|
|
1452
|
+
return [
|
|
1453
|
+
{ mode: "wired", command: line("build", config.configurations.wired, "generic/platform=iOS") },
|
|
1454
|
+
{ mode: "sim", command: line("build", config.configurations.sim, "platform=iOS Simulator") },
|
|
1455
|
+
{
|
|
1456
|
+
mode: "archive",
|
|
1457
|
+
command: line("archive", config.configurations.archive, "generic/platform=iOS")
|
|
1458
|
+
}
|
|
1459
|
+
];
|
|
1460
|
+
}
|
|
1461
|
+
var sameValue = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
1462
|
+
function detectDrift(config, detection) {
|
|
1463
|
+
const drift = [];
|
|
1464
|
+
const add = (path, current, detected, note2) => {
|
|
1465
|
+
if (!detected || sameValue(current, detected.value)) return;
|
|
1466
|
+
drift.push({
|
|
1467
|
+
path,
|
|
1468
|
+
current,
|
|
1469
|
+
detected: detected.value,
|
|
1470
|
+
source: detected.source,
|
|
1471
|
+
...note2 ? { note: note2 } : {}
|
|
1472
|
+
});
|
|
1473
|
+
};
|
|
1474
|
+
add("project.iosDir", config.project.iosDir, detection.iosDir);
|
|
1475
|
+
add("project.xcodeproj", config.project.xcodeproj, detection.xcodeproj);
|
|
1476
|
+
add("project.xcworkspace", config.project.xcworkspace, detection.xcworkspace);
|
|
1477
|
+
add("project.teamId", config.project.teamId, detection.teamId);
|
|
1478
|
+
add("project.baseBundleId", config.project.baseBundleId, detection.baseBundleId);
|
|
1479
|
+
if (detection.schemes.length > 0 && !detection.schemes.includes(config.project.scheme)) {
|
|
1480
|
+
const replacement = detection.scheme?.value ?? detection.schemes[0];
|
|
1481
|
+
drift.push({
|
|
1482
|
+
path: "project.scheme",
|
|
1483
|
+
current: config.project.scheme,
|
|
1484
|
+
detected: replacement,
|
|
1485
|
+
note: `the project has no scheme named "${config.project.scheme}" any more`,
|
|
1486
|
+
source: detection.scheme?.source ?? detection.iosDir.source
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
const available = detection.configurations;
|
|
1490
|
+
if (available) {
|
|
1491
|
+
add("configurations.available", config.configurations.available, available);
|
|
1492
|
+
for (const field of ["wired", "sim", "archive"]) {
|
|
1493
|
+
const current = config.configurations[field];
|
|
1494
|
+
if (available.value.includes(current)) continue;
|
|
1495
|
+
const fallback = field === "archive" ? "Release" : "Debug";
|
|
1496
|
+
drift.push({
|
|
1497
|
+
path: `configurations.${field}`,
|
|
1498
|
+
current,
|
|
1499
|
+
detected: available.value.includes(fallback) ? fallback : available.value[0],
|
|
1500
|
+
note: `the project has no "${current}" build configuration any more`,
|
|
1501
|
+
source: available.source
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
return drift;
|
|
1506
|
+
}
|
|
1507
|
+
function setPath(raw, path, value) {
|
|
1508
|
+
const parts = path.split(".");
|
|
1509
|
+
let node = raw;
|
|
1510
|
+
for (const part of parts.slice(0, -1)) {
|
|
1511
|
+
const next = node[part];
|
|
1512
|
+
if (typeof next !== "object" || next === null) node[part] = {};
|
|
1513
|
+
node = node[part];
|
|
1514
|
+
}
|
|
1515
|
+
node[parts.at(-1)] = value;
|
|
1516
|
+
}
|
|
1517
|
+
var teamIdProblem = (value) => /^[A-Z0-9]{10}$/.test(value) ? void 0 : "an Apple team id is 10 uppercase alphanumerics";
|
|
1518
|
+
var bundleIdProblem = (value) => /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/.test(value) ? void 0 : "a reverse-DNS bundle id, e.g. io.acme.app.dev";
|
|
1519
|
+
var httpsProblem = (value) => {
|
|
1520
|
+
if (!value.startsWith("https://")) return "must be https:// \u2014 iOS refuses to install over http";
|
|
1521
|
+
try {
|
|
1522
|
+
new URL(value);
|
|
1523
|
+
return void 0;
|
|
1524
|
+
} catch {
|
|
1525
|
+
return "not a URL";
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
var envNameProblem = (value) => /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(value) ? void 0 : "must be a plain identifier";
|
|
1529
|
+
var isAuto = (boundary, options) => options.yes === true || !boundary.interactive;
|
|
1530
|
+
async function runInit(boundary, options, deps) {
|
|
1531
|
+
const root = resolve3(options.cwd ?? boundary.cwd());
|
|
1532
|
+
const configPath = join5(root, CONFIG_FILENAMES[0]);
|
|
1533
|
+
const existing = boundary.fs.exists(configPath);
|
|
1534
|
+
const detection = detectProject(boundary, {
|
|
1535
|
+
root,
|
|
1536
|
+
...options.iosDir ? { iosDir: options.iosDir } : {}
|
|
1537
|
+
});
|
|
1538
|
+
for (const warning of detection.warnings) boundary.log.warn(`! ${warning}`);
|
|
1539
|
+
return existing ? repair(boundary, options, deps, configPath, detection) : create(boundary, options, deps, configPath, detection);
|
|
1540
|
+
}
|
|
1541
|
+
async function create(boundary, options, deps, configPath, detection) {
|
|
1542
|
+
const { prompts } = deps;
|
|
1543
|
+
const auto = isAuto(boundary, options);
|
|
1544
|
+
const missing = [];
|
|
1545
|
+
const ask = async (spec) => {
|
|
1546
|
+
if (spec.given !== void 0) {
|
|
1547
|
+
const problem = spec.validate?.(spec.given);
|
|
1548
|
+
if (problem) fail(`${spec.flag} ${spec.given}: ${problem}`);
|
|
1549
|
+
return spec.given;
|
|
1550
|
+
}
|
|
1551
|
+
if (auto) {
|
|
1552
|
+
if (spec.detected) return spec.detected.value;
|
|
1553
|
+
missing.push({ field: spec.field, flag: spec.flag });
|
|
1554
|
+
return "";
|
|
1555
|
+
}
|
|
1556
|
+
return prompts.text({
|
|
1557
|
+
name: spec.field,
|
|
1558
|
+
message: spec.message,
|
|
1559
|
+
...spec.detected ? { initial: spec.detected.value, hint: `from ${spec.detected.source}` } : {},
|
|
1560
|
+
...spec.validate ? { validate: spec.validate } : {}
|
|
1561
|
+
});
|
|
1562
|
+
};
|
|
1563
|
+
const iosDir = await ask({
|
|
1564
|
+
field: "project.iosDir",
|
|
1565
|
+
flag: "--ios-dir",
|
|
1566
|
+
message: "Directory holding the Xcode project",
|
|
1567
|
+
given: options.iosDir,
|
|
1568
|
+
detected: detection.iosDir
|
|
1569
|
+
});
|
|
1570
|
+
const xcodeproj = options.xcodeproj ?? detection.xcodeproj?.value;
|
|
1571
|
+
const xcworkspace = options.xcworkspace ?? detection.xcworkspace?.value;
|
|
1572
|
+
if (!xcodeproj && !xcworkspace) {
|
|
1573
|
+
missing.push({ field: "project.xcodeproj", flag: "--xcodeproj" });
|
|
1574
|
+
}
|
|
1575
|
+
const scheme = await ask({
|
|
1576
|
+
field: "project.scheme",
|
|
1577
|
+
flag: "--scheme",
|
|
1578
|
+
message: "Scheme to build",
|
|
1579
|
+
given: options.scheme,
|
|
1580
|
+
detected: detection.scheme
|
|
1581
|
+
});
|
|
1582
|
+
const teamId = await ask({
|
|
1583
|
+
field: "project.teamId",
|
|
1584
|
+
flag: "--team-id",
|
|
1585
|
+
message: "Apple team id",
|
|
1586
|
+
given: options.teamId,
|
|
1587
|
+
detected: detection.teamId,
|
|
1588
|
+
validate: teamIdProblem
|
|
1589
|
+
});
|
|
1590
|
+
const baseBundleId = await ask({
|
|
1591
|
+
field: "project.baseBundleId",
|
|
1592
|
+
flag: "--bundle-id",
|
|
1593
|
+
message: "Bundle id a variant build extends",
|
|
1594
|
+
given: options.bundleId,
|
|
1595
|
+
detected: detection.baseBundleId,
|
|
1596
|
+
validate: bundleIdProblem
|
|
1597
|
+
});
|
|
1598
|
+
const displayName = await ask({
|
|
1599
|
+
field: "variant.displayName",
|
|
1600
|
+
flag: "--display-name",
|
|
1601
|
+
message: "Home-screen label for a plain build",
|
|
1602
|
+
given: options.displayName,
|
|
1603
|
+
detected: detection.displayName
|
|
1604
|
+
});
|
|
1605
|
+
const available = options.configurations ?? detection.configurations?.value;
|
|
1606
|
+
if (!available) {
|
|
1607
|
+
boundary.log.warn(
|
|
1608
|
+
`! no build configurations were read out of the project, so ${DEFAULT_CONFIGURATIONS.join(
|
|
1609
|
+
" and "
|
|
1610
|
+
)} are assumed.`
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1613
|
+
const configurations = available ?? DEFAULT_CONFIGURATIONS;
|
|
1614
|
+
const pickConfiguration = async (field, flag, message, given, preferred) => {
|
|
1615
|
+
if (given !== void 0) {
|
|
1616
|
+
if (!configurations.includes(given)) {
|
|
1617
|
+
fail(`${flag} ${given}: the project has no "${given}" build configuration`);
|
|
1618
|
+
}
|
|
1619
|
+
return given;
|
|
1620
|
+
}
|
|
1621
|
+
if (configurations.includes(preferred)) return preferred;
|
|
1622
|
+
if (auto) {
|
|
1623
|
+
missing.push({ field: `configurations.${field}`, flag });
|
|
1624
|
+
return "";
|
|
1625
|
+
}
|
|
1626
|
+
return prompts.select({
|
|
1627
|
+
name: `configurations.${field}`,
|
|
1628
|
+
message,
|
|
1629
|
+
options: configurations.map((value) => ({ value }))
|
|
1630
|
+
});
|
|
1631
|
+
};
|
|
1632
|
+
const wired = await pickConfiguration(
|
|
1633
|
+
"wired",
|
|
1634
|
+
"--configuration-wired",
|
|
1635
|
+
"Build configuration for a cabled install",
|
|
1636
|
+
options.wired,
|
|
1637
|
+
"Debug"
|
|
1638
|
+
);
|
|
1639
|
+
const sim = await pickConfiguration(
|
|
1640
|
+
"sim",
|
|
1641
|
+
"--configuration-sim",
|
|
1642
|
+
"Build configuration for a simulator install",
|
|
1643
|
+
options.sim,
|
|
1644
|
+
"Debug"
|
|
1645
|
+
);
|
|
1646
|
+
const archive = await pickConfiguration(
|
|
1647
|
+
"archive",
|
|
1648
|
+
"--configuration-archive",
|
|
1649
|
+
"Build configuration for an archive",
|
|
1650
|
+
options.archive,
|
|
1651
|
+
"Release"
|
|
1652
|
+
);
|
|
1653
|
+
const ascKeyId = await ask({
|
|
1654
|
+
field: "credentials.ascKeyId",
|
|
1655
|
+
flag: "--asc-key-id-env",
|
|
1656
|
+
message: "Environment variable holding the App Store Connect key id",
|
|
1657
|
+
given: options.ascKeyIdEnv,
|
|
1658
|
+
detected: { value: "ASC_API_KEY_ID", source: "the jetbridge default" },
|
|
1659
|
+
validate: envNameProblem
|
|
1660
|
+
});
|
|
1661
|
+
const ascIssuerId = await ask({
|
|
1662
|
+
field: "credentials.ascIssuerId",
|
|
1663
|
+
flag: "--asc-issuer-id-env",
|
|
1664
|
+
message: "Environment variable holding the App Store Connect issuer id",
|
|
1665
|
+
given: options.ascIssuerIdEnv,
|
|
1666
|
+
detected: { value: "ASC_API_ISSUER_ID", source: "the jetbridge default" },
|
|
1667
|
+
validate: envNameProblem
|
|
1668
|
+
});
|
|
1669
|
+
let xcodegen = false;
|
|
1670
|
+
if (detection.projectYml) {
|
|
1671
|
+
xcodegen = auto ? true : await prompts.confirm({
|
|
1672
|
+
name: "project.xcodegen",
|
|
1673
|
+
message: `Run xcodegen from ${detection.projectYml.value} before each build?`,
|
|
1674
|
+
initial: true
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
const wantsOta = options.ota ?? (auto ? false : await prompts.confirm({
|
|
1678
|
+
name: "ota.enabled",
|
|
1679
|
+
message: "Deliver builds over the air to your own bucket?",
|
|
1680
|
+
initial: false
|
|
1681
|
+
}));
|
|
1682
|
+
let ota;
|
|
1683
|
+
if (wantsOta) {
|
|
1684
|
+
const bucket = await ask({
|
|
1685
|
+
field: "ota.storage.bucket",
|
|
1686
|
+
flag: "--ota-bucket",
|
|
1687
|
+
message: "Bucket builds are uploaded to",
|
|
1688
|
+
given: options.otaBucket
|
|
1689
|
+
});
|
|
1690
|
+
const region = await ask({
|
|
1691
|
+
field: "ota.storage.region",
|
|
1692
|
+
flag: "--ota-region",
|
|
1693
|
+
message: "Bucket region",
|
|
1694
|
+
given: options.otaRegion,
|
|
1695
|
+
detected: { value: "us-east-1", source: "the jetbridge default" }
|
|
1696
|
+
});
|
|
1697
|
+
const endpoint = options.otaEndpoint ?? (auto ? "" : await prompts.text({
|
|
1698
|
+
name: "ota.storage.endpoint",
|
|
1699
|
+
message: "S3-compatible endpoint (blank for AWS)"
|
|
1700
|
+
}));
|
|
1701
|
+
const publicBaseUrl = await ask({
|
|
1702
|
+
field: "ota.storage.publicBaseUrl",
|
|
1703
|
+
flag: "--ota-public-base-url",
|
|
1704
|
+
message: "Public https:// base URL the uploads are readable from",
|
|
1705
|
+
given: options.otaPublicBaseUrl,
|
|
1706
|
+
validate: httpsProblem
|
|
1707
|
+
});
|
|
1708
|
+
ota = { bucket, region, publicBaseUrl, ...endpoint ? { endpoint } : {} };
|
|
1709
|
+
}
|
|
1710
|
+
if (missing.length > 0) {
|
|
1711
|
+
fail(
|
|
1712
|
+
"these could not be worked out from the project, and there is nobody to ask:\n" + missing.map((entry) => ` ${entry.field} \u2014 pass ${entry.flag}`).join("\n")
|
|
1713
|
+
);
|
|
1714
|
+
}
|
|
1715
|
+
if (ota) {
|
|
1716
|
+
const kept = await verifyOta(boundary, deps, ota, auto);
|
|
1717
|
+
if (!kept) return { status: "declined", configPath, drift: [] };
|
|
1718
|
+
}
|
|
1719
|
+
const raw = assembleConfig({
|
|
1720
|
+
iosDir,
|
|
1721
|
+
...xcodeproj ? { xcodeproj } : {},
|
|
1722
|
+
...xcworkspace ? { xcworkspace } : {},
|
|
1723
|
+
scheme,
|
|
1724
|
+
teamId,
|
|
1725
|
+
baseBundleId,
|
|
1726
|
+
...detection.projectYml ? { projectYml: detection.projectYml.value } : {},
|
|
1727
|
+
xcodegen,
|
|
1728
|
+
configurations: { available: configurations, wired, sim, archive },
|
|
1729
|
+
displayName,
|
|
1730
|
+
targets: detection.targets.map((target) => ({
|
|
1731
|
+
name: target.name,
|
|
1732
|
+
...target.bundleIdSuffix ? { bundleIdSuffix: target.bundleIdSuffix } : {},
|
|
1733
|
+
...target.entitlements ? { entitlements: target.entitlements.value } : {}
|
|
1734
|
+
})),
|
|
1735
|
+
credentials: { ascKeyId, ascIssuerId },
|
|
1736
|
+
...ota ? { ota } : {}
|
|
1737
|
+
});
|
|
1738
|
+
return finish(boundary, deps, configPath, raw, auto, options, []);
|
|
1739
|
+
}
|
|
1740
|
+
var KEEP_OTA = { name: "ota.continue", message: "Keep these OTA settings anyway?" };
|
|
1741
|
+
async function verifyOta(boundary, deps, ota, auto) {
|
|
1742
|
+
if (!deps.otaRoundTrip) {
|
|
1743
|
+
boundary.log.warn(
|
|
1744
|
+
"! the OTA settings were not verified \u2014 the bucket round trip was skipped because no checker was wired in."
|
|
1745
|
+
);
|
|
1746
|
+
return auto ? true : deps.prompts.confirm({ ...KEEP_OTA, initial: false });
|
|
1747
|
+
}
|
|
1748
|
+
const result = await deps.otaRoundTrip(boundary, { ...ota, prefix: "builds" });
|
|
1749
|
+
if (result.ok) {
|
|
1750
|
+
boundary.log.info(`\u2713 ${result.detail}`);
|
|
1751
|
+
return true;
|
|
1752
|
+
}
|
|
1753
|
+
boundary.log.warn(`! the OTA settings could not be verified: ${result.detail}`);
|
|
1754
|
+
if (auto) {
|
|
1755
|
+
fail(
|
|
1756
|
+
`the OTA round trip failed: ${result.detail}.
|
|
1757
|
+
Fix the bucket, or re-run without --ota to leave over-the-air delivery out.`
|
|
1758
|
+
);
|
|
1759
|
+
}
|
|
1760
|
+
return deps.prompts.confirm({ ...KEEP_OTA, initial: false });
|
|
1761
|
+
}
|
|
1762
|
+
function warnAboutCredentials(boundary, config) {
|
|
1763
|
+
const unresolved = [
|
|
1764
|
+
["credentials.ascKeyId", config.credentials.ascKeyId],
|
|
1765
|
+
["credentials.ascIssuerId", config.credentials.ascIssuerId]
|
|
1766
|
+
].filter(([, name]) => boundary.env(name) === void 0);
|
|
1767
|
+
for (const [field, name] of unresolved) {
|
|
1768
|
+
boundary.log.warn(
|
|
1769
|
+
`! ${name} is not set in this environment \u2014 ${field} names it, and anything that talks to App Store Connect will fail until it resolves.`
|
|
1770
|
+
);
|
|
1771
|
+
}
|
|
1772
|
+
if (unresolved.length === 0 && localCredentials(boundary, config) === null) {
|
|
1773
|
+
boundary.log.warn(`! ${missingCredentialsMessage(config)}`);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
async function finish(boundary, deps, configPath, raw, auto, options, drift) {
|
|
1777
|
+
const checked = parseConfig(raw);
|
|
1778
|
+
if (!checked.ok) {
|
|
1779
|
+
fail(`the answers do not make a valid config:
|
|
1780
|
+
${formatConfigErrors(checked.errors)}`);
|
|
1781
|
+
}
|
|
1782
|
+
warnAboutCredentials(boundary, checked.config);
|
|
1783
|
+
const contents = serializeConfig(raw);
|
|
1784
|
+
deps.prompts.note(contents.trimEnd(), configPath);
|
|
1785
|
+
for (const preview of commandPreviews(projectFrom(configPath, checked.config))) {
|
|
1786
|
+
boundary.log.info(` ${preview.mode.padEnd(7)} ${preview.command}`);
|
|
1787
|
+
}
|
|
1788
|
+
if (auto) {
|
|
1789
|
+
if (options.yes !== true) {
|
|
1790
|
+
fail(`nothing was written \u2014 re-run with --yes to accept these values without a terminal.`);
|
|
1791
|
+
}
|
|
1792
|
+
} else {
|
|
1793
|
+
const write = await deps.prompts.confirm({
|
|
1794
|
+
name: "write",
|
|
1795
|
+
message: `Write ${configPath}?`,
|
|
1796
|
+
initial: true
|
|
1797
|
+
});
|
|
1798
|
+
if (!write) {
|
|
1799
|
+
boundary.log.info("nothing was written.");
|
|
1800
|
+
return { status: "declined", configPath, drift };
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
boundary.fs.write(configPath, contents);
|
|
1804
|
+
let written;
|
|
1805
|
+
try {
|
|
1806
|
+
written = JSON.parse(boundary.fs.read(configPath));
|
|
1807
|
+
} catch (e) {
|
|
1808
|
+
return fail(`${configPath} was written but is not valid JSON \u2014 ${e.message}`);
|
|
1809
|
+
}
|
|
1810
|
+
const reread = parseConfig(written);
|
|
1811
|
+
if (!reread.ok) {
|
|
1812
|
+
fail(
|
|
1813
|
+
`${configPath} was written but jetbridge refuses it:
|
|
1814
|
+
${formatConfigErrors(reread.errors)}`
|
|
1815
|
+
);
|
|
1816
|
+
}
|
|
1817
|
+
boundary.log.info(`wrote ${configPath}`);
|
|
1818
|
+
return { status: "written", configPath, config: reread.config, drift };
|
|
1819
|
+
}
|
|
1820
|
+
async function repair(boundary, options, deps, configPath, detection) {
|
|
1821
|
+
const auto = isAuto(boundary, options);
|
|
1822
|
+
let raw;
|
|
1823
|
+
try {
|
|
1824
|
+
raw = JSON.parse(boundary.fs.read(configPath));
|
|
1825
|
+
} catch (e) {
|
|
1826
|
+
return fail(`${configPath} is not valid JSON \u2014 ${e.message}`);
|
|
1827
|
+
}
|
|
1828
|
+
const parsed = parseConfig(raw);
|
|
1829
|
+
if (!parsed.ok) {
|
|
1830
|
+
fail(
|
|
1831
|
+
`${configPath} already exists but jetbridge refuses it, so there is nothing to compare against:
|
|
1832
|
+
${formatConfigErrors(parsed.errors)}
|
|
1833
|
+
Fix or delete it, then re-run.`
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
const drift = detectDrift(parsed.config, detection);
|
|
1837
|
+
if (drift.length === 0) {
|
|
1838
|
+
boundary.log.info(`${configPath} still matches the project \u2014 nothing to change.`);
|
|
1839
|
+
return { status: "unchanged", configPath, drift };
|
|
1840
|
+
}
|
|
1841
|
+
boundary.log.info(`${configPath} and the project disagree:`);
|
|
1842
|
+
for (const entry of drift) {
|
|
1843
|
+
const reason = entry.note ? ` \u2014 ${entry.note}` : "";
|
|
1844
|
+
boundary.log.info(
|
|
1845
|
+
` ${entry.path}: ${JSON.stringify(entry.current)} \u2192 ${JSON.stringify(entry.detected)}${reason} (${entry.source})`
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
1848
|
+
const merged = raw;
|
|
1849
|
+
const accepted = [];
|
|
1850
|
+
for (const entry of drift) {
|
|
1851
|
+
const take = auto || await deps.prompts.confirm({
|
|
1852
|
+
name: `update:${entry.path}`,
|
|
1853
|
+
message: `Update ${entry.path} to ${JSON.stringify(entry.detected)}?`,
|
|
1854
|
+
initial: true
|
|
1855
|
+
});
|
|
1856
|
+
if (!take) continue;
|
|
1857
|
+
setPath(merged, entry.path, entry.detected);
|
|
1858
|
+
accepted.push(entry);
|
|
1859
|
+
}
|
|
1860
|
+
if (accepted.length === 0) {
|
|
1861
|
+
boundary.log.info("nothing was changed.");
|
|
1862
|
+
return { status: "unchanged", configPath, drift };
|
|
1863
|
+
}
|
|
1864
|
+
return finish(boundary, deps, configPath, merged, auto, options, accepted);
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// src/ota.ts
|
|
1868
|
+
import { join as join12 } from "path";
|
|
1869
|
+
|
|
1870
|
+
// src/assets.ts
|
|
1871
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
1872
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
1873
|
+
import { fileURLToPath } from "url";
|
|
1874
|
+
var cachedRoot;
|
|
1875
|
+
function packageRoot() {
|
|
1876
|
+
if (cachedRoot) return cachedRoot;
|
|
1877
|
+
let dir = dirname3(fileURLToPath(import.meta.url));
|
|
1878
|
+
for (; ; ) {
|
|
1879
|
+
if (existsSync2(join6(dir, "package.json"))) {
|
|
1880
|
+
cachedRoot = dir;
|
|
1881
|
+
return dir;
|
|
1882
|
+
}
|
|
1883
|
+
const parent = dirname3(dir);
|
|
1884
|
+
if (parent === dir) {
|
|
1885
|
+
throw new Error(
|
|
1886
|
+
`could not find the jetbridge package root above ${dirname3(fileURLToPath(import.meta.url))}.
|
|
1887
|
+
Reinstall the package \u2014 its templates/ directory is missing.`
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
dir = parent;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
function templatePath(name) {
|
|
1894
|
+
return join6(packageRoot(), "templates", name);
|
|
1895
|
+
}
|
|
1896
|
+
function readTemplate(name) {
|
|
1897
|
+
const path = templatePath(name);
|
|
1898
|
+
if (!existsSync2(path)) {
|
|
1899
|
+
throw new Error(`missing template ${path} \u2014 reinstall jetbridge, its assets are incomplete`);
|
|
1900
|
+
}
|
|
1901
|
+
return readFileSync2(path, "utf8");
|
|
1902
|
+
}
|
|
1903
|
+
function fillTemplate(template, values) {
|
|
1904
|
+
let page = template;
|
|
1905
|
+
for (const [key, value] of Object.entries(values)) {
|
|
1906
|
+
page = page.replaceAll(`{{${key}}}`, () => value);
|
|
1907
|
+
}
|
|
1908
|
+
const missing = [...new Set(page.match(/\{\{[A-Z_]+\}\}/g) ?? [])];
|
|
1909
|
+
if (missing.length > 0) {
|
|
1910
|
+
throw new Error(
|
|
1911
|
+
`the template has unsubstituted placeholders: ${missing.join(", ")}.
|
|
1912
|
+
Every {{TOKEN}} needs a value \u2014 pass it, or drop it from the template.`
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1915
|
+
return page;
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
// src/build.ts
|
|
1919
|
+
import { join as join8 } from "path";
|
|
1920
|
+
|
|
1921
|
+
// src/signing.ts
|
|
1922
|
+
import { createHash } from "crypto";
|
|
1923
|
+
import { join as join7 } from "path";
|
|
1924
|
+
function profileSettingName(target) {
|
|
1925
|
+
if (target.profileSetting) return target.profileSetting;
|
|
1926
|
+
const key = (target.bundleIdSuffix ?? "app").toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1927
|
+
return `JETBRIDGE_PROFILE_${key}`;
|
|
1928
|
+
}
|
|
1929
|
+
function signSettings(suffix, profiles, config) {
|
|
1930
|
+
if (!suffix) return [];
|
|
1931
|
+
const settings = [`${config.variant.buildSettings.signStyle}=Manual`];
|
|
1932
|
+
for (const target of config.variant.targets) {
|
|
1933
|
+
const profile = profiles.byTarget[target.name];
|
|
1934
|
+
if (profile) settings.push(`${profileSettingName(target)}=${profile}`);
|
|
1935
|
+
}
|
|
1936
|
+
return settings;
|
|
1937
|
+
}
|
|
1938
|
+
function variantSettings(suffix, displayName, config) {
|
|
1939
|
+
const names = config.variant.buildSettings;
|
|
1940
|
+
return [
|
|
1941
|
+
...suffix ? [`${names.bundleSuffix}=.${suffix}`] : [],
|
|
1942
|
+
...displayName ? [`${names.displayName}=${displayName}`] : []
|
|
1943
|
+
];
|
|
1944
|
+
}
|
|
1945
|
+
function parseProfilePlist(xml) {
|
|
1946
|
+
const name = /<key>Name<\/key>\s*<string>([^<]*)<\/string>/.exec(xml)?.[1];
|
|
1947
|
+
const expires = /<key>ExpirationDate<\/key>\s*<date>([^<]*)<\/date>/.exec(xml)?.[1];
|
|
1948
|
+
if (!name || !expires) return null;
|
|
1949
|
+
const devices = /* @__PURE__ */ new Set();
|
|
1950
|
+
const deviceBlock = /<key>ProvisionedDevices<\/key>\s*<array>([\s\S]*?)<\/array>/.exec(xml)?.[1];
|
|
1951
|
+
for (const match of (deviceBlock ?? "").matchAll(/<string>([^<]+)<\/string>/g)) {
|
|
1952
|
+
devices.add(match[1]);
|
|
1953
|
+
}
|
|
1954
|
+
const certificateSha1 = /* @__PURE__ */ new Set();
|
|
1955
|
+
const certificateBlock = /<key>DeveloperCertificates<\/key>\s*<array>([\s\S]*?)<\/array>/.exec(
|
|
1956
|
+
xml
|
|
1957
|
+
)?.[1];
|
|
1958
|
+
for (const match of (certificateBlock ?? "").matchAll(/<data>([\s\S]*?)<\/data>/g)) {
|
|
1959
|
+
const der = Buffer.from(match[1].replace(/\s+/g, ""), "base64");
|
|
1960
|
+
certificateSha1.add(createHash("sha1").update(der).digest("hex").toUpperCase());
|
|
1961
|
+
}
|
|
1962
|
+
return { name, expiresMs: Date.parse(expires), devices, certificateSha1 };
|
|
1963
|
+
}
|
|
1964
|
+
function localSigningThumbprints(boundary) {
|
|
1965
|
+
const output = boundary.exec.runSync("security", [
|
|
1966
|
+
"find-identity",
|
|
1967
|
+
"-v",
|
|
1968
|
+
"-p",
|
|
1969
|
+
"codesigning"
|
|
1970
|
+
]).stdout;
|
|
1971
|
+
const thumbprints = /* @__PURE__ */ new Set();
|
|
1972
|
+
for (const match of output.matchAll(/\b([0-9A-F]{40})\b/g)) thumbprints.add(match[1]);
|
|
1973
|
+
return thumbprints;
|
|
1974
|
+
}
|
|
1975
|
+
var EXPIRY_MARGIN_MS = 24 * 60 * 60 * 1e3;
|
|
1976
|
+
function cachedSigning(boundary, config, options) {
|
|
1977
|
+
try {
|
|
1978
|
+
const directory = profileDirectory(boundary);
|
|
1979
|
+
if (!boundary.fs.exists(directory)) return null;
|
|
1980
|
+
const identities = localSigningThumbprints(boundary);
|
|
1981
|
+
if (identities.size === 0) return null;
|
|
1982
|
+
const wanted = new Map(
|
|
1983
|
+
config.variant.targets.map((target) => [
|
|
1984
|
+
profileNameFor(target, options.suffix, config),
|
|
1985
|
+
target.name
|
|
1986
|
+
])
|
|
1987
|
+
);
|
|
1988
|
+
if (wanted.size === 0) return null;
|
|
1989
|
+
if (options.deviceUdids.length === 0 || options.deviceUdids.some((udid) => !udid)) return null;
|
|
1990
|
+
const found = {};
|
|
1991
|
+
for (const file of boundary.fs.readdir(directory)) {
|
|
1992
|
+
if (!file.endsWith(".mobileprovision")) continue;
|
|
1993
|
+
if (Object.keys(found).length === wanted.size) break;
|
|
1994
|
+
const decoded = boundary.exec.runSync("security", ["cms", "-D", "-i", join7(directory, file)]);
|
|
1995
|
+
if (!decoded.ok) continue;
|
|
1996
|
+
const parsed = parseProfilePlist(decoded.stdout);
|
|
1997
|
+
if (!parsed) continue;
|
|
1998
|
+
const targetName = wanted.get(parsed.name);
|
|
1999
|
+
if (!targetName) continue;
|
|
2000
|
+
if (Number.isNaN(parsed.expiresMs)) continue;
|
|
2001
|
+
if (parsed.expiresMs - options.now * 1e3 < EXPIRY_MARGIN_MS) continue;
|
|
2002
|
+
if (!options.deviceUdids.every((udid) => parsed.devices.has(udid))) continue;
|
|
2003
|
+
if (![...parsed.certificateSha1].some((sha) => identities.has(sha))) continue;
|
|
2004
|
+
found[targetName] = parsed.name;
|
|
2005
|
+
}
|
|
2006
|
+
return Object.keys(found).length === wanted.size ? { byTarget: found } : null;
|
|
2007
|
+
} catch {
|
|
2008
|
+
return null;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// src/build.ts
|
|
2013
|
+
var buildNumber = (boundary) => String(boundary.now());
|
|
2014
|
+
function authArgs(boundary, config) {
|
|
2015
|
+
const credentials2 = localCredentials(boundary, config);
|
|
2016
|
+
if (!credentials2) return [];
|
|
2017
|
+
return [
|
|
2018
|
+
"-authenticationKeyPath",
|
|
2019
|
+
credentials2.keyPath,
|
|
2020
|
+
"-authenticationKeyID",
|
|
2021
|
+
credentials2.keyId,
|
|
2022
|
+
"-authenticationKeyIssuerID",
|
|
2023
|
+
credentials2.issuerId
|
|
2024
|
+
];
|
|
2025
|
+
}
|
|
2026
|
+
function buildArgs(boundary, project, request) {
|
|
2027
|
+
const { config } = project;
|
|
2028
|
+
return [
|
|
2029
|
+
"build",
|
|
2030
|
+
...project.xcodebuildTarget(),
|
|
2031
|
+
"-scheme",
|
|
2032
|
+
config.project.scheme,
|
|
2033
|
+
"-configuration",
|
|
2034
|
+
request.configuration,
|
|
2035
|
+
"-destination",
|
|
2036
|
+
request.destination,
|
|
2037
|
+
"-derivedDataPath",
|
|
2038
|
+
request.derivedDataPath,
|
|
2039
|
+
`CURRENT_PROJECT_VERSION=${request.buildNumber}`,
|
|
2040
|
+
// No separate dSYM on the inner loop. Generating one for every target adds
|
|
2041
|
+
// seconds to each incremental install, for a debug artifact a dev build
|
|
2042
|
+
// never reads: a non-stripped build symbolicates from its own DWARF.
|
|
2043
|
+
...request.withDsym ? [] : ["DEBUG_INFORMATION_FORMAT=dwarf"],
|
|
2044
|
+
...request.gitSha ? [`${config.variant.buildSettings.gitSha}=${request.gitSha}`] : [],
|
|
2045
|
+
...variantSettings(request.suffix, request.displayName, config),
|
|
2046
|
+
...signSettings(request.suffix, request.profiles, config),
|
|
2047
|
+
"-allowProvisioningUpdates",
|
|
2048
|
+
...authArgs(boundary, config),
|
|
2049
|
+
"-quiet"
|
|
2050
|
+
];
|
|
2051
|
+
}
|
|
2052
|
+
function productPath(request, config, platform) {
|
|
2053
|
+
return join8(
|
|
2054
|
+
request.derivedDataPath,
|
|
2055
|
+
"Build",
|
|
2056
|
+
"Products",
|
|
2057
|
+
`${request.configuration}-${platform}`,
|
|
2058
|
+
`${config.project.scheme}.app`
|
|
2059
|
+
);
|
|
2060
|
+
}
|
|
2061
|
+
async function requireToolchain(boundary, project, binaries) {
|
|
2062
|
+
for (const binary of binaries) {
|
|
2063
|
+
const found = await boundary.exec.run("command", ["-v", binary], { allowFail: true });
|
|
2064
|
+
if (!found.ok) fail(`${binary} was not found on PATH`);
|
|
2065
|
+
}
|
|
2066
|
+
const [, target] = project.xcodebuildTarget();
|
|
2067
|
+
if (!boundary.fs.exists(target)) {
|
|
2068
|
+
fail(
|
|
2069
|
+
`missing ${target}.
|
|
2070
|
+
` + (project.config.project.projectYml ? " Generate the project first, then re-run." : " Check project.xcodeproj in the config.")
|
|
2071
|
+
);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
async function generateProject(boundary, project) {
|
|
2075
|
+
if (!project.config.project.xcodegen) return;
|
|
2076
|
+
boundary.log.step("regenerating the Xcode project");
|
|
2077
|
+
const result = await boundary.exec.run("xcodegen", ["generate"], {
|
|
2078
|
+
cwd: project.iosPath(),
|
|
2079
|
+
allowFail: true
|
|
2080
|
+
});
|
|
2081
|
+
if (!result.ok) fail(`xcodegen failed:
|
|
2082
|
+
${(result.stderr || result.stdout).trim()}`);
|
|
2083
|
+
}
|
|
2084
|
+
async function runHook(boundary, project, which) {
|
|
2085
|
+
const command = project.config.hooks[which];
|
|
2086
|
+
if (!command) return;
|
|
2087
|
+
boundary.log.step(`${which}: ${command}`);
|
|
2088
|
+
const result = await boundary.exec.run("/bin/sh", ["-c", command], {
|
|
2089
|
+
cwd: project.root,
|
|
2090
|
+
stdio: "inherit",
|
|
2091
|
+
allowFail: true
|
|
2092
|
+
});
|
|
2093
|
+
if (!result.ok) fail(`the ${which} hook failed (exit ${result.code}): ${command}`);
|
|
2094
|
+
}
|
|
2095
|
+
async function build(boundary, project, request) {
|
|
2096
|
+
const args = buildArgs(boundary, project, request);
|
|
2097
|
+
boundary.log.step(
|
|
2098
|
+
`building ${request.configuration}/${project.config.project.scheme} (build ${request.buildNumber})`
|
|
2099
|
+
);
|
|
2100
|
+
const result = await boundary.exec.run("xcodebuild", args, {
|
|
2101
|
+
cwd: project.root,
|
|
2102
|
+
allowFail: true
|
|
2103
|
+
});
|
|
2104
|
+
if (!result.ok) {
|
|
2105
|
+
const tail = (result.stderr || result.stdout).trim().split("\n").slice(-20).join("\n");
|
|
2106
|
+
fail(`xcodebuild failed:
|
|
2107
|
+
${tail}`);
|
|
2108
|
+
}
|
|
2109
|
+
return result;
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
// src/entitlements.ts
|
|
2113
|
+
var codeSignLine = (path) => `CODE_SIGN_ENTITLEMENTS = ${/[^A-Za-z0-9/._]/.test(path) ? `"${path}"` : path};`;
|
|
2114
|
+
function swappableTargets(project) {
|
|
2115
|
+
return project.config.variant.targets.filter((target) => target.entitlements && target.variantEntitlements).map((target) => ({ from: target.entitlements, to: target.variantEntitlements }));
|
|
2116
|
+
}
|
|
2117
|
+
var pbxprojPath = (project) => project.iosPath(project.config.project.xcodeproj ?? "", "project.pbxproj");
|
|
2118
|
+
function applySwap(boundary, project) {
|
|
2119
|
+
const path = pbxprojPath(project);
|
|
2120
|
+
const swaps = swappableTargets(project);
|
|
2121
|
+
const before = boundary.fs.read(path);
|
|
2122
|
+
let after = before;
|
|
2123
|
+
for (const swap of swaps) {
|
|
2124
|
+
after = after.replaceAll(codeSignLine(swap.from), codeSignLine(swap.to));
|
|
2125
|
+
}
|
|
2126
|
+
const applied = swaps.every((swap) => after.includes(codeSignLine(swap.to)));
|
|
2127
|
+
if (after === before || !applied) {
|
|
2128
|
+
fail(
|
|
2129
|
+
"the entitlement swap matched no CODE_SIGN_ENTITLEMENTS in the project file.\n Check that variant.targets[].entitlements matches the path the project spells,\n and regenerate the project if it is stale."
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
boundary.fs.write(path, after);
|
|
2133
|
+
}
|
|
2134
|
+
function findStrandedSwap(boundary, project) {
|
|
2135
|
+
const path = pbxprojPath(project);
|
|
2136
|
+
if (!boundary.fs.exists(path)) return null;
|
|
2137
|
+
const contents = boundary.fs.read(path);
|
|
2138
|
+
const stranded = swappableTargets(project).find(
|
|
2139
|
+
(swap) => contents.includes(codeSignLine(swap.to))
|
|
2140
|
+
);
|
|
2141
|
+
return stranded ? path : null;
|
|
2142
|
+
}
|
|
2143
|
+
var FATAL_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
2144
|
+
var SIGNAL_EXIT_CODES = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 };
|
|
2145
|
+
async function withEntitlementSwap(boundary, project, options, body) {
|
|
2146
|
+
if (!options.suffix || swappableTargets(project).length === 0) return body();
|
|
2147
|
+
const stranded = findStrandedSwap(boundary, project);
|
|
2148
|
+
if (stranded) {
|
|
2149
|
+
fail(
|
|
2150
|
+
`${stranded} still carries a variant entitlement swap from an interrupted run.
|
|
2151
|
+
Restore it first (\`git checkout -- ${stranded}\`), then re-run.`
|
|
2152
|
+
);
|
|
2153
|
+
}
|
|
2154
|
+
const path = pbxprojPath(project);
|
|
2155
|
+
let swapped = false;
|
|
2156
|
+
const restore = () => {
|
|
2157
|
+
if (!swapped) return;
|
|
2158
|
+
swapped = false;
|
|
2159
|
+
boundary.log.info("restoring the project file (variant entitlement swap)");
|
|
2160
|
+
boundary.fs.write(path, boundary.fs.read(options.backupPath));
|
|
2161
|
+
};
|
|
2162
|
+
const handlers = FATAL_SIGNALS.map(
|
|
2163
|
+
(signal) => [
|
|
2164
|
+
signal,
|
|
2165
|
+
() => {
|
|
2166
|
+
boundary.log.warn(`${signal} \u2014 restoring the project file before exit`);
|
|
2167
|
+
restore();
|
|
2168
|
+
process.exit(SIGNAL_EXIT_CODES[signal] ?? 1);
|
|
2169
|
+
}
|
|
2170
|
+
]
|
|
2171
|
+
);
|
|
2172
|
+
for (const [signal, handler] of handlers) process.on(signal, handler);
|
|
2173
|
+
try {
|
|
2174
|
+
boundary.fs.write(options.backupPath, boundary.fs.read(path));
|
|
2175
|
+
boundary.log.step("patching the project file \u2192 reduced variant entitlements");
|
|
2176
|
+
applySwap(boundary, project);
|
|
2177
|
+
swapped = true;
|
|
2178
|
+
return await body();
|
|
2179
|
+
} finally {
|
|
2180
|
+
restore();
|
|
2181
|
+
for (const [signal, handler] of handlers) process.removeListener(signal, handler);
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
// src/manifest.ts
|
|
2186
|
+
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2187
|
+
var PLIST_HEADER = '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n';
|
|
2188
|
+
function renderManifestPlist(input) {
|
|
2189
|
+
const x = escapeHtml;
|
|
2190
|
+
const imageAsset = (kind, url) => `
|
|
2191
|
+
<dict>
|
|
2192
|
+
<key>kind</key>
|
|
2193
|
+
<string>${kind}</string>
|
|
2194
|
+
<key>url</key>
|
|
2195
|
+
<string>${x(url)}</string>
|
|
2196
|
+
</dict>`;
|
|
2197
|
+
const extraAssets = (input.displayImageUrl ? imageAsset("display-image", input.displayImageUrl) : "") + (input.fullSizeImageUrl ? imageAsset("full-size-image", input.fullSizeImageUrl) : "");
|
|
2198
|
+
return `${PLIST_HEADER}<dict>
|
|
2199
|
+
<key>items</key>
|
|
2200
|
+
<array>
|
|
2201
|
+
<dict>
|
|
2202
|
+
<key>assets</key>
|
|
2203
|
+
<array>
|
|
2204
|
+
<dict>
|
|
2205
|
+
<key>kind</key>
|
|
2206
|
+
<string>software-package</string>
|
|
2207
|
+
<key>url</key>
|
|
2208
|
+
<string>${x(input.ipaUrl)}</string>
|
|
2209
|
+
</dict>${extraAssets}
|
|
2210
|
+
</array>
|
|
2211
|
+
<key>metadata</key>
|
|
2212
|
+
<dict>
|
|
2213
|
+
<key>bundle-identifier</key>
|
|
2214
|
+
<string>${x(input.bundleId)}</string>
|
|
2215
|
+
<key>bundle-version</key>
|
|
2216
|
+
<string>${x(input.bundleVersion)}</string>
|
|
2217
|
+
<key>kind</key>
|
|
2218
|
+
<string>software</string>
|
|
2219
|
+
<key>title</key>
|
|
2220
|
+
<string>${x(input.title)}</string>
|
|
2221
|
+
</dict>
|
|
2222
|
+
</dict>
|
|
2223
|
+
</array>
|
|
2224
|
+
</dict>
|
|
2225
|
+
</plist>
|
|
2226
|
+
`;
|
|
2227
|
+
}
|
|
2228
|
+
var itmsServicesUrl = (manifestUrl) => `itms-services://?action=download-manifest&url=${encodeURIComponent(manifestUrl)}`;
|
|
2229
|
+
function renderExportOptionsPlist(input) {
|
|
2230
|
+
const x = escapeHtml;
|
|
2231
|
+
const profiles = Object.entries(input.provisioningProfiles ?? {});
|
|
2232
|
+
const manual = profiles.length > 0;
|
|
2233
|
+
const profileDict = manual ? `
|
|
2234
|
+
<key>provisioningProfiles</key>
|
|
2235
|
+
<dict>
|
|
2236
|
+
${profiles.map(
|
|
2237
|
+
([bundleId, profile]) => ` <key>${x(bundleId)}</key>
|
|
2238
|
+
<string>${x(profile)}</string>`
|
|
2239
|
+
).join("\n")}
|
|
2240
|
+
</dict>` : "";
|
|
2241
|
+
return `${PLIST_HEADER}<dict>
|
|
2242
|
+
<key>method</key>
|
|
2243
|
+
<string>${x(input.method)}</string>
|
|
2244
|
+
<key>teamID</key>
|
|
2245
|
+
<string>${x(input.teamId)}</string>
|
|
2246
|
+
<key>signingStyle</key>
|
|
2247
|
+
<string>${manual ? "manual" : "automatic"}</string>
|
|
2248
|
+
<key>destination</key>
|
|
2249
|
+
<string>export</string>
|
|
2250
|
+
<key>compileBitcode</key>
|
|
2251
|
+
<false/>
|
|
2252
|
+
<key>uploadSymbols</key>
|
|
2253
|
+
<false/>
|
|
2254
|
+
<key>stripSwiftSymbols</key>
|
|
2255
|
+
<true/>${profileDict}
|
|
2256
|
+
</dict>
|
|
2257
|
+
</plist>
|
|
2258
|
+
`;
|
|
2259
|
+
}
|
|
2260
|
+
|
|
2261
|
+
// src/storage.ts
|
|
2262
|
+
import {
|
|
2263
|
+
GetObjectCommand,
|
|
2264
|
+
PutObjectCommand,
|
|
2265
|
+
S3Client
|
|
2266
|
+
} from "@aws-sdk/client-s3";
|
|
2267
|
+
import { randomBytes } from "crypto";
|
|
2268
|
+
import { join as join9 } from "path";
|
|
2269
|
+
var awsS3Factory = (config) => new S3Client(config);
|
|
2270
|
+
function credentials(boundary, ota) {
|
|
2271
|
+
const accessKeyId = boundary.env(ota.storage.accessKeyId)?.trim();
|
|
2272
|
+
const secretAccessKey = boundary.env(ota.storage.secretAccessKey)?.trim();
|
|
2273
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
2274
|
+
const missing = [
|
|
2275
|
+
!accessKeyId ? ota.storage.accessKeyId : null,
|
|
2276
|
+
!secretAccessKey ? ota.storage.secretAccessKey : null
|
|
2277
|
+
].filter(Boolean);
|
|
2278
|
+
fail(
|
|
2279
|
+
`the OTA bucket credentials are not set: ${missing.join(", ")}.
|
|
2280
|
+
Export them in this shell, or point ota.storage.accessKeyId / secretAccessKey at the
|
|
2281
|
+
variable names you already use.`
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
return { accessKeyId, secretAccessKey };
|
|
2285
|
+
}
|
|
2286
|
+
var MUTABLE = [".html", ".json", ".png"];
|
|
2287
|
+
var cacheControlFor = (key) => MUTABLE.some((suffix) => key.endsWith(suffix)) ? "no-cache" : "public, max-age=31536000, immutable";
|
|
2288
|
+
function createStore(boundary, ota, factory = awsS3Factory) {
|
|
2289
|
+
const { bucket, region, endpoint } = ota.storage;
|
|
2290
|
+
const client = factory({
|
|
2291
|
+
region,
|
|
2292
|
+
// An S3-compatible host (R2, MinIO, Backblaze) rarely serves virtual-hosted
|
|
2293
|
+
// style, and getting it wrong reads as a DNS failure rather than a config one.
|
|
2294
|
+
...endpoint ? { endpoint, forcePathStyle: true } : {},
|
|
2295
|
+
credentials: credentials(boundary, ota)
|
|
2296
|
+
});
|
|
2297
|
+
return {
|
|
2298
|
+
async put(key, body, contentType) {
|
|
2299
|
+
await client.send(
|
|
2300
|
+
new PutObjectCommand({
|
|
2301
|
+
Bucket: bucket,
|
|
2302
|
+
Key: key,
|
|
2303
|
+
Body: body,
|
|
2304
|
+
ContentType: contentType,
|
|
2305
|
+
// No `ACL: public-read`: readability comes from the bucket policy on
|
|
2306
|
+
// the prefix, which is the only thing that works on a bucket with
|
|
2307
|
+
// Block Public ACLs on — which is the default on a new bucket.
|
|
2308
|
+
CacheControl: cacheControlFor(key)
|
|
2309
|
+
})
|
|
2310
|
+
);
|
|
2311
|
+
},
|
|
2312
|
+
async getText(key) {
|
|
2313
|
+
try {
|
|
2314
|
+
const result = await client.send(new GetObjectCommand({ Bucket: bucket, Key: key }));
|
|
2315
|
+
return await result.Body?.transformToString() ?? null;
|
|
2316
|
+
} catch (error) {
|
|
2317
|
+
const code = error.name ?? error.Code;
|
|
2318
|
+
if (code === "NoSuchKey" || code === "NotFound") return null;
|
|
2319
|
+
throw error;
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
function objectPrefix(ota, token) {
|
|
2325
|
+
const segments = [
|
|
2326
|
+
ota.storage.prefix.replace(/^\/+|\/+$/g, ""),
|
|
2327
|
+
ota.access === "path" ? token : ""
|
|
2328
|
+
];
|
|
2329
|
+
return segments.filter(Boolean).join("/");
|
|
2330
|
+
}
|
|
2331
|
+
function objectKey(ota, token, ...segments) {
|
|
2332
|
+
return [objectPrefix(ota, token), ...segments].filter(Boolean).join("/");
|
|
2333
|
+
}
|
|
2334
|
+
function publicUrl(ota, key) {
|
|
2335
|
+
return `${ota.storage.publicBaseUrl.replace(/\/+$/, "")}/${key}`;
|
|
2336
|
+
}
|
|
2337
|
+
function tokenPath(boundary, bundleId) {
|
|
2338
|
+
return join9(boundary.homedir(), "Library", "Caches", "jetbridge", "ota", `${bundleId}.token`);
|
|
2339
|
+
}
|
|
2340
|
+
function projectToken(boundary, bundleId) {
|
|
2341
|
+
const path = tokenPath(boundary, bundleId);
|
|
2342
|
+
if (boundary.fs.exists(path)) {
|
|
2343
|
+
const existing = boundary.fs.read(path).trim();
|
|
2344
|
+
if (existing) return existing;
|
|
2345
|
+
}
|
|
2346
|
+
const token = randomBytes(6).toString("hex");
|
|
2347
|
+
boundary.fs.write(path, `${token}
|
|
2348
|
+
`);
|
|
2349
|
+
return token;
|
|
2350
|
+
}
|
|
2351
|
+
async function verifyReachable(boundary, ota, manifestUrl) {
|
|
2352
|
+
let status;
|
|
2353
|
+
try {
|
|
2354
|
+
const response = await boundary.http({ method: "HEAD", url: manifestUrl, headers: {} });
|
|
2355
|
+
status = response.status;
|
|
2356
|
+
} catch (error) {
|
|
2357
|
+
fail(
|
|
2358
|
+
`could not reach the uploaded manifest at ${manifestUrl} \u2014 ${error.message}.
|
|
2359
|
+
Check that ota.storage.publicBaseUrl points at how bucket "${ota.storage.bucket}" is served.`
|
|
2360
|
+
);
|
|
2361
|
+
}
|
|
2362
|
+
if (status >= 200 && status < 300) return;
|
|
2363
|
+
const cause = status === 403 || status === 401 ? `the bucket policy on "${ota.storage.bucket}" does not allow public reads of this prefix` : status === 404 ? "the object is not at that URL, so ota.storage.publicBaseUrl or prefix does not match the bucket" : "the bucket returned an unexpected status";
|
|
2364
|
+
fail(
|
|
2365
|
+
`the manifest is not reachable: HTTP ${status} on ${manifestUrl}.
|
|
2366
|
+
Likely cause: ${cause}.
|
|
2367
|
+
Grant s3:GetObject on "${ota.storage.prefix}/*" to everyone (never s3:ListBucket), then
|
|
2368
|
+
re-run. iOS reports this failure only as "Cannot connect", so it is checked here instead.`
|
|
2369
|
+
);
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
// src/wired.ts
|
|
2373
|
+
import { join as join11 } from "path";
|
|
2374
|
+
|
|
2375
|
+
// src/devices.ts
|
|
2376
|
+
import { join as join10 } from "path";
|
|
2377
|
+
var idOf = (device) => device.identifier ?? "";
|
|
2378
|
+
var udidOf = (device) => device.hardwareProperties?.udid ?? "";
|
|
2379
|
+
var nameOf = (device) => device.deviceProperties?.name ?? "?";
|
|
2380
|
+
var transportOf = (device) => device.connectionProperties?.transportType ?? "";
|
|
2381
|
+
var isAvailable = (device) => device.connectionProperties?.pairingState === "paired" && transportOf(device) !== "";
|
|
2382
|
+
var isCabled = (device) => transportOf(device) === "wired";
|
|
2383
|
+
var transportLabel = (device) => {
|
|
2384
|
+
if (!isAvailable(device)) return "unavailable";
|
|
2385
|
+
return isCabled(device) ? "wired" : "Wi-Fi";
|
|
2386
|
+
};
|
|
2387
|
+
async function pairedDevices(boundary, config, scratchDir) {
|
|
2388
|
+
const jsonPath = join10(scratchDir, "devices.json");
|
|
2389
|
+
boundary.fs.mkdirp(scratchDir);
|
|
2390
|
+
const result = await boundary.exec.run("xcrun", [
|
|
2391
|
+
"devicectl",
|
|
2392
|
+
"list",
|
|
2393
|
+
"devices",
|
|
2394
|
+
"--json-output",
|
|
2395
|
+
jsonPath
|
|
2396
|
+
]);
|
|
2397
|
+
if (!result.ok || !boundary.fs.exists(jsonPath)) {
|
|
2398
|
+
fail(
|
|
2399
|
+
"`devicectl list devices` failed \u2014 is a device paired?\n Pair one in Xcode (Window \u203A Devices and Simulators), then re-run."
|
|
2400
|
+
);
|
|
2401
|
+
}
|
|
2402
|
+
let parsed;
|
|
2403
|
+
try {
|
|
2404
|
+
parsed = JSON.parse(boundary.fs.read(jsonPath));
|
|
2405
|
+
} catch {
|
|
2406
|
+
return fail("`devicectl list devices` produced output that is not JSON");
|
|
2407
|
+
}
|
|
2408
|
+
const wanted = new Set(config.project.deviceTypes);
|
|
2409
|
+
return (parsed.result?.devices ?? []).filter(
|
|
2410
|
+
(device) => wanted.has(device.hardwareProperties?.deviceType ?? "")
|
|
2411
|
+
);
|
|
2412
|
+
}
|
|
2413
|
+
function resolveTargets(boundary, devices, deviceFilter) {
|
|
2414
|
+
boundary.log.info("paired devices:");
|
|
2415
|
+
for (const device of devices) {
|
|
2416
|
+
boundary.log.info(` ${idOf(device)} ${nameOf(device)} [${transportLabel(device)}]`);
|
|
2417
|
+
}
|
|
2418
|
+
let selected;
|
|
2419
|
+
if (deviceFilter) {
|
|
2420
|
+
selected = devices.filter(
|
|
2421
|
+
(device) => idOf(device) === deviceFilter || nameOf(device) === deviceFilter || udidOf(device) === deviceFilter || device.hardwareProperties?.serialNumber === deviceFilter
|
|
2422
|
+
);
|
|
2423
|
+
if (selected.length === 0) {
|
|
2424
|
+
fail(`--device ${deviceFilter} is not a paired device (see the list above)`);
|
|
2425
|
+
}
|
|
2426
|
+
const [only] = selected;
|
|
2427
|
+
if (only && !isAvailable(only)) {
|
|
2428
|
+
fail(`${nameOf(only)} is paired but has no transport \u2014 plug it in, or join it to Wi-Fi.`);
|
|
2429
|
+
}
|
|
2430
|
+
} else {
|
|
2431
|
+
selected = devices.filter(isAvailable);
|
|
2432
|
+
if (selected.length === 0) {
|
|
2433
|
+
fail(
|
|
2434
|
+
"no paired device is reachable \u2014 plug one in, or join it to this Mac's Wi-Fi.\n (`jetbridge ota` needs no device at all)"
|
|
2435
|
+
);
|
|
2436
|
+
}
|
|
2437
|
+
const overTheAir = selected.filter((device) => !isCabled(device));
|
|
2438
|
+
if (overTheAir.length > 0) {
|
|
2439
|
+
boundary.log.info(
|
|
2440
|
+
`over Wi-Fi (slower): ${overTheAir.map(nameOf).join(", ")} \u2014 cable them for the fast loop`
|
|
2441
|
+
);
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
return selected.map((device) => ({
|
|
2445
|
+
id: idOf(device),
|
|
2446
|
+
name: nameOf(device),
|
|
2447
|
+
udid: udidOf(device)
|
|
2448
|
+
}));
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
// src/wired.ts
|
|
2452
|
+
function derivedDataPath(boundary, suffix) {
|
|
2453
|
+
return join11(boundary.homedir(), "Library", "Caches", "jetbridge", suffix || "default");
|
|
2454
|
+
}
|
|
2455
|
+
function scratchPath(boundary, suffix) {
|
|
2456
|
+
return join11(
|
|
2457
|
+
boundary.homedir(),
|
|
2458
|
+
"Library",
|
|
2459
|
+
"Caches",
|
|
2460
|
+
"jetbridge",
|
|
2461
|
+
".scratch",
|
|
2462
|
+
suffix || "default"
|
|
2463
|
+
);
|
|
2464
|
+
}
|
|
2465
|
+
async function resolveSigning(boundary, project, options, targets) {
|
|
2466
|
+
if (!options.suffix) return { byTarget: {} };
|
|
2467
|
+
const deviceUdids = targets.map((target) => target.udid);
|
|
2468
|
+
if (!options.reprovision) {
|
|
2469
|
+
const cached = cachedSigning(boundary, project.config, {
|
|
2470
|
+
suffix: options.suffix,
|
|
2471
|
+
deviceUdids,
|
|
2472
|
+
now: boundary.now()
|
|
2473
|
+
});
|
|
2474
|
+
if (cached) {
|
|
2475
|
+
boundary.log.info(
|
|
2476
|
+
"signing: cached profiles already cover these devices \u2014 skipping provisioning"
|
|
2477
|
+
);
|
|
2478
|
+
return cached;
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
const provisioned = await provisionVariant(boundary, project, {
|
|
2482
|
+
suffix: options.suffix,
|
|
2483
|
+
displayName: options.displayName
|
|
2484
|
+
});
|
|
2485
|
+
return {
|
|
2486
|
+
byTarget: Object.fromEntries(provisioned.map((p) => [p.target, p.profileName]))
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
async function wiredInstall(boundary, project, options) {
|
|
2490
|
+
const { config } = project;
|
|
2491
|
+
const configuration = options.configuration ?? config.configurations.wired;
|
|
2492
|
+
if (!config.configurations.available.includes(configuration)) {
|
|
2493
|
+
fail(
|
|
2494
|
+
`"${configuration}" is not one of this project's build configurations (${config.configurations.available.join(", ")})`
|
|
2495
|
+
);
|
|
2496
|
+
}
|
|
2497
|
+
if (options.suffix && !localCredentials(boundary, config)) {
|
|
2498
|
+
fail(
|
|
2499
|
+
"a variant build has to register a new bundle id, which needs App Store Connect credentials.\n Drop the variant to build the plain bundle id instead."
|
|
2500
|
+
);
|
|
2501
|
+
}
|
|
2502
|
+
await requireToolchain(boundary, project, ["xcodebuild", "xcrun"]);
|
|
2503
|
+
await generateProject(boundary, project);
|
|
2504
|
+
await runHook(boundary, project, "preBuild");
|
|
2505
|
+
const derivedData = derivedDataPath(boundary, options.suffix);
|
|
2506
|
+
if (options.clean) {
|
|
2507
|
+
boundary.log.info("--clean: wiping DerivedData for a build from scratch");
|
|
2508
|
+
boundary.fs.rm(derivedData, { recursive: true });
|
|
2509
|
+
}
|
|
2510
|
+
boundary.fs.mkdirp(derivedData);
|
|
2511
|
+
const scratch = scratchPath(boundary, options.suffix);
|
|
2512
|
+
boundary.fs.rm(scratch, { recursive: true });
|
|
2513
|
+
boundary.fs.mkdirp(scratch);
|
|
2514
|
+
const targets = resolveTargets(
|
|
2515
|
+
boundary,
|
|
2516
|
+
await pairedDevices(boundary, config, scratch),
|
|
2517
|
+
options.device ?? ""
|
|
2518
|
+
);
|
|
2519
|
+
const profiles = await resolveSigning(boundary, project, options, targets);
|
|
2520
|
+
const appPath = await withEntitlementSwap(
|
|
2521
|
+
boundary,
|
|
2522
|
+
project,
|
|
2523
|
+
{ suffix: options.suffix, backupPath: join11(scratch, "project.pbxproj.orig") },
|
|
2524
|
+
async () => {
|
|
2525
|
+
const request = {
|
|
2526
|
+
configuration,
|
|
2527
|
+
suffix: options.suffix,
|
|
2528
|
+
displayName: options.displayName,
|
|
2529
|
+
profiles,
|
|
2530
|
+
derivedDataPath: derivedData,
|
|
2531
|
+
destination: "generic/platform=iOS",
|
|
2532
|
+
buildNumber: buildNumber(boundary)
|
|
2533
|
+
};
|
|
2534
|
+
await build(boundary, project, request);
|
|
2535
|
+
const built = productPath(request, config, "iphoneos");
|
|
2536
|
+
if (!boundary.fs.exists(built)) {
|
|
2537
|
+
fail(`the build reported success but produced no app at ${built}`);
|
|
2538
|
+
}
|
|
2539
|
+
return built;
|
|
2540
|
+
}
|
|
2541
|
+
);
|
|
2542
|
+
boundary.log.info(`built \u2192 ${appPath}`);
|
|
2543
|
+
await runHook(boundary, project, "postBuild");
|
|
2544
|
+
const bundleId = bundleIdFor(options.suffix, config);
|
|
2545
|
+
const failures = [];
|
|
2546
|
+
for (const target of targets) {
|
|
2547
|
+
boundary.log.step(`installing to ${target.name} (${target.id})`);
|
|
2548
|
+
const result = await boundary.exec.run(
|
|
2549
|
+
"xcrun",
|
|
2550
|
+
["devicectl", "device", "install", "app", "--device", target.id, appPath],
|
|
2551
|
+
{ allowFail: true }
|
|
2552
|
+
);
|
|
2553
|
+
if (result.ok) {
|
|
2554
|
+
boundary.log.info(`installed ${bundleId} ("${options.displayName}") \u2192 ${target.name}`);
|
|
2555
|
+
} else {
|
|
2556
|
+
boundary.log.warn(`install failed on ${target.name} (${target.id})`);
|
|
2557
|
+
failures.push(target.name);
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
if (failures.length > 0) {
|
|
2561
|
+
fail(`${failures.length} of ${targets.length} installs failed: ${failures.join(", ")}`);
|
|
2562
|
+
}
|
|
2563
|
+
boundary.log.info(`done \u2014 ${targets.length} device(s), ${bundleId} ("${options.displayName}")`);
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
// src/ota.ts
|
|
2567
|
+
var PROFILE_TYPES = {
|
|
2568
|
+
"ad-hoc": "IOS_APP_ADHOC",
|
|
2569
|
+
enterprise: "IOS_APP_INHOUSE"
|
|
2570
|
+
};
|
|
2571
|
+
var IPA_NAME = "app.ipa";
|
|
2572
|
+
var REGISTRY_NAME = "builds.json";
|
|
2573
|
+
var decodeEntities = (text2) => text2.replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", '"').replaceAll("'", "'").replaceAll("'", "'").replaceAll("&", "&");
|
|
2574
|
+
function parsePlist2(xml) {
|
|
2575
|
+
const tag = /<(\/?)([A-Za-z]+)[^>]*?(\/?)>/g;
|
|
2576
|
+
const start = xml.indexOf("<plist");
|
|
2577
|
+
if (start === -1) fail("that file is not a plist \u2014 it has no <plist> element");
|
|
2578
|
+
tag.lastIndex = start;
|
|
2579
|
+
const next = () => {
|
|
2580
|
+
const match = tag.exec(xml);
|
|
2581
|
+
if (!match) fail("the plist ended in the middle of a value \u2014 it is truncated or malformed");
|
|
2582
|
+
return {
|
|
2583
|
+
closing: match[1] === "/",
|
|
2584
|
+
name: match[2],
|
|
2585
|
+
selfClosing: match[3] === "/",
|
|
2586
|
+
start: match.index,
|
|
2587
|
+
end: tag.lastIndex
|
|
2588
|
+
};
|
|
2589
|
+
};
|
|
2590
|
+
const textUntilClose = (from) => decodeEntities(xml.slice(from, next().start));
|
|
2591
|
+
const parseValue = (name, selfClosing, from) => {
|
|
2592
|
+
if (name === "true" || name === "false") {
|
|
2593
|
+
if (!selfClosing) next();
|
|
2594
|
+
return name === "true";
|
|
2595
|
+
}
|
|
2596
|
+
if (name === "dict") {
|
|
2597
|
+
const dict = {};
|
|
2598
|
+
for (; ; ) {
|
|
2599
|
+
const token = next();
|
|
2600
|
+
if (token.closing && token.name === "dict") return dict;
|
|
2601
|
+
if (token.name !== "key") fail(`unexpected <${token.name}> where a plist key was expected`);
|
|
2602
|
+
const key = textUntilClose(token.end);
|
|
2603
|
+
const valueToken = next();
|
|
2604
|
+
dict[key] = parseValue(valueToken.name, valueToken.selfClosing, valueToken.end);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
if (name === "array") {
|
|
2608
|
+
const array = [];
|
|
2609
|
+
for (; ; ) {
|
|
2610
|
+
const token = next();
|
|
2611
|
+
if (token.closing && token.name === "array") return array;
|
|
2612
|
+
array.push(parseValue(token.name, token.selfClosing, token.end));
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
return selfClosing ? "" : textUntilClose(from);
|
|
2616
|
+
};
|
|
2617
|
+
next();
|
|
2618
|
+
const root = next();
|
|
2619
|
+
if (root.name !== "dict") fail("the plist does not hold a dictionary at its root");
|
|
2620
|
+
const value = parseValue("dict", false, root.end);
|
|
2621
|
+
return value;
|
|
2622
|
+
}
|
|
2623
|
+
function plistString(root, path, fallback) {
|
|
2624
|
+
let value = root;
|
|
2625
|
+
for (const segment of path.split(".")) {
|
|
2626
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return fallback;
|
|
2627
|
+
value = value[segment];
|
|
2628
|
+
if (value === void 0) return fallback;
|
|
2629
|
+
}
|
|
2630
|
+
if (Array.isArray(value)) value = value[0];
|
|
2631
|
+
if (typeof value === "boolean") return String(value);
|
|
2632
|
+
return typeof value === "string" && value !== "" ? value : fallback;
|
|
2633
|
+
}
|
|
2634
|
+
var certificateType = (identity) => identity.split(":")[0].trim() || "unknown";
|
|
2635
|
+
var utcStamp = (unixSeconds) => new Date(unixSeconds * 1e3).toISOString().replace("T", " ").replace(/\..+$/, " UTC");
|
|
2636
|
+
async function gitProvenance(boundary, root) {
|
|
2637
|
+
const git = async (...args) => {
|
|
2638
|
+
const result = await boundary.exec.run("git", ["-C", root, ...args], { allowFail: true });
|
|
2639
|
+
return result.ok ? result.stdout.trim() : "";
|
|
2640
|
+
};
|
|
2641
|
+
const branch = await git("rev-parse", "--abbrev-ref", "HEAD");
|
|
2642
|
+
return {
|
|
2643
|
+
branch: branch === "HEAD" || branch === "" ? "detached HEAD" : branch,
|
|
2644
|
+
commit: await git("rev-parse", "--short", "HEAD") || "\u2014",
|
|
2645
|
+
// A dirty tree means the .ipa matches no commit. The page says so rather
|
|
2646
|
+
// than printing a SHA that quietly misrepresents what is installing.
|
|
2647
|
+
dirty: await git("status", "--porcelain") !== ""
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2650
|
+
function readPlistFile(boundary, path) {
|
|
2651
|
+
const raw = boundary.fs.read(path);
|
|
2652
|
+
if (raw.includes("<plist")) return parsePlist2(raw);
|
|
2653
|
+
const converted = boundary.exec.runSync("plutil", ["-convert", "xml1", "-o", "-", path], {
|
|
2654
|
+
allowFail: true
|
|
2655
|
+
});
|
|
2656
|
+
return converted.ok && converted.stdout.includes("<plist") ? parsePlist2(converted.stdout) : null;
|
|
2657
|
+
}
|
|
2658
|
+
async function archiveMetadata(boundary, project, options) {
|
|
2659
|
+
const archivePlist = join12(options.archivePath, "Info.plist");
|
|
2660
|
+
if (!boundary.fs.exists(archivePlist)) {
|
|
2661
|
+
fail(
|
|
2662
|
+
`the archive at ${options.archivePath} has no Info.plist \u2014 the archive step did not finish`
|
|
2663
|
+
);
|
|
2664
|
+
}
|
|
2665
|
+
const archive = readPlistFile(boundary, archivePlist);
|
|
2666
|
+
if (!archive) {
|
|
2667
|
+
fail(
|
|
2668
|
+
`could not read ${archivePlist}.
|
|
2669
|
+
Check it with \`plutil -p\` \u2014 the bundle id and version of the build are read from it.`
|
|
2670
|
+
);
|
|
2671
|
+
}
|
|
2672
|
+
const properties = "ApplicationProperties";
|
|
2673
|
+
const applicationPath = plistString(archive, `${properties}.ApplicationPath`, "");
|
|
2674
|
+
const appPlist = applicationPath ? join12(options.archivePath, "Products", applicationPath, "Info.plist") : "";
|
|
2675
|
+
const app = (appPlist && boundary.fs.exists(appPlist) ? readPlistFile(boundary, appPlist) : null) ?? {};
|
|
2676
|
+
const version = plistString(archive, `${properties}.CFBundleShortVersionString`, "0.0.0");
|
|
2677
|
+
const build2 = plistString(archive, `${properties}.CFBundleVersion`, "0");
|
|
2678
|
+
const provenance = await gitProvenance(boundary, project.root);
|
|
2679
|
+
return {
|
|
2680
|
+
appName: plistString(
|
|
2681
|
+
app,
|
|
2682
|
+
"CFBundleDisplayName",
|
|
2683
|
+
plistString(app, "CFBundleName", project.config.variant.displayName)
|
|
2684
|
+
),
|
|
2685
|
+
bundleId: plistString(
|
|
2686
|
+
archive,
|
|
2687
|
+
`${properties}.CFBundleIdentifier`,
|
|
2688
|
+
project.config.project.baseBundleId
|
|
2689
|
+
),
|
|
2690
|
+
version,
|
|
2691
|
+
build: build2,
|
|
2692
|
+
versionTag: `v${version} \xB7 build ${build2}`,
|
|
2693
|
+
teamId: plistString(archive, `${properties}.Team`, project.config.project.teamId),
|
|
2694
|
+
signedBy: certificateType(plistString(archive, `${properties}.SigningIdentity`, "unknown")),
|
|
2695
|
+
archs: plistString(archive, `${properties}.Architectures`, "arm64"),
|
|
2696
|
+
minIos: plistString(app, "MinimumOSVersion", "\u2014"),
|
|
2697
|
+
sdk: plistString(app, "DTPlatformVersion", "\u2014"),
|
|
2698
|
+
xcodeBuild: plistString(app, "DTXcodeBuild", "\u2014"),
|
|
2699
|
+
configuration: options.configuration,
|
|
2700
|
+
...provenance,
|
|
2701
|
+
variantBadge: options.suffix ? `variant \xB7 ${options.suffix}` : "plain",
|
|
2702
|
+
builtAt: utcStamp(boundary.now())
|
|
2703
|
+
};
|
|
2704
|
+
}
|
|
2705
|
+
var buildIdFor = (meta) => `${meta.bundleId}-${meta.build}`;
|
|
2706
|
+
var megabytes = (bytes) => `${Math.floor(bytes / 1024 / 1024)} MB`;
|
|
2707
|
+
var brandTitle = (config, ota) => ota.branding.title ?? config.variant.displayName;
|
|
2708
|
+
var brandAccent = (ota) => ota.branding.accent ?? "#f4f0e6";
|
|
2709
|
+
function renderRow(record, manifestUrl) {
|
|
2710
|
+
const x = escapeHtml;
|
|
2711
|
+
const commit = record.dirty ? `${record.commit} (dirty)` : record.commit;
|
|
2712
|
+
return ` <div class="build">
|
|
2713
|
+
<div class="top">
|
|
2714
|
+
<span class="title">${x(record.appName)}</span>
|
|
2715
|
+
<span class="badge">${x(record.variantBadge)}</span>
|
|
2716
|
+
</div>
|
|
2717
|
+
<dl>
|
|
2718
|
+
<dt>Bundle</dt><dd>${x(record.bundleId)}</dd>
|
|
2719
|
+
<dt>Version</dt><dd>${x(record.version)} <span class="dim">\xB7 build ${x(record.build)}</span></dd>
|
|
2720
|
+
<dt>Branch</dt><dd>${x(record.branch)}</dd>
|
|
2721
|
+
<dt>Commit</dt><dd>${x(commit)}</dd>
|
|
2722
|
+
<dt>Size</dt><dd>${x(record.ipaSizeLabel)}</dd>
|
|
2723
|
+
<dt>Built</dt><dd>${x(record.builtAt)}</dd>
|
|
2724
|
+
</dl>
|
|
2725
|
+
<a class="install-btn" href="${x(itmsServicesUrl(manifestUrl))}">Install ${x(record.versionTag)}</a>
|
|
2726
|
+
</div>`;
|
|
2727
|
+
}
|
|
2728
|
+
function renderIndexPage(records, options) {
|
|
2729
|
+
const sorted = sortRecords(records);
|
|
2730
|
+
const rows = sorted.length ? sorted.map(
|
|
2731
|
+
(record) => renderRow(
|
|
2732
|
+
record,
|
|
2733
|
+
publicUrl(
|
|
2734
|
+
options.ota,
|
|
2735
|
+
objectKey(options.ota, options.token, "builds", record.buildId, "manifest.plist")
|
|
2736
|
+
)
|
|
2737
|
+
)
|
|
2738
|
+
).join("\n") : ' <p class="empty">No builds uploaded yet.</p>';
|
|
2739
|
+
return fillTemplate(readTemplate("index-page.html"), {
|
|
2740
|
+
BRAND_TITLE: escapeHtml(brandTitle(options.config, options.ota)),
|
|
2741
|
+
ACCENT: brandAccent(options.ota),
|
|
2742
|
+
BUILD_COUNT: String(sorted.length),
|
|
2743
|
+
ROWS: rows,
|
|
2744
|
+
GENERATED_AT: escapeHtml(options.generatedAt)
|
|
2745
|
+
});
|
|
2746
|
+
}
|
|
2747
|
+
function renderInstallPage(meta, options) {
|
|
2748
|
+
const x = escapeHtml;
|
|
2749
|
+
return fillTemplate(readTemplate("install-page.html"), {
|
|
2750
|
+
BRAND_TITLE: x(brandTitle(options.config, options.ota)),
|
|
2751
|
+
ACCENT: brandAccent(options.ota),
|
|
2752
|
+
APP_NAME: x(meta.appName),
|
|
2753
|
+
VARIANT_BADGE: x(meta.variantBadge),
|
|
2754
|
+
BUNDLE_ID: x(meta.bundleId),
|
|
2755
|
+
VERSION: x(meta.version),
|
|
2756
|
+
BUILD: x(meta.build),
|
|
2757
|
+
GIT_BRANCH: x(meta.branch),
|
|
2758
|
+
GIT_COMMIT: x(meta.dirty ? `${meta.commit} (dirty)` : meta.commit),
|
|
2759
|
+
CONFIGURATION: x(meta.configuration),
|
|
2760
|
+
ARCHS: x(meta.archs),
|
|
2761
|
+
IPA_SIZE: x(options.ipaSizeLabel),
|
|
2762
|
+
MIN_IOS: x(meta.minIos),
|
|
2763
|
+
SDK: x(meta.sdk),
|
|
2764
|
+
XCODE_BUILD: x(meta.xcodeBuild),
|
|
2765
|
+
SIGNED_BY: x(meta.signedBy),
|
|
2766
|
+
TEAM_ID: x(meta.teamId),
|
|
2767
|
+
BUILT_AT: x(meta.builtAt),
|
|
2768
|
+
INSTALL_HREF: x(itmsServicesUrl(options.manifestUrl))
|
|
2769
|
+
});
|
|
2770
|
+
}
|
|
2771
|
+
var sortRecords = (records) => [...records].sort((a, b) => b.uploadedAt.localeCompare(a.uploadedAt));
|
|
2772
|
+
function mergeRecords(existing, record, maxBuilds) {
|
|
2773
|
+
const kept = existing.filter((row) => row.buildId !== record.buildId);
|
|
2774
|
+
return sortRecords([record, ...kept]).slice(0, maxBuilds);
|
|
2775
|
+
}
|
|
2776
|
+
async function readRegistry(store, key) {
|
|
2777
|
+
const text2 = await store.getText(key);
|
|
2778
|
+
if (!text2) return [];
|
|
2779
|
+
try {
|
|
2780
|
+
const parsed = JSON.parse(text2);
|
|
2781
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
2782
|
+
} catch {
|
|
2783
|
+
return [];
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
function archiveArgs(boundary, project, request) {
|
|
2787
|
+
const { config } = project;
|
|
2788
|
+
return [
|
|
2789
|
+
"archive",
|
|
2790
|
+
...project.xcodebuildTarget(),
|
|
2791
|
+
"-scheme",
|
|
2792
|
+
config.project.scheme,
|
|
2793
|
+
"-configuration",
|
|
2794
|
+
request.configuration,
|
|
2795
|
+
"-destination",
|
|
2796
|
+
"generic/platform=iOS",
|
|
2797
|
+
"-archivePath",
|
|
2798
|
+
request.archivePath,
|
|
2799
|
+
`CURRENT_PROJECT_VERSION=${request.buildNumber}`,
|
|
2800
|
+
...request.gitSha ? [`${config.variant.buildSettings.gitSha}=${request.gitSha}`] : [],
|
|
2801
|
+
...variantSettings(request.suffix, request.displayName, config),
|
|
2802
|
+
...signSettings(request.suffix, request.profiles, config),
|
|
2803
|
+
"-allowProvisioningUpdates",
|
|
2804
|
+
...authArgs(boundary, config),
|
|
2805
|
+
"-quiet"
|
|
2806
|
+
];
|
|
2807
|
+
}
|
|
2808
|
+
function exportArgs(boundary, config, options) {
|
|
2809
|
+
return [
|
|
2810
|
+
"-exportArchive",
|
|
2811
|
+
"-archivePath",
|
|
2812
|
+
options.archivePath,
|
|
2813
|
+
"-exportOptionsPlist",
|
|
2814
|
+
options.optionsPlist,
|
|
2815
|
+
"-exportPath",
|
|
2816
|
+
options.exportDir,
|
|
2817
|
+
"-allowProvisioningUpdates",
|
|
2818
|
+
...authArgs(boundary, config),
|
|
2819
|
+
"-quiet"
|
|
2820
|
+
];
|
|
2821
|
+
}
|
|
2822
|
+
function exportProfileMap(config, suffix, profiles) {
|
|
2823
|
+
if (!suffix) return {};
|
|
2824
|
+
const map = {};
|
|
2825
|
+
for (const target of config.variant.targets) {
|
|
2826
|
+
const profile = profiles.byTarget[target.name];
|
|
2827
|
+
if (profile) map[targetBundleId(target, suffix, config)] = profile;
|
|
2828
|
+
}
|
|
2829
|
+
return map;
|
|
2830
|
+
}
|
|
2831
|
+
async function runArchive(boundary, project, request) {
|
|
2832
|
+
boundary.log.step(
|
|
2833
|
+
`archiving ${request.configuration}/${project.config.project.scheme} (build ${request.buildNumber})`
|
|
2834
|
+
);
|
|
2835
|
+
const result = await boundary.exec.run("xcodebuild", archiveArgs(boundary, project, request), {
|
|
2836
|
+
cwd: project.root,
|
|
2837
|
+
allowFail: true
|
|
2838
|
+
});
|
|
2839
|
+
if (!result.ok) {
|
|
2840
|
+
const tail = (result.stderr || result.stdout).trim().split("\n").slice(-20).join("\n");
|
|
2841
|
+
fail(`xcodebuild archive failed:
|
|
2842
|
+
${tail}`);
|
|
2843
|
+
}
|
|
2844
|
+
if (!boundary.fs.exists(request.archivePath)) {
|
|
2845
|
+
fail(
|
|
2846
|
+
`the archive reported success but produced nothing at ${request.archivePath}.
|
|
2847
|
+
Check that the scheme is shared and archives from Xcode.`
|
|
2848
|
+
);
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
async function runExport(boundary, project, options) {
|
|
2852
|
+
boundary.log.step("exporting the .ipa");
|
|
2853
|
+
const result = await boundary.exec.run(
|
|
2854
|
+
"xcodebuild",
|
|
2855
|
+
exportArgs(boundary, project.config, options),
|
|
2856
|
+
{ cwd: project.root, allowFail: true }
|
|
2857
|
+
);
|
|
2858
|
+
if (!result.ok) {
|
|
2859
|
+
const tail = (result.stderr || result.stdout).trim().split("\n").slice(-20).join("\n");
|
|
2860
|
+
fail(`xcodebuild -exportArchive failed:
|
|
2861
|
+
${tail}`);
|
|
2862
|
+
}
|
|
2863
|
+
const produced = boundary.fs.readdir(options.exportDir).filter((name) => name.endsWith(".ipa")).sort();
|
|
2864
|
+
const ipa = produced[0];
|
|
2865
|
+
if (!ipa) {
|
|
2866
|
+
fail(
|
|
2867
|
+
`the export produced no .ipa in ${options.exportDir}.
|
|
2868
|
+
Check that ota.exportMethod matches a certificate this machine holds.`
|
|
2869
|
+
);
|
|
2870
|
+
}
|
|
2871
|
+
return join12(options.exportDir, ipa);
|
|
2872
|
+
}
|
|
2873
|
+
function requireOta(project) {
|
|
2874
|
+
const ota = project.config.ota;
|
|
2875
|
+
if (!ota) {
|
|
2876
|
+
fail(
|
|
2877
|
+
'this project has no "ota" block in its config, so there is nowhere to publish to.\n Add ota.storage (bucket, region, publicBaseUrl) and re-run.'
|
|
2878
|
+
);
|
|
2879
|
+
}
|
|
2880
|
+
return ota;
|
|
2881
|
+
}
|
|
2882
|
+
async function otaInstall(boundary, project, options) {
|
|
2883
|
+
const { config } = project;
|
|
2884
|
+
const ota = requireOta(project);
|
|
2885
|
+
const configuration = options.configuration ?? config.configurations.archive;
|
|
2886
|
+
if (!config.configurations.available.includes(configuration)) {
|
|
2887
|
+
fail(
|
|
2888
|
+
`"${configuration}" is not one of this project's build configurations (${config.configurations.available.join(", ")})`
|
|
2889
|
+
);
|
|
2890
|
+
}
|
|
2891
|
+
credentials(boundary, ota);
|
|
2892
|
+
await requireToolchain(boundary, project, ["xcodebuild"]);
|
|
2893
|
+
await generateProject(boundary, project);
|
|
2894
|
+
await runHook(boundary, project, "preBuild");
|
|
2895
|
+
const work = join12(scratchPath(boundary, options.suffix), "ota");
|
|
2896
|
+
boundary.fs.rm(work, { recursive: true });
|
|
2897
|
+
boundary.fs.mkdirp(work);
|
|
2898
|
+
const archivePath = join12(work, `${config.project.scheme}.xcarchive`);
|
|
2899
|
+
const exportDir = join12(work, "export");
|
|
2900
|
+
const profiles = options.suffix ? {
|
|
2901
|
+
byTarget: Object.fromEntries(
|
|
2902
|
+
(await provisionVariant(boundary, project, {
|
|
2903
|
+
suffix: options.suffix,
|
|
2904
|
+
displayName: options.displayName,
|
|
2905
|
+
profileType: PROFILE_TYPES[ota.exportMethod]
|
|
2906
|
+
})).map((profile) => [profile.target, profile.profileName])
|
|
2907
|
+
)
|
|
2908
|
+
} : { byTarget: {} };
|
|
2909
|
+
const request = {
|
|
2910
|
+
configuration,
|
|
2911
|
+
suffix: options.suffix,
|
|
2912
|
+
displayName: options.displayName,
|
|
2913
|
+
profiles,
|
|
2914
|
+
archivePath,
|
|
2915
|
+
buildNumber: buildNumber(boundary),
|
|
2916
|
+
...options.gitSha ? { gitSha: options.gitSha } : {}
|
|
2917
|
+
};
|
|
2918
|
+
await withEntitlementSwap(
|
|
2919
|
+
boundary,
|
|
2920
|
+
project,
|
|
2921
|
+
{ suffix: options.suffix, backupPath: join12(work, "project.pbxproj.orig") },
|
|
2922
|
+
() => runArchive(boundary, project, request)
|
|
2923
|
+
);
|
|
2924
|
+
const optionsPlist = join12(work, "exportOptions.plist");
|
|
2925
|
+
boundary.fs.write(
|
|
2926
|
+
optionsPlist,
|
|
2927
|
+
renderExportOptionsPlist({
|
|
2928
|
+
teamId: config.project.teamId,
|
|
2929
|
+
method: ota.exportMethod,
|
|
2930
|
+
provisioningProfiles: exportProfileMap(config, options.suffix, profiles)
|
|
2931
|
+
})
|
|
2932
|
+
);
|
|
2933
|
+
const ipa = await runExport(boundary, project, { archivePath, exportDir, optionsPlist });
|
|
2934
|
+
const meta = await archiveMetadata(boundary, project, {
|
|
2935
|
+
archivePath,
|
|
2936
|
+
suffix: options.suffix,
|
|
2937
|
+
configuration
|
|
2938
|
+
});
|
|
2939
|
+
if (meta.dirty) boundary.log.warn("the working tree is dirty \u2014 this .ipa matches no commit");
|
|
2940
|
+
await runHook(boundary, project, "postBuild");
|
|
2941
|
+
return publish(boundary, project, { ota, ipa, meta, s3: options.s3 });
|
|
2942
|
+
}
|
|
2943
|
+
async function publish(boundary, project, options) {
|
|
2944
|
+
const { config } = project;
|
|
2945
|
+
const { ota, meta } = options;
|
|
2946
|
+
const token = projectToken(boundary, config.project.baseBundleId);
|
|
2947
|
+
const store = createStore(boundary, ota, options.s3);
|
|
2948
|
+
const buildId = buildIdFor(meta);
|
|
2949
|
+
const key = (...segments) => objectKey(ota, token, ...segments);
|
|
2950
|
+
const buildKey = (...segments) => key("builds", buildId, ...segments);
|
|
2951
|
+
const ipaBytes = boundary.fs.size(options.ipa);
|
|
2952
|
+
const ipaSizeLabel = megabytes(ipaBytes);
|
|
2953
|
+
const iconPath = config.project.appIcon ? project.path(config.project.appIcon) : "";
|
|
2954
|
+
const iconUrl = iconPath && boundary.fs.exists(iconPath) ? publicUrl(ota, key("icon.png")) : void 0;
|
|
2955
|
+
if (iconUrl) {
|
|
2956
|
+
await store.put(key("icon.png"), boundary.fs.readBytes(iconPath), "image/png");
|
|
2957
|
+
}
|
|
2958
|
+
boundary.log.step(`uploading ${ipaSizeLabel} .ipa \u2192 ${ota.storage.bucket}/${buildKey(IPA_NAME)}`);
|
|
2959
|
+
await store.put(
|
|
2960
|
+
buildKey(IPA_NAME),
|
|
2961
|
+
boundary.fs.readBytes(options.ipa),
|
|
2962
|
+
"application/octet-stream"
|
|
2963
|
+
);
|
|
2964
|
+
const manifestUrl = publicUrl(ota, buildKey("manifest.plist"));
|
|
2965
|
+
await store.put(
|
|
2966
|
+
buildKey("manifest.plist"),
|
|
2967
|
+
renderManifestPlist({
|
|
2968
|
+
bundleId: meta.bundleId,
|
|
2969
|
+
bundleVersion: meta.version,
|
|
2970
|
+
title: meta.appName,
|
|
2971
|
+
ipaUrl: publicUrl(ota, buildKey(IPA_NAME)),
|
|
2972
|
+
...iconUrl ? { displayImageUrl: iconUrl, fullSizeImageUrl: iconUrl } : {}
|
|
2973
|
+
}),
|
|
2974
|
+
"text/xml"
|
|
2975
|
+
);
|
|
2976
|
+
await store.put(
|
|
2977
|
+
buildKey("index.html"),
|
|
2978
|
+
renderInstallPage(meta, { config, ota, manifestUrl, ipaSizeLabel }),
|
|
2979
|
+
"text/html; charset=utf-8"
|
|
2980
|
+
);
|
|
2981
|
+
const record = {
|
|
2982
|
+
buildId,
|
|
2983
|
+
appName: meta.appName,
|
|
2984
|
+
bundleId: meta.bundleId,
|
|
2985
|
+
version: meta.version,
|
|
2986
|
+
build: meta.build,
|
|
2987
|
+
versionTag: meta.versionTag,
|
|
2988
|
+
variantBadge: meta.variantBadge,
|
|
2989
|
+
branch: meta.branch,
|
|
2990
|
+
commit: meta.commit,
|
|
2991
|
+
dirty: meta.dirty,
|
|
2992
|
+
ipaSizeLabel,
|
|
2993
|
+
ipaSizeBytes: ipaBytes,
|
|
2994
|
+
builtAt: meta.builtAt,
|
|
2995
|
+
uploadedAt: new Date(boundary.now() * 1e3).toISOString()
|
|
2996
|
+
};
|
|
2997
|
+
const merged = mergeRecords(await readRegistry(store, key(REGISTRY_NAME)), record, ota.maxBuilds);
|
|
2998
|
+
await store.put(key(REGISTRY_NAME), JSON.stringify(merged, null, 2), "application/json");
|
|
2999
|
+
await store.put(
|
|
3000
|
+
key("index.html"),
|
|
3001
|
+
renderIndexPage(merged, { config, ota, token, generatedAt: utcStamp(boundary.now()) }),
|
|
3002
|
+
"text/html; charset=utf-8"
|
|
3003
|
+
);
|
|
3004
|
+
await verifyReachable(boundary, ota, manifestUrl);
|
|
3005
|
+
const installUrl = publicUrl(ota, buildKey("index.html"));
|
|
3006
|
+
const indexUrl = publicUrl(ota, key("index.html"));
|
|
3007
|
+
boundary.log.info(
|
|
3008
|
+
`published ${meta.versionTag} (${ipaSizeLabel}) \u2014 open in Safari: ${installUrl}`
|
|
3009
|
+
);
|
|
3010
|
+
boundary.log.info(`${merged.length} build(s) listed at ${indexUrl}`);
|
|
3011
|
+
return { installUrl, indexUrl, manifestUrl, record, builds: merged.length };
|
|
3012
|
+
}
|
|
3013
|
+
async function reindex(boundary, project, options = {}) {
|
|
3014
|
+
const ota = requireOta(project);
|
|
3015
|
+
const token = projectToken(boundary, project.config.project.baseBundleId);
|
|
3016
|
+
const store = createStore(boundary, ota, options.s3);
|
|
3017
|
+
const records = await readRegistry(store, objectKey(ota, token, REGISTRY_NAME));
|
|
3018
|
+
const page = renderIndexPage(records, {
|
|
3019
|
+
config: project.config,
|
|
3020
|
+
ota,
|
|
3021
|
+
token,
|
|
3022
|
+
generatedAt: utcStamp(boundary.now())
|
|
3023
|
+
});
|
|
3024
|
+
await store.put(objectKey(ota, token, "index.html"), page, "text/html; charset=utf-8");
|
|
3025
|
+
const indexUrl = publicUrl(ota, objectKey(ota, token, "index.html"));
|
|
3026
|
+
boundary.log.info(`reindexed ${records.length} build(s) \u2192 ${indexUrl}`);
|
|
3027
|
+
return { indexUrl, builds: records.length };
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
// src/prompts.ts
|
|
3031
|
+
import { confirm, isCancel, note, select, text } from "@clack/prompts";
|
|
3032
|
+
var orCancel = (value) => {
|
|
3033
|
+
if (isCancel(value)) fail("cancelled \u2014 nothing was written");
|
|
3034
|
+
return value;
|
|
3035
|
+
};
|
|
3036
|
+
var withHint = (question) => question.hint ? `${question.message} (${question.hint})` : question.message;
|
|
3037
|
+
function nonInteractivePrompter(reason) {
|
|
3038
|
+
const refuse = (question) => fail(
|
|
3039
|
+
`"${question.message}" needs an answer, and ${reason}.
|
|
3040
|
+
Pass the flag that supplies ${question.name}, or re-run on a terminal.`
|
|
3041
|
+
);
|
|
3042
|
+
return {
|
|
3043
|
+
text: async (question) => refuse(question),
|
|
3044
|
+
confirm: async (question) => refuse(question),
|
|
3045
|
+
select: async (question) => refuse(question),
|
|
3046
|
+
note(message, title) {
|
|
3047
|
+
console.error(title ? `${title}
|
|
3048
|
+
${message}` : message);
|
|
3049
|
+
}
|
|
3050
|
+
};
|
|
3051
|
+
}
|
|
3052
|
+
function clackPrompter() {
|
|
3053
|
+
if (!isInteractive()) {
|
|
3054
|
+
return nonInteractivePrompter("this run has no terminal to ask on");
|
|
3055
|
+
}
|
|
3056
|
+
return {
|
|
3057
|
+
async text(question) {
|
|
3058
|
+
const answer = orCancel(
|
|
3059
|
+
await text({
|
|
3060
|
+
message: withHint(question),
|
|
3061
|
+
initialValue: question.initial,
|
|
3062
|
+
validate: question.validate ? (value) => question.validate?.(value ?? "") : void 0
|
|
3063
|
+
})
|
|
3064
|
+
);
|
|
3065
|
+
return answer;
|
|
3066
|
+
},
|
|
3067
|
+
async confirm(question) {
|
|
3068
|
+
return orCancel(
|
|
3069
|
+
await confirm({ message: withHint(question), initialValue: question.initial ?? true })
|
|
3070
|
+
);
|
|
3071
|
+
},
|
|
3072
|
+
async select(question) {
|
|
3073
|
+
const answer = orCancel(
|
|
3074
|
+
await select({
|
|
3075
|
+
message: withHint(question),
|
|
3076
|
+
options: question.options.map((option) => ({
|
|
3077
|
+
value: option.value,
|
|
3078
|
+
label: option.label ?? option.value,
|
|
3079
|
+
...option.hint ? { hint: option.hint } : {}
|
|
3080
|
+
})),
|
|
3081
|
+
initialValue: question.initial
|
|
3082
|
+
})
|
|
3083
|
+
);
|
|
3084
|
+
return answer;
|
|
3085
|
+
},
|
|
3086
|
+
note(message, title) {
|
|
3087
|
+
note(message, title);
|
|
3088
|
+
}
|
|
3089
|
+
};
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
// src/simulator.ts
|
|
3093
|
+
var isBooted = (simulator) => simulator.state === "Booted";
|
|
3094
|
+
async function listSimulators(boundary) {
|
|
3095
|
+
const result = await boundary.exec.run("xcrun", ["simctl", "list", "devices", "-j"], {
|
|
3096
|
+
allowFail: true
|
|
3097
|
+
});
|
|
3098
|
+
if (!result.ok) {
|
|
3099
|
+
fail(
|
|
3100
|
+
"`simctl list devices` failed \u2014 are the Xcode command line tools selected?\n Run `sudo xcode-select -s /Applications/Xcode.app`, then re-run."
|
|
3101
|
+
);
|
|
3102
|
+
}
|
|
3103
|
+
let parsed;
|
|
3104
|
+
try {
|
|
3105
|
+
parsed = JSON.parse(result.stdout);
|
|
3106
|
+
} catch {
|
|
3107
|
+
return fail("`simctl list devices` produced output that is not JSON");
|
|
3108
|
+
}
|
|
3109
|
+
const simulators = [];
|
|
3110
|
+
for (const [runtime, devices] of Object.entries(parsed.devices ?? {})) {
|
|
3111
|
+
for (const device of devices) {
|
|
3112
|
+
if (!device.udid) continue;
|
|
3113
|
+
simulators.push({
|
|
3114
|
+
udid: device.udid,
|
|
3115
|
+
name: device.name ?? "?",
|
|
3116
|
+
state: device.state ?? "Unknown",
|
|
3117
|
+
available: device.isAvailable ?? true,
|
|
3118
|
+
deviceTypeIdentifier: device.deviceTypeIdentifier ?? "",
|
|
3119
|
+
runtime
|
|
3120
|
+
});
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
return simulators;
|
|
3124
|
+
}
|
|
3125
|
+
var matchesProjectDeviceType = (simulator, config) => config.project.deviceTypes.some(
|
|
3126
|
+
(type) => simulator.deviceTypeIdentifier.includes(`SimDeviceType.${type}`)
|
|
3127
|
+
);
|
|
3128
|
+
function resolveSimulator(boundary, simulators, config, wanted) {
|
|
3129
|
+
if (wanted) {
|
|
3130
|
+
const match = simulators.find((simulator) => simulator.udid === wanted) ?? simulators.find((simulator) => simulator.name === wanted && simulator.available);
|
|
3131
|
+
if (!match) {
|
|
3132
|
+
const names = simulators.filter((simulator) => simulator.available).map((simulator) => `${simulator.name} (${simulator.udid})`);
|
|
3133
|
+
fail(
|
|
3134
|
+
`--device ${wanted} is not an available simulator name or udid.
|
|
3135
|
+
Available: ${names.join(", ") || "(none \u2014 install a runtime in Xcode \u203A Settings \u203A Components)"}`
|
|
3136
|
+
);
|
|
3137
|
+
}
|
|
3138
|
+
if (!match.available) {
|
|
3139
|
+
fail(
|
|
3140
|
+
`simulator ${match.name} (${match.udid}) is unavailable \u2014 its runtime is not installed.
|
|
3141
|
+
Install it in Xcode \u203A Settings \u203A Components, or name another simulator.`
|
|
3142
|
+
);
|
|
3143
|
+
}
|
|
3144
|
+
return match;
|
|
3145
|
+
}
|
|
3146
|
+
const candidates = simulators.filter(
|
|
3147
|
+
(simulator) => simulator.available && matchesProjectDeviceType(simulator, config)
|
|
3148
|
+
);
|
|
3149
|
+
const chosen = candidates.find(isBooted) ?? candidates[0];
|
|
3150
|
+
if (!chosen) {
|
|
3151
|
+
fail(
|
|
3152
|
+
`no available ${config.project.deviceTypes.join("/")} simulator is installed.
|
|
3153
|
+
Add one in Xcode \u203A Settings \u203A Components, or name one with --device.`
|
|
3154
|
+
);
|
|
3155
|
+
}
|
|
3156
|
+
boundary.log.info(
|
|
3157
|
+
`simulator: ${chosen.name} (${chosen.udid})${isBooted(chosen) ? " \u2014 already booted" : ""}`
|
|
3158
|
+
);
|
|
3159
|
+
return chosen;
|
|
3160
|
+
}
|
|
3161
|
+
async function bootSimulator(boundary, simulator) {
|
|
3162
|
+
if (isBooted(simulator)) return;
|
|
3163
|
+
boundary.log.step(`booting ${simulator.name}`);
|
|
3164
|
+
const result = await boundary.exec.run("xcrun", ["simctl", "boot", simulator.udid], {
|
|
3165
|
+
allowFail: true
|
|
3166
|
+
});
|
|
3167
|
+
if (!result.ok && !/current state: Booted/i.test(result.stderr || result.stdout)) {
|
|
3168
|
+
fail(
|
|
3169
|
+
`could not boot ${simulator.name} (${simulator.udid}).
|
|
3170
|
+
Try \`xcrun simctl shutdown ${simulator.udid}\` and re-run.`
|
|
3171
|
+
);
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
async function installApp(boundary, simulator, appPath) {
|
|
3175
|
+
const result = await boundary.exec.run("xcrun", ["simctl", "install", simulator.udid, appPath], {
|
|
3176
|
+
allowFail: true
|
|
3177
|
+
});
|
|
3178
|
+
if (!result.ok) {
|
|
3179
|
+
fail(
|
|
3180
|
+
`could not install ${appPath} on ${simulator.name}:
|
|
3181
|
+
${(result.stderr || result.stdout).trim()}`
|
|
3182
|
+
);
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
async function launchApp(boundary, simulator, bundleId) {
|
|
3186
|
+
await boundary.exec.run("xcrun", ["simctl", "terminate", simulator.udid, bundleId], {
|
|
3187
|
+
allowFail: true
|
|
3188
|
+
});
|
|
3189
|
+
const result = await boundary.exec.run("xcrun", ["simctl", "launch", simulator.udid, bundleId], {
|
|
3190
|
+
allowFail: true
|
|
3191
|
+
});
|
|
3192
|
+
if (!result.ok) {
|
|
3193
|
+
fail(
|
|
3194
|
+
`installed ${bundleId} but could not launch it on ${simulator.name}:
|
|
3195
|
+
${(result.stderr || result.stdout).trim()}
|
|
3196
|
+
Open it from the simulator home screen to see why.`
|
|
3197
|
+
);
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3201
|
+
// src/sim.ts
|
|
3202
|
+
async function simInstall(boundary, project, options) {
|
|
3203
|
+
const { config } = project;
|
|
3204
|
+
const configuration = options.configuration ?? config.configurations.sim;
|
|
3205
|
+
if (!config.configurations.available.includes(configuration)) {
|
|
3206
|
+
fail(
|
|
3207
|
+
`"${configuration}" is not one of this project's build configurations (${config.configurations.available.join(", ")})`
|
|
3208
|
+
);
|
|
3209
|
+
}
|
|
3210
|
+
await requireToolchain(boundary, project, ["xcodebuild", "xcrun"]);
|
|
3211
|
+
await generateProject(boundary, project);
|
|
3212
|
+
await runHook(boundary, project, "preBuild");
|
|
3213
|
+
const simulator = resolveSimulator(
|
|
3214
|
+
boundary,
|
|
3215
|
+
await listSimulators(boundary),
|
|
3216
|
+
config,
|
|
3217
|
+
options.device ?? ""
|
|
3218
|
+
);
|
|
3219
|
+
await bootSimulator(boundary, simulator);
|
|
3220
|
+
const derivedData = derivedDataPath(boundary, options.suffix);
|
|
3221
|
+
if (options.clean) {
|
|
3222
|
+
boundary.log.info("--clean: wiping DerivedData for a build from scratch");
|
|
3223
|
+
boundary.fs.rm(derivedData, { recursive: true });
|
|
3224
|
+
}
|
|
3225
|
+
boundary.fs.mkdirp(derivedData);
|
|
3226
|
+
const request = {
|
|
3227
|
+
configuration,
|
|
3228
|
+
suffix: options.suffix,
|
|
3229
|
+
displayName: options.displayName,
|
|
3230
|
+
// Empty on purpose: nothing signs a simulator build, so there is no profile
|
|
3231
|
+
// to point it at and `provisionVariant` is never called from this flow.
|
|
3232
|
+
profiles: { byTarget: {} },
|
|
3233
|
+
derivedDataPath: derivedData,
|
|
3234
|
+
destination: `platform=iOS Simulator,id=${simulator.udid}`,
|
|
3235
|
+
buildNumber: buildNumber(boundary)
|
|
3236
|
+
};
|
|
3237
|
+
await build(boundary, project, request);
|
|
3238
|
+
const appPath = productPath(request, config, "iphonesimulator");
|
|
3239
|
+
if (!boundary.fs.exists(appPath)) {
|
|
3240
|
+
fail(`the build reported success but produced no app at ${appPath}`);
|
|
3241
|
+
}
|
|
3242
|
+
boundary.log.info(`built \u2192 ${appPath}`);
|
|
3243
|
+
await runHook(boundary, project, "postBuild");
|
|
3244
|
+
const bundleId = bundleIdFor(options.suffix, config);
|
|
3245
|
+
boundary.log.step(`installing ${bundleId} \u2192 ${simulator.name}`);
|
|
3246
|
+
await installApp(boundary, simulator, appPath);
|
|
3247
|
+
await launchApp(boundary, simulator, bundleId);
|
|
3248
|
+
boundary.log.info(
|
|
3249
|
+
`installed + launched ${bundleId} ("${options.displayName}") \u2192 ${simulator.name}`
|
|
3250
|
+
);
|
|
3251
|
+
if (options.suffix && !localCredentials(boundary, config)) {
|
|
3252
|
+
boundary.log.info(
|
|
3253
|
+
"no App Store Connect credentials here \u2014 fine for a simulator, but `jetbridge wired` needs them."
|
|
3254
|
+
);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
|
|
3258
|
+
// src/git.ts
|
|
3259
|
+
function currentBranch(boundary, cwd) {
|
|
3260
|
+
const result = boundary.exec.runSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
3261
|
+
cwd,
|
|
3262
|
+
allowFail: true
|
|
3263
|
+
});
|
|
3264
|
+
if (!result.ok) return "";
|
|
3265
|
+
const branch = result.stdout.trim();
|
|
3266
|
+
return branch === "HEAD" ? "" : branch;
|
|
3267
|
+
}
|
|
3268
|
+
function branchSuffix(boundary, project) {
|
|
3269
|
+
const branch = currentBranch(boundary, project.root);
|
|
3270
|
+
if (!branch) {
|
|
3271
|
+
fail(
|
|
3272
|
+
"--suffix needs a value here: there is no current git branch to derive one from.\n Pass one explicitly, e.g. --suffix wave."
|
|
3273
|
+
);
|
|
3274
|
+
}
|
|
3275
|
+
return branch;
|
|
3276
|
+
}
|
|
3277
|
+
|
|
3278
|
+
// src/cli.ts
|
|
3279
|
+
function resolveVariant(boundary, project, options) {
|
|
3280
|
+
const raw = options.suffix === true ? branchSuffix(boundary, project) : typeof options.suffix === "string" ? options.suffix : "";
|
|
3281
|
+
return {
|
|
3282
|
+
suffix: raw ? sanitizeSuffix(raw, project.config) : "",
|
|
3283
|
+
displayName: displayNameFor(raw, options.name ?? "", project.config)
|
|
3284
|
+
};
|
|
3285
|
+
}
|
|
3286
|
+
var program = new Command();
|
|
3287
|
+
program.name("jetbridge").description("Build, sign and deliver iOS dev builds \u2014 to a simulator, a cable, or your bucket.").option("--config-file <path>", "use this config file instead of the nearest one").option("--non-interactive", "never prompt, even on a terminal").showHelpAfterError();
|
|
3288
|
+
var open = () => {
|
|
3289
|
+
const boundary = nodeBoundary({ nonInteractive: Boolean(program.opts().nonInteractive) });
|
|
3290
|
+
const configPath = program.opts().configFile;
|
|
3291
|
+
return { boundary, project: loadProject(boundary, { configPath }) };
|
|
3292
|
+
};
|
|
3293
|
+
var parseName = (value) => {
|
|
3294
|
+
try {
|
|
3295
|
+
return sanitizeName(value);
|
|
3296
|
+
} catch {
|
|
3297
|
+
throw new InvalidArgumentError("must contain letters or digits");
|
|
3298
|
+
}
|
|
3299
|
+
};
|
|
3300
|
+
var parseSuffix = (value) => {
|
|
3301
|
+
if (value.includes(".")) {
|
|
3302
|
+
throw new InvalidArgumentError("just the last segment \u2014 the full bundle id is built for you");
|
|
3303
|
+
}
|
|
3304
|
+
if (!/[A-Za-z0-9]/.test(value)) {
|
|
3305
|
+
throw new InvalidArgumentError("must contain letters or digits");
|
|
3306
|
+
}
|
|
3307
|
+
return value;
|
|
3308
|
+
};
|
|
3309
|
+
var SUFFIX_FLAG = "-s, --suffix [slug]";
|
|
3310
|
+
var SUFFIX_HELP = "variant build; a bare flag names it after the current git branch";
|
|
3311
|
+
var NAME_FLAG = "-n, --name <name>";
|
|
3312
|
+
var NAME_HELP = "home-screen display name";
|
|
3313
|
+
program.command("init").description("write jetbridge.config.json by inspecting this Xcode project").option("-y, --yes", "accept every detected default and never prompt").option("--ios-dir <dir>", "directory holding the Xcode project").option("--scheme <name>", "scheme to build").option("--team-id <id>", "Apple team id").option("--bundle-id <id>", "base bundle id").option("--display-name <name>", "home-screen label for a plain build").option("--ota", "configure over-the-air delivery").option("--ota-bucket <name>").option("--ota-region <region>").option("--ota-endpoint <url>", "for an S3-compatible host (R2, MinIO, Backblaze)").option("--ota-public-base-url <url>", "where uploaded builds are readable (https only)").action(async (options) => {
|
|
3314
|
+
const boundary = nodeBoundary({ nonInteractive: Boolean(program.opts().nonInteractive) });
|
|
3315
|
+
const result = await runInit(
|
|
3316
|
+
boundary,
|
|
3317
|
+
{
|
|
3318
|
+
yes: Boolean(options.yes),
|
|
3319
|
+
iosDir: options.iosDir,
|
|
3320
|
+
scheme: options.scheme,
|
|
3321
|
+
teamId: options.teamId,
|
|
3322
|
+
bundleId: options.bundleId,
|
|
3323
|
+
displayName: options.displayName,
|
|
3324
|
+
ota: Boolean(options.ota),
|
|
3325
|
+
otaBucket: options.otaBucket,
|
|
3326
|
+
otaRegion: options.otaRegion,
|
|
3327
|
+
otaEndpoint: options.otaEndpoint,
|
|
3328
|
+
otaPublicBaseUrl: options.otaPublicBaseUrl
|
|
3329
|
+
},
|
|
3330
|
+
{ prompts: clackPrompter() }
|
|
3331
|
+
);
|
|
3332
|
+
if (result.status === "written") console.error(chalk.green(`wrote ${result.configPath}`));
|
|
3333
|
+
else if (result.status === "unchanged") {
|
|
3334
|
+
console.error(chalk.dim(`${result.configPath} is already up to date`));
|
|
3335
|
+
} else console.error(chalk.dim("nothing written"));
|
|
3336
|
+
});
|
|
3337
|
+
function resolveDestination(options) {
|
|
3338
|
+
const wantsDevice = options.device !== void 0;
|
|
3339
|
+
const wantsSimulator = options.simulator !== void 0;
|
|
3340
|
+
if (wantsDevice && wantsSimulator) fail("pass --device or --simulator, not both");
|
|
3341
|
+
const chosen = wantsDevice ? options.device : options.simulator;
|
|
3342
|
+
return {
|
|
3343
|
+
kind: wantsDevice ? "device" : "simulator",
|
|
3344
|
+
id: typeof chosen === "string" ? chosen : ""
|
|
3345
|
+
};
|
|
3346
|
+
}
|
|
3347
|
+
program.command("install").description("build and install \u2014 on a simulator by default, or over the cable with --device").option(SUFFIX_FLAG, SUFFIX_HELP, parseSuffix).option(NAME_FLAG, NAME_HELP, parseName).option("-d, --device [id]", "install over the cable; give an id to pick one device").option("--simulator [name]", "install on a simulator (the default); give a name or udid").option("-c, --configuration <name>", "build configuration").option("--clean", "wipe cached DerivedData first").option("--reprovision", "bypass the profile cache and provision fresh (--device only)").action(async (options) => {
|
|
3348
|
+
const { boundary, project } = open();
|
|
3349
|
+
const destination = resolveDestination(options);
|
|
3350
|
+
const variant = resolveVariant(boundary, project, options);
|
|
3351
|
+
if (destination.kind === "simulator") {
|
|
3352
|
+
if (options.reprovision) fail("--reprovision only applies to a --device install");
|
|
3353
|
+
await simInstall(boundary, project, {
|
|
3354
|
+
...variant,
|
|
3355
|
+
device: destination.id,
|
|
3356
|
+
configuration: options.configuration,
|
|
3357
|
+
clean: Boolean(options.clean)
|
|
3358
|
+
});
|
|
3359
|
+
return;
|
|
3360
|
+
}
|
|
3361
|
+
await wiredInstall(boundary, project, {
|
|
3362
|
+
...variant,
|
|
3363
|
+
device: destination.id,
|
|
3364
|
+
configuration: options.configuration,
|
|
3365
|
+
clean: Boolean(options.clean),
|
|
3366
|
+
reprovision: Boolean(options.reprovision)
|
|
3367
|
+
});
|
|
3368
|
+
});
|
|
3369
|
+
program.command("link").description("archive, upload to your bucket, and print a link anyone can install from").option(SUFFIX_FLAG, SUFFIX_HELP, parseSuffix).option(NAME_FLAG, NAME_HELP, parseName).option("-c, --configuration <name>", "build configuration").action(async (options) => {
|
|
3370
|
+
const { boundary, project } = open();
|
|
3371
|
+
const result = await otaInstall(boundary, project, {
|
|
3372
|
+
...resolveVariant(boundary, project, options),
|
|
3373
|
+
configuration: options.configuration
|
|
3374
|
+
});
|
|
3375
|
+
console.error("");
|
|
3376
|
+
console.error(chalk.green(`install: ${result.installUrl}`));
|
|
3377
|
+
console.error(chalk.dim(`builds: ${result.indexUrl}`));
|
|
3378
|
+
});
|
|
3379
|
+
program.command("reindex").description("rebuild the build index page from what is in the bucket").action(async () => {
|
|
3380
|
+
const { boundary, project } = open();
|
|
3381
|
+
const url = await reindex(boundary, project, {});
|
|
3382
|
+
console.error(chalk.green(`rebuilt: ${url}`));
|
|
3383
|
+
});
|
|
3384
|
+
var bundles = program.command("bundles").description("variant bundle ids and profiles registered with Apple for this project");
|
|
3385
|
+
bundles.command("ls", { isDefault: true }).alias("list").description("what this project has registered").option("--json", "machine-readable output").action(async (options) => {
|
|
3386
|
+
const { boundary, project } = open();
|
|
3387
|
+
await listBundles(boundary, project, { json: Boolean(options.json) });
|
|
3388
|
+
});
|
|
3389
|
+
bundles.command("provision [slug]").description("register and refresh profiles now, without building").action(async (slug) => {
|
|
3390
|
+
const { boundary, project } = open();
|
|
3391
|
+
const variant = resolveVariant(boundary, project, { suffix: slug ?? true });
|
|
3392
|
+
await provisionBundles(boundary, project, variant);
|
|
3393
|
+
});
|
|
3394
|
+
bundles.command("rm <slug...>").description("remove these variants by name").option("-y, --yes", "actually delete (without this, the plan is printed and nothing changes)").action(async (slugs, options) => {
|
|
3395
|
+
for (const slug of slugs) assertSingleSegmentLoose(slug);
|
|
3396
|
+
const { boundary, project } = open();
|
|
3397
|
+
await removeBundles(boundary, project, {
|
|
3398
|
+
suffixes: slugs.map((value) => sanitizeSuffix(value, project.config)),
|
|
3399
|
+
yes: Boolean(options.yes)
|
|
3400
|
+
});
|
|
3401
|
+
});
|
|
3402
|
+
bundles.command("prune").description("remove variants whose git branch is gone from the remote").option("-y, --yes", "actually delete (without this, the plan is printed and nothing changes)").action(async (options) => {
|
|
3403
|
+
const { boundary, project } = open();
|
|
3404
|
+
await pruneBundles(boundary, project, { yes: Boolean(options.yes) });
|
|
3405
|
+
});
|
|
3406
|
+
function assertSingleSegmentLoose(value) {
|
|
3407
|
+
if (value.includes(".")) {
|
|
3408
|
+
fail(`"${value}": just the last segment \u2014 the full bundle id is built for you (e.g. "wave")`);
|
|
3409
|
+
}
|
|
3410
|
+
return value;
|
|
3411
|
+
}
|
|
3412
|
+
try {
|
|
3413
|
+
await program.parseAsync(process.argv);
|
|
3414
|
+
} catch (error) {
|
|
3415
|
+
if (error instanceof JetbridgeError) {
|
|
3416
|
+
console.error(chalk.red(`\u2717 ${error.message}`));
|
|
3417
|
+
} else {
|
|
3418
|
+
console.error(chalk.red(`\u2717 ${error?.stack ?? String(error)}`));
|
|
3419
|
+
}
|
|
3420
|
+
process.exit(1);
|
|
3421
|
+
}
|
|
3422
|
+
export {
|
|
3423
|
+
assertSingleSegment,
|
|
3424
|
+
resolveVariant
|
|
3425
|
+
};
|
|
3426
|
+
//# sourceMappingURL=cli.js.map
|