@workover/mcp 0.10.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -2
- package/feedback.mjs +123 -0
- package/index.mjs +313 -17
- package/lib.mjs +425 -4
- package/package.json +5 -2
- package/site-folder.mjs +778 -0
- package/site-setup.mjs +925 -0
package/site-folder.mjs
ADDED
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
// A Help Center from a docs folder on disk: `workover site import --dir`, `workover site appearance`,
|
|
2
|
+
// `workover site redirects`, and the MCP server's tools for the same.
|
|
3
|
+
//
|
|
4
|
+
// THE SAME FILE ships in @workover/cli (apps/cli/site-folder.mjs) and @workover/mcp
|
|
5
|
+
// (apps/mcp/site-folder.mjs), as site-setup.mjs does; `apps/mcp/site-setup.test.mjs` fails when the
|
|
6
|
+
// copies differ.
|
|
7
|
+
//
|
|
8
|
+
// WHY THIS EXISTS. The agent setup flow (WO-1401) could import a docs site from a URL, but not the
|
|
9
|
+
// docs a person keeps in a folder or a repository, and not the site's branding. Workover's own Help
|
|
10
|
+
// Center (docs-seed/ in this repo) was loaded by a script that signed in with a browser session
|
|
11
|
+
// cookie, which is exactly what an agent must not need (WO-1421). Everything here goes through
|
|
12
|
+
// routes a `site` token reaches (`workover login --site`).
|
|
13
|
+
//
|
|
14
|
+
// Two layouts are read:
|
|
15
|
+
//
|
|
16
|
+
// - **Workover's folder** (docs-seed/): `_site.json` (name, subdomain, `tabs` with their folders
|
|
17
|
+
// and groups, `appearance`, `redirects`, optional `assets`) and `<tab>/<slug>.md` pages whose
|
|
18
|
+
// front matter gives title, description, group, order, icon, slug, hidden and redirect_from.
|
|
19
|
+
// - **Mintlify's** (`docs.json`, or the older `mint.json`): its navigation (tabs, groups, pages),
|
|
20
|
+
// each page `<path>.mdx` or `<path>.md`, its `redirects`, colors, logo and favicon.
|
|
21
|
+
//
|
|
22
|
+
// Pages are sent as Markdown and rendered by the API with its importer's converter (MDX, Mintlify's
|
|
23
|
+
// components, GitHub alerts), so a folder becomes the same documents an import of the published
|
|
24
|
+
// site would. An import is keyed by page address: a page the site already has keeps its document
|
|
25
|
+
// and its edits, so running it again adds only what is new.
|
|
26
|
+
//
|
|
27
|
+
// No ANSI and no network of its own: `call(path, { method, body })` is the same caller site-setup.mjs
|
|
28
|
+
// takes, and `upload(projectId, file)` posts a file to the logo route and resolves its URL.
|
|
29
|
+
|
|
30
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
31
|
+
import { basename, dirname, extname, join, relative, sep } from 'node:path';
|
|
32
|
+
|
|
33
|
+
/** The API takes 5 MB of JSON per request; each import stays under this. */
|
|
34
|
+
export const MAX_IMPORT_BYTES = 4 * 1024 * 1024;
|
|
35
|
+
/** A site keeps at most this many redirects (sites.service.ts saveRedirects). */
|
|
36
|
+
export const MAX_REDIRECTS = 500;
|
|
37
|
+
/** The logo route's limit (site-assets), checked before the upload so a wrong pick says so at once. */
|
|
38
|
+
export const MAX_ASSET_BYTES = 2 * 1024 * 1024;
|
|
39
|
+
export const ASSET_TYPES = {
|
|
40
|
+
'.svg': 'image/svg+xml',
|
|
41
|
+
'.png': 'image/png',
|
|
42
|
+
'.jpg': 'image/jpeg',
|
|
43
|
+
'.jpeg': 'image/jpeg',
|
|
44
|
+
'.webp': 'image/webp',
|
|
45
|
+
'.ico': 'image/x-icon',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const folderError = (message) => Object.assign(new Error(message), { status: 400 });
|
|
49
|
+
|
|
50
|
+
// ------------------------------------------------------------------ small parsers
|
|
51
|
+
|
|
52
|
+
/** `s` without any run of `ch` at either end: loops, not a regex, so a long run costs linear time. */
|
|
53
|
+
function trimChar(s, ch) {
|
|
54
|
+
let start = 0;
|
|
55
|
+
let end = s.length;
|
|
56
|
+
while (start < end && s[start] === ch) start += 1;
|
|
57
|
+
while (end > start && s[end - 1] === ch) end -= 1;
|
|
58
|
+
return s.slice(start, end);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function scalar(raw) {
|
|
62
|
+
const v = raw.trim();
|
|
63
|
+
if (v.startsWith('"')) {
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(v);
|
|
66
|
+
} catch {
|
|
67
|
+
return v.slice(1, v.endsWith('"') ? -1 : undefined);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (v.startsWith("'") && v.endsWith("'") && v.length >= 2) return v.slice(1, -1).split("''").join("'");
|
|
71
|
+
if (/^-?\d+(\.\d+)?$/.test(v)) return Number(v);
|
|
72
|
+
if (v === 'true' || v === 'false') return v === 'true';
|
|
73
|
+
return v;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Front matter as `{ data, body }`: `key: value` lines (a value quoted, a number, true/false or a
|
|
78
|
+
* bare word) and `key:` followed by ` - item` lines for a list. A file with none is all body.
|
|
79
|
+
*/
|
|
80
|
+
export function parseFrontMatter(text) {
|
|
81
|
+
const src = String(text ?? '').replace(/\r\n?/g, '\n');
|
|
82
|
+
if (!src.startsWith('---\n')) return { data: {}, body: src };
|
|
83
|
+
const end = src.indexOf('\n---', 4);
|
|
84
|
+
if (end < 0) return { data: {}, body: src };
|
|
85
|
+
const data = {};
|
|
86
|
+
let list = null;
|
|
87
|
+
for (const line of src.slice(4, end).split('\n')) {
|
|
88
|
+
if (!line.trim() || line.trim().startsWith('#')) continue;
|
|
89
|
+
const item = /^\s+-\s+(.*)$/.exec(line);
|
|
90
|
+
if (item && list) {
|
|
91
|
+
list.push(scalar(item[1]));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const kv = /^([A-Za-z_][\w-]*):(.*)$/.exec(line);
|
|
95
|
+
if (!kv) continue;
|
|
96
|
+
if (kv[2].trim() === '') list = data[kv[1]] = [];
|
|
97
|
+
else {
|
|
98
|
+
list = null;
|
|
99
|
+
data[kv[1]] = scalar(kv[2]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const after = src.indexOf('\n', end + 4);
|
|
103
|
+
return { data, body: after < 0 ? '' : src.slice(after + 1) };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** A page address the API takes: lowercase segments of letters, digits and hyphens. */
|
|
107
|
+
export function slugFrom(path) {
|
|
108
|
+
const parts = String(path ?? '')
|
|
109
|
+
.split('/')
|
|
110
|
+
.map((p) =>
|
|
111
|
+
trimChar(
|
|
112
|
+
p
|
|
113
|
+
.trim()
|
|
114
|
+
.toLowerCase()
|
|
115
|
+
.replace(/\.(mdx|md)$/, '')
|
|
116
|
+
.replace(/[^a-z0-9-]+/g, '-'),
|
|
117
|
+
'-',
|
|
118
|
+
),
|
|
119
|
+
)
|
|
120
|
+
.filter(Boolean);
|
|
121
|
+
return parts.join('/');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const CALLOUTS = new Set(['note', 'info', 'tip', 'warning', 'check', 'danger']);
|
|
125
|
+
|
|
126
|
+
/** The attribute value of an MDX prop, with what would close it escaped. */
|
|
127
|
+
const attr = (s) => String(s ?? '').split('&').join('&').split('"').join('"');
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* A docs-seed page's own Markdown in the dialect the API's converter reads:
|
|
131
|
+
*
|
|
132
|
+
* - a card grid, `:::cards 2` then `- Title | /href | icon | Text.` lines and `:::`, becomes
|
|
133
|
+
* `<CardGroup cols={2}>` with a `<Card>` per line;
|
|
134
|
+
* - a callout, a quote opening `> **Warning:** text`, becomes a GitHub alert (`> [!WARNING]`).
|
|
135
|
+
*
|
|
136
|
+
* Code blocks are left as they are.
|
|
137
|
+
*/
|
|
138
|
+
export function seedMarkdown(markdown) {
|
|
139
|
+
const out = [];
|
|
140
|
+
let fence = null;
|
|
141
|
+
let cards = null;
|
|
142
|
+
for (const line of String(markdown ?? '').replace(/\r\n?/g, '\n').split('\n')) {
|
|
143
|
+
const f = /^\s*(`{3,}|~{3,})/.exec(line);
|
|
144
|
+
if (fence) {
|
|
145
|
+
out.push(line);
|
|
146
|
+
if (f && f[1][0] === fence[0] && f[1].length >= fence.length) fence = null;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (cards) {
|
|
150
|
+
if (line.trim() === ':::') {
|
|
151
|
+
out.push(`<CardGroup cols={${cards.cols}}>`, ...cards.items, '</CardGroup>');
|
|
152
|
+
cards = null;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const item = line.trim().startsWith('-') ? line.trim().slice(1) : '';
|
|
156
|
+
const [title, href, icon, text] = item.split('|').map((s) => s.trim());
|
|
157
|
+
if (title) {
|
|
158
|
+
const props = [`title="${attr(title)}"`, href ? `href="${attr(href)}"` : '', icon ? `icon="${attr(icon)}"` : '']
|
|
159
|
+
.filter(Boolean)
|
|
160
|
+
.join(' ');
|
|
161
|
+
cards.items.push(`<Card ${props}>`, text || '', '</Card>');
|
|
162
|
+
}
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (f) {
|
|
166
|
+
fence = f[1];
|
|
167
|
+
out.push(line);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const open = /^:::cards(?:\s+(\d))?$/.exec(line.trim());
|
|
171
|
+
if (open) {
|
|
172
|
+
cards = { cols: open[1] || '2', items: [] };
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const callout = /^>\s*\*\*([A-Za-z]+):?\*\*:?\s?(.*)$/.exec(line);
|
|
176
|
+
if (callout && CALLOUTS.has(callout[1].toLowerCase())) {
|
|
177
|
+
out.push(`> [!${callout[1].toUpperCase()}]`);
|
|
178
|
+
if (callout[2]) out.push(`> ${callout[2]}`);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
out.push(line);
|
|
182
|
+
}
|
|
183
|
+
return out.join('\n');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ------------------------------------------------------------------ reading a folder
|
|
187
|
+
|
|
188
|
+
function walk(dir) {
|
|
189
|
+
const out = [];
|
|
190
|
+
for (const name of readdirSync(dir).sort()) {
|
|
191
|
+
if (name.startsWith('.')) continue;
|
|
192
|
+
const p = join(dir, name);
|
|
193
|
+
if (statSync(p).isDirectory()) out.push(...walk(p));
|
|
194
|
+
else if (/\.(md|mdx)$/i.test(name)) out.push(p);
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const posix = (p) => p.split(sep).join('/');
|
|
200
|
+
|
|
201
|
+
/** Markdown with its code blocks and code spans taken out, so an example in them is not read. */
|
|
202
|
+
function withoutCode(markdown) {
|
|
203
|
+
const kept = [];
|
|
204
|
+
let fence = null;
|
|
205
|
+
for (const line of String(markdown).split('\n')) {
|
|
206
|
+
const f = /^\s*(`{3,}|~{3,})/.exec(line);
|
|
207
|
+
if (fence) {
|
|
208
|
+
if (f && f[1][0] === fence[0] && f[1].length >= fence.length) fence = null;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (f) {
|
|
212
|
+
fence = f[1];
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
// Between an odd and an even backtick is a code span.
|
|
216
|
+
kept.push(line.split('`').filter((_, i) => i % 2 === 0).join(' '));
|
|
217
|
+
}
|
|
218
|
+
return kept.join('\n');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Images a page names by a path in the folder: they cannot be read from there, so they are named. */
|
|
222
|
+
function localImages(source) {
|
|
223
|
+
const markdown = withoutCode(source);
|
|
224
|
+
const out = [];
|
|
225
|
+
for (const m of String(markdown).matchAll(/!\[[^\]]*\]\(\s*<?([^)\s>]+)/g)) {
|
|
226
|
+
const src = m[1];
|
|
227
|
+
if (!/^(https?:|data:)/i.test(src)) out.push(src);
|
|
228
|
+
}
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The folder a config sits in, and the config, from a folder or the config file itself. */
|
|
233
|
+
function locate(path) {
|
|
234
|
+
const p = String(path ?? '').trim();
|
|
235
|
+
if (!p) throw folderError('Name the docs folder with --dir <path>.');
|
|
236
|
+
if (!existsSync(p)) throw folderError(`${p}: no such file or folder.`);
|
|
237
|
+
if (statSync(p).isFile()) return { dir: dirname(p), file: p };
|
|
238
|
+
for (const name of ['_site.json', 'docs.json', 'mint.json'])
|
|
239
|
+
if (existsSync(join(p, name))) return { dir: p, file: join(p, name) };
|
|
240
|
+
throw folderError(
|
|
241
|
+
`${p} has no _site.json (a Workover docs folder) and no docs.json or mint.json (a Mintlify one).`,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const readJson = (file) => {
|
|
246
|
+
try {
|
|
247
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
248
|
+
} catch (e) {
|
|
249
|
+
throw folderError(`${file}: not valid JSON (${e.message}).`);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/** A Workover docs folder (`_site.json` + `<tab>/<slug>.md`), as the plan the API is sent. */
|
|
254
|
+
function workoverFolder(dir, site) {
|
|
255
|
+
if (!Array.isArray(site.tabs) || !site.tabs.length)
|
|
256
|
+
throw folderError('_site.json lists no tabs. Each needs a dir, a title and its groups.');
|
|
257
|
+
const warnings = [];
|
|
258
|
+
const imports = [];
|
|
259
|
+
const icons = {};
|
|
260
|
+
const redirects = [];
|
|
261
|
+
const apiReferences = [];
|
|
262
|
+
const seen = new Map();
|
|
263
|
+
for (const tab of site.tabs) {
|
|
264
|
+
const tabDir = join(dir, String(tab.dir ?? ''));
|
|
265
|
+
// A tab made from an OpenAPI spec (WO-1432): the Help Center makes its pages and keeps them in
|
|
266
|
+
// step with the spec, so it needs no folder. One with a folder as well keeps those pages first.
|
|
267
|
+
if (typeof tab.openapi === 'string') {
|
|
268
|
+
const ref = specReference(tab.openapi, { tab: tab.title, directory: tab.directory }, '_site.json', warnings);
|
|
269
|
+
if (ref) apiReferences.push(ref);
|
|
270
|
+
if (tab.icon) icons[`group:${tab.title}`] = String(tab.icon);
|
|
271
|
+
if (!tab.dir) continue;
|
|
272
|
+
}
|
|
273
|
+
if (!tab.dir || !existsSync(tabDir)) {
|
|
274
|
+
warnings.push(`_site.json: the folder for tab "${tab.title}" (${tab.dir}) does not exist.`);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (tab.icon) icons[`group:${tab.title}`] = String(tab.icon);
|
|
278
|
+
const groups = Array.isArray(tab.groups) ? tab.groups.map(String) : [];
|
|
279
|
+
const pages = [];
|
|
280
|
+
for (const file of walk(tabDir)) {
|
|
281
|
+
const rel = posix(relative(dir, file));
|
|
282
|
+
const { data, body } = parseFrontMatter(readFileSync(file, 'utf8'));
|
|
283
|
+
const slug = slugFrom(data.slug ?? posix(relative(tabDir, file)));
|
|
284
|
+
if (!slug) {
|
|
285
|
+
warnings.push(`${rel}: no usable address; left out.`);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (seen.has(slug)) {
|
|
289
|
+
warnings.push(`${rel}: the address "${slug}" is also ${seen.get(slug)}'s; left out.`);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
seen.set(slug, rel);
|
|
293
|
+
const group = data.group === undefined ? groups[0] : String(data.group);
|
|
294
|
+
if (!groups.includes(group)) warnings.push(`${rel}: group "${group}" is not one of ${tab.title}'s; placed last.`);
|
|
295
|
+
for (const img of localImages(body)) warnings.push(`${rel}: the image ${img} is a file in the folder, which is not uploaded.`);
|
|
296
|
+
if (data.icon) icons[`page:${slug}`] = String(data.icon);
|
|
297
|
+
for (const from of Array.isArray(data.redirect_from) ? data.redirect_from : []) {
|
|
298
|
+
const f = slugFrom(from);
|
|
299
|
+
if (f && f !== slug) redirects.push({ from: f, to: slug });
|
|
300
|
+
}
|
|
301
|
+
pages.push({
|
|
302
|
+
slug,
|
|
303
|
+
group,
|
|
304
|
+
order: typeof data.order === 'number' ? data.order : Number.POSITIVE_INFINITY,
|
|
305
|
+
title: typeof data.title === 'string' ? data.title : basename(file, extname(file)),
|
|
306
|
+
article: {
|
|
307
|
+
slug,
|
|
308
|
+
...(typeof data.title === 'string' ? { title: data.title } : {}),
|
|
309
|
+
...(typeof data.description === 'string' ? { description: data.description } : {}),
|
|
310
|
+
markdown: seedMarkdown(body),
|
|
311
|
+
...(data.hidden === true ? { hidden: true } : {}),
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
const order = [...groups, ...new Set(pages.map((p) => p.group).filter((g) => !groups.includes(g)))];
|
|
316
|
+
const children = order
|
|
317
|
+
.map((g) => ({
|
|
318
|
+
kind: 'group',
|
|
319
|
+
title: g,
|
|
320
|
+
children: pages
|
|
321
|
+
.filter((p) => p.group === g)
|
|
322
|
+
.sort((a, b) => a.order - b.order || a.title.localeCompare(b.title))
|
|
323
|
+
.map((p) => ({ kind: 'page', slug: p.slug })),
|
|
324
|
+
}))
|
|
325
|
+
.filter((g) => g.children.length);
|
|
326
|
+
if (!pages.length) continue;
|
|
327
|
+
imports.push({
|
|
328
|
+
tab: String(tab.title),
|
|
329
|
+
export: { nav: [{ kind: 'group', title: String(tab.title), children }], articles: pages.map((p) => p.article) },
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
for (const r of Array.isArray(site.redirects) ? site.redirects : []) {
|
|
333
|
+
const from = slugFrom(r?.from);
|
|
334
|
+
const to = /^https:\/\//.test(String(r?.to ?? '')) ? String(r.to) : slugFrom(r?.to);
|
|
335
|
+
if (from && to) redirects.push({ from, to });
|
|
336
|
+
}
|
|
337
|
+
const assets = {};
|
|
338
|
+
for (const key of ['logoLight', 'logoDark', 'favicon', 'faviconDark'])
|
|
339
|
+
if (typeof site.assets?.[key] === 'string') assets[key] = join(dir, site.assets[key]);
|
|
340
|
+
return {
|
|
341
|
+
layout: 'workover',
|
|
342
|
+
dir,
|
|
343
|
+
name: typeof site.name === 'string' ? site.name : null,
|
|
344
|
+
subdomain: typeof site.subdomain === 'string' ? site.subdomain : null,
|
|
345
|
+
imports,
|
|
346
|
+
structure: { navigation: 'tabs', icons },
|
|
347
|
+
appearance: site.appearance && typeof site.appearance === 'object' ? site.appearance : {},
|
|
348
|
+
assets,
|
|
349
|
+
redirects,
|
|
350
|
+
apiReferences,
|
|
351
|
+
warnings,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* A spec-backed API reference as the API is sent it, or null (with a warning) when the spec is not
|
|
357
|
+
* one a hosted site can read again: an https URL, or `{api}/openapi.json` for the environment's own
|
|
358
|
+
* API (how Workover's own docs-seed names its spec, so the same folder imports into staging and
|
|
359
|
+
* production). A file in the folder is not: the site re-reads the spec every hour.
|
|
360
|
+
*/
|
|
361
|
+
function specReference(spec, { tab, group, directory }, where, warnings) {
|
|
362
|
+
const value = String(spec).trim();
|
|
363
|
+
if (!value.startsWith('{api}/') && !value.startsWith('https://')) {
|
|
364
|
+
warnings.push(
|
|
365
|
+
`${where}: the OpenAPI spec of "${group ?? tab}" (${value}) is not an https URL, so it was not added. Publish the spec and name its URL; the site reads it again whenever it changes.`,
|
|
366
|
+
);
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
spec: value,
|
|
371
|
+
tab: String(tab),
|
|
372
|
+
...(group ? { group: String(group) } : {}),
|
|
373
|
+
...(typeof directory === 'string' ? { directory } : {}),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** One page of a Mintlify navigation: its file, read as it is (the API reads its front matter). */
|
|
378
|
+
function mintlifyPage(dir, path, ctx) {
|
|
379
|
+
const ref = trimChar(String(path), '/');
|
|
380
|
+
const file = ['.mdx', '.md'].map((ext) => join(dir, `${ref}${ext}`)).find((f) => existsSync(f));
|
|
381
|
+
if (!file) {
|
|
382
|
+
ctx.warnings.push(`${ref}: listed in the navigation, but there is no ${ref}.mdx or ${ref}.md; left out.`);
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
const slug = slugFrom(ref);
|
|
386
|
+
if (!slug || ctx.seen.has(slug)) return slug ? { kind: 'page', slug } : null;
|
|
387
|
+
const markdown = readFileSync(file, 'utf8');
|
|
388
|
+
for (const img of localImages(markdown))
|
|
389
|
+
ctx.warnings.push(`${ref}: the image ${img} is a file in the folder, which is not uploaded.`);
|
|
390
|
+
ctx.seen.add(slug);
|
|
391
|
+
ctx.articles.push({ slug, markdown });
|
|
392
|
+
return { kind: 'page', slug };
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** A Mintlify navigation entry list (strings, and `{ group, pages }` objects) as nav items. */
|
|
396
|
+
function mintlifyItems(dir, entries, ctx) {
|
|
397
|
+
const out = [];
|
|
398
|
+
for (const e of Array.isArray(entries) ? entries : []) {
|
|
399
|
+
if (typeof e === 'string') {
|
|
400
|
+
const page = mintlifyPage(dir, e, ctx);
|
|
401
|
+
if (page) out.push(page);
|
|
402
|
+
} else if (e && typeof e === 'object' && typeof e.page === 'string') {
|
|
403
|
+
const page = mintlifyPage(dir, e.page, ctx);
|
|
404
|
+
if (page) out.push(page);
|
|
405
|
+
} else if (e && typeof e === 'object' && (e.group || e.pages)) {
|
|
406
|
+
const children = mintlifyItems(dir, e.pages, ctx);
|
|
407
|
+
if (e.icon && e.group) ctx.icons[`group:${e.group}`] = String(e.icon);
|
|
408
|
+
if (children.length) out.push({ kind: 'group', title: String(e.group ?? 'Pages'), children });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** A Mintlify folder (`docs.json` or `mint.json`), as the plan the API is sent. */
|
|
415
|
+
function mintlifyFolder(dir, config, fileName) {
|
|
416
|
+
const ctx = { warnings: [], seen: new Set(), articles: [], icons: {}, apiReferences: [] };
|
|
417
|
+
const nav = config.navigation;
|
|
418
|
+
const sections = [];
|
|
419
|
+
if (Array.isArray(nav)) sections.push({ title: null, items: mintlifyItems(dir, nav, ctx) });
|
|
420
|
+
else if (nav && typeof nav === 'object') {
|
|
421
|
+
if (Array.isArray(nav.tabs) && nav.tabs.length) {
|
|
422
|
+
for (const tab of nav.tabs) {
|
|
423
|
+
const title = String(tab.tab ?? tab.name ?? 'Docs');
|
|
424
|
+
if (tab.icon) ctx.icons[`group:${title}`] = String(tab.icon);
|
|
425
|
+
// A tab or group whose pages are made from a spec: `"openapi": "<url>"` (or `{ source }`).
|
|
426
|
+
const specOf = (o) => (typeof o?.openapi === 'string' ? o.openapi : typeof o?.openapi?.source === 'string' ? o.openapi.source : null);
|
|
427
|
+
if (specOf(tab)) {
|
|
428
|
+
const ref = specReference(specOf(tab), { tab: title }, fileName, ctx.warnings);
|
|
429
|
+
if (ref) ctx.apiReferences.push(ref);
|
|
430
|
+
}
|
|
431
|
+
for (const g of Array.isArray(tab.groups) ? tab.groups : [])
|
|
432
|
+
if (g && typeof g === 'object' && specOf(g)) {
|
|
433
|
+
const ref = specReference(specOf(g), { tab: title, group: String(g.group ?? 'API') }, fileName, ctx.warnings);
|
|
434
|
+
if (ref) ctx.apiReferences.push(ref);
|
|
435
|
+
}
|
|
436
|
+
const items = [...mintlifyItems(dir, tab.groups, ctx), ...mintlifyItems(dir, tab.pages, ctx)];
|
|
437
|
+
if (items.length) sections.push({ title, items });
|
|
438
|
+
}
|
|
439
|
+
} else sections.push({ title: null, items: [...mintlifyItems(dir, nav.groups, ctx), ...mintlifyItems(dir, nav.pages, ctx)] });
|
|
440
|
+
for (const key of ['versions', 'languages', 'dropdowns', 'anchors'])
|
|
441
|
+
if (Array.isArray(nav[key]) && nav[key].length)
|
|
442
|
+
ctx.warnings.push(`${fileName}: navigation.${key} is not read from a folder; import the published site with --url for it.`);
|
|
443
|
+
}
|
|
444
|
+
if (!ctx.articles.length && !ctx.apiReferences.length) throw folderError(`${fileName} names no page that exists in ${dir}.`);
|
|
445
|
+
// One request per tab, as the API would get from the tabs' own exports.
|
|
446
|
+
const imports = [];
|
|
447
|
+
for (const s of sections) {
|
|
448
|
+
const slugs = new Set();
|
|
449
|
+
const collect = (items) => {
|
|
450
|
+
for (const i of items) {
|
|
451
|
+
if (i.kind === 'page') slugs.add(i.slug);
|
|
452
|
+
else collect(i.children);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
collect(s.items);
|
|
456
|
+
imports.push({
|
|
457
|
+
tab: s.title ?? 'Pages',
|
|
458
|
+
export: {
|
|
459
|
+
nav: s.title ? [{ kind: 'group', title: s.title, children: s.items }] : s.items,
|
|
460
|
+
articles: ctx.articles.filter((a) => slugs.has(a.slug)),
|
|
461
|
+
},
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const tabs = sections.some((s) => s.title);
|
|
465
|
+
const appearance = {};
|
|
466
|
+
if (typeof config.colors?.primary === 'string') appearance.primary = config.colors.primary;
|
|
467
|
+
if (typeof config.colors?.dark === 'string') appearance.primaryDark = config.colors.dark;
|
|
468
|
+
const assets = {};
|
|
469
|
+
const local = (v) => (typeof v === 'string' && !/^https?:/i.test(v) ? join(dir, trimChar(v, '/')) : null);
|
|
470
|
+
const logo = config.logo;
|
|
471
|
+
const light = local(typeof logo === 'string' ? logo : logo?.light);
|
|
472
|
+
const dark = local(typeof logo === 'string' ? null : logo?.dark);
|
|
473
|
+
const favicon = local(config.favicon);
|
|
474
|
+
if (light) assets.logoLight = light;
|
|
475
|
+
if (dark) assets.logoDark = dark;
|
|
476
|
+
if (favicon) assets.favicon = favicon;
|
|
477
|
+
const redirects = [];
|
|
478
|
+
for (const r of Array.isArray(config.redirects) ? config.redirects : []) {
|
|
479
|
+
const from = slugFrom(r?.source);
|
|
480
|
+
const to = /^https:\/\//.test(String(r?.destination ?? '')) ? String(r.destination) : slugFrom(r?.destination);
|
|
481
|
+
// A pattern (`/old/:slug*`) is not a path: the site's redirects are exact.
|
|
482
|
+
if (from && to && !String(r.source).includes(':') && !String(r.source).includes('*')) redirects.push({ from, to });
|
|
483
|
+
}
|
|
484
|
+
return {
|
|
485
|
+
layout: 'mintlify',
|
|
486
|
+
dir,
|
|
487
|
+
name: typeof config.name === 'string' ? config.name : null,
|
|
488
|
+
subdomain: null,
|
|
489
|
+
imports,
|
|
490
|
+
structure: { navigation: tabs ? 'tabs' : null, icons: ctx.icons },
|
|
491
|
+
appearance,
|
|
492
|
+
assets,
|
|
493
|
+
redirects,
|
|
494
|
+
apiReferences: ctx.apiReferences,
|
|
495
|
+
warnings: ctx.warnings,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** A docs folder (or its `_site.json` / `docs.json`), read into what the API is sent. */
|
|
500
|
+
export function readDocsFolder(path) {
|
|
501
|
+
const { dir, file } = locate(path);
|
|
502
|
+
const name = basename(file);
|
|
503
|
+
const config = readJson(file);
|
|
504
|
+
if (name === '_site.json') return workoverFolder(dir, config);
|
|
505
|
+
if (name === 'docs.json' || name === 'mint.json') return mintlifyFolder(dir, config, name);
|
|
506
|
+
throw folderError(`${file}: expected _site.json, docs.json or mint.json.`);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** How many pages a plan holds. */
|
|
510
|
+
export const pageCount = (plan) => plan.imports.reduce((n, i) => n + i.export.articles.length, 0);
|
|
511
|
+
|
|
512
|
+
// ------------------------------------------------------------------ calls
|
|
513
|
+
|
|
514
|
+
/** Every page address in a draft navigation (GET /sites/project/:id `nav`). */
|
|
515
|
+
export function navSlugs(nav) {
|
|
516
|
+
const out = new Set();
|
|
517
|
+
const walkNav = (items) => {
|
|
518
|
+
for (const i of items ?? []) {
|
|
519
|
+
if (i.kind === 'group') walkNav(i.children);
|
|
520
|
+
else if (i.slug) out.add(i.slug);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
walkNav(nav);
|
|
524
|
+
return out;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
async function siteOf(call, projectId) {
|
|
528
|
+
const view = await call(`/sites/project/${projectId}`);
|
|
529
|
+
if (!view?.site)
|
|
530
|
+
throw Object.assign(
|
|
531
|
+
new Error(`Project #${projectId} has no Help Center. \`workover site create --project ${projectId}\` adds one.`),
|
|
532
|
+
{ status: 404 },
|
|
533
|
+
);
|
|
534
|
+
return view;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** The site's appearance with `next` laid over it, and whether anything changed. */
|
|
538
|
+
function merged(current, next) {
|
|
539
|
+
const out = { ...(current ?? {}) };
|
|
540
|
+
for (const [k, v] of Object.entries(next)) if (v !== undefined && v !== null) out[k] = v;
|
|
541
|
+
return { appearance: out, changed: JSON.stringify(out) !== JSON.stringify(current ?? {}) };
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** An import's answer in the background-state shape (`{ status, result }`), as site-setup.mjs reads it. */
|
|
545
|
+
const asJob = (answer) =>
|
|
546
|
+
answer && typeof answer === 'object' && ['running', 'done', 'failed', 'none'].includes(answer.status)
|
|
547
|
+
? answer
|
|
548
|
+
: { status: 'done', result: answer };
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Import a docs folder into the project's Help Center: one import per tab, each skipped when every
|
|
552
|
+
* page in it is already on the site, then the site's navigation style and icons (filled in, never
|
|
553
|
+
* replacing an icon someone chose). `waitFor(first)` is site-setup.mjs's `waitForJob`, bound by the
|
|
554
|
+
* caller to this project's import.
|
|
555
|
+
*/
|
|
556
|
+
export async function importFolder(call, { projectId, plan, waitFor }) {
|
|
557
|
+
const view = await siteOf(call, projectId);
|
|
558
|
+
const have = navSlugs(view.nav);
|
|
559
|
+
const tabs = [];
|
|
560
|
+
for (const i of plan.imports) {
|
|
561
|
+
const bytes = new TextEncoder().encode(JSON.stringify({ export: i.export })).length;
|
|
562
|
+
if (bytes > MAX_IMPORT_BYTES)
|
|
563
|
+
throw folderError(`The "${i.tab}" tab is ${Math.round(bytes / 1024)} KB, over the ${MAX_IMPORT_BYTES / 1024 / 1024} MB one import takes. Split it into two tabs.`);
|
|
564
|
+
const fresh = i.export.articles.filter((a) => !have.has(a.slug)).length;
|
|
565
|
+
const kept = i.export.articles.length - fresh;
|
|
566
|
+
if (!fresh) {
|
|
567
|
+
tabs.push({ tab: i.tab, created: 0, kept, skipped: true });
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
const state = await waitFor(
|
|
571
|
+
asJob(await call(`/sites/project/${projectId}/import`, { method: 'POST', body: { export: i.export } })),
|
|
572
|
+
);
|
|
573
|
+
if (state?.status !== 'done') return { status: state?.status ?? 'failed', state, tabs, tab: i.tab };
|
|
574
|
+
tabs.push({ tab: i.tab, created: state.result?.created ?? 0, kept: state.result?.kept ?? kept });
|
|
575
|
+
}
|
|
576
|
+
const current = (await call(`/sites/project/${projectId}`))?.site?.appearance ?? {};
|
|
577
|
+
const next = {
|
|
578
|
+
...(plan.structure?.navigation ? { navigation: plan.structure.navigation } : {}),
|
|
579
|
+
icons: { ...(plan.structure?.icons ?? {}), ...(current.icons ?? {}) },
|
|
580
|
+
};
|
|
581
|
+
const { appearance, changed } = merged(current, next);
|
|
582
|
+
if (changed) await call(`/sites/project/${projectId}`, { method: 'PUT', body: { appearance } });
|
|
583
|
+
// Spec-backed tabs last, so a folder tab of the same name is already in place for them to join.
|
|
584
|
+
const apiReferences = [];
|
|
585
|
+
for (const ref of plan.apiReferences ?? []) apiReferences.push(...(await addApiReference(call, { projectId, ...ref })).references);
|
|
586
|
+
return { status: 'done', tabs, apiReferences, structureSaved: changed, warnings: plan.warnings ?? [] };
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Add a spec-backed API reference tab (or a group in one) and sync it: `POST .../api-references`.
|
|
591
|
+
* Safe to repeat. The answer lists the reference with how its sync went (`outcome`), or, when the
|
|
592
|
+
* sync takes longer than the API waits, `{ running: true }` (its last sync shows in `listApiReferences`).
|
|
593
|
+
*/
|
|
594
|
+
export async function addApiReference(call, { projectId, spec, tab, group, directory }) {
|
|
595
|
+
const answer = await call(`/sites/project/${projectId}/api-references`, {
|
|
596
|
+
method: 'POST',
|
|
597
|
+
body: { spec, ...(tab ? { tab } : {}), ...(group ? { group } : {}), ...(directory ? { directory } : {}) },
|
|
598
|
+
});
|
|
599
|
+
return answer?.status === 'running' ? { running: true, references: [] } : { references: answer?.references ?? [] };
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** Sync every spec-backed API reference of the project now ("the spec changed"). */
|
|
603
|
+
export async function syncApiReferences(call, { projectId }) {
|
|
604
|
+
const answer = await call(`/sites/project/${projectId}/api-references/sync`, { method: 'POST', body: {} });
|
|
605
|
+
return answer?.status === 'running' ? { running: true, references: [] } : { references: answer?.references ?? [] };
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** The project's spec-backed API references and how their last sync went. */
|
|
609
|
+
export async function listApiReferences(call, { projectId }) {
|
|
610
|
+
return { references: (await call(`/sites/project/${projectId}/api-references`))?.references ?? [] };
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Stop following a spec: the reference named by its tab (and group) goes, its pages stay as
|
|
615
|
+
* ordinary pages. Null when the project has no such reference.
|
|
616
|
+
*/
|
|
617
|
+
export async function removeApiReference(call, { projectId, tab = 'API reference', group }) {
|
|
618
|
+
const { references } = await listApiReferences(call, { projectId });
|
|
619
|
+
const ref = references.find((r) => r.tab === tab && (r.group ?? null) === (group ?? null));
|
|
620
|
+
if (!ref) return null;
|
|
621
|
+
const res = await call(`/sites/project/${projectId}/api-references/${ref.id}`, { method: 'DELETE' });
|
|
622
|
+
return { ...ref, pagesKept: res?.pagesKept ?? ref.pages };
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** One line per reference: where its pages are, how many, and what its last sync did. */
|
|
626
|
+
export function apiReferenceLines(refs) {
|
|
627
|
+
return refs.flatMap((r) => {
|
|
628
|
+
const o = r.outcome ?? r.lastSummary ?? {};
|
|
629
|
+
const where = r.group ? `${r.tab} › ${r.group}` : r.tab;
|
|
630
|
+
const did =
|
|
631
|
+
o.status === 'busy'
|
|
632
|
+
? 'a sync is already running'
|
|
633
|
+
: o.status === 'failed' || r.lastStatus === 'failed'
|
|
634
|
+
? `✗ ${o.error ?? r.lastError ?? 'the last sync failed'}`
|
|
635
|
+
: `${r.pages} page(s): ${o.added ?? 0} added, ${o.updated ?? 0} updated, ${o.removed ?? 0} removed, ${o.published ?? 0} published${o.waitingForFirstPublish ? ' (they go live with the first publish)' : ''}`;
|
|
636
|
+
return [` ${where.padEnd(28)} ${did}`, ` ${''.padEnd(28)} from ${r.spec === r.url || !r.url ? r.spec : `${r.spec} (${r.url})`}`];
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** What `workover site api add|sync|list` prints. */
|
|
641
|
+
export function renderApiReferences(res, { projectId, verb }) {
|
|
642
|
+
if (res.running)
|
|
643
|
+
return ['', ` … the sync is still running on project #${projectId}. \`workover site api list --project ${projectId}\` shows how it went.`, ''];
|
|
644
|
+
if (!res.references.length)
|
|
645
|
+
return ['', ` Project #${projectId} has no API reference made from a spec. \`workover site api add --project ${projectId} --spec <url>\` adds one.`, ''];
|
|
646
|
+
const failed = res.references.some((r) => (r.outcome ?? {}).status === 'failed');
|
|
647
|
+
const head =
|
|
648
|
+
verb === 'list'
|
|
649
|
+
? ` Project #${projectId}'s API references:`
|
|
650
|
+
: failed
|
|
651
|
+
? ` ✗ Synced project #${projectId}'s API reference, with problems:`
|
|
652
|
+
: ` ✓ ${verb === 'add' ? 'Added and synced' : 'Synced'} project #${projectId}'s API reference.`;
|
|
653
|
+
return ['', head, ...apiReferenceLines(res.references), ''];
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** Why a file will not do as a logo or favicon, before it is sent; null when it may go. */
|
|
657
|
+
export function assetProblem(file) {
|
|
658
|
+
const ext = extname(String(file)).toLowerCase();
|
|
659
|
+
if (!existsSync(file)) return `${file}: no such file.`;
|
|
660
|
+
if (!ASSET_TYPES[ext]) return `${file}: use an SVG, PNG, JPEG, WebP or ICO image.`;
|
|
661
|
+
if (statSync(file).size > MAX_ASSET_BYTES) return `${file}: use an image under 2 MB.`;
|
|
662
|
+
return null;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const ASSET_KEYS = ['logoLight', 'logoDark', 'favicon', 'faviconDark'];
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* The site's appearance from a config's `appearance` block and from flags (flags win), with the logo
|
|
669
|
+
* and favicon files uploaded through the Customize tab's route first. Settings not given are kept.
|
|
670
|
+
*/
|
|
671
|
+
export async function setAppearance(call, upload, { projectId, appearance = {}, files = {} }) {
|
|
672
|
+
for (const key of ASSET_KEYS) {
|
|
673
|
+
if (!files[key]) continue;
|
|
674
|
+
const problem = assetProblem(files[key]);
|
|
675
|
+
if (problem) throw folderError(problem);
|
|
676
|
+
}
|
|
677
|
+
const view = await siteOf(call, projectId);
|
|
678
|
+
const uploaded = {};
|
|
679
|
+
for (const key of ASSET_KEYS) if (files[key]) uploaded[key] = await upload(projectId, files[key]);
|
|
680
|
+
const current = view.site.appearance ?? {};
|
|
681
|
+
const next = { ...appearance, ...uploaded };
|
|
682
|
+
if (appearance.icons) next.icons = { ...(current.icons ?? {}), ...appearance.icons };
|
|
683
|
+
const out = merged(current, next);
|
|
684
|
+
if (out.changed) await call(`/sites/project/${projectId}`, { method: 'PUT', body: { appearance: out.appearance } });
|
|
685
|
+
return { projectId, changed: out.changed, uploaded, appearance: out.appearance };
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* `upload(projectId, file)` for setAppearance: the file posted as `file` to the Customize tab's logo
|
|
690
|
+
* route, which vets it (type, size, the bytes themselves) and answers its URL. `send(path, init)`
|
|
691
|
+
* is an authenticated fetch that answers the parsed JSON.
|
|
692
|
+
*/
|
|
693
|
+
export const uploadWith = (send) => async (projectId, file) => {
|
|
694
|
+
const form = new FormData();
|
|
695
|
+
const type = ASSET_TYPES[extname(file).toLowerCase()] ?? 'application/octet-stream';
|
|
696
|
+
form.append('file', new Blob([readFileSync(file)], { type }), basename(file));
|
|
697
|
+
const res = await send(`/sites/project/${projectId}/assets`, { method: 'POST', body: form });
|
|
698
|
+
if (typeof res?.url !== 'string') throw new Error(`Uploading ${file} did not return its address.`);
|
|
699
|
+
return res.url;
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
/** The site's redirects plus these, never replacing one it has: safe to run again. */
|
|
703
|
+
export async function addRedirects(call, { projectId, redirects }) {
|
|
704
|
+
await siteOf(call, projectId);
|
|
705
|
+
const current = await call(`/sites/project/${projectId}/redirects`);
|
|
706
|
+
const every = Array.isArray(current) ? current : current?.redirects ?? [];
|
|
707
|
+
// Only the manual rows are saved back (the API keeps its automatic ones), but an address either
|
|
708
|
+
// kind already sends somewhere is left alone: adding never changes where a link goes.
|
|
709
|
+
const rows = every.filter((r) => !r.kind || r.kind === 'manual');
|
|
710
|
+
const have = new Set(every.map((r) => r.from));
|
|
711
|
+
const added = [];
|
|
712
|
+
for (const r of redirects ?? []) {
|
|
713
|
+
if (!r?.from || !r?.to || have.has(r.from)) continue;
|
|
714
|
+
have.add(r.from);
|
|
715
|
+
added.push({ from: r.from, to: r.to });
|
|
716
|
+
}
|
|
717
|
+
const all = [...rows.map((r) => ({ from: r.from, to: r.to })), ...added];
|
|
718
|
+
if (all.length > MAX_REDIRECTS)
|
|
719
|
+
throw folderError(`That makes ${all.length} redirects; a site keeps at most ${MAX_REDIRECTS}.`);
|
|
720
|
+
if (added.length) await call(`/sites/project/${projectId}/redirects`, { method: 'PUT', body: { redirects: all } });
|
|
721
|
+
return { projectId, added: added.length, total: all.length, kept: rows.length };
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// ------------------------------------------------------------------ what the person reads
|
|
725
|
+
|
|
726
|
+
export function renderFolderImport(res, { projectId, plan }) {
|
|
727
|
+
const lines = [''];
|
|
728
|
+
if (res.status !== 'done') {
|
|
729
|
+
const err = res.state?.error ? `: ${res.state.error}` : '';
|
|
730
|
+
lines.push(
|
|
731
|
+
res.status === 'running'
|
|
732
|
+
? ` … the "${res.tab}" tab is still importing. Run the same command again to carry on; pages already in are kept.`
|
|
733
|
+
: ` ✗ The "${res.tab}" tab did not import${err}`,
|
|
734
|
+
);
|
|
735
|
+
} else {
|
|
736
|
+
const created = res.tabs.reduce((n, t) => n + t.created, 0);
|
|
737
|
+
lines.push(` ✓ Imported ${plan.layout === 'mintlify' ? 'the Mintlify folder' : 'the docs folder'} into project #${projectId}: ${created} new page(s).`);
|
|
738
|
+
}
|
|
739
|
+
for (const t of res.tabs)
|
|
740
|
+
lines.push(` ${t.tab.padEnd(28)} ${t.skipped ? `nothing new, ${t.kept} kept` : `${t.created} new, ${t.kept} kept`}`);
|
|
741
|
+
if (res.structureSaved) lines.push(' Saved the navigation style and icons.');
|
|
742
|
+
if (res.apiReferences?.length) lines.push(' API reference from a spec (kept in step with it, and published by its sync):', ...apiReferenceLines(res.apiReferences));
|
|
743
|
+
const warnings = res.warnings ?? plan.warnings ?? [];
|
|
744
|
+
if (warnings.length) {
|
|
745
|
+
lines.push('', ` ${warnings.length} note(s):`);
|
|
746
|
+
for (const w of warnings.slice(0, 20)) lines.push(` - ${w}`);
|
|
747
|
+
if (warnings.length > 20) lines.push(` … and ${warnings.length - 20} more (--json lists them all).`);
|
|
748
|
+
}
|
|
749
|
+
if (res.status === 'done') {
|
|
750
|
+
lines.push('', ' Next:');
|
|
751
|
+
if (plan.appearance && Object.keys(plan.appearance).length || Object.keys(plan.assets ?? {}).length)
|
|
752
|
+
lines.push(` workover site appearance --project ${projectId} --from ${plan.dir}`);
|
|
753
|
+
if (plan.redirects?.length) lines.push(` workover site redirects --project ${projectId} --from ${plan.dir} (${plan.redirects.length})`);
|
|
754
|
+
lines.push(` workover site publish --project ${projectId}`);
|
|
755
|
+
}
|
|
756
|
+
lines.push('');
|
|
757
|
+
return lines;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export function renderAppearance(res) {
|
|
761
|
+
const lines = [''];
|
|
762
|
+
lines.push(res.changed ? ` ✓ Saved the Help Center's appearance on project #${res.projectId}.` : ` Nothing to change on project #${res.projectId}: the appearance already says that.`);
|
|
763
|
+
for (const [k, url] of Object.entries(res.uploaded ?? {})) lines.push(` Uploaded ${k}: ${url}`);
|
|
764
|
+
const a = res.appearance ?? {};
|
|
765
|
+
if (a.primary) lines.push(` Primary color: ${a.primary}${a.primaryDark ? ` (dark ${a.primaryDark})` : ''}`);
|
|
766
|
+
lines.push('', ' It shows on the site once it is published (`workover site publish`).', '');
|
|
767
|
+
return lines;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
export function renderRedirects(res) {
|
|
771
|
+
return [
|
|
772
|
+
'',
|
|
773
|
+
res.added
|
|
774
|
+
? ` ✓ Added ${res.added} redirect(s) to project #${res.projectId} (${res.total} in all).`
|
|
775
|
+
: ` No new redirects: project #${res.projectId} has all of them already (${res.total} in all).`,
|
|
776
|
+
'',
|
|
777
|
+
];
|
|
778
|
+
}
|