@mintlify/cli 4.0.1358 → 4.0.1360
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/bin/addDomain.js +49 -9
- package/bin/cli.js +7 -2
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/addDomain.tsx +74 -4
- package/src/cli.tsx +11 -6
package/bin/addDomain.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { getRelativeRecordName } from '@mintlify/common';
|
|
11
|
+
import { getRelativeRecordName, normalizeBasePath, validateCustomDomainBasePath, } from '@mintlify/common';
|
|
12
12
|
import { addLog, ErrorLog, removeLastLog, SpinnerLog, SuccessLog } from '@mintlify/previewing';
|
|
13
13
|
import { Box, Text } from 'ink';
|
|
14
14
|
import { authenticatedFetch } from './authenticatedFetch.js';
|
|
@@ -19,13 +19,21 @@ import { getCliSubdomains } from './status.js';
|
|
|
19
19
|
const DNS_POLL_INTERVAL_MS = 5000;
|
|
20
20
|
const DNS_POLL_MAX_ATTEMPTS = 3;
|
|
21
21
|
const DOMAIN_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/i;
|
|
22
|
-
export function addDomain(domain) {
|
|
22
|
+
export function addDomain(domain, basePath) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var _a, _b, _c;
|
|
24
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
25
25
|
if (!DOMAIN_PATTERN.test(domain)) {
|
|
26
26
|
addLog(_jsx(ErrorLog, { message: `invalid domain "${domain}". Expected a bare hostname, e.g. docs.example.com` }));
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
+
const normalizedBasePath = normalizeBasePath(basePath === null || basePath === void 0 ? void 0 : basePath.trim());
|
|
30
|
+
if (normalizedBasePath) {
|
|
31
|
+
const basePathError = validateCustomDomainBasePath(normalizedBasePath);
|
|
32
|
+
if (basePathError) {
|
|
33
|
+
addLog(_jsx(ErrorLog, { message: `invalid base path "${basePath}": ${basePathError}` }));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
29
37
|
const accessToken = yield getAccessToken();
|
|
30
38
|
if (!accessToken) {
|
|
31
39
|
addLog(_jsx(ErrorLog, { message: "not logged in. Run `mint login` to authenticate." }));
|
|
@@ -44,7 +52,7 @@ export function addDomain(domain) {
|
|
|
44
52
|
const addRes = yield authenticatedFetch(`${API_URL}/api/cli/deployment/custom-domain/${subdomain}/${domain}`, {
|
|
45
53
|
method: 'POST',
|
|
46
54
|
headers: { 'Content-Type': 'application/json' },
|
|
47
|
-
body: JSON.stringify({ basePath: '' }),
|
|
55
|
+
body: JSON.stringify({ basePath: normalizedBasePath ? '/docs' : '' }),
|
|
48
56
|
});
|
|
49
57
|
if (!addRes.ok) {
|
|
50
58
|
const body = yield addRes.json().catch(() => ({}));
|
|
@@ -52,10 +60,37 @@ export function addDomain(domain) {
|
|
|
52
60
|
return;
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
|
-
catch (
|
|
63
|
+
catch (_h) {
|
|
56
64
|
addLog(_jsx(ErrorLog, { message: "could not reach the server" }));
|
|
57
65
|
return;
|
|
58
66
|
}
|
|
67
|
+
let basePathSaved = false;
|
|
68
|
+
let basePathPending = false;
|
|
69
|
+
if (normalizedBasePath) {
|
|
70
|
+
addLog(_jsx(SpinnerLog, { message: `setting base path to ${normalizedBasePath}...` }));
|
|
71
|
+
try {
|
|
72
|
+
const basePathRes = yield authenticatedFetch(`${API_URL}/api/cli/deployment/base-path/${subdomain}`, {
|
|
73
|
+
method: 'PUT',
|
|
74
|
+
headers: { 'Content-Type': 'application/json' },
|
|
75
|
+
body: JSON.stringify({ basePath: normalizedBasePath }),
|
|
76
|
+
});
|
|
77
|
+
removeLastLog();
|
|
78
|
+
if (basePathRes.ok) {
|
|
79
|
+
const body = (yield basePathRes.json().catch(() => ({})));
|
|
80
|
+
basePathSaved = true;
|
|
81
|
+
basePathPending = Boolean(body.pendingBasePathUpdate);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const body = (yield basePathRes.json().catch(() => ({})));
|
|
85
|
+
const reason = (_e = (_d = (_c = (_b = body.issues) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : body.error) !== null && _e !== void 0 ? _e : 'unknown error';
|
|
86
|
+
addLog(_jsx(ErrorLog, { message: `domain added, but base path was not saved: ${reason}` }));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (_j) {
|
|
90
|
+
removeLastLog();
|
|
91
|
+
addLog(_jsx(ErrorLog, { message: "domain added, but base path was not saved: could not reach the server" }));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
59
94
|
const maxWaitSeconds = ((DNS_POLL_MAX_ATTEMPTS - 1) * DNS_POLL_INTERVAL_MS) / 1000;
|
|
60
95
|
addLog(_jsx(SpinnerLog, { message: `waiting for DNS records to generate (up to ${maxWaitSeconds}s)...` }));
|
|
61
96
|
let dnsRecords = [];
|
|
@@ -65,7 +100,7 @@ export function addDomain(domain) {
|
|
|
65
100
|
const checkRes = yield authenticatedFetch(`${API_URL}/api/cli/deployment/custom-domain/${subdomain}/${domain}`);
|
|
66
101
|
if (checkRes.ok) {
|
|
67
102
|
const body = (yield checkRes.json());
|
|
68
|
-
dnsRecords = (
|
|
103
|
+
dnsRecords = (_g = (_f = body.cloudflare) === null || _f === void 0 ? void 0 : _f.dnsRecords) !== null && _g !== void 0 ? _g : [];
|
|
69
104
|
const stillGenerating = dnsRecords.some((record) => record.value === 'loading');
|
|
70
105
|
if (dnsRecords.length > 0 && !stillGenerating) {
|
|
71
106
|
recordsReady = true;
|
|
@@ -77,14 +112,19 @@ export function addDomain(domain) {
|
|
|
77
112
|
}
|
|
78
113
|
}
|
|
79
114
|
}
|
|
80
|
-
catch (
|
|
115
|
+
catch (_k) {
|
|
81
116
|
removeLastLog();
|
|
82
117
|
addLog(_jsx(ErrorLog, { message: "domain added, but could not fetch DNS records" }));
|
|
83
118
|
return;
|
|
84
119
|
}
|
|
85
120
|
removeLastLog();
|
|
86
121
|
const readyTxtRecords = dnsRecords.filter((record) => record.type === 'TXT' && record.value !== 'loading');
|
|
87
|
-
|
|
88
|
-
|
|
122
|
+
const successMessage = basePathPending
|
|
123
|
+
? `domain ${domain} added; base path ${normalizedBasePath} queued for the next deploy`
|
|
124
|
+
: basePathSaved
|
|
125
|
+
? `domain ${domain} added (serving at ${normalizedBasePath})`
|
|
126
|
+
: `domain ${domain} added`;
|
|
127
|
+
addLog(_jsx(SuccessLog, { message: successMessage }));
|
|
128
|
+
addLog(_jsxs(Box, { flexDirection: "column", gap: 1, paddingY: 1, children: [_jsx(Text, { bold: true, children: "Add these DNS records with your domain provider:" }), _jsxs(Box, { flexDirection: "column", paddingLeft: 3, children: [readyTxtRecords.map((record) => (_jsxs(Text, { children: ["TXT ", getRelativeRecordName(record.domain, domain), " \u2192 ", record.value] }, record.domain))), _jsxs(Text, { children: ["CNAME ", getRelativeRecordName(domain, domain), " \u2192 ", CUSTOM_DOMAIN_CNAME_TARGET] })] }), _jsx(Text, { dimColor: true, children: "Add the TXT records first; add the CNAME once they're validated." }), basePathPending && (_jsx(Text, { dimColor: true, children: "The base path takes effect when that deploy finishes; the current path stays up until then." })), basePathSaved && (_jsxs(Text, { dimColor: true, children: ["The CNAME sends all paths on ", domain, " to Mintlify. Only add it if this domain hosts nothing else. Otherwise, set up a reverse proxy for ", normalizedBasePath, ": https://www.mintlify.com/docs/deploy/docs-subpath"] })), !recordsReady && (_jsx(Text, { dimColor: true, children: "Some TXT records are still being generated. Check the dashboard in a moment for the rest." }))] }));
|
|
89
129
|
});
|
|
90
130
|
}
|
package/bin/cli.js
CHANGED
|
@@ -372,12 +372,17 @@ export const cli = ({ packageName = 'mint' }) => {
|
|
|
372
372
|
});
|
|
373
373
|
yield terminate(0);
|
|
374
374
|
}))
|
|
375
|
-
.command('add-domain <domain>', 'Add a custom domain to your deployment', (yargs) => yargs
|
|
375
|
+
.command('add-domain <domain>', 'Add a custom domain to your deployment', (yargs) => yargs
|
|
376
|
+
.positional('domain', {
|
|
376
377
|
type: 'string',
|
|
377
378
|
demandOption: true,
|
|
378
379
|
description: 'The custom domain to add (e.g. docs.example.com)',
|
|
380
|
+
})
|
|
381
|
+
.option('basePath', {
|
|
382
|
+
type: 'string',
|
|
383
|
+
description: 'Serve the docs under a base path (e.g. /docs)',
|
|
379
384
|
}), (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
380
|
-
yield addDomain(argv.domain);
|
|
385
|
+
yield addDomain(argv.domain, argv.basePath);
|
|
381
386
|
yield terminate(0);
|
|
382
387
|
}))
|
|
383
388
|
.command('config', 'Manage CLI configuration', (yargs) => yargs
|