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,87 @@
|
|
|
1
|
+
import pg from "pg";
|
|
2
|
+
import { withRetry } from "../lib/retry.mjs";
|
|
3
|
+
import { requiredEnv } from "../shared/config.mjs";
|
|
4
|
+
|
|
5
|
+
export function createDatabasePool() {
|
|
6
|
+
const sslValue = (process.env.OTA_DATABASE_SSL || "true").toLowerCase();
|
|
7
|
+
return new pg.Pool({
|
|
8
|
+
connectionString: requiredEnv("OTA_DATABASE_URL"),
|
|
9
|
+
ssl: ["false", "0"].includes(sslValue)
|
|
10
|
+
? false
|
|
11
|
+
: { rejectUnauthorized: false },
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function writeDatabaseRecords(pool, update, latest) {
|
|
16
|
+
await withRetry(`Database publish ${update.id}`, async () => {
|
|
17
|
+
const client = await pool.connect();
|
|
18
|
+
try {
|
|
19
|
+
await client.query("BEGIN");
|
|
20
|
+
await client.query(
|
|
21
|
+
`INSERT INTO ota_updates (
|
|
22
|
+
id, update_id, build_id, runtime_version, channel, platform,
|
|
23
|
+
created_at, created_at_path, storage_bucket, storage_base_path,
|
|
24
|
+
is_active, disabled_at, assets_count, launch_asset_path, comment,
|
|
25
|
+
manifest
|
|
26
|
+
) VALUES (
|
|
27
|
+
$1, $1, $1, $2, $3, $4,
|
|
28
|
+
$5, $6, $7, $8,
|
|
29
|
+
false, $5, $9, $10, $11,
|
|
30
|
+
$12::jsonb
|
|
31
|
+
)
|
|
32
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
33
|
+
runtime_version = EXCLUDED.runtime_version,
|
|
34
|
+
channel = EXCLUDED.channel,
|
|
35
|
+
platform = EXCLUDED.platform,
|
|
36
|
+
created_at = EXCLUDED.created_at,
|
|
37
|
+
created_at_path = EXCLUDED.created_at_path,
|
|
38
|
+
storage_bucket = EXCLUDED.storage_bucket,
|
|
39
|
+
storage_base_path = EXCLUDED.storage_base_path,
|
|
40
|
+
is_active = false,
|
|
41
|
+
disabled_at = EXCLUDED.disabled_at,
|
|
42
|
+
assets_count = EXCLUDED.assets_count,
|
|
43
|
+
launch_asset_path = EXCLUDED.launch_asset_path,
|
|
44
|
+
comment = EXCLUDED.comment,
|
|
45
|
+
manifest = EXCLUDED.manifest`,
|
|
46
|
+
[
|
|
47
|
+
update.id,
|
|
48
|
+
update.runtimeVersion,
|
|
49
|
+
update.channel,
|
|
50
|
+
update.platform,
|
|
51
|
+
update.createdAt,
|
|
52
|
+
update.createdAtPath,
|
|
53
|
+
update.storageBucket,
|
|
54
|
+
update.storageBasePath,
|
|
55
|
+
update.assets.length,
|
|
56
|
+
update.launchAsset.path,
|
|
57
|
+
update.comment,
|
|
58
|
+
JSON.stringify(update),
|
|
59
|
+
],
|
|
60
|
+
);
|
|
61
|
+
await client.query(
|
|
62
|
+
`INSERT INTO ota_update_channels (
|
|
63
|
+
runtime_version, channel, platform,
|
|
64
|
+
latest_update_id, latest_created_at, latest_created_at_path
|
|
65
|
+
) VALUES ($1, $2, $3, $4, $5, $6)
|
|
66
|
+
ON CONFLICT (runtime_version, channel, platform) DO UPDATE SET
|
|
67
|
+
latest_update_id = EXCLUDED.latest_update_id,
|
|
68
|
+
latest_created_at = EXCLUDED.latest_created_at,
|
|
69
|
+
latest_created_at_path = EXCLUDED.latest_created_at_path`,
|
|
70
|
+
[
|
|
71
|
+
latest.runtimeVersion,
|
|
72
|
+
latest.channel,
|
|
73
|
+
latest.platform,
|
|
74
|
+
latest.updateId,
|
|
75
|
+
latest.createdAt,
|
|
76
|
+
latest.createdAtPath,
|
|
77
|
+
],
|
|
78
|
+
);
|
|
79
|
+
await client.query("COMMIT");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
await client.query("ROLLBACK");
|
|
82
|
+
throw error;
|
|
83
|
+
} finally {
|
|
84
|
+
client.release();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { contentType, listFiles } from "../lib/common.mjs";
|
|
5
|
+
import { withRetry } from "../lib/retry.mjs";
|
|
6
|
+
import { requiredEnv } from "../shared/config.mjs";
|
|
7
|
+
|
|
8
|
+
export function createStorageClient() {
|
|
9
|
+
return new S3Client({
|
|
10
|
+
region: process.env.R2_REGION || "auto",
|
|
11
|
+
endpoint: requiredEnv("R2_ENDPOINT"),
|
|
12
|
+
forcePathStyle: ["true", "1"].includes(
|
|
13
|
+
(process.env.S3_FORCE_PATH_STYLE || "false").toLowerCase(),
|
|
14
|
+
),
|
|
15
|
+
credentials: {
|
|
16
|
+
accessKeyId: requiredEnv("R2_ACCESS_KEY_ID"),
|
|
17
|
+
secretAccessKey: requiredEnv("R2_SECRET_ACCESS_KEY"),
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function uploadObject(storage, input) {
|
|
23
|
+
await withRetry(`Upload ${input.key}`, () =>
|
|
24
|
+
storage.send(
|
|
25
|
+
new PutObjectCommand({
|
|
26
|
+
Bucket: input.bucket,
|
|
27
|
+
Key: input.key,
|
|
28
|
+
Body: input.body,
|
|
29
|
+
ContentType: input.contentType,
|
|
30
|
+
}),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function uploadDirectory(
|
|
36
|
+
storage,
|
|
37
|
+
bucket,
|
|
38
|
+
outputDir,
|
|
39
|
+
basePath,
|
|
40
|
+
) {
|
|
41
|
+
const files = await listFiles(outputDir);
|
|
42
|
+
for (const filePath of files) {
|
|
43
|
+
const relativePath = path
|
|
44
|
+
.relative(outputDir, filePath)
|
|
45
|
+
.split(path.sep)
|
|
46
|
+
.join("/");
|
|
47
|
+
if (relativePath === "update-meta.json") {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
await uploadObject(storage, {
|
|
51
|
+
bucket,
|
|
52
|
+
key: `${basePath}/${relativePath}`,
|
|
53
|
+
body: await fs.promises.readFile(filePath),
|
|
54
|
+
contentType: contentType(relativePath, false),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import dotenv from "dotenv";
|
|
6
|
+
import {
|
|
7
|
+
createDatabasePool,
|
|
8
|
+
writeDatabaseRecords,
|
|
9
|
+
} from "./api/database-client.mjs";
|
|
10
|
+
import {
|
|
11
|
+
createStorageClient,
|
|
12
|
+
uploadDirectory,
|
|
13
|
+
uploadObject,
|
|
14
|
+
} from "./api/storage-client.mjs";
|
|
15
|
+
import {
|
|
16
|
+
assetMetadata,
|
|
17
|
+
datePath,
|
|
18
|
+
} from "./lib/common.mjs";
|
|
19
|
+
import { getExpoExportCommand } from "./lib/expo-export-command.mjs";
|
|
20
|
+
import { loadPublishConfig } from "./shared/config.mjs";
|
|
21
|
+
|
|
22
|
+
dotenv.config({ path: ".env.ota" });
|
|
23
|
+
|
|
24
|
+
function parseArgs(argv) {
|
|
25
|
+
const options = { platform: "all", message: "" };
|
|
26
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
27
|
+
const argument = argv[index];
|
|
28
|
+
if (argument === "--platform" || argument === "--message") {
|
|
29
|
+
const value = argv[index + 1];
|
|
30
|
+
if (!value || value.startsWith("--")) {
|
|
31
|
+
throw new Error(`Missing value for ${argument}`);
|
|
32
|
+
}
|
|
33
|
+
options[argument.slice(2)] = value.trim();
|
|
34
|
+
index += 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Unknown argument: ${argument}`);
|
|
38
|
+
}
|
|
39
|
+
if (!["all", "ios", "android"].includes(options.platform)) {
|
|
40
|
+
throw new Error("--platform must be all, ios or android.");
|
|
41
|
+
}
|
|
42
|
+
if (!options.message) {
|
|
43
|
+
throw new Error("--message is required.");
|
|
44
|
+
}
|
|
45
|
+
return options;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function publishPlatform({
|
|
49
|
+
appJson,
|
|
50
|
+
bucket,
|
|
51
|
+
channel,
|
|
52
|
+
message,
|
|
53
|
+
platform,
|
|
54
|
+
pool,
|
|
55
|
+
runtimeVersion,
|
|
56
|
+
storage,
|
|
57
|
+
}) {
|
|
58
|
+
const outputDir = path.resolve(".ota-dist", platform);
|
|
59
|
+
fs.rmSync(outputDir, { recursive: true, force: true });
|
|
60
|
+
const exportCommand = getExpoExportCommand({ outputDir, platform });
|
|
61
|
+
execFileSync(exportCommand.command, exportCommand.args, {
|
|
62
|
+
stdio: "inherit",
|
|
63
|
+
env: process.env,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const metadataPath = path.join(outputDir, "metadata.json");
|
|
67
|
+
const metadata = JSON.parse(fs.readFileSync(metadataPath, "utf8"));
|
|
68
|
+
const platformMetadata = metadata.fileMetadata?.[platform];
|
|
69
|
+
if (!platformMetadata?.bundle) {
|
|
70
|
+
throw new Error(`Expo metadata is missing the ${platform} bundle.`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const createdAt = new Date().toISOString();
|
|
74
|
+
const createdAtPath = datePath(createdAt);
|
|
75
|
+
const updateId = crypto.randomUUID();
|
|
76
|
+
Object.assign(metadata, {
|
|
77
|
+
runtimeVersion,
|
|
78
|
+
createdAt,
|
|
79
|
+
createdAtPath,
|
|
80
|
+
updateId,
|
|
81
|
+
});
|
|
82
|
+
fs.writeFileSync(metadataPath, `${JSON.stringify(metadata, null, 2)}\n`);
|
|
83
|
+
|
|
84
|
+
const assets = await Promise.all(
|
|
85
|
+
(platformMetadata.assets || []).map((asset) =>
|
|
86
|
+
assetMetadata(outputDir, asset.path, false, asset.ext),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
const launchAsset = await assetMetadata(
|
|
90
|
+
outputDir,
|
|
91
|
+
platformMetadata.bundle,
|
|
92
|
+
true,
|
|
93
|
+
);
|
|
94
|
+
const basePath = `${runtimeVersion}/${platform}/${createdAtPath}/${channel}/${updateId}`;
|
|
95
|
+
const update = {
|
|
96
|
+
id: updateId,
|
|
97
|
+
runtimeVersion,
|
|
98
|
+
channel,
|
|
99
|
+
comment: message,
|
|
100
|
+
createdAt,
|
|
101
|
+
createdAtPath,
|
|
102
|
+
buildId: updateId,
|
|
103
|
+
platform,
|
|
104
|
+
assets,
|
|
105
|
+
launchAsset,
|
|
106
|
+
storageBucket: bucket,
|
|
107
|
+
storageBasePath: basePath,
|
|
108
|
+
expoClient: {
|
|
109
|
+
...(appJson.expo || {}),
|
|
110
|
+
updates: undefined,
|
|
111
|
+
hooks: undefined,
|
|
112
|
+
plugins: undefined,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
const latest = {
|
|
116
|
+
id: updateId,
|
|
117
|
+
updateId,
|
|
118
|
+
buildId: updateId,
|
|
119
|
+
runtimeVersion,
|
|
120
|
+
channel,
|
|
121
|
+
comment: message,
|
|
122
|
+
platform,
|
|
123
|
+
createdAt,
|
|
124
|
+
createdAtPath,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
fs.writeFileSync(
|
|
128
|
+
path.join(outputDir, "update-info.json"),
|
|
129
|
+
`${JSON.stringify(update, null, 2)}\n`,
|
|
130
|
+
);
|
|
131
|
+
fs.writeFileSync(
|
|
132
|
+
path.join(outputDir, "update-meta.json"),
|
|
133
|
+
`${JSON.stringify(
|
|
134
|
+
{ isActive: false, updatedAt: null, disabledAt: createdAt },
|
|
135
|
+
null,
|
|
136
|
+
2,
|
|
137
|
+
)}\n`,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
await uploadDirectory(storage, bucket, outputDir, basePath);
|
|
141
|
+
const latestBody = JSON.stringify(latest, null, 2);
|
|
142
|
+
await uploadObject(storage, {
|
|
143
|
+
bucket,
|
|
144
|
+
key: `${runtimeVersion}/${platform}/channels/${channel}/latest.json`,
|
|
145
|
+
body: latestBody,
|
|
146
|
+
contentType: "application/json",
|
|
147
|
+
});
|
|
148
|
+
await uploadObject(storage, {
|
|
149
|
+
bucket,
|
|
150
|
+
key: `${runtimeVersion}/${platform}/latest.json`,
|
|
151
|
+
body: latestBody,
|
|
152
|
+
contentType: "application/json",
|
|
153
|
+
});
|
|
154
|
+
await writeDatabaseRecords(pool, update, latest);
|
|
155
|
+
|
|
156
|
+
console.log(
|
|
157
|
+
`Published inactive ${platform} update ${updateId} for ${channel}/${runtimeVersion}.`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const options = parseArgs(process.argv.slice(2));
|
|
162
|
+
const config = loadPublishConfig();
|
|
163
|
+
const platforms =
|
|
164
|
+
options.platform === "all" ? ["android", "ios"] : [options.platform];
|
|
165
|
+
const storage = createStorageClient();
|
|
166
|
+
const pool = createDatabasePool();
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
for (const platform of platforms) {
|
|
170
|
+
await publishPlatform({
|
|
171
|
+
...config,
|
|
172
|
+
message: options.message,
|
|
173
|
+
platform,
|
|
174
|
+
pool,
|
|
175
|
+
storage,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
} finally {
|
|
179
|
+
await pool.end();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
console.log("Publish completed. Activate the update in the admin panel.");
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
const CONTENT_TYPES = {
|
|
6
|
+
bundle: "application/javascript",
|
|
7
|
+
hbc: "application/octet-stream",
|
|
8
|
+
js: "application/javascript",
|
|
9
|
+
jpeg: "image/jpeg",
|
|
10
|
+
jpg: "image/jpeg",
|
|
11
|
+
json: "application/json",
|
|
12
|
+
otf: "font/otf",
|
|
13
|
+
png: "image/png",
|
|
14
|
+
svg: "image/svg+xml",
|
|
15
|
+
ttf: "font/ttf",
|
|
16
|
+
webp: "image/webp",
|
|
17
|
+
woff: "font/woff",
|
|
18
|
+
woff2: "font/woff2",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function normalizeExtension(filePath, explicitExtension) {
|
|
22
|
+
return String(explicitExtension || path.extname(filePath))
|
|
23
|
+
.replace(/^\./, "")
|
|
24
|
+
.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function contentType(filePath, isLaunchAsset, explicitExtension) {
|
|
28
|
+
if (isLaunchAsset) {
|
|
29
|
+
return "application/javascript";
|
|
30
|
+
}
|
|
31
|
+
const extension = normalizeExtension(filePath, explicitExtension);
|
|
32
|
+
return CONTENT_TYPES[extension] || "application/octet-stream";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function base64Url(value) {
|
|
36
|
+
return value.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function datePath(iso) {
|
|
40
|
+
const date = new Date(iso);
|
|
41
|
+
if (Number.isNaN(date.getTime())) {
|
|
42
|
+
throw new Error(`Invalid createdAt value: ${iso}`);
|
|
43
|
+
}
|
|
44
|
+
const day = String(date.getUTCDate()).padStart(2, "0");
|
|
45
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
46
|
+
return `${day}.${month}.${date.getUTCFullYear()}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function assetMetadata(
|
|
50
|
+
outputDir,
|
|
51
|
+
filePath,
|
|
52
|
+
isLaunchAsset,
|
|
53
|
+
extension,
|
|
54
|
+
) {
|
|
55
|
+
const content = await fs.promises.readFile(path.join(outputDir, filePath));
|
|
56
|
+
const normalizedExtension = normalizeExtension(filePath, extension);
|
|
57
|
+
return {
|
|
58
|
+
path: filePath.split(path.sep).join("/"),
|
|
59
|
+
hash: base64Url(
|
|
60
|
+
crypto.createHash("sha256").update(content).digest("base64"),
|
|
61
|
+
),
|
|
62
|
+
key: crypto.createHash("md5").update(content).digest("hex"),
|
|
63
|
+
contentType: contentType(filePath, isLaunchAsset, extension),
|
|
64
|
+
isLaunchAsset,
|
|
65
|
+
...(isLaunchAsset
|
|
66
|
+
? { fileExtension: ".bundle" }
|
|
67
|
+
: normalizedExtension
|
|
68
|
+
? { fileExtension: `.${normalizedExtension}` }
|
|
69
|
+
: {}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function listFiles(directory) {
|
|
74
|
+
const entries = await fs.promises.readdir(directory, {
|
|
75
|
+
withFileTypes: true,
|
|
76
|
+
});
|
|
77
|
+
const nested = await Promise.all(
|
|
78
|
+
entries.map(async (entry) => {
|
|
79
|
+
const fullPath = path.join(directory, entry.name);
|
|
80
|
+
return entry.isDirectory() ? listFiles(fullPath) : [fullPath];
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
return nested.flat();
|
|
84
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
export function getExpoExportCommand({
|
|
4
|
+
appRoot = process.cwd(),
|
|
5
|
+
outputDir,
|
|
6
|
+
platform,
|
|
7
|
+
}) {
|
|
8
|
+
return {
|
|
9
|
+
command: path.join(
|
|
10
|
+
appRoot,
|
|
11
|
+
"node_modules",
|
|
12
|
+
".bin",
|
|
13
|
+
process.platform === "win32" ? "expo.cmd" : "expo",
|
|
14
|
+
),
|
|
15
|
+
args: [
|
|
16
|
+
"export",
|
|
17
|
+
"--clear",
|
|
18
|
+
"--platform",
|
|
19
|
+
platform,
|
|
20
|
+
"--output-dir",
|
|
21
|
+
outputDir,
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export async function withRetry(label, task, options = {}) {
|
|
2
|
+
const attempts = options.attempts || 3;
|
|
3
|
+
const baseDelayMs = options.baseDelayMs || 500;
|
|
4
|
+
let lastError;
|
|
5
|
+
|
|
6
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
7
|
+
try {
|
|
8
|
+
return await task();
|
|
9
|
+
} catch (error) {
|
|
10
|
+
lastError = error;
|
|
11
|
+
if (attempt < attempts) {
|
|
12
|
+
await new Promise((resolve) =>
|
|
13
|
+
setTimeout(resolve, baseDelayMs * attempt),
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
throw new Error(
|
|
20
|
+
`${label} failed after ${attempts} attempts: ${
|
|
21
|
+
lastError instanceof Error ? lastError.message : String(lastError)
|
|
22
|
+
}`,
|
|
23
|
+
{ cause: lastError },
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
|
|
3
|
+
export function requiredEnv(name) {
|
|
4
|
+
const value = process.env[name]?.trim();
|
|
5
|
+
if (!value) {
|
|
6
|
+
throw new Error(`Missing ${name} in .env.ota`);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function loadPublishConfig() {
|
|
12
|
+
const appJson = JSON.parse(fs.readFileSync("app.json", "utf8"));
|
|
13
|
+
const configuredChannel =
|
|
14
|
+
appJson.expo?.updates?.requestHeaders?.["expo-channel-name"];
|
|
15
|
+
const channel = (
|
|
16
|
+
process.env.EXPO_UPDATE_CHANNEL ||
|
|
17
|
+
configuredChannel ||
|
|
18
|
+
""
|
|
19
|
+
)
|
|
20
|
+
.trim()
|
|
21
|
+
.toLowerCase();
|
|
22
|
+
|
|
23
|
+
if (!channel) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"Set EXPO_UPDATE_CHANNEL in .env.ota or configure expo-channel-name in app.json.",
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (configuredChannel && configuredChannel !== channel) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Channel mismatch: app.json=${configuredChannel}, .env.ota=${channel}`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const runtimeVersion =
|
|
35
|
+
appJson.expo.runtimeVersion?.policy === "appVersion"
|
|
36
|
+
? appJson.expo.version
|
|
37
|
+
: appJson.expo.runtimeVersion;
|
|
38
|
+
if (typeof runtimeVersion !== "string" || !runtimeVersion.trim()) {
|
|
39
|
+
throw new Error("app.json must contain a string runtimeVersion.");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
appJson,
|
|
44
|
+
channel,
|
|
45
|
+
runtimeVersion: runtimeVersion.trim(),
|
|
46
|
+
bucket: requiredEnv("R2_BUCKET"),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
set -eu
|
|
4
|
+
|
|
5
|
+
PROJECT_ROOT="$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)"
|
|
6
|
+
MANIFEST_PATH="$(find "$PROJECT_ROOT/android/app/build" -type f -name app.manifest 2>/dev/null | head -n 1 || true)"
|
|
7
|
+
|
|
8
|
+
if [ -z "$MANIFEST_PATH" ]; then
|
|
9
|
+
echo "Embedded update registration failed: Android app.manifest was not found." >&2
|
|
10
|
+
[ "${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ] && exit 1
|
|
11
|
+
exit 0
|
|
12
|
+
fi
|
|
13
|
+
|
|
14
|
+
if ! node "$PROJECT_ROOT/scripts/ota-register-embedded/index.mjs" \
|
|
15
|
+
--manifest "$MANIFEST_PATH" \
|
|
16
|
+
--platform android; then
|
|
17
|
+
[ "${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ] && exit 1
|
|
18
|
+
fi
|