molt-ota 0.0.0-stage → 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 +37 -2
- package/dist/args.js +42 -0
- package/dist/cli.js +4 -0
- package/dist/commands/approve.js +38 -0
- package/dist/commands/publish.js +218 -0
- package/dist/commands/releases.js +59 -0
- package/dist/commands/rollback.js +51 -0
- package/dist/config.js +64 -0
- package/dist/errors.js +23 -0
- package/dist/expo.js +64 -0
- package/dist/format.js +43 -0
- package/dist/git.js +30 -0
- package/dist/http.js +215 -0
- package/dist/io.js +8 -0
- package/dist/main.js +66 -0
- package/dist/release.js +36 -0
- package/dist/version.js +4 -0
- package/dist/zip.js +174 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dennis van den Brock
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# molt-ota
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command-line client for [Molt](https://github.com/Shweit/molt), the self-hosted Expo Updates server. Publish an update from your Expo project, roll it out gradually and roll it back, from your terminal or CI.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
export MOLT_URL=https://ota.example.com MOLT_APP=example-app MOLT_ENV=production
|
|
7
|
+
export MOLT_TOKEN=... # read from a secret in CI
|
|
8
|
+
|
|
9
|
+
npx molt-ota publish
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`publish` exports iOS and Android with your project's own Expo CLI, zips the export, uploads it and makes it live. It needs Node.js 22 or later.
|
|
13
|
+
|
|
14
|
+
## Commands
|
|
15
|
+
|
|
16
|
+
| Command | What it does |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `molt-ota publish` | Export, upload and publish. `--draft` only uploads, `--rollout 10` starts at 10%. |
|
|
19
|
+
| `molt-ota releases list` | List releases with the status of each platform. |
|
|
20
|
+
| `molt-ota releases show <id>` | Show one release. |
|
|
21
|
+
| `molt-ota approve <id> --rollout 50` | Activate a draft or widen a rollout. |
|
|
22
|
+
| `molt-ota rollback --runtime-version 1.0.0 --platform ios --release <id>` | Serve an earlier release again. Use `--embedded` to go back to the update in the app. |
|
|
23
|
+
|
|
24
|
+
Add `--json` to any command for machine-readable output. Run `molt-ota <command> --help` for all options.
|
|
25
|
+
|
|
26
|
+
## Good to know
|
|
27
|
+
|
|
28
|
+
- The token is read only from `MOLT_TOKEN`. There is no flag for it, so it stays out of your shell history.
|
|
29
|
+
- It refuses to send the token over plain `http://`, except to localhost.
|
|
30
|
+
- The runtime version comes from `runtimeVersion` in your app config when that is a plain string. Otherwise pass `--runtime-version`.
|
|
31
|
+
- A token that may only upload can publish drafts with `--draft`. A second credential approves them.
|
|
32
|
+
- Retried uploads carry an idempotency key, so a flaky network never creates a second release.
|
|
33
|
+
|
|
34
|
+
See the [CLI reference](https://github.com/Shweit/molt/blob/master/docs/cli.md) for every option, permissions, JSON output, exit codes and a GitHub Actions example.
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { UsageError } from "./errors.js";
|
|
2
|
+
/** Options every command that talks to a server accepts. */
|
|
3
|
+
export const globalOptions = {
|
|
4
|
+
url: { type: 'string' },
|
|
5
|
+
app: { type: 'string' },
|
|
6
|
+
env: { type: 'string' },
|
|
7
|
+
json: { type: 'boolean' },
|
|
8
|
+
insecure: { type: 'boolean' },
|
|
9
|
+
help: { type: 'boolean', short: 'h' },
|
|
10
|
+
};
|
|
11
|
+
export const CONNECTION_HELP = `Connection:
|
|
12
|
+
--url <url> Molt server URL (or MOLT_URL)
|
|
13
|
+
--app <name> App name (or MOLT_APP)
|
|
14
|
+
--env <name> Environment name (or MOLT_ENV)
|
|
15
|
+
MOLT_TOKEN Access token. Only read from the environment, never from a flag.
|
|
16
|
+
--json Print machine-readable JSON to stdout
|
|
17
|
+
--insecure Allow plain HTTP to a host other than localhost
|
|
18
|
+
-h, --help Show this help
|
|
19
|
+
`;
|
|
20
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
21
|
+
/** Parses a whole number flag such as `--rollout 10`. */
|
|
22
|
+
export function integer(flag, value, min, max) {
|
|
23
|
+
if (value === undefined)
|
|
24
|
+
return undefined;
|
|
25
|
+
const parsed = /^\d+$/.test(value) ? Number(value) : Number.NaN;
|
|
26
|
+
if (!Number.isInteger(parsed) || parsed < min || parsed > max) {
|
|
27
|
+
throw new UsageError(`${flag} must be a whole number from ${min} to ${max}.`);
|
|
28
|
+
}
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
export function releaseId(value) {
|
|
32
|
+
if (!value || !UUID.test(value)) {
|
|
33
|
+
throw new UsageError('Expected a release id (a UUID). List releases with "molt-ota releases list".');
|
|
34
|
+
}
|
|
35
|
+
return value.toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
/** `--platform` for rollbacks, where the API also accepts `all`. */
|
|
38
|
+
export function platformSelection(value) {
|
|
39
|
+
if (value === 'ios' || value === 'android' || value === 'all')
|
|
40
|
+
return value;
|
|
41
|
+
throw new UsageError('--platform must be ios, android or all.');
|
|
42
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { CONNECTION_HELP, globalOptions, integer, releaseId } from "../args.js";
|
|
3
|
+
import { resolveTarget, scopePath } from "../config.js";
|
|
4
|
+
import { UsageError } from "../errors.js";
|
|
5
|
+
import { printJson, variantText } from "../format.js";
|
|
6
|
+
import { createClient } from "../http.js";
|
|
7
|
+
import { tryGetRelease } from "../release.js";
|
|
8
|
+
export const APPROVE_HELP = `Usage:
|
|
9
|
+
molt-ota approve <release-id> [--rollout <1-100>]
|
|
10
|
+
|
|
11
|
+
Activate a draft, or widen the rollout of a release that is already live. Without --rollout
|
|
12
|
+
the percentage requested at upload time is used. Needs the approve permission.
|
|
13
|
+
|
|
14
|
+
${CONNECTION_HELP}`;
|
|
15
|
+
const options = { ...globalOptions, rollout: { type: 'string' } };
|
|
16
|
+
export async function approveCommand(argv, io) {
|
|
17
|
+
const { values, positionals } = parseArgs({ args: argv, options, allowPositionals: true, strict: true });
|
|
18
|
+
if (values.help) {
|
|
19
|
+
io.stdout(APPROVE_HELP);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
if (positionals.length !== 1)
|
|
23
|
+
throw new UsageError('"approve" takes exactly one release id.');
|
|
24
|
+
const id = releaseId(positionals[0]);
|
|
25
|
+
const percentage = integer('--rollout', values.rollout, 1, 100);
|
|
26
|
+
const target = resolveTarget(values, io.env);
|
|
27
|
+
const client = createClient(target, io);
|
|
28
|
+
await client.post(`${scopePath(target)}/releases/${id}/approve`, percentage === undefined ? {} : { percentage });
|
|
29
|
+
const release = await tryGetRelease(client, target, id, io);
|
|
30
|
+
if (values.json) {
|
|
31
|
+
printJson(io, { id, approved: true, release: release ?? null });
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
io.stdout(`Approved release ${id}${percentage === undefined ? '' : ` at ${percentage}%`}.\n`);
|
|
35
|
+
for (const variant of release?.variants ?? [])
|
|
36
|
+
io.stdout(` ${variantText(variant)}\n`);
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdtemp, readFile, rm, stat } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
6
|
+
import { CONNECTION_HELP, globalOptions, integer } from "../args.js";
|
|
7
|
+
import { resolveTarget, scopePath } from "../config.js";
|
|
8
|
+
import { ApiError, CliError, NetworkError, UsageError } from "../errors.js";
|
|
9
|
+
import { exportApp, readPublicConfig, resolveExpoCli } from "../expo.js";
|
|
10
|
+
import { printJson, variantText } from "../format.js";
|
|
11
|
+
import { MAX_FIELD_BYTES, readGitInfo, truncateUtf8 } from "../git.js";
|
|
12
|
+
import { createClient } from "../http.js";
|
|
13
|
+
import { tryGetRelease } from "../release.js";
|
|
14
|
+
import { buildArchive } from "../zip.js";
|
|
15
|
+
export const PUBLISH_HELP = `Usage:
|
|
16
|
+
molt-ota publish [options]
|
|
17
|
+
|
|
18
|
+
Export the Expo app, zip the export and upload it. The update goes live right away. Use
|
|
19
|
+
--draft to only upload it, which works with a token that may not approve (upload permission only).
|
|
20
|
+
|
|
21
|
+
Options:
|
|
22
|
+
--project <dir> Expo project directory (default: current directory)
|
|
23
|
+
--platform <ios|android|all>
|
|
24
|
+
Platforms to export (default: all, meaning ios and android)
|
|
25
|
+
--runtime-version <v> Runtime version. Read from the app config when it is a plain string.
|
|
26
|
+
--draft Upload a draft and do not publish it
|
|
27
|
+
--rollout <1-100> Percentage of clients that receive the update (default: 100)
|
|
28
|
+
--export-dir <dir> Zip an existing "expo export" directory instead of exporting
|
|
29
|
+
--archive <file.zip> Upload an existing archive as is (needs --runtime-version)
|
|
30
|
+
--idempotency-key <key> Make a retry of this upload safe (default: a random key)
|
|
31
|
+
--no-git Do not send the current commit hash and subject
|
|
32
|
+
--commit-hash <hash> Commit hash to record (default: HEAD)
|
|
33
|
+
--commit-message <text> Commit message to record (default: subject of HEAD)
|
|
34
|
+
|
|
35
|
+
${CONNECTION_HELP}`;
|
|
36
|
+
const options = {
|
|
37
|
+
...globalOptions,
|
|
38
|
+
project: { type: 'string' },
|
|
39
|
+
platform: { type: 'string' },
|
|
40
|
+
'runtime-version': { type: 'string' },
|
|
41
|
+
draft: { type: 'boolean' },
|
|
42
|
+
rollout: { type: 'string' },
|
|
43
|
+
'export-dir': { type: 'string' },
|
|
44
|
+
archive: { type: 'string' },
|
|
45
|
+
'idempotency-key': { type: 'string' },
|
|
46
|
+
'no-git': { type: 'boolean' },
|
|
47
|
+
'commit-hash': { type: 'string' },
|
|
48
|
+
'commit-message': { type: 'string' },
|
|
49
|
+
};
|
|
50
|
+
function isRecord(value) {
|
|
51
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
function publishPlatforms(value) {
|
|
54
|
+
if (value === undefined || value === 'all')
|
|
55
|
+
return ['ios', 'android'];
|
|
56
|
+
if (value === 'ios' || value === 'android')
|
|
57
|
+
return [value];
|
|
58
|
+
throw new UsageError('--platform must be ios, android or all.');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Takes the runtime version from the app config when that is unambiguous: every value that
|
|
62
|
+
* applies to the chosen platforms must be the same plain string. Anything else needs a flag.
|
|
63
|
+
*/
|
|
64
|
+
export function resolveRuntimeVersion(config, platforms) {
|
|
65
|
+
const app = isRecord(config) && isRecord(config.expo) ? config.expo : isRecord(config) ? config : {};
|
|
66
|
+
const candidates = [['runtimeVersion', app.runtimeVersion]];
|
|
67
|
+
for (const platform of platforms) {
|
|
68
|
+
const section = app[platform];
|
|
69
|
+
candidates.push([`${platform}.runtimeVersion`, isRecord(section) ? section.runtimeVersion : undefined]);
|
|
70
|
+
}
|
|
71
|
+
const defined = candidates.filter(([, value]) => value !== undefined);
|
|
72
|
+
if (defined.length === 0) {
|
|
73
|
+
throw new CliError('The app config does not set a runtimeVersion.', [
|
|
74
|
+
'Pass --runtime-version, or set "runtimeVersion" in app.json.',
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
for (const [name, value] of defined) {
|
|
78
|
+
if (typeof value !== 'string' || value === '') {
|
|
79
|
+
throw new CliError(`${name} is not a plain string (${JSON.stringify(value)}).`, [
|
|
80
|
+
'Policies such as "appVersion" are resolved when the native app is built, so the CLI cannot know the value.',
|
|
81
|
+
'Pass --runtime-version with the value your installed builds report.',
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const distinct = [...new Set(defined.map(([, value]) => value))];
|
|
86
|
+
if (distinct.length > 1) {
|
|
87
|
+
throw new CliError(`The app config sets different runtime versions: ${defined.map(([name, value]) => `${name}=${String(value)}`).join(', ')}.`, [
|
|
88
|
+
'Pass --runtime-version. If the platforms differ, publish them one by one with --platform.',
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
return distinct[0];
|
|
92
|
+
}
|
|
93
|
+
const mib = (bytes) => `${(bytes / 1024 ** 2).toFixed(1)} MiB`;
|
|
94
|
+
/** The `expoconfig.json` of an existing export, if there is a readable one. */
|
|
95
|
+
async function readExistingConfig(exportDir) {
|
|
96
|
+
try {
|
|
97
|
+
return JSON.parse(await readFile(path.join(exportDir, 'expoconfig.json'), 'utf8'));
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export async function publishCommand(argv, io) {
|
|
104
|
+
const { values, positionals } = parseArgs({ args: argv, options, allowPositionals: true, strict: true });
|
|
105
|
+
if (values.help) {
|
|
106
|
+
io.stdout(PUBLISH_HELP);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
if (positionals.length > 0)
|
|
110
|
+
throw new UsageError('"publish" takes no positional arguments.');
|
|
111
|
+
if (values['export-dir'] && values.archive)
|
|
112
|
+
throw new UsageError('Use either --export-dir or --archive, not both.');
|
|
113
|
+
if (values.archive && !values['runtime-version']) {
|
|
114
|
+
throw new UsageError('--archive needs --runtime-version, because the CLI does not open the archive.');
|
|
115
|
+
}
|
|
116
|
+
const platforms = publishPlatforms(values.platform);
|
|
117
|
+
const rollout = integer('--rollout', values.rollout, 1, 100);
|
|
118
|
+
const runtimeFlag = values['runtime-version'];
|
|
119
|
+
if (runtimeFlag !== undefined && (runtimeFlag === '' || runtimeFlag.length > 255)) {
|
|
120
|
+
throw new UsageError('--runtime-version must be 1 to 255 characters long.');
|
|
121
|
+
}
|
|
122
|
+
const idempotencyKey = values['idempotency-key'] ?? randomUUID();
|
|
123
|
+
if (idempotencyKey === '' || idempotencyKey.length > 255) {
|
|
124
|
+
throw new UsageError('--idempotency-key must be 1 to 255 characters long.');
|
|
125
|
+
}
|
|
126
|
+
// Check the connection settings before the slow part, so a typo does not cost an export.
|
|
127
|
+
const target = resolveTarget(values, io.env);
|
|
128
|
+
const client = createClient(target, io);
|
|
129
|
+
const draft = values.draft === true;
|
|
130
|
+
const log = (message) => io.stderr(`${message}\n`);
|
|
131
|
+
const projectDir = path.resolve(io.cwd, values.project ?? '.');
|
|
132
|
+
const workDir = await mkdtemp(path.join(os.tmpdir(), 'molt-ota-'));
|
|
133
|
+
try {
|
|
134
|
+
const prepared = await prepare();
|
|
135
|
+
const { runtimeVersion } = prepared;
|
|
136
|
+
const git = values['no-git'] ? {} : readGitInfo(projectDir);
|
|
137
|
+
const commitHash = values['commit-hash'] ?? git.commitHash;
|
|
138
|
+
const commitMessage = values['commit-message'] ?? git.commitMessage;
|
|
139
|
+
const fields = { runtimeVersion, publish: draft ? 'false' : 'true' };
|
|
140
|
+
if (rollout !== undefined)
|
|
141
|
+
fields.rolloutPercentage = String(rollout);
|
|
142
|
+
if (commitHash)
|
|
143
|
+
fields.commitHash = truncateUtf8(commitHash, MAX_FIELD_BYTES);
|
|
144
|
+
if (commitMessage)
|
|
145
|
+
fields.commitMessage = truncateUtf8(commitMessage, MAX_FIELD_BYTES);
|
|
146
|
+
log(`Uploading ${mib(prepared.archiveBytes)} to ${target.origin} as ${target.app}/${target.env}…`);
|
|
147
|
+
let id;
|
|
148
|
+
try {
|
|
149
|
+
const response = await client.upload(`${scopePath(target)}/releases`, {
|
|
150
|
+
filePath: prepared.archivePath,
|
|
151
|
+
fileSize: prepared.archiveBytes,
|
|
152
|
+
fields,
|
|
153
|
+
idempotencyKey,
|
|
154
|
+
});
|
|
155
|
+
if (!isRecord(response) || typeof response.id !== 'string') {
|
|
156
|
+
throw new CliError('The server did not return a release id.');
|
|
157
|
+
}
|
|
158
|
+
id = response.id;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error instanceof ApiError && error.status === 401 && !draft) {
|
|
162
|
+
error.hints.push('If this token only has the upload permission, publish a draft with --draft and approve it with a second credential.');
|
|
163
|
+
}
|
|
164
|
+
// The server may have stored the release before the connection broke or it answered 5xx.
|
|
165
|
+
if (error instanceof NetworkError || (error instanceof ApiError && error.status >= 500)) {
|
|
166
|
+
error.hints.push(`Retry with --idempotency-key ${idempotencyKey} so a half-finished upload does not create a second release.`);
|
|
167
|
+
}
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
const release = await tryGetRelease(client, target, id, io);
|
|
171
|
+
if (values.json) {
|
|
172
|
+
printJson(io, { id, draft, runtimeVersion, idempotencyKey, release: release ?? null });
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
io.stdout(`${draft ? 'Uploaded draft' : 'Published release'} ${id} (runtime ${runtimeVersion}).\n`);
|
|
176
|
+
for (const variant of release?.variants ?? [])
|
|
177
|
+
io.stdout(` ${variantText(variant)}\n`);
|
|
178
|
+
if (draft)
|
|
179
|
+
io.stdout(`Next: molt-ota approve ${id} [--rollout <1-100>]\n`);
|
|
180
|
+
else if (release?.variants.some((variant) => variant.status === 'publicationPending')) {
|
|
181
|
+
io.stdout(`Publication is still being finalized. Check again with: molt-ota releases show ${id}\n`);
|
|
182
|
+
}
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
await rm(workDir, { recursive: true, force: true });
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Produces the archive to upload from whichever source the flags selected. The app config is
|
|
190
|
+
* read before the slow export, so a missing runtime version fails right away.
|
|
191
|
+
*/
|
|
192
|
+
async function prepare() {
|
|
193
|
+
if (values.archive) {
|
|
194
|
+
const archivePath = path.resolve(io.cwd, values.archive);
|
|
195
|
+
// The flag is required together with --archive, which was checked above.
|
|
196
|
+
return { archivePath, archiveBytes: (await stat(archivePath)).size, runtimeVersion: runtimeFlag };
|
|
197
|
+
}
|
|
198
|
+
const exportDirFlag = values['export-dir'];
|
|
199
|
+
const exportDir = exportDirFlag ? path.resolve(io.cwd, exportDirFlag) : path.join(workDir, 'dist');
|
|
200
|
+
const expoCli = exportDirFlag ? undefined : resolveExpoCli(projectDir);
|
|
201
|
+
// An expoconfig.json inside an existing export wins. Otherwise ask Expo for the public config.
|
|
202
|
+
const existing = exportDirFlag ? await readExistingConfig(exportDir) : undefined;
|
|
203
|
+
const expoConfig = existing === undefined ? await readPublicConfig(expoCli ?? resolveExpoCli(projectDir), projectDir) : undefined;
|
|
204
|
+
const config = existing ?? expoConfig;
|
|
205
|
+
const runtimeVersion = runtimeFlag ?? resolveRuntimeVersion(config, platforms);
|
|
206
|
+
if (expoCli) {
|
|
207
|
+
log(`Exporting ${platforms.join(' and ')} with the Expo CLI…`);
|
|
208
|
+
await exportApp(expoCli, projectDir, exportDir, platforms);
|
|
209
|
+
}
|
|
210
|
+
const archivePath = path.join(workDir, 'export.zip');
|
|
211
|
+
log('Creating the archive…');
|
|
212
|
+
const summary = await buildArchive({ exportDir, expoConfig, outFile: archivePath });
|
|
213
|
+
for (const warning of summary.warnings)
|
|
214
|
+
io.stderr(`warning: ${warning}\n`);
|
|
215
|
+
log(`Archived ${summary.entries} files (${mib(summary.bytes)}) for ${summary.platforms.join(' and ')}.`);
|
|
216
|
+
return { archivePath, archiveBytes: summary.archiveBytes, runtimeVersion };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { CONNECTION_HELP, globalOptions, integer, releaseId } from "../args.js";
|
|
3
|
+
import { resolveTarget, scopePath } from "../config.js";
|
|
4
|
+
import { UsageError } from "../errors.js";
|
|
5
|
+
import { printJson, releaseDetails, releaseTable } from "../format.js";
|
|
6
|
+
import { createClient } from "../http.js";
|
|
7
|
+
import { asReleaseList, getRelease } from "../release.js";
|
|
8
|
+
export const RELEASES_HELP = `Usage:
|
|
9
|
+
molt-ota releases list [--runtime-version <v>] [--limit <1-100>] [--offset <n>]
|
|
10
|
+
molt-ota releases show <release-id>
|
|
11
|
+
|
|
12
|
+
List releases newest first, or show one release with the status of each platform.
|
|
13
|
+
|
|
14
|
+
${CONNECTION_HELP}`;
|
|
15
|
+
const options = {
|
|
16
|
+
...globalOptions,
|
|
17
|
+
'runtime-version': { type: 'string' },
|
|
18
|
+
limit: { type: 'string' },
|
|
19
|
+
offset: { type: 'string' },
|
|
20
|
+
};
|
|
21
|
+
export async function releasesCommand(argv, io) {
|
|
22
|
+
const [subcommand, ...rest] = argv;
|
|
23
|
+
if (!subcommand || subcommand === '--help' || subcommand === '-h') {
|
|
24
|
+
io.stdout(RELEASES_HELP);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
if (subcommand !== 'list' && subcommand !== 'show') {
|
|
28
|
+
throw new UsageError(`Unknown releases command "${subcommand}". Use "list" or "show".`);
|
|
29
|
+
}
|
|
30
|
+
const { values, positionals } = parseArgs({ args: rest, options, allowPositionals: true, strict: true });
|
|
31
|
+
if (values.help) {
|
|
32
|
+
io.stdout(RELEASES_HELP);
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
const target = resolveTarget(values, io.env);
|
|
36
|
+
const client = createClient(target, io);
|
|
37
|
+
if (subcommand === 'list') {
|
|
38
|
+
if (positionals.length > 0)
|
|
39
|
+
throw new UsageError('"releases list" takes no arguments.');
|
|
40
|
+
const releases = asReleaseList(await client.get(`${scopePath(target)}/releases`, {
|
|
41
|
+
runtimeVersion: values['runtime-version'],
|
|
42
|
+
limit: integer('--limit', values.limit, 1, 100),
|
|
43
|
+
offset: integer('--offset', values.offset, 0, Number.MAX_SAFE_INTEGER),
|
|
44
|
+
}));
|
|
45
|
+
if (values.json)
|
|
46
|
+
printJson(io, { releases });
|
|
47
|
+
else
|
|
48
|
+
io.stdout(`${releaseTable(releases)}\n`);
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
if (positionals.length !== 1)
|
|
52
|
+
throw new UsageError('"releases show" takes exactly one release id.');
|
|
53
|
+
const release = await getRelease(client, target, releaseId(positionals[0]));
|
|
54
|
+
if (values.json)
|
|
55
|
+
printJson(io, release);
|
|
56
|
+
else
|
|
57
|
+
io.stdout(`${releaseDetails(release)}\n`);
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { CONNECTION_HELP, globalOptions, platformSelection, releaseId } from "../args.js";
|
|
3
|
+
import { resolveTarget, scopePath } from "../config.js";
|
|
4
|
+
import { UsageError } from "../errors.js";
|
|
5
|
+
import { printJson } from "../format.js";
|
|
6
|
+
import { createClient } from "../http.js";
|
|
7
|
+
export const ROLLBACK_HELP = `Usage:
|
|
8
|
+
molt-ota rollback --runtime-version <v> --platform <ios|android|all> --release <release-id>
|
|
9
|
+
molt-ota rollback --runtime-version <v> --platform <ios|android|all> --embedded
|
|
10
|
+
|
|
11
|
+
Serve an earlier release again, or tell clients to go back to the update embedded in the app.
|
|
12
|
+
You must choose one of --release and --embedded. Needs the approve permission.
|
|
13
|
+
|
|
14
|
+
${CONNECTION_HELP}`;
|
|
15
|
+
const options = {
|
|
16
|
+
...globalOptions,
|
|
17
|
+
'runtime-version': { type: 'string' },
|
|
18
|
+
platform: { type: 'string' },
|
|
19
|
+
release: { type: 'string' },
|
|
20
|
+
embedded: { type: 'boolean' },
|
|
21
|
+
};
|
|
22
|
+
export async function rollbackCommand(argv, io) {
|
|
23
|
+
const { values, positionals } = parseArgs({ args: argv, options, allowPositionals: true, strict: true });
|
|
24
|
+
if (values.help) {
|
|
25
|
+
io.stdout(ROLLBACK_HELP);
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
if (positionals.length > 0)
|
|
29
|
+
throw new UsageError('"rollback" takes no positional arguments.');
|
|
30
|
+
const runtimeVersion = values['runtime-version'];
|
|
31
|
+
if (!runtimeVersion)
|
|
32
|
+
throw new UsageError('--runtime-version is required.');
|
|
33
|
+
const platform = platformSelection(values.platform);
|
|
34
|
+
if ((values.release === undefined) === (values.embedded !== true)) {
|
|
35
|
+
throw new UsageError('Choose exactly one of --release <id> and --embedded.');
|
|
36
|
+
}
|
|
37
|
+
const target = resolveTarget(values, io.env);
|
|
38
|
+
const client = createClient(target, io);
|
|
39
|
+
const release = values.release === undefined ? undefined : releaseId(values.release);
|
|
40
|
+
await client.post(`${scopePath(target)}/rollbacks`, {
|
|
41
|
+
runtimeVersion,
|
|
42
|
+
platform,
|
|
43
|
+
...(release ? { releaseId: release } : {}),
|
|
44
|
+
});
|
|
45
|
+
const destination = release ? `release ${release}` : 'the embedded update';
|
|
46
|
+
if (values.json)
|
|
47
|
+
printJson(io, { runtimeVersion, platform, releaseId: release ?? null });
|
|
48
|
+
else
|
|
49
|
+
io.stdout(`Rolled ${platform} clients on runtime ${runtimeVersion} back to ${destination}.\n`);
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { UsageError } from "./errors.js";
|
|
2
|
+
const NAME = /^[a-zA-Z0-9_-]{1,128}$/;
|
|
3
|
+
const TOKEN = /^[\x21-\x7e]+$/;
|
|
4
|
+
function isLoopback(hostname) {
|
|
5
|
+
const host = hostname.toLowerCase();
|
|
6
|
+
return host === 'localhost' || host === '[::1]' || host === '::1' || /^127(\.\d{1,3}){3}$/.test(host);
|
|
7
|
+
}
|
|
8
|
+
/** Flags win over environment variables. The token is only read from `MOLT_TOKEN`. */
|
|
9
|
+
export function resolveTarget(flags, env) {
|
|
10
|
+
const rawUrl = flags.url ?? env.MOLT_URL;
|
|
11
|
+
const app = flags.app ?? env.MOLT_APP;
|
|
12
|
+
const environment = flags.env ?? env.MOLT_ENV;
|
|
13
|
+
const token = env.MOLT_TOKEN?.trim();
|
|
14
|
+
const missing = [];
|
|
15
|
+
if (!rawUrl)
|
|
16
|
+
missing.push('--url (or MOLT_URL)');
|
|
17
|
+
if (!app)
|
|
18
|
+
missing.push('--app (or MOLT_APP)');
|
|
19
|
+
if (!environment)
|
|
20
|
+
missing.push('--env (or MOLT_ENV)');
|
|
21
|
+
if (!token)
|
|
22
|
+
missing.push('MOLT_TOKEN');
|
|
23
|
+
if (!rawUrl || !app || !environment || !token) {
|
|
24
|
+
throw new UsageError(`Missing configuration: ${missing.join(', ')}.`);
|
|
25
|
+
}
|
|
26
|
+
let url;
|
|
27
|
+
try {
|
|
28
|
+
url = new URL(rawUrl);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new UsageError(`Invalid URL: ${rawUrl}`);
|
|
32
|
+
}
|
|
33
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
34
|
+
throw new UsageError(`The URL must use http or https: ${rawUrl}`);
|
|
35
|
+
}
|
|
36
|
+
if (url.username || url.password) {
|
|
37
|
+
throw new UsageError('The URL must not contain credentials. Pass the token in MOLT_TOKEN.');
|
|
38
|
+
}
|
|
39
|
+
if (url.search || url.hash) {
|
|
40
|
+
throw new UsageError('The URL must not contain a query string or fragment.');
|
|
41
|
+
}
|
|
42
|
+
if (url.protocol === 'http:' && !isLoopback(url.hostname) && !flags.insecure) {
|
|
43
|
+
throw new UsageError(`Refusing to send the token over plain HTTP to ${url.host}. Use an https:// URL, or pass --insecure.`);
|
|
44
|
+
}
|
|
45
|
+
if (!NAME.test(app)) {
|
|
46
|
+
throw new UsageError(`Invalid app name "${app}". Use 1 to 128 letters, digits, "-" or "_".`);
|
|
47
|
+
}
|
|
48
|
+
if (!NAME.test(environment)) {
|
|
49
|
+
throw new UsageError(`Invalid environment name "${environment}". Use 1 to 128 letters, digits, "-" or "_".`);
|
|
50
|
+
}
|
|
51
|
+
if (!TOKEN.test(token)) {
|
|
52
|
+
throw new UsageError('MOLT_TOKEN contains whitespace or control characters.');
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
origin: url.origin,
|
|
56
|
+
basePath: url.pathname.replace(/\/+$/, ''),
|
|
57
|
+
token,
|
|
58
|
+
app,
|
|
59
|
+
env: environment,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function scopePath(target) {
|
|
63
|
+
return `/v1/apps/${target.app}/environments/${target.env}`;
|
|
64
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Wrong flags or missing configuration. Exit code 2. */
|
|
2
|
+
export class UsageError extends Error {
|
|
3
|
+
}
|
|
4
|
+
/** A failure the user can act on. Exit code 1. Hints are printed after the message. */
|
|
5
|
+
export class CliError extends Error {
|
|
6
|
+
hints;
|
|
7
|
+
constructor(message, hints = []) {
|
|
8
|
+
super(message);
|
|
9
|
+
// Copy, because callers add hints and the arrays they pass in may be shared constants.
|
|
10
|
+
this.hints = [...hints];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The server answered with an error status or an unexpected redirect. */
|
|
14
|
+
export class ApiError extends CliError {
|
|
15
|
+
status;
|
|
16
|
+
constructor(status, message, hints = []) {
|
|
17
|
+
super(message, hints);
|
|
18
|
+
this.status = status;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The request never produced a usable response. */
|
|
22
|
+
export class NetworkError extends CliError {
|
|
23
|
+
}
|
package/dist/expo.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { CliError } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Finds the Expo CLI the project itself depends on. Going through node resolution instead of
|
|
7
|
+
* `npx` follows monorepo hoisting, needs no shell on Windows and never downloads a package.
|
|
8
|
+
*/
|
|
9
|
+
export function resolveExpoCli(projectDir) {
|
|
10
|
+
try {
|
|
11
|
+
return createRequire(path.join(projectDir, 'package.json')).resolve('expo/bin/cli');
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error && typeof error === 'object' && 'code' in error && error.code === 'MODULE_NOT_FOUND') {
|
|
15
|
+
throw new CliError(`Could not find the "expo" package from ${projectDir}.`, [
|
|
16
|
+
'Install the project dependencies first, or point --project at your Expo app.',
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Runs the Expo CLI with this Node binary. Progress goes to stderr, stdout is optionally captured. */
|
|
23
|
+
function runExpo(cli, args, cwd, captureStdout) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const child = spawn(process.execPath, [cli, ...args], {
|
|
26
|
+
cwd,
|
|
27
|
+
stdio: ['ignore', captureStdout ? 'pipe' : 2, 2],
|
|
28
|
+
});
|
|
29
|
+
const chunks = [];
|
|
30
|
+
child.stdout?.on('data', (chunk) => chunks.push(chunk));
|
|
31
|
+
child.on('error', (error) => reject(new CliError(`Could not start the Expo CLI: ${error.message}`)));
|
|
32
|
+
child.on('close', (code) => {
|
|
33
|
+
if (code === 0)
|
|
34
|
+
resolve(Buffer.concat(chunks).toString('utf8'));
|
|
35
|
+
else
|
|
36
|
+
reject(new CliError(`"expo ${args[0]}" failed with exit code ${code}. Its output is shown above.`));
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function exportApp(cli, projectDir, outputDir, platforms) {
|
|
41
|
+
const flags = platforms.flatMap((platform) => ['--platform', platform]);
|
|
42
|
+
return runExpo(cli, ['export', ...flags, '--output-dir', outputDir], projectDir, false);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* `expo config --json` prints one JSON line, but other tools may write to stdout before it.
|
|
46
|
+
* Take the whole output if it is JSON, else the last line that looks like an object.
|
|
47
|
+
*/
|
|
48
|
+
export function parseConfigOutput(stdout) {
|
|
49
|
+
const candidates = [stdout.trim(), ...stdout.split('\n').map((line) => line.trim()).filter((line) => line.startsWith('{')).reverse()];
|
|
50
|
+
for (const candidate of candidates) {
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(candidate);
|
|
53
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// try the next candidate
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw new CliError('"expo config" did not print a JSON object.', ['Run "npx expo config --type public --json" in the project to see its output.']);
|
|
61
|
+
}
|
|
62
|
+
export async function readPublicConfig(cli, projectDir) {
|
|
63
|
+
return parseConfigOutput(await runExpo(cli, ['config', '--type', 'public', '--json'], projectDir, true));
|
|
64
|
+
}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function printJson(io, value) {
|
|
2
|
+
io.stdout(`${JSON.stringify(value, null, 2)}\n`);
|
|
3
|
+
}
|
|
4
|
+
export function variantText(variant) {
|
|
5
|
+
const percentage = variant.rolloutPercentage === null ? '' : ` ${variant.rolloutPercentage}%`;
|
|
6
|
+
return `${variant.platform} ${variant.status}${percentage}`;
|
|
7
|
+
}
|
|
8
|
+
/** Left-aligned columns separated by two spaces. */
|
|
9
|
+
export function table(header, rows) {
|
|
10
|
+
const all = [header, ...rows];
|
|
11
|
+
const widths = header.map((_, column) => Math.max(...all.map((row) => (row[column] ?? '').length)));
|
|
12
|
+
return all.map((row) => row.map((cell, column) => cell.padEnd(widths[column] ?? 0)).join(' ').trimEnd()).join('\n');
|
|
13
|
+
}
|
|
14
|
+
function created(release) {
|
|
15
|
+
return release.createdAt.slice(0, 16).replace('T', ' ');
|
|
16
|
+
}
|
|
17
|
+
export function releaseTable(releases) {
|
|
18
|
+
if (releases.length === 0)
|
|
19
|
+
return 'No releases.';
|
|
20
|
+
return table(['ID', 'RUNTIME', 'CREATED (UTC)', 'COMMIT', 'PLATFORMS'], releases.map((release) => [
|
|
21
|
+
release.id,
|
|
22
|
+
release.runtimeVersion,
|
|
23
|
+
created(release),
|
|
24
|
+
release.commitHash?.slice(0, 7) ?? '-',
|
|
25
|
+
release.variants.map(variantText).join(', '),
|
|
26
|
+
]));
|
|
27
|
+
}
|
|
28
|
+
export function releaseDetails(release) {
|
|
29
|
+
const lines = [
|
|
30
|
+
`Release ${release.id}`,
|
|
31
|
+
` runtime ${release.runtimeVersion}`,
|
|
32
|
+
` created ${created(release)} UTC`,
|
|
33
|
+
];
|
|
34
|
+
if (release.commitHash)
|
|
35
|
+
lines.push(` commit ${release.commitHash}`);
|
|
36
|
+
if (release.commitMessage)
|
|
37
|
+
lines.push(` message ${release.commitMessage}`);
|
|
38
|
+
lines.push(` requested rollout ${release.requestedRolloutPercentage}%`);
|
|
39
|
+
for (const variant of release.variants) {
|
|
40
|
+
lines.push(` ${variantText(variant)}${variant.updateId ? ` (update ${variant.updateId})` : ''}`);
|
|
41
|
+
}
|
|
42
|
+
return lines.join('\n');
|
|
43
|
+
}
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
/** Molt rejects form fields longer than this many bytes. */
|
|
3
|
+
export const MAX_FIELD_BYTES = 4096;
|
|
4
|
+
/** Shortens text to at most `maxBytes` bytes of UTF-8 without cutting a character in half. */
|
|
5
|
+
export function truncateUtf8(text, maxBytes) {
|
|
6
|
+
const bytes = Buffer.from(text, 'utf8');
|
|
7
|
+
if (bytes.length <= maxBytes)
|
|
8
|
+
return text;
|
|
9
|
+
let end = maxBytes;
|
|
10
|
+
while (end > 0 && ((bytes[end] ?? 0) & 0xc0) === 0x80)
|
|
11
|
+
end--;
|
|
12
|
+
return bytes.subarray(0, end).toString('utf8');
|
|
13
|
+
}
|
|
14
|
+
function git(cwd, args) {
|
|
15
|
+
try {
|
|
16
|
+
const out = execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
17
|
+
return out.trim() || undefined;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** The current commit and its subject line, or nothing outside a Git repository. */
|
|
24
|
+
export function readGitInfo(cwd) {
|
|
25
|
+
const commitHash = git(cwd, ['rev-parse', 'HEAD']);
|
|
26
|
+
if (!commitHash)
|
|
27
|
+
return {};
|
|
28
|
+
const subject = git(cwd, ['log', '-1', '--pretty=%s']);
|
|
29
|
+
return { commitHash, ...(subject ? { commitMessage: truncateUtf8(subject, MAX_FIELD_BYTES) } : {}) };
|
|
30
|
+
}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createReadStream } from 'node:fs';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import https from 'node:https';
|
|
5
|
+
import { pipeline } from 'node:stream';
|
|
6
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
7
|
+
import { ApiError, CliError, NetworkError } from "./errors.js";
|
|
8
|
+
import { VERSION } from "./version.js";
|
|
9
|
+
const DEFAULT_RETRY_DELAYS_MS = [1000, 3000];
|
|
10
|
+
/** How long to wait for "100 Continue" before sending the body anyway, like curl does. */
|
|
11
|
+
const DEFAULT_CONTINUE_TIMEOUT_MS = 1000;
|
|
12
|
+
const CHUNK_BYTES = 64 * 1024;
|
|
13
|
+
/**
|
|
14
|
+
* Sends one request. There are no timeouts for the answer: Molt replies to an upload only after
|
|
15
|
+
* it has ingested the archive, which can take minutes.
|
|
16
|
+
*
|
|
17
|
+
* With `Expect: 100-continue` the body is held back until the server agrees. Molt checks the
|
|
18
|
+
* token before it reads the body, so a wrong token or a missing app fails at once instead of
|
|
19
|
+
* after the whole upload, and without the connection reset that follows an early answer. A server
|
|
20
|
+
* that never answers the header gets the body after `continueTimeoutMs`. A response that still
|
|
21
|
+
* arrives while the body streams wins over the write error that follows it.
|
|
22
|
+
*/
|
|
23
|
+
function exchange(url, method, headers, body, continueTimeoutMs) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
let settled = false;
|
|
26
|
+
let gotResponse = false;
|
|
27
|
+
let continueTimer;
|
|
28
|
+
const finish = (fn) => {
|
|
29
|
+
if (!settled) {
|
|
30
|
+
settled = true;
|
|
31
|
+
clearTimeout(continueTimer);
|
|
32
|
+
fn();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const fail = (error) => finish(() => {
|
|
36
|
+
req.destroy();
|
|
37
|
+
reject(error instanceof CliError ? error : networkError(url, error));
|
|
38
|
+
});
|
|
39
|
+
const transport = url.protocol === 'https:' ? https : http;
|
|
40
|
+
const req = transport.request(url, { method, headers, agent: false }, (res) => {
|
|
41
|
+
gotResponse = true;
|
|
42
|
+
const chunks = [];
|
|
43
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
44
|
+
res.on('end', () => finish(() => {
|
|
45
|
+
if (!req.writableEnded)
|
|
46
|
+
req.destroy();
|
|
47
|
+
resolve({
|
|
48
|
+
status: res.statusCode ?? 0,
|
|
49
|
+
location: typeof res.headers.location === 'string' ? res.headers.location : undefined,
|
|
50
|
+
body: Buffer.concat(chunks),
|
|
51
|
+
});
|
|
52
|
+
}));
|
|
53
|
+
res.on('error', fail);
|
|
54
|
+
res.on('close', () => {
|
|
55
|
+
if (!res.complete)
|
|
56
|
+
fail(new Error('connection closed before the response was complete'));
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
req.on('error', fail);
|
|
60
|
+
let bodyStarted = false;
|
|
61
|
+
const sendBody = (source) => {
|
|
62
|
+
if (bodyStarted || settled)
|
|
63
|
+
return;
|
|
64
|
+
bodyStarted = true;
|
|
65
|
+
pipeline(source(), req, (error) => {
|
|
66
|
+
// After an early response the write error is expected. Our own errors always win.
|
|
67
|
+
if (error && (error instanceof CliError || !gotResponse))
|
|
68
|
+
fail(error);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
if (!body) {
|
|
72
|
+
req.end();
|
|
73
|
+
}
|
|
74
|
+
else if (String(headers.expect ?? '').toLowerCase() === '100-continue') {
|
|
75
|
+
req.flushHeaders();
|
|
76
|
+
req.once('continue', () => sendBody(body));
|
|
77
|
+
continueTimer = setTimeout(() => sendBody(body), continueTimeoutMs);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
sendBody(body);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function networkError(url, error) {
|
|
85
|
+
const reason = error && typeof error === 'object' && 'code' in error && typeof error.code === 'string'
|
|
86
|
+
? error.code
|
|
87
|
+
: error instanceof Error
|
|
88
|
+
? error.message
|
|
89
|
+
: String(error);
|
|
90
|
+
return new NetworkError(`Could not talk to ${url.origin}: ${reason}`, [
|
|
91
|
+
'Check MOLT_URL and your network connection.',
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
const STATUS_HINTS = {
|
|
95
|
+
401: [
|
|
96
|
+
'Check MOLT_TOKEN and that the token may perform this operation for this app and environment.',
|
|
97
|
+
'In simple mode the administrator token only works on release routes when OTA_READ_TOKEN is set on the server.',
|
|
98
|
+
],
|
|
99
|
+
404: [
|
|
100
|
+
'Check the app, environment and release id. Create environments with the administrator token (see the quickstart).',
|
|
101
|
+
],
|
|
102
|
+
413: ['The archive exceeds the server limit (OTA_MAX_UPLOAD_BYTES, 512 MiB by default).'],
|
|
103
|
+
};
|
|
104
|
+
function describe(raw) {
|
|
105
|
+
const text = raw.body.toString('utf8');
|
|
106
|
+
if (!text.trim())
|
|
107
|
+
return { json: undefined, text: '' };
|
|
108
|
+
try {
|
|
109
|
+
return { json: JSON.parse(text), text };
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return { json: undefined, text };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function toResult(url, raw) {
|
|
116
|
+
if (raw.status >= 300 && raw.status < 400) {
|
|
117
|
+
throw new ApiError(raw.status, `Unexpected redirect (${raw.status}) from ${url.origin}${raw.location ? ` to ${raw.location}` : ''}.`, [
|
|
118
|
+
'Check the scheme and host in MOLT_URL, for example http versus https.',
|
|
119
|
+
'The CLI does not follow redirects because it sends your token.',
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
const { json, text } = describe(raw);
|
|
123
|
+
if (raw.status >= 400) {
|
|
124
|
+
const serverMessage = json && typeof json === 'object' && 'error' in json && typeof json.error === 'string'
|
|
125
|
+
? json.error
|
|
126
|
+
: text.replace(/\s+/g, ' ').trim().slice(0, 200);
|
|
127
|
+
throw new ApiError(raw.status, `The server answered ${raw.status}${serverMessage ? `: ${serverMessage}` : '.'}`, STATUS_HINTS[raw.status] ?? []);
|
|
128
|
+
}
|
|
129
|
+
return json;
|
|
130
|
+
}
|
|
131
|
+
/** Builds the multipart body by hand so Content-Length is known and the file streams from disk. */
|
|
132
|
+
function multipart(input) {
|
|
133
|
+
const boundary = `molt-ota-${randomUUID()}`;
|
|
134
|
+
const fields = Object.entries(input.fields).map(([name, value]) => Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`));
|
|
135
|
+
const fileHead = Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="export.zip"\r\nContent-Type: application/zip\r\n\r\n`);
|
|
136
|
+
const tail = Buffer.from(`\r\n--${boundary}--\r\n`);
|
|
137
|
+
const length = [...fields, fileHead, tail].reduce((sum, part) => sum + part.length, 0) + input.fileSize;
|
|
138
|
+
async function* body() {
|
|
139
|
+
yield* fields;
|
|
140
|
+
yield fileHead;
|
|
141
|
+
let sent = 0;
|
|
142
|
+
for await (const chunk of createReadStream(input.filePath, { highWaterMark: CHUNK_BYTES })) {
|
|
143
|
+
sent += chunk.length;
|
|
144
|
+
yield chunk;
|
|
145
|
+
}
|
|
146
|
+
if (sent !== input.fileSize)
|
|
147
|
+
throw new CliError('The archive changed while it was being uploaded.');
|
|
148
|
+
yield tail;
|
|
149
|
+
}
|
|
150
|
+
return { contentType: `multipart/form-data; boundary=${boundary}`, length, body };
|
|
151
|
+
}
|
|
152
|
+
export function createClient(target, options = {}) {
|
|
153
|
+
const delays = options.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS;
|
|
154
|
+
const continueTimeoutMs = options.continueTimeoutMs ?? DEFAULT_CONTINUE_TIMEOUT_MS;
|
|
155
|
+
const urlFor = (path, query) => {
|
|
156
|
+
const url = new URL(`${target.origin}${target.basePath}${path}`);
|
|
157
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
158
|
+
if (value !== undefined)
|
|
159
|
+
url.searchParams.set(key, String(value));
|
|
160
|
+
}
|
|
161
|
+
return url;
|
|
162
|
+
};
|
|
163
|
+
const baseHeaders = () => ({
|
|
164
|
+
authorization: `Bearer ${target.token}`,
|
|
165
|
+
accept: 'application/json',
|
|
166
|
+
'user-agent': `molt-ota/${VERSION}`,
|
|
167
|
+
});
|
|
168
|
+
async function send(url, method, initialHeaders, body, retry) {
|
|
169
|
+
let headers = initialHeaders;
|
|
170
|
+
for (let attempt = 0;; attempt++) {
|
|
171
|
+
const canRetry = retry && attempt < delays.length;
|
|
172
|
+
try {
|
|
173
|
+
const raw = await exchange(url, method, headers, body, continueTimeoutMs);
|
|
174
|
+
if (raw.status === 417 && headers.expect !== undefined) {
|
|
175
|
+
// A proxy that does not support "Expect: 100-continue". Send the body without it.
|
|
176
|
+
const { expect: _expect, ...rest } = headers;
|
|
177
|
+
headers = rest;
|
|
178
|
+
attempt--;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (raw.status >= 500 && canRetry) {
|
|
182
|
+
await sleep(delays[attempt] ?? 0);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
return toResult(url, raw);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (error instanceof NetworkError && canRetry) {
|
|
189
|
+
await sleep(delays[attempt] ?? 0);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
get: (path, query) => send(urlFor(path, query), 'GET', baseHeaders(), undefined, true),
|
|
198
|
+
post(path, body) {
|
|
199
|
+
const payload = Buffer.from(JSON.stringify(body));
|
|
200
|
+
const headers = { ...baseHeaders(), 'content-type': 'application/json', 'content-length': payload.length };
|
|
201
|
+
return send(urlFor(path), 'POST', headers, async function* () { yield payload; }, false);
|
|
202
|
+
},
|
|
203
|
+
upload(path, input) {
|
|
204
|
+
const form = multipart(input);
|
|
205
|
+
const headers = {
|
|
206
|
+
...baseHeaders(),
|
|
207
|
+
'content-type': form.contentType,
|
|
208
|
+
'content-length': form.length,
|
|
209
|
+
'idempotency-key': input.idempotencyKey,
|
|
210
|
+
expect: '100-continue',
|
|
211
|
+
};
|
|
212
|
+
return send(urlFor(path), 'POST', headers, form.body, true);
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
package/dist/io.js
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { UsageError, CliError } from "./errors.js";
|
|
2
|
+
import { VERSION } from "./version.js";
|
|
3
|
+
import { approveCommand } from "./commands/approve.js";
|
|
4
|
+
import { publishCommand } from "./commands/publish.js";
|
|
5
|
+
import { releasesCommand } from "./commands/releases.js";
|
|
6
|
+
import { rollbackCommand } from "./commands/rollback.js";
|
|
7
|
+
const HELP = `molt-ota ${VERSION} - command-line client for the Molt Expo Updates server
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
molt-ota <command> [options]
|
|
11
|
+
|
|
12
|
+
Commands:
|
|
13
|
+
publish Export the app, upload it and make it live (or --draft)
|
|
14
|
+
releases List releases or show one
|
|
15
|
+
approve Activate a draft or widen a rollout
|
|
16
|
+
rollback Serve an earlier release or the embedded update again
|
|
17
|
+
|
|
18
|
+
Run "molt-ota <command> --help" for the options of a command.
|
|
19
|
+
|
|
20
|
+
Environment:
|
|
21
|
+
MOLT_URL, MOLT_APP, MOLT_ENV Server, app and environment (flags override them)
|
|
22
|
+
MOLT_TOKEN Access token
|
|
23
|
+
`;
|
|
24
|
+
const commands = {
|
|
25
|
+
publish: publishCommand,
|
|
26
|
+
releases: releasesCommand,
|
|
27
|
+
approve: approveCommand,
|
|
28
|
+
rollback: rollbackCommand,
|
|
29
|
+
};
|
|
30
|
+
function isParseError(error) {
|
|
31
|
+
return error instanceof Error && 'code' in error && String(error.code).startsWith('ERR_PARSE_ARGS');
|
|
32
|
+
}
|
|
33
|
+
/** Runs the CLI and returns the exit code: 0 success, 1 failure, 2 wrong usage. */
|
|
34
|
+
export async function run(argv, io) {
|
|
35
|
+
const [name, ...rest] = argv;
|
|
36
|
+
if (!name || name === '--help' || name === '-h' || name === 'help') {
|
|
37
|
+
io.stdout(HELP);
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
if (name === '--version' || name === '-v') {
|
|
41
|
+
io.stdout(`${VERSION}\n`);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
const command = commands[name];
|
|
45
|
+
if (!command) {
|
|
46
|
+
io.stderr(`error: unknown command "${name}".\n\n${HELP}`);
|
|
47
|
+
return 2;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return await command(rest, io);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error instanceof UsageError || isParseError(error)) {
|
|
54
|
+
io.stderr(`error: ${error.message}\nRun "molt-ota ${name} --help" for usage.\n`);
|
|
55
|
+
return 2;
|
|
56
|
+
}
|
|
57
|
+
if (error instanceof CliError) {
|
|
58
|
+
io.stderr(`error: ${error.message}\n`);
|
|
59
|
+
for (const hint of error.hints)
|
|
60
|
+
io.stderr(`hint: ${hint}\n`);
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
io.stderr(`error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/release.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { scopePath } from "./config.js";
|
|
2
|
+
import { ApiError, CliError } from "./errors.js";
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
export function asRelease(value) {
|
|
7
|
+
if (!isRecord(value) || typeof value.id !== 'string' || !Array.isArray(value.variants)) {
|
|
8
|
+
throw new CliError('The server sent a release in an unexpected format.');
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
export function asReleaseList(value) {
|
|
13
|
+
if (!isRecord(value) || !Array.isArray(value.releases)) {
|
|
14
|
+
throw new CliError('The server sent a release list in an unexpected format.');
|
|
15
|
+
}
|
|
16
|
+
return value.releases.map(asRelease);
|
|
17
|
+
}
|
|
18
|
+
export async function getRelease(client, target, id) {
|
|
19
|
+
return asRelease(await client.get(`${scopePath(target)}/releases/${id}`));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads a release back to show what is live now. The action that came before already
|
|
23
|
+
* succeeded, so a token without read permission only costs the summary, not the exit code.
|
|
24
|
+
*/
|
|
25
|
+
export async function tryGetRelease(client, target, id, io) {
|
|
26
|
+
try {
|
|
27
|
+
return await getRelease(client, target, id);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof ApiError && error.status === 401) {
|
|
31
|
+
io.stderr('warning: this token may not read releases, so the current status is not shown.\n');
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/version.js
ADDED
package/dist/zip.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { once } from 'node:events';
|
|
2
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
3
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { finished } from 'node:stream/promises';
|
|
6
|
+
import { Zip, ZipDeflate } from 'fflate';
|
|
7
|
+
import { CliError } from "./errors.js";
|
|
8
|
+
/** Molt's default limits (OTA_MAX_ZIP_ENTRIES, OTA_MAX_EXPANDED_BYTES, OTA_MAX_UPLOAD_BYTES). */
|
|
9
|
+
const LIMITS = { entries: 10_000, expandedBytes: 1024 ** 3, archiveBytes: 512 * 1024 ** 2 };
|
|
10
|
+
const CHUNK_BYTES = 64 * 1024;
|
|
11
|
+
const PLATFORMS = ['ios', 'android'];
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates `metadata.json` the way Molt reads it and returns the files it refers to. Molt only
|
|
17
|
+
* accepts "/" in those paths, but Expo writes the platform separator, so backslashes are fixed here.
|
|
18
|
+
*/
|
|
19
|
+
export function inspectMetadata(raw) {
|
|
20
|
+
let meta;
|
|
21
|
+
try {
|
|
22
|
+
meta = JSON.parse(raw.toString('utf8'));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new CliError('metadata.json in the export is not valid JSON.');
|
|
26
|
+
}
|
|
27
|
+
const files = isRecord(meta) ? meta.fileMetadata : undefined;
|
|
28
|
+
if (!isRecord(files))
|
|
29
|
+
throw new CliError('metadata.json has no "fileMetadata" section. Is this an "expo export" directory?');
|
|
30
|
+
const platforms = [];
|
|
31
|
+
const referenced = [];
|
|
32
|
+
let changed = false;
|
|
33
|
+
const fix = (value) => {
|
|
34
|
+
const fixed = value.replaceAll('\\', '/');
|
|
35
|
+
if (fixed !== value)
|
|
36
|
+
changed = true;
|
|
37
|
+
referenced.push(fixed);
|
|
38
|
+
return fixed;
|
|
39
|
+
};
|
|
40
|
+
for (const platform of PLATFORMS) {
|
|
41
|
+
const entry = files[platform];
|
|
42
|
+
if (entry === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
if (!isRecord(entry) || typeof entry.bundle !== 'string' || !entry.bundle || !Array.isArray(entry.assets)) {
|
|
45
|
+
throw new CliError(`metadata.json lists ${platform} without a bundle and an assets array.`);
|
|
46
|
+
}
|
|
47
|
+
entry.bundle = fix(entry.bundle);
|
|
48
|
+
for (const asset of entry.assets) {
|
|
49
|
+
if (!isRecord(asset) || typeof asset.path !== 'string' || typeof asset.ext !== 'string') {
|
|
50
|
+
throw new CliError(`metadata.json lists an ${platform} asset without a path and an extension.`);
|
|
51
|
+
}
|
|
52
|
+
asset.path = fix(asset.path);
|
|
53
|
+
}
|
|
54
|
+
platforms.push(platform);
|
|
55
|
+
}
|
|
56
|
+
if (platforms.length === 0) {
|
|
57
|
+
throw new CliError('The export contains neither an iOS nor an Android bundle.', [
|
|
58
|
+
'Export with "expo export --platform ios --platform android".',
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
return { data: changed ? Buffer.from(JSON.stringify(meta)) : raw, platforms, referenced, hasWeb: files.web !== undefined };
|
|
62
|
+
}
|
|
63
|
+
async function collectFiles(root) {
|
|
64
|
+
const entries = [];
|
|
65
|
+
for (const dirent of await readdir(root, { withFileTypes: true, recursive: true })) {
|
|
66
|
+
if (!dirent.isFile())
|
|
67
|
+
continue;
|
|
68
|
+
const file = path.join(dirent.parentPath, dirent.name);
|
|
69
|
+
entries.push({
|
|
70
|
+
name: path.relative(root, file).split(path.sep).join('/'),
|
|
71
|
+
file,
|
|
72
|
+
size: (await stat(file)).size,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
76
|
+
}
|
|
77
|
+
/** Compresses the entries into `outFile`, streaming files in chunks so memory stays flat. */
|
|
78
|
+
async function writeZip(entries, outFile) {
|
|
79
|
+
const out = createWriteStream(outFile);
|
|
80
|
+
const pending = [];
|
|
81
|
+
let failure;
|
|
82
|
+
const zip = new Zip((error, chunk) => {
|
|
83
|
+
if (error)
|
|
84
|
+
failure = error;
|
|
85
|
+
else
|
|
86
|
+
pending.push(chunk);
|
|
87
|
+
});
|
|
88
|
+
const flush = async () => {
|
|
89
|
+
if (failure)
|
|
90
|
+
throw failure;
|
|
91
|
+
for (const chunk of pending.splice(0)) {
|
|
92
|
+
if (!out.write(chunk))
|
|
93
|
+
await once(out, 'drain');
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
for (const entry of entries) {
|
|
98
|
+
const member = new ZipDeflate(entry.name, { level: 6 });
|
|
99
|
+
zip.add(member);
|
|
100
|
+
if (entry.data) {
|
|
101
|
+
member.push(entry.data, true);
|
|
102
|
+
await flush();
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// Hold back one chunk so the last push can carry the final flag.
|
|
106
|
+
let held;
|
|
107
|
+
for await (const chunk of createReadStream(entry.file, { highWaterMark: CHUNK_BYTES })) {
|
|
108
|
+
if (held) {
|
|
109
|
+
member.push(held, false);
|
|
110
|
+
await flush();
|
|
111
|
+
}
|
|
112
|
+
held = chunk;
|
|
113
|
+
}
|
|
114
|
+
member.push(held ?? new Uint8Array(0), true);
|
|
115
|
+
await flush();
|
|
116
|
+
}
|
|
117
|
+
zip.end();
|
|
118
|
+
await flush();
|
|
119
|
+
out.end();
|
|
120
|
+
await finished(out);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
zip.terminate();
|
|
124
|
+
out.destroy();
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Zips an `expo export` directory the way Molt expects it: `metadata.json` and `expoconfig.json`
|
|
130
|
+
* at the root. `expoConfig` is the output of `expo config --type public --json`. Without it the
|
|
131
|
+
* directory must already contain an `expoconfig.json`.
|
|
132
|
+
*/
|
|
133
|
+
export async function buildArchive(options) {
|
|
134
|
+
const entries = await collectFiles(options.exportDir);
|
|
135
|
+
const byName = new Map(entries.map((entry) => [entry.name, entry]));
|
|
136
|
+
const metadataEntry = byName.get('metadata.json');
|
|
137
|
+
if (!metadataEntry?.file) {
|
|
138
|
+
throw new CliError(`${options.exportDir} has no metadata.json. Is it the output of "expo export"?`);
|
|
139
|
+
}
|
|
140
|
+
const metadata = inspectMetadata(await readFile(metadataEntry.file));
|
|
141
|
+
metadataEntry.data = metadata.data;
|
|
142
|
+
metadataEntry.size = metadata.data.length;
|
|
143
|
+
const missing = metadata.referenced.filter((name) => !byName.has(name));
|
|
144
|
+
if (missing.length > 0) {
|
|
145
|
+
const shown = missing.slice(0, 5).join(', ');
|
|
146
|
+
throw new CliError(`metadata.json refers to files that are missing from the export: ${shown}${missing.length > 5 ? ', …' : ''}.`, [
|
|
147
|
+
'Run the export again and upload its complete output.',
|
|
148
|
+
]);
|
|
149
|
+
}
|
|
150
|
+
if (options.expoConfig !== undefined) {
|
|
151
|
+
const data = Buffer.from(JSON.stringify(options.expoConfig));
|
|
152
|
+
byName.set('expoconfig.json', { name: 'expoconfig.json', data, size: data.length });
|
|
153
|
+
}
|
|
154
|
+
else if (!byName.has('expoconfig.json')) {
|
|
155
|
+
throw new CliError(`${options.exportDir} has no expoconfig.json.`, [
|
|
156
|
+
'Run "npx expo config --type public --json > expoconfig.json" in the project and put the file next to metadata.json.',
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
const all = [...byName.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
160
|
+
await writeZip(all, options.outFile);
|
|
161
|
+
const bytes = all.reduce((sum, entry) => sum + entry.size, 0);
|
|
162
|
+
const archiveBytes = (await stat(options.outFile)).size;
|
|
163
|
+
const warnings = [];
|
|
164
|
+
if (metadata.hasWeb) {
|
|
165
|
+
warnings.push('The export contains a web bundle. Molt ignores it, but it enlarges the archive. Export only iOS and Android.');
|
|
166
|
+
}
|
|
167
|
+
if (all.length > LIMITS.entries)
|
|
168
|
+
warnings.push(`The archive has ${all.length} files. Molt rejects more than ${LIMITS.entries} by default (OTA_MAX_ZIP_ENTRIES).`);
|
|
169
|
+
if (bytes > LIMITS.expandedBytes)
|
|
170
|
+
warnings.push('The export is larger than 1 GiB. Molt rejects that by default (OTA_MAX_EXPANDED_BYTES).');
|
|
171
|
+
if (archiveBytes > LIMITS.archiveBytes)
|
|
172
|
+
warnings.push('The archive is larger than 512 MiB. Molt rejects that by default (OTA_MAX_UPLOAD_BYTES).');
|
|
173
|
+
return { entries: all.length, bytes, archiveBytes, platforms: metadata.platforms, warnings };
|
|
174
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "molt-ota",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Command-line client for the Molt self-hosted Expo Updates server: publish updates, roll them out and roll them back.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"molt-ota": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=22"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"expo",
|
|
20
|
+
"expo-updates",
|
|
21
|
+
"ota",
|
|
22
|
+
"over-the-air",
|
|
23
|
+
"self-hosted",
|
|
24
|
+
"react-native",
|
|
25
|
+
"molt"
|
|
26
|
+
],
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/Shweit/molt.git",
|
|
30
|
+
"directory": "cli"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/Shweit/molt#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/Shweit/molt/issues"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.build.json",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"test": "node --test test/*.test.ts",
|
|
43
|
+
"prepack": "npm run build"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"fflate": "0.8.3"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "22.20.5",
|
|
50
|
+
"typescript": "5.9.3"
|
|
51
|
+
}
|
|
52
|
+
}
|