@mintlify/previewing
Version:
Preview Mintlify docs locally
101 lines (100 loc) • 6.49 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import Spinner from 'ink-spinner';
import { useState, useEffect } from 'react';
import { setLoggingCallbacks } from './logging-state.js';
export const EmptyLineLog = () => _jsx(Text, { children: " " });
export const LaunchLog = ({ localUrl, networkUrl }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`✓ preview ready, local: ${localUrl}, network: ${networkUrl} press ctrl+c to exit the preview`);
return null;
}
return (_jsxs(Box, { flexDirection: "column", alignItems: "flex-start", children: [_jsxs(Text, { children: [_jsx(Text, { color: "green", bold: true, children: "\u2713" }), ' ', _jsx(Text, { children: "preview ready" })] }), _jsx(EmptyLineLog, {}), _jsxs(Text, { children: ['\u00A0'.repeat(2), "local", '\u00A0'.repeat(3), "\u2192", '\u00A0'.repeat(1), localUrl] }), networkUrl && (_jsxs(Text, { children: ['\u00A0'.repeat(2), "network", '\u00A0'.repeat(1), "\u2192", '\u00A0'.repeat(1), networkUrl] })), _jsx(EmptyLineLog, {}), _jsxs(Text, { dimColor: true, children: ["press ", _jsx(Text, { bold: true, children: "ctrl+c" }), " to exit the preview"] }), _jsx(EmptyLineLog, {})] }));
};
export const InfoLog = ({ message }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`info ${message}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "blue", bold: true, children: "info" }), _jsxs(Text, { children: [" ", message] })] }));
};
export const SuccessLog = ({ message }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`success ${message}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: "success" }), _jsxs(Text, { children: [" ", message] })] }));
};
export const SpinnerLog = ({ message }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`${message}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: _jsx(Spinner, { type: "dots" }) }), _jsxs(Text, { children: [" ", message] })] }));
};
export const WarningLog = ({ message }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`warning ${message}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "yellow", bold: true, children: "warning" }), _jsxs(Text, { children: [" ", message] })] }));
};
export const UpdateLog = ({ updateCommand }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`update available - run \`${updateCommand}\` to get the latest version`);
return null;
}
return (_jsxs(Box, { flexDirection: "column", alignItems: "flex-start", children: [_jsxs(Text, { children: [_jsx(Text, { color: "yellow", bold: true, children: "update available" }), _jsxs(Text, { children: [' ', "- run `", _jsx(Text, { bold: true, children: updateCommand }), "` to get the latest version"] })] }), _jsx(EmptyLineLog, {})] }));
};
export const ErrorLog = ({ message }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`error ${message}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "red", bold: true, children: "error" }), _jsxs(Text, { children: [" ", message] })] }));
};
export const AddedLog = ({ filename }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`added ${filename}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: "added" }), _jsxs(Text, { children: [" ", filename] })] }));
};
export const EditedLog = ({ filename }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`edited ${filename}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "yellow", bold: true, children: "edited" }), _jsxs(Text, { children: [" ", filename] })] }));
};
export const DeletedLog = ({ filename }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`deleted ${filename}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "red", bold: true, children: "deleted" }), _jsxs(Text, { children: [" ", filename] })] }));
};
export const BrokenLinksLog = ({ brokenLinksByFile, }) => {
const totalBrokenLinks = Object.values(brokenLinksByFile).reduce((acc, arr) => acc + arr.length, 0);
const totalFiles = Object.keys(brokenLinksByFile).length;
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`found ${totalBrokenLinks} broken links in ${totalFiles} files`);
return null;
}
return (_jsxs(Box, { flexDirection: "column", alignItems: "flex-start", children: [_jsxs(Text, { children: [_jsx(Text, { children: "found" }), _jsxs(Text, { color: "yellow", bold: true, children: [' ', totalBrokenLinks, " broken links"] }), _jsxs(Text, { children: [" in ", totalFiles, " files"] })] }), _jsx(EmptyLineLog, {}), Object.entries(brokenLinksByFile).map(([filename, brokenLinks]) => (_jsxs(Box, { flexDirection: "column", alignItems: "flex-start", children: [_jsx(Box, { children: _jsx(Text, { bold: true, children: filename }) }), brokenLinks.map((link, index) => (_jsxs(Text, { children: ['\u00A0'.repeat(1), "\u23BF", '\u00A0'.repeat(2), link] }, `${link}-${index}`))), _jsx(EmptyLineLog, {})] }, filename)))] }));
};
export const RenamedLog = ({ before, after }) => {
if (process.env.CLI_TEST_MODE === 'true') {
console.log(`success renamed ${before} to ${after}`);
return null;
}
return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: "success" }), _jsxs(Text, { children: [' ', "renamed ", before, " to ", after] })] }));
};
export const Logs = () => {
const [logs, setLogs] = useState([]);
const [changeLogs, setChangeLogs] = useState([]);
useEffect(() => {
setLoggingCallbacks(setLogs, setChangeLogs);
}, []);
return (_jsxs(_Fragment, { children: [logs.map((log, idx) => (_jsx(Box, { children: log }, idx))), changeLogs.length > 0 && (_jsxs(Box, { flexDirection: "column", alignItems: "flex-start", children: [_jsxs(Text, { children: [_jsx(Text, { dimColor: true, bold: true, children: "\u00B1" }), ' ', _jsx(Text, { children: "changes" })] }), changeLogs.map((log, idx) => (_jsx(Box, { children: log }, `change-${idx}`)))] }))] }));
};