create-expo-updates-server 0.1.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/LICENSE +21 -0
- package/README.md +19 -0
- package/bin/create-expo-updates-server.mjs +5 -0
- package/dist/template/.env.docker.example +15 -0
- package/dist/template/.env.example +35 -0
- package/dist/template/Dockerfile +42 -0
- package/dist/template/LICENSE +21 -0
- package/dist/template/README.md +665 -0
- package/dist/template/app/api/admin/access-tokens/[id]/route.ts +25 -0
- package/dist/template/app/api/admin/access-tokens/route.test.ts +73 -0
- package/dist/template/app/api/admin/access-tokens/route.ts +90 -0
- package/dist/template/app/api/admin/embedded-updates/[embeddedUpdateId]/route.ts +25 -0
- package/dist/template/app/api/admin/embedded-updates/route.test.ts +102 -0
- package/dist/template/app/api/admin/embedded-updates/route.ts +47 -0
- package/dist/template/app/api/admin/emergency-redirects/[id]/route.ts +62 -0
- package/dist/template/app/api/admin/emergency-redirects/route.test.ts +84 -0
- package/dist/template/app/api/admin/emergency-redirects/route.ts +56 -0
- package/dist/template/app/api/admin/login/route.test.ts +55 -0
- package/dist/template/app/api/admin/login/route.ts +52 -0
- package/dist/template/app/api/admin/logout/route.ts +20 -0
- package/dist/template/app/api/admin/session/route.ts +15 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +33 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +29 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +29 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +96 -0
- package/dist/template/app/api/admin/updates/route.test.ts +142 -0
- package/dist/template/app/api/admin/updates/route.ts +32 -0
- package/dist/template/app/api/assets/route.ts +6 -0
- package/dist/template/app/api/health/route.test.ts +26 -0
- package/dist/template/app/api/health/route.ts +42 -0
- package/dist/template/app/api/manifest/route.ts +6 -0
- package/dist/template/app/api/update-complete/route.ts +6 -0
- package/dist/template/app/favicon.ico +0 -0
- package/dist/template/app/globals.css +26 -0
- package/dist/template/app/layout.tsx +34 -0
- package/dist/template/app/login/page.tsx +77 -0
- package/dist/template/app/page.tsx +12 -0
- package/dist/template/app/updates/[encodedKey]/page.tsx +482 -0
- package/dist/template/app/updates/embedded/page.tsx +164 -0
- package/dist/template/app/updates/emergency-redirects/page.tsx +430 -0
- package/dist/template/app/updates/layout.tsx +14 -0
- package/dist/template/app/updates/page.tsx +281 -0
- package/dist/template/docker-compose.yml +100 -0
- package/dist/template/docs/expo-app-setup.md +497 -0
- package/dist/template/docs/getting-started.md +502 -0
- package/dist/template/docs/getting-started.ru.md +623 -0
- package/dist/template/docs/index.md +57 -0
- package/dist/template/docs/migrations/schema.sql +363 -0
- package/dist/template/docs/npm-installer.md +83 -0
- package/dist/template/docs/operations-guide.md +270 -0
- package/dist/template/docs/ota-emergency-recovery.md +109 -0
- package/dist/template/docs/supabase-setup.md +133 -0
- package/dist/template/eslint.config.mjs +30 -0
- package/dist/template/gitignore.template +58 -0
- package/dist/template/next.config.ts +7 -0
- package/dist/template/package-lock.json +12156 -0
- package/dist/template/package.json +50 -0
- package/dist/template/postcss.config.mjs +7 -0
- package/dist/template/public/file.svg +1 -0
- package/dist/template/public/globe.svg +1 -0
- package/dist/template/public/next.svg +1 -0
- package/dist/template/public/vercel.svg +1 -0
- package/dist/template/public/window.svg +1 -0
- package/dist/template/scripts/configure-expo-app.mjs +145 -0
- package/dist/template/scripts/create-access-token.mjs +135 -0
- package/dist/template/scripts/create-admin.mjs +169 -0
- package/dist/template/scripts/import-emergency-redirects.mjs +126 -0
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +64 -0
- package/dist/template/scripts/lib/expo-app-configurator.mjs +666 -0
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +463 -0
- package/dist/template/scripts/lib/expo-app-prompts.mjs +139 -0
- package/dist/template/scripts/lib/expo-app-prompts.test.ts +97 -0
- package/dist/template/scripts/lib/expo-export-command.test.ts +31 -0
- package/dist/template/scripts/lib/ota-publish-retry.test.ts +33 -0
- package/dist/template/scripts/manage-emergency-redirect.mjs +483 -0
- package/dist/template/scripts/sync-docker-database-password.sh +16 -0
- package/dist/template/src/client/admin-api.ts +174 -0
- package/dist/template/src/client/admin-types.ts +93 -0
- package/dist/template/src/client/logout-button.tsx +31 -0
- package/dist/template/src/server/controllers/assets.ts +216 -0
- package/dist/template/src/server/controllers/manifest.test.ts +403 -0
- package/dist/template/src/server/controllers/manifest.ts +626 -0
- package/dist/template/src/server/controllers/update-complete.ts +36 -0
- package/dist/template/src/server/lib/admin-access-tokens.ts +169 -0
- package/dist/template/src/server/lib/admin-api.ts +101 -0
- package/dist/template/src/server/lib/admin-auth.ts +208 -0
- package/dist/template/src/server/lib/admin-embedded-updates.ts +150 -0
- package/dist/template/src/server/lib/admin-updates.ts +1282 -0
- package/dist/template/src/server/lib/common.js +24 -0
- package/dist/template/src/server/lib/emergency-channel-redirects.ts +310 -0
- package/dist/template/src/server/lib/env.js +8 -0
- package/dist/template/src/server/lib/manifest-helpers.js +91 -0
- package/dist/template/src/server/lib/response.js +11 -0
- package/dist/template/src/server/lib/signing.js +55 -0
- package/dist/template/src/server/lib/supabase.js +763 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +269 -0
- package/dist/template/src/server/manifest/manifest-request.ts +21 -0
- package/dist/template/src/server/manifest/manifest-response.ts +235 -0
- package/dist/template/src/server/manifest/manifest-values.ts +62 -0
- package/dist/template/templates/expo-app/.env.ota.example +18 -0
- package/dist/template/templates/expo-app/ci_scripts/ci_post_xcodebuild.sh +6 -0
- package/dist/template/templates/expo-app/ci_scripts/register-embedded-update.sh +36 -0
- package/dist/template/templates/expo-app/plugins/with-ota-embedded-registration.js +33 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +87 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/api/storage-client.mjs +57 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/index.mjs +182 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/common.mjs +84 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/expo-export-command.mjs +24 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/retry.mjs +25 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/shared/config.mjs +48 -0
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/android-register-embedded-update.sh +18 -0
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +275 -0
- package/dist/template/tsconfig.json +36 -0
- package/dist/template/vitest.config.mts +20 -0
- package/dist/template-manifest.json +564 -0
- package/lib/cli.mjs +549 -0
- package/package.json +41 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
+
import { configureExpoApp } from "./expo-app-configurator.mjs";
|
|
7
|
+
|
|
8
|
+
const temporaryDirectories: string[] = [];
|
|
9
|
+
|
|
10
|
+
function createFixture() {
|
|
11
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ota-expo-config-"));
|
|
12
|
+
temporaryDirectories.push(root);
|
|
13
|
+
|
|
14
|
+
const appRoot = path.join(root, "app");
|
|
15
|
+
fs.mkdirSync(appRoot, { recursive: true });
|
|
16
|
+
fs.writeFileSync(
|
|
17
|
+
path.join(appRoot, "package.json"),
|
|
18
|
+
JSON.stringify(
|
|
19
|
+
{
|
|
20
|
+
name: "fixture-app",
|
|
21
|
+
private: true,
|
|
22
|
+
scripts: { start: "expo start" },
|
|
23
|
+
dependencies: { expo: "~56.0.0" },
|
|
24
|
+
},
|
|
25
|
+
null,
|
|
26
|
+
2,
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
fs.writeFileSync(path.join(appRoot, "package-lock.json"), "{}");
|
|
30
|
+
fs.writeFileSync(
|
|
31
|
+
path.join(appRoot, "app.json"),
|
|
32
|
+
JSON.stringify(
|
|
33
|
+
{
|
|
34
|
+
expo: {
|
|
35
|
+
name: "Fixture",
|
|
36
|
+
slug: "fixture",
|
|
37
|
+
extra: { existing: true },
|
|
38
|
+
updates: {
|
|
39
|
+
requestHeaders: { "x-existing": "value" },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
null,
|
|
44
|
+
2,
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const certificatePath = path.join(root, "certificate.pem");
|
|
49
|
+
execFileSync("openssl", [
|
|
50
|
+
"req",
|
|
51
|
+
"-x509",
|
|
52
|
+
"-newkey",
|
|
53
|
+
"rsa:2048",
|
|
54
|
+
"-nodes",
|
|
55
|
+
"-sha256",
|
|
56
|
+
"-days",
|
|
57
|
+
"1",
|
|
58
|
+
"-subj",
|
|
59
|
+
"/CN=fixture",
|
|
60
|
+
"-addext",
|
|
61
|
+
"basicConstraints=critical,CA:FALSE",
|
|
62
|
+
"-addext",
|
|
63
|
+
"keyUsage=critical,digitalSignature",
|
|
64
|
+
"-addext",
|
|
65
|
+
"extendedKeyUsage=codeSigning",
|
|
66
|
+
"-keyout",
|
|
67
|
+
path.join(root, "private-key.pem"),
|
|
68
|
+
"-out",
|
|
69
|
+
certificatePath,
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
return { appRoot, certificatePath };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function createRunner() {
|
|
76
|
+
const calls: Array<{
|
|
77
|
+
command: string;
|
|
78
|
+
args: string[];
|
|
79
|
+
cwd: string;
|
|
80
|
+
}> = [];
|
|
81
|
+
|
|
82
|
+
const commandRunner = (command: string, args: string[], cwd: string) => {
|
|
83
|
+
calls.push({ command, args, cwd });
|
|
84
|
+
|
|
85
|
+
if (args.join(" ") === "expo install expo-updates") {
|
|
86
|
+
const packagePath = path.join(cwd, "package.json");
|
|
87
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
|
88
|
+
packageJson.dependencies["expo-updates"] = "~56.0.0";
|
|
89
|
+
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return { calls, commandRunner };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
afterEach(() => {
|
|
97
|
+
for (const directory of temporaryDirectories.splice(0)) {
|
|
98
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("configureExpoApp", () => {
|
|
103
|
+
it("configures receiving, publishing and native prebuild", () => {
|
|
104
|
+
const { appRoot, certificatePath } = createFixture();
|
|
105
|
+
const { calls, commandRunner } = createRunner();
|
|
106
|
+
|
|
107
|
+
const result = configureExpoApp(
|
|
108
|
+
{
|
|
109
|
+
app: appRoot,
|
|
110
|
+
certificate: certificatePath,
|
|
111
|
+
serverUrl: "https://updates.example.com/",
|
|
112
|
+
channel: "Production",
|
|
113
|
+
runtimeVersion: "1.2.3",
|
|
114
|
+
platform: "all",
|
|
115
|
+
},
|
|
116
|
+
{ commandRunner },
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const appJson = JSON.parse(
|
|
120
|
+
fs.readFileSync(path.join(appRoot, "app.json"), "utf8"),
|
|
121
|
+
);
|
|
122
|
+
const packageJson = JSON.parse(
|
|
123
|
+
fs.readFileSync(path.join(appRoot, "package.json"), "utf8"),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(result).toMatchObject({
|
|
127
|
+
appRoot,
|
|
128
|
+
manifestUrl: "https://updates.example.com/api/manifest",
|
|
129
|
+
channel: "production",
|
|
130
|
+
runtimeVersion: "1.2.3",
|
|
131
|
+
platform: "all",
|
|
132
|
+
packageManager: "npm",
|
|
133
|
+
publisherEnvConfigured: false,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(appJson.expo.runtimeVersion).toBe("1.2.3");
|
|
137
|
+
expect(appJson.expo.updates).toMatchObject({
|
|
138
|
+
enabled: true,
|
|
139
|
+
url: "https://updates.example.com/api/manifest",
|
|
140
|
+
checkAutomatically: "NEVER",
|
|
141
|
+
codeSigningCertificate:
|
|
142
|
+
"./certificates/code-signing-certificate.pem",
|
|
143
|
+
requestHeaders: {
|
|
144
|
+
"x-existing": "value",
|
|
145
|
+
"expo-channel-name": "production",
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
expect(appJson.expo.extra).toEqual({
|
|
149
|
+
existing: true,
|
|
150
|
+
updateChannel: "production",
|
|
151
|
+
});
|
|
152
|
+
expect(appJson.expo.plugins).toContain(
|
|
153
|
+
"./plugins/with-ota-embedded-registration",
|
|
154
|
+
);
|
|
155
|
+
expect(packageJson.dependencies["expo-updates"]).toBe("~56.0.0");
|
|
156
|
+
expect(packageJson.scripts["ota:publish"]).toBe(
|
|
157
|
+
"node scripts/ota-publish/index.mjs",
|
|
158
|
+
);
|
|
159
|
+
expect(packageJson.scripts["ota:build:android:apk"]).toContain(
|
|
160
|
+
"scripts/ota-register-embedded/android-register-embedded-update.sh",
|
|
161
|
+
);
|
|
162
|
+
expect(
|
|
163
|
+
fs.readFileSync(
|
|
164
|
+
path.join(
|
|
165
|
+
appRoot,
|
|
166
|
+
"certificates",
|
|
167
|
+
"code-signing-certificate.pem",
|
|
168
|
+
),
|
|
169
|
+
"utf8",
|
|
170
|
+
),
|
|
171
|
+
).toContain("BEGIN CERTIFICATE");
|
|
172
|
+
expect(
|
|
173
|
+
fs.existsSync(path.join(appRoot, "scripts", "ota-publish", "index.mjs")),
|
|
174
|
+
).toBe(true);
|
|
175
|
+
expect(
|
|
176
|
+
fs.existsSync(
|
|
177
|
+
path.join(
|
|
178
|
+
appRoot,
|
|
179
|
+
"scripts",
|
|
180
|
+
"ota-publish",
|
|
181
|
+
"lib",
|
|
182
|
+
"expo-export-command.mjs",
|
|
183
|
+
),
|
|
184
|
+
),
|
|
185
|
+
).toBe(true);
|
|
186
|
+
expect(
|
|
187
|
+
fs.existsSync(
|
|
188
|
+
path.join(
|
|
189
|
+
appRoot,
|
|
190
|
+
"scripts",
|
|
191
|
+
"ota-publish",
|
|
192
|
+
"api",
|
|
193
|
+
"storage-client.mjs",
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
).toBe(true);
|
|
197
|
+
expect(
|
|
198
|
+
fs.existsSync(
|
|
199
|
+
path.join(
|
|
200
|
+
appRoot,
|
|
201
|
+
"scripts",
|
|
202
|
+
"ota-publish",
|
|
203
|
+
"api",
|
|
204
|
+
"database-client.mjs",
|
|
205
|
+
),
|
|
206
|
+
),
|
|
207
|
+
).toBe(true);
|
|
208
|
+
expect(fs.existsSync(path.join(appRoot, ".env.ota.example"))).toBe(true);
|
|
209
|
+
expect(
|
|
210
|
+
fs.existsSync(
|
|
211
|
+
path.join(
|
|
212
|
+
appRoot,
|
|
213
|
+
"scripts",
|
|
214
|
+
"ota-register-embedded",
|
|
215
|
+
"index.mjs",
|
|
216
|
+
),
|
|
217
|
+
),
|
|
218
|
+
).toBe(true);
|
|
219
|
+
expect(
|
|
220
|
+
fs.existsSync(
|
|
221
|
+
path.join(
|
|
222
|
+
appRoot,
|
|
223
|
+
"scripts",
|
|
224
|
+
"ota-register-embedded",
|
|
225
|
+
"android-register-embedded-update.sh",
|
|
226
|
+
),
|
|
227
|
+
),
|
|
228
|
+
).toBe(true);
|
|
229
|
+
expect(
|
|
230
|
+
fs.existsSync(
|
|
231
|
+
path.join(
|
|
232
|
+
appRoot,
|
|
233
|
+
"plugins",
|
|
234
|
+
"with-ota-embedded-registration.js",
|
|
235
|
+
),
|
|
236
|
+
),
|
|
237
|
+
).toBe(true);
|
|
238
|
+
expect(
|
|
239
|
+
fs.existsSync(
|
|
240
|
+
path.join(appRoot, "ci_scripts", "register-embedded-update.sh"),
|
|
241
|
+
),
|
|
242
|
+
).toBe(true);
|
|
243
|
+
expect(
|
|
244
|
+
fs.existsSync(
|
|
245
|
+
path.join(appRoot, "ci_scripts", "ci_post_xcodebuild.sh"),
|
|
246
|
+
),
|
|
247
|
+
).toBe(true);
|
|
248
|
+
expect(fs.readFileSync(path.join(appRoot, ".gitignore"), "utf8")).toBe(
|
|
249
|
+
".env.ota\n.ota-dist/\n",
|
|
250
|
+
);
|
|
251
|
+
expect(
|
|
252
|
+
fs.readFileSync(path.join(appRoot, ".env.ota.example"), "utf8"),
|
|
253
|
+
).toContain("EXPO_UPDATE_CHANNEL=production");
|
|
254
|
+
expect(calls).toEqual([
|
|
255
|
+
{
|
|
256
|
+
command: "npx",
|
|
257
|
+
args: ["expo", "install", "expo-updates"],
|
|
258
|
+
cwd: appRoot,
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
command: "npm",
|
|
262
|
+
args: [
|
|
263
|
+
"install",
|
|
264
|
+
"--save-dev",
|
|
265
|
+
"@aws-sdk/client-s3",
|
|
266
|
+
"dotenv",
|
|
267
|
+
"pg",
|
|
268
|
+
],
|
|
269
|
+
cwd: appRoot,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
command: "npx",
|
|
273
|
+
args: ["expo", "prebuild"],
|
|
274
|
+
cwd: appRoot,
|
|
275
|
+
},
|
|
276
|
+
]);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("creates publisher credentials from local Docker settings", () => {
|
|
280
|
+
const { appRoot, certificatePath } = createFixture();
|
|
281
|
+
const serverRoot = path.dirname(appRoot);
|
|
282
|
+
fs.writeFileSync(
|
|
283
|
+
path.join(serverRoot, ".env"),
|
|
284
|
+
[
|
|
285
|
+
"POSTGRES_USER=ota_user",
|
|
286
|
+
"POSTGRES_PASSWORD=db-password-with-@",
|
|
287
|
+
"POSTGRES_DB=ota_database",
|
|
288
|
+
"POSTGRES_PORT=5433",
|
|
289
|
+
"MINIO_ROOT_USER=storage_user",
|
|
290
|
+
"MINIO_ROOT_PASSWORD=storage-password",
|
|
291
|
+
"MINIO_API_PORT=9100",
|
|
292
|
+
"OTA_STORAGE_BUCKET=custom-bucket",
|
|
293
|
+
"",
|
|
294
|
+
].join("\n"),
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
const result = configureExpoApp(
|
|
298
|
+
{
|
|
299
|
+
app: appRoot,
|
|
300
|
+
certificate: certificatePath,
|
|
301
|
+
serverUrl: "https://example-3000.euw.devtunnels.ms",
|
|
302
|
+
channel: "development",
|
|
303
|
+
runtimeVersion: "1.0.0",
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
commandRunner: createRunner().commandRunner,
|
|
307
|
+
serverRoot,
|
|
308
|
+
},
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const publisherEnv = fs.readFileSync(
|
|
312
|
+
path.join(appRoot, ".env.ota"),
|
|
313
|
+
"utf8",
|
|
314
|
+
);
|
|
315
|
+
expect(result.publisherEnvConfigured).toBe(true);
|
|
316
|
+
expect(publisherEnv).toContain(
|
|
317
|
+
"OTA_SERVER_URL=https://example-3000.euw.devtunnels.ms/api/manifest",
|
|
318
|
+
);
|
|
319
|
+
expect(publisherEnv).toContain(
|
|
320
|
+
"OTA_DATABASE_URL=postgresql://ota_user:db-password-with-%40@127.0.0.1:5433/ota_database",
|
|
321
|
+
);
|
|
322
|
+
expect(publisherEnv).toContain("R2_ENDPOINT=http://127.0.0.1:9100");
|
|
323
|
+
expect(publisherEnv).toContain("R2_ACCESS_KEY_ID=storage_user");
|
|
324
|
+
expect(publisherEnv).toContain(
|
|
325
|
+
"R2_SECRET_ACCESS_KEY=storage-password",
|
|
326
|
+
);
|
|
327
|
+
expect(publisherEnv).toContain("R2_BUCKET=custom-bucket");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("stops an existing Android Gradle daemon before prebuild", () => {
|
|
331
|
+
const { appRoot, certificatePath } = createFixture();
|
|
332
|
+
const gradleWrapper = path.join(appRoot, "android", "gradlew");
|
|
333
|
+
fs.mkdirSync(path.dirname(gradleWrapper), { recursive: true });
|
|
334
|
+
fs.writeFileSync(gradleWrapper, "#!/bin/sh\n");
|
|
335
|
+
const { calls, commandRunner } = createRunner();
|
|
336
|
+
|
|
337
|
+
configureExpoApp(
|
|
338
|
+
{
|
|
339
|
+
app: appRoot,
|
|
340
|
+
certificate: certificatePath,
|
|
341
|
+
serverUrl: "https://updates.example.com",
|
|
342
|
+
channel: "production",
|
|
343
|
+
runtimeVersion: "1.0.0",
|
|
344
|
+
platform: "android",
|
|
345
|
+
},
|
|
346
|
+
{ commandRunner },
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const stopIndex = calls.findIndex(
|
|
350
|
+
(call) => call.command === gradleWrapper && call.args[0] === "--stop",
|
|
351
|
+
);
|
|
352
|
+
const prebuildIndex = calls.findIndex(
|
|
353
|
+
(call) => call.args.join(" ") === "expo prebuild --platform android",
|
|
354
|
+
);
|
|
355
|
+
expect(stopIndex).toBeGreaterThan(-1);
|
|
356
|
+
expect(prebuildIndex).toBeGreaterThan(stopIndex);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("rejects dynamic Expo config in static mode", () => {
|
|
360
|
+
const { appRoot, certificatePath } = createFixture();
|
|
361
|
+
fs.writeFileSync(path.join(appRoot, "app.config.ts"), "export default {};");
|
|
362
|
+
|
|
363
|
+
expect(() =>
|
|
364
|
+
configureExpoApp(
|
|
365
|
+
{
|
|
366
|
+
app: appRoot,
|
|
367
|
+
certificate: certificatePath,
|
|
368
|
+
serverUrl: "https://updates.example.com",
|
|
369
|
+
channel: "production",
|
|
370
|
+
runtimeVersion: "1.0.0",
|
|
371
|
+
},
|
|
372
|
+
{ commandRunner: () => undefined },
|
|
373
|
+
),
|
|
374
|
+
).toThrow("app.config.ts overrides app.json");
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("rejects a private key passed as the public certificate", () => {
|
|
378
|
+
const { appRoot, certificatePath } = createFixture();
|
|
379
|
+
fs.writeFileSync(
|
|
380
|
+
certificatePath,
|
|
381
|
+
"-----BEGIN PRIVATE KEY-----\nfixture\n-----END PRIVATE KEY-----\n",
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
expect(() =>
|
|
385
|
+
configureExpoApp(
|
|
386
|
+
{
|
|
387
|
+
app: appRoot,
|
|
388
|
+
certificate: certificatePath,
|
|
389
|
+
serverUrl: "https://updates.example.com",
|
|
390
|
+
channel: "production",
|
|
391
|
+
runtimeVersion: "1.0.0",
|
|
392
|
+
},
|
|
393
|
+
{ commandRunner: () => undefined },
|
|
394
|
+
),
|
|
395
|
+
).toThrow("public PEM certificate");
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it("rejects certificates without Expo code-signing extensions", () => {
|
|
399
|
+
const { appRoot, certificatePath } = createFixture();
|
|
400
|
+
execFileSync("openssl", [
|
|
401
|
+
"req",
|
|
402
|
+
"-x509",
|
|
403
|
+
"-newkey",
|
|
404
|
+
"rsa:2048",
|
|
405
|
+
"-nodes",
|
|
406
|
+
"-sha256",
|
|
407
|
+
"-days",
|
|
408
|
+
"1",
|
|
409
|
+
"-subj",
|
|
410
|
+
"/CN=invalid-fixture",
|
|
411
|
+
"-keyout",
|
|
412
|
+
path.join(path.dirname(certificatePath), "invalid-private-key.pem"),
|
|
413
|
+
"-out",
|
|
414
|
+
certificatePath,
|
|
415
|
+
]);
|
|
416
|
+
|
|
417
|
+
expect(() =>
|
|
418
|
+
configureExpoApp(
|
|
419
|
+
{
|
|
420
|
+
app: appRoot,
|
|
421
|
+
certificate: certificatePath,
|
|
422
|
+
serverUrl: "https://updates.example.com",
|
|
423
|
+
channel: "production",
|
|
424
|
+
runtimeVersion: "1.0.0",
|
|
425
|
+
},
|
|
426
|
+
{ commandRunner: () => undefined },
|
|
427
|
+
),
|
|
428
|
+
).toThrow("Extended Key Usage: Code Signing");
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("does not overwrite generated publisher files without force", () => {
|
|
432
|
+
const { appRoot, certificatePath } = createFixture();
|
|
433
|
+
const originalAppJson = fs.readFileSync(
|
|
434
|
+
path.join(appRoot, "app.json"),
|
|
435
|
+
"utf8",
|
|
436
|
+
);
|
|
437
|
+
const publisherPath = path.join(
|
|
438
|
+
appRoot,
|
|
439
|
+
"scripts",
|
|
440
|
+
"ota-publish",
|
|
441
|
+
"index.mjs",
|
|
442
|
+
);
|
|
443
|
+
fs.mkdirSync(path.dirname(publisherPath), { recursive: true });
|
|
444
|
+
fs.writeFileSync(publisherPath, "custom publisher");
|
|
445
|
+
|
|
446
|
+
expect(() =>
|
|
447
|
+
configureExpoApp(
|
|
448
|
+
{
|
|
449
|
+
app: appRoot,
|
|
450
|
+
certificate: certificatePath,
|
|
451
|
+
serverUrl: "https://updates.example.com",
|
|
452
|
+
channel: "production",
|
|
453
|
+
runtimeVersion: "1.0.0",
|
|
454
|
+
},
|
|
455
|
+
{ commandRunner: () => undefined },
|
|
456
|
+
),
|
|
457
|
+
).toThrow("Re-run with --force");
|
|
458
|
+
|
|
459
|
+
expect(fs.readFileSync(path.join(appRoot, "app.json"), "utf8")).toBe(
|
|
460
|
+
originalAppJson,
|
|
461
|
+
);
|
|
462
|
+
});
|
|
463
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
const TEXT = {
|
|
5
|
+
ru: {
|
|
6
|
+
app: "Путь к корню Expo-приложения",
|
|
7
|
+
certificate: "Путь к public certificate",
|
|
8
|
+
serverUrl: "URL OTA-сервера",
|
|
9
|
+
channel: "Channel",
|
|
10
|
+
runtimeVersion: "Runtime version",
|
|
11
|
+
platform: "Платформа: all, ios или android",
|
|
12
|
+
force: "Перезаписывать ранее созданные CLI-файлы? [y/N]",
|
|
13
|
+
confirm: "Продолжить настройку и запустить expo prebuild? [y/N]",
|
|
14
|
+
cancelled: "Настройка отменена.",
|
|
15
|
+
summary: "Будут применены настройки:",
|
|
16
|
+
},
|
|
17
|
+
en: {
|
|
18
|
+
app: "Expo application root path",
|
|
19
|
+
certificate: "Public certificate path",
|
|
20
|
+
serverUrl: "OTA server URL",
|
|
21
|
+
channel: "Channel",
|
|
22
|
+
runtimeVersion: "Runtime version",
|
|
23
|
+
platform: "Platform: all, ios or android",
|
|
24
|
+
force: "Overwrite files previously generated by the CLI? [y/N]",
|
|
25
|
+
confirm: "Continue and run expo prebuild? [y/N]",
|
|
26
|
+
cancelled: "Configuration cancelled.",
|
|
27
|
+
summary: "The following configuration will be applied:",
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function readAppDefaults(appRoot) {
|
|
32
|
+
try {
|
|
33
|
+
const appJson = JSON.parse(
|
|
34
|
+
fs.readFileSync(path.join(appRoot, "app.json"), "utf8"),
|
|
35
|
+
);
|
|
36
|
+
return {
|
|
37
|
+
channel:
|
|
38
|
+
appJson.expo?.updates?.requestHeaders?.["expo-channel-name"] ||
|
|
39
|
+
appJson.expo?.extra?.updateChannel ||
|
|
40
|
+
"development",
|
|
41
|
+
runtimeVersion:
|
|
42
|
+
typeof appJson.expo?.runtimeVersion === "string"
|
|
43
|
+
? appJson.expo.runtimeVersion
|
|
44
|
+
: "",
|
|
45
|
+
serverUrl: appJson.expo?.updates?.url || "http://localhost:3000",
|
|
46
|
+
};
|
|
47
|
+
} catch {
|
|
48
|
+
return {
|
|
49
|
+
channel: "development",
|
|
50
|
+
runtimeVersion: "",
|
|
51
|
+
serverUrl: "http://localhost:3000",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function askWithDefault(ask, question, defaultValue = "") {
|
|
57
|
+
const suffix = defaultValue ? ` (${defaultValue})` : "";
|
|
58
|
+
const answer = (await ask(`${question}${suffix}: `)).trim();
|
|
59
|
+
return answer || defaultValue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isYes(value) {
|
|
63
|
+
return ["y", "yes", "д", "да"].includes(value.trim().toLowerCase());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function collectInteractiveOptions(
|
|
67
|
+
initialOptions,
|
|
68
|
+
{
|
|
69
|
+
ask,
|
|
70
|
+
serverRoot = process.cwd(),
|
|
71
|
+
log = console.log,
|
|
72
|
+
},
|
|
73
|
+
) {
|
|
74
|
+
const languageAnswer = await askWithDefault(
|
|
75
|
+
ask,
|
|
76
|
+
"Язык / Language [ru/en]",
|
|
77
|
+
"ru",
|
|
78
|
+
);
|
|
79
|
+
const language = languageAnswer.toLowerCase() === "en" ? "en" : "ru";
|
|
80
|
+
const text = TEXT[language];
|
|
81
|
+
const options = { ...initialOptions };
|
|
82
|
+
|
|
83
|
+
options.app = await askWithDefault(ask, text.app, options.app || "");
|
|
84
|
+
const appRoot = path.resolve(options.app);
|
|
85
|
+
const appDefaults = readAppDefaults(appRoot);
|
|
86
|
+
|
|
87
|
+
options.certificate = await askWithDefault(
|
|
88
|
+
ask,
|
|
89
|
+
text.certificate,
|
|
90
|
+
options.certificate ||
|
|
91
|
+
path.join(
|
|
92
|
+
serverRoot,
|
|
93
|
+
"local-certificates",
|
|
94
|
+
"code-signing-certificate.pem",
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
options.serverUrl = await askWithDefault(
|
|
98
|
+
ask,
|
|
99
|
+
text.serverUrl,
|
|
100
|
+
options.serverUrl || appDefaults.serverUrl,
|
|
101
|
+
);
|
|
102
|
+
options.channel = await askWithDefault(
|
|
103
|
+
ask,
|
|
104
|
+
text.channel,
|
|
105
|
+
options.channel || appDefaults.channel,
|
|
106
|
+
);
|
|
107
|
+
options.runtimeVersion = await askWithDefault(
|
|
108
|
+
ask,
|
|
109
|
+
text.runtimeVersion,
|
|
110
|
+
options.runtimeVersion || appDefaults.runtimeVersion,
|
|
111
|
+
);
|
|
112
|
+
options.platform = await askWithDefault(
|
|
113
|
+
ask,
|
|
114
|
+
text.platform,
|
|
115
|
+
options.platform || "all",
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (options.force !== true) {
|
|
119
|
+
options.force = isYes(await ask(`${text.force}: `));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
log("");
|
|
123
|
+
log(text.summary);
|
|
124
|
+
log(` app: ${path.resolve(options.app)}`);
|
|
125
|
+
log(` certificate: ${path.resolve(options.certificate)}`);
|
|
126
|
+
log(` server: ${options.serverUrl}`);
|
|
127
|
+
log(` channel: ${options.channel}`);
|
|
128
|
+
log(` runtime: ${options.runtimeVersion}`);
|
|
129
|
+
log(` platform: ${options.platform}`);
|
|
130
|
+
log(` overwrite: ${options.force ? "yes" : "no"}`);
|
|
131
|
+
log("");
|
|
132
|
+
|
|
133
|
+
const confirmed = isYes(await ask(`${text.confirm}: `));
|
|
134
|
+
if (!confirmed) {
|
|
135
|
+
throw new Error(text.cancelled);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return options;
|
|
139
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { collectInteractiveOptions } from "./expo-app-prompts.mjs";
|
|
6
|
+
|
|
7
|
+
const temporaryDirectories: string[] = [];
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
for (const directory of temporaryDirectories.splice(0)) {
|
|
11
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("collectInteractiveOptions", () => {
|
|
16
|
+
it("uses application defaults and confirms the configuration", async () => {
|
|
17
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ota-prompts-"));
|
|
18
|
+
temporaryDirectories.push(root);
|
|
19
|
+
const appRoot = path.join(root, "app");
|
|
20
|
+
fs.mkdirSync(appRoot);
|
|
21
|
+
fs.writeFileSync(
|
|
22
|
+
path.join(appRoot, "app.json"),
|
|
23
|
+
JSON.stringify({
|
|
24
|
+
expo: {
|
|
25
|
+
runtimeVersion: "1.1.20",
|
|
26
|
+
updates: {
|
|
27
|
+
url: "http://localhost:3000/api/manifest",
|
|
28
|
+
requestHeaders: {
|
|
29
|
+
"expo-channel-name": "development",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const answers = [
|
|
37
|
+
"ru",
|
|
38
|
+
appRoot,
|
|
39
|
+
"",
|
|
40
|
+
"",
|
|
41
|
+
"",
|
|
42
|
+
"",
|
|
43
|
+
"",
|
|
44
|
+
"n",
|
|
45
|
+
"да",
|
|
46
|
+
];
|
|
47
|
+
const logs: string[] = [];
|
|
48
|
+
|
|
49
|
+
const result = await collectInteractiveOptions(
|
|
50
|
+
{},
|
|
51
|
+
{
|
|
52
|
+
ask: async () => answers.shift() || "",
|
|
53
|
+
serverRoot: root,
|
|
54
|
+
log: (value) => logs.push(value),
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(result).toEqual({
|
|
59
|
+
app: appRoot,
|
|
60
|
+
certificate: path.join(
|
|
61
|
+
root,
|
|
62
|
+
"local-certificates",
|
|
63
|
+
"code-signing-certificate.pem",
|
|
64
|
+
),
|
|
65
|
+
serverUrl: "http://localhost:3000/api/manifest",
|
|
66
|
+
channel: "development",
|
|
67
|
+
runtimeVersion: "1.1.20",
|
|
68
|
+
platform: "all",
|
|
69
|
+
force: false,
|
|
70
|
+
});
|
|
71
|
+
expect(logs.join("\n")).toContain("Будут применены настройки");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("cancels unless the user explicitly confirms", async () => {
|
|
75
|
+
const answers = [
|
|
76
|
+
"en",
|
|
77
|
+
"/tmp/app",
|
|
78
|
+
"/tmp/certificate.pem",
|
|
79
|
+
"https://updates.example.com",
|
|
80
|
+
"production",
|
|
81
|
+
"1.0.0",
|
|
82
|
+
"android",
|
|
83
|
+
"n",
|
|
84
|
+
"n",
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
await expect(
|
|
88
|
+
collectInteractiveOptions(
|
|
89
|
+
{},
|
|
90
|
+
{
|
|
91
|
+
ask: async () => answers.shift() || "",
|
|
92
|
+
log: () => undefined,
|
|
93
|
+
},
|
|
94
|
+
),
|
|
95
|
+
).rejects.toThrow("Configuration cancelled");
|
|
96
|
+
});
|
|
97
|
+
});
|