@mintlify/previewing 4.0.593 → 4.0.595

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.
@@ -0,0 +1,11 @@
1
+ import os from 'os';
2
+ export const getLocalNetworkIp = () => {
3
+ const interfaces = os.networkInterfaces();
4
+ for (const name of Object.keys(interfaces)) {
5
+ for (const iface of interfaces[name] || []) {
6
+ if (iface.family === 'IPv4' && !iface.internal) {
7
+ return iface.address;
8
+ }
9
+ }
10
+ }
11
+ };
@@ -1,11 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  import open from 'better-opn';
2
- import Chalk from 'chalk';
3
3
  import express from 'express';
4
4
  import { createServer } from 'http';
5
5
  import { Server as SocketServer } from 'socket.io';
6
6
  import { NEXT_PUBLIC_PATH } from '../constants.js';
7
+ import { addLog, LaunchLog, removeLastLog } from '../logs.js';
7
8
  import { maybeFixMissingWindowsEnvVar } from '../util.js';
8
9
  import listener from './listener/index.js';
10
+ import { getLocalNetworkIp } from './network.js';
9
11
  import { setupNext } from './setupNext.js';
10
12
  export const run = async (argv) => {
11
13
  const port = argv.port || '3000';
@@ -14,6 +16,7 @@ export const run = async (argv) => {
14
16
  const server = createServer(app);
15
17
  const io = new SocketServer(server);
16
18
  const requestHandler = await setupNext();
19
+ const localIp = getLocalNetworkIp();
17
20
  // next-server is bugged, public files added after starting aren't served
18
21
  app.use('/', express.static(NEXT_PUBLIC_PATH));
19
22
  app.all('*', (req, res) => requestHandler(req, res));
@@ -21,10 +24,8 @@ export const run = async (argv) => {
21
24
  io.emit('reload');
22
25
  };
23
26
  server.listen(currentPort, () => {
24
- console.log(`${Chalk.green(`Your local preview is available at http://localhost:${port}`)}`);
25
- // Note: We wait for this exact text to be sure the server is ready in the cli e2e test,
26
- // if it changes, the test will fail/require an update.
27
- console.log(`${Chalk.green('Press Ctrl+C any time to stop the local preview.')}`);
27
+ removeLastLog();
28
+ addLog(_jsx(LaunchLog, { localUrl: `http://localhost:${port}`, networkUrl: localIp ? `http://${localIp}:${port}` : undefined }));
28
29
  /**
29
30
  * We're running into a known bug with the `open` package, where Windows machines error out because process.env.SYSTEMROOT is not set:
30
31
  * https://github.com/sindresorhus/open/issues/292
package/dist/logs.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ export declare const EmptyLineLog: () => import("react/jsx-runtime").JSX.Element;
2
+ export declare const LaunchLog: ({ localUrl, networkUrl }: {
3
+ localUrl: string;
4
+ networkUrl?: string;
5
+ }) => import("react/jsx-runtime").JSX.Element;
6
+ export declare const InfoLog: ({ message }: {
7
+ message: string;
8
+ }) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const SuccessLog: ({ message }: {
10
+ message: string;
11
+ }) => import("react/jsx-runtime").JSX.Element;
12
+ export declare const SpinnerLog: ({ message }: {
13
+ message: string;
14
+ }) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const WarningLog: ({ message }: {
16
+ message: string;
17
+ }) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const UpdateLog: ({ updateCommand }: {
19
+ updateCommand: string;
20
+ }) => import("react/jsx-runtime").JSX.Element;
21
+ export declare const ErrorLog: ({ message }: {
22
+ message: string;
23
+ }) => import("react/jsx-runtime").JSX.Element;
24
+ export declare const AddedLog: ({ filename }: {
25
+ filename: string;
26
+ }) => import("react/jsx-runtime").JSX.Element;
27
+ export declare const EditedLog: ({ filename }: {
28
+ filename: string;
29
+ }) => import("react/jsx-runtime").JSX.Element;
30
+ export declare const DeletedLog: ({ filename }: {
31
+ filename: string;
32
+ }) => import("react/jsx-runtime").JSX.Element;
33
+ export declare const BrokenLinksLog: ({ brokenLinksByFile, }: {
34
+ brokenLinksByFile: Record<string, string[]>;
35
+ }) => import("react/jsx-runtime").JSX.Element;
36
+ export declare const RenamedLog: ({ before, after }: {
37
+ before: string;
38
+ after: string;
39
+ }) => import("react/jsx-runtime").JSX.Element;
40
+ export declare const Logs: React.FC;
41
+ export declare const addLog: (log: React.ReactNode) => void;
42
+ export declare const addChangeLog: (log: React.ReactNode) => void;
43
+ export declare const clearLogs: () => void;
44
+ export declare const removeLastLog: () => void;
package/dist/logs.js ADDED
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ import Spinner from 'ink-spinner';
4
+ import { useState, useEffect } from 'react';
5
+ export const EmptyLineLog = () => _jsx(Text, { children: " " });
6
+ export const LaunchLog = ({ localUrl, networkUrl }) => {
7
+ 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, {})] }));
8
+ };
9
+ export const InfoLog = ({ message }) => {
10
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "blue", bold: true, children: "info" }), _jsxs(Text, { children: [" ", message] })] }));
11
+ };
12
+ export const SuccessLog = ({ message }) => {
13
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: "success" }), _jsxs(Text, { children: [" ", message] })] }));
14
+ };
15
+ export const SpinnerLog = ({ message }) => {
16
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: _jsx(Spinner, { type: "dots" }) }), _jsxs(Text, { children: [" ", message] })] }));
17
+ };
18
+ export const WarningLog = ({ message }) => {
19
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "yellow", bold: true, children: "warning" }), _jsxs(Text, { children: [" ", message] })] }));
20
+ };
21
+ export const UpdateLog = ({ updateCommand }) => {
22
+ 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, {})] }));
23
+ };
24
+ export const ErrorLog = ({ message }) => {
25
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "red", bold: true, children: "error" }), _jsxs(Text, { children: [" ", message] })] }));
26
+ };
27
+ export const AddedLog = ({ filename }) => {
28
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: "added" }), _jsxs(Text, { children: [" ", filename] })] }));
29
+ };
30
+ export const EditedLog = ({ filename }) => {
31
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "yellow", bold: true, children: "edited" }), _jsxs(Text, { children: [" ", filename] })] }));
32
+ };
33
+ export const DeletedLog = ({ filename }) => {
34
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "red", bold: true, children: "deleted" }), _jsxs(Text, { children: [" ", filename] })] }));
35
+ };
36
+ export const BrokenLinksLog = ({ brokenLinksByFile, }) => {
37
+ const totalBrokenLinks = Object.values(brokenLinksByFile).reduce((acc, arr) => acc + arr.length, 0);
38
+ const totalFiles = Object.keys(brokenLinksByFile).length;
39
+ 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) => (_jsxs(Text, { children: ['\u00A0'.repeat(1), "\u23BF", '\u00A0'.repeat(2), link] }, link))), _jsx(EmptyLineLog, {})] }, filename)))] }));
40
+ };
41
+ export const RenamedLog = ({ before, after }) => {
42
+ return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: "success" }), _jsxs(Text, { children: [' ', "renamed ", before, " to ", after] })] }));
43
+ };
44
+ export const Logs = () => {
45
+ const [logs, setLogs] = useState([]);
46
+ const [changeLogs, setChangeLogs] = useState([]);
47
+ useEffect(() => {
48
+ global.addLog = (log) => setLogs((prev) => [...prev, log]);
49
+ global.addChangeLog = (log) => setChangeLogs((prev) => [...prev, log]);
50
+ global.clearLogs = () => setLogs([]);
51
+ global.removeLastLog = () => setLogs((prev) => prev.slice(0, -1));
52
+ }, []);
53
+ 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}`)))] }))] }));
54
+ };
55
+ export const addLog = (log) => {
56
+ global.addLog?.(log);
57
+ };
58
+ export const addChangeLog = (log) => {
59
+ global.addChangeLog?.(log);
60
+ };
61
+ export const clearLogs = () => {
62
+ global.clearLogs?.();
63
+ };
64
+ export const removeLastLog = () => {
65
+ global.removeLastLog?.();
66
+ };