@mintlify/previewing 4.0.614 → 4.0.615

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.
@@ -5,7 +5,7 @@ import { mockProcessExit } from 'vitest-mock-process';
5
5
  import { dev } from '../index.js';
6
6
  import { downloadTargetMint, getTargetMintVersion } from '../local-preview/client.js';
7
7
  import { run } from '../local-preview/run.js';
8
- import * as logs from '../logs.js';
8
+ import * as logs from '../logging-state.js';
9
9
  const originalChdir = process.chdir;
10
10
  vi.mock('fs-extra', () => {
11
11
  const mocks = {
@@ -4,7 +4,7 @@ import tar from 'tar';
4
4
  import { mockProcessExit } from 'vitest-mock-process';
5
5
  import * as constants from '../constants.js';
6
6
  import { downloadTargetMint } from '../local-preview/client.js';
7
- import * as logs from '../logs.js';
7
+ import * as logs from '../logging-state.js';
8
8
  import * as utils from '../util.js';
9
9
  vi.mock('fs-extra', () => {
10
10
  const mocks = {
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ import { getTargetMintVersion, downloadTargetMint } from './local-preview/client
2
2
  import dev from './local-preview/index.js';
3
3
  import { getClientVersion } from './util.js';
4
4
  export * from './logs.js';
5
+ export * from './logging-state.js';
5
6
  export { dev, getClientVersion, getTargetMintVersion, downloadTargetMint };
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ import { getTargetMintVersion, downloadTargetMint } from './local-preview/client
2
2
  import dev from './local-preview/index.js';
3
3
  import { getClientVersion } from './util.js';
4
4
  export * from './logs.js';
5
+ export * from './logging-state.js';
5
6
  export { dev, getClientVersion, getTargetMintVersion, downloadTargetMint };
@@ -5,7 +5,8 @@ import isOnline from 'is-online';
5
5
  import { pipeline } from 'node:stream/promises';
6
6
  import tar from 'tar';
7
7
  import { DOT_MINTLIFY, DOT_MINTLIFY_LAST, VERSION_PATH, TAR_PATH, TARGET_MINT_VERSION_URL, } from '../constants.js';
8
- import { addLog, clearLogs, ErrorLog, SpinnerLog, WarningLog } from '../logs.js';
8
+ import { addLog, clearLogs } from '../logging-state.js';
9
+ import { ErrorLog, SpinnerLog, WarningLog } from '../logs.js';
9
10
  import { restoreMintlifyLast, getTarUrl } from '../util.js';
10
11
  export const getTargetMintVersion = async () => {
11
12
  const hasInternet = await isOnline();
@@ -72,6 +73,7 @@ export const downloadTargetMint = async ({ targetVersion, existingVersion, }) =>
72
73
  process.exit(1);
73
74
  }
74
75
  }
76
+ clearLogs();
75
77
  fse.removeSync(TAR_PATH);
76
78
  if (fse.existsSync(DOT_MINTLIFY_LAST)) {
77
79
  fse.removeSync(DOT_MINTLIFY_LAST);
@@ -3,7 +3,8 @@ import { prebuild } from '@mintlify/prebuild';
3
3
  import fse, { pathExists } from 'fs-extra';
4
4
  import isOnline from 'is-online';
5
5
  import { CLIENT_PATH, DOT_MINTLIFY, CMD_EXEC_PATH, VERSION_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, } from '../constants.js';
6
- import { addLog, clearLogs, ErrorLog, SpinnerLog, UpdateLog, WarningLog } from '../logs.js';
6
+ import { addLog, clearLogs } from '../logging-state.js';
7
+ import { ErrorLog, SpinnerLog, UpdateLog, WarningLog } from '../logs.js';
7
8
  import { getTargetMintVersion, downloadTargetMint } from './client.js';
8
9
  import { run } from './run.js';
9
10
  const dev = async (argv) => {
@@ -45,10 +46,12 @@ const dev = async (argv) => {
45
46
  fse.emptyDirSync(NEXT_PROPS_PATH);
46
47
  process.chdir(CLIENT_PATH);
47
48
  try {
49
+ clearLogs();
48
50
  addLog(_jsx(SpinnerLog, { message: "preparing local preview..." }));
49
51
  await prebuild(CMD_EXEC_PATH, { localSchema, groups });
50
52
  }
51
53
  catch (err) {
54
+ clearLogs();
52
55
  const errorText = err instanceof Error && err.message ? err.message : 'prebuild step failed';
53
56
  addLog(_jsx(ErrorLog, { message: errorText }));
54
57
  await new Promise((resolve) => setTimeout(resolve, 50));
@@ -9,7 +9,8 @@ import fs from 'fs/promises';
9
9
  import yaml from 'js-yaml';
10
10
  import pathUtil from 'path';
11
11
  import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH, CLIENT_PATH } from '../../constants.js';
12
- import { AddedLog, addChangeLog, DeletedLog, EditedLog } from '../../logs.js';
12
+ import { addChangeLog } from '../../logging-state.js';
13
+ import { AddedLog, DeletedLog, EditedLog } from '../../logs.js';
13
14
  import { generateDependentSnippets } from './generateDependentSnippets.js';
14
15
  import { generatePagesWithImports } from './generatePagesWithImports.js';
15
16
  import { getDocsState } from './getDocsState.js';
@@ -4,7 +4,8 @@ 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
+ import { addLog, removeLastLog } from '../logging-state.js';
8
+ import { LaunchLog } from '../logs.js';
8
9
  import { maybeFixMissingWindowsEnvVar } from '../util.js';
9
10
  import listener from './listener/index.js';
10
11
  import { getLocalNetworkIp } from './network.js';
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export declare const setLoggingCallbacks: (setLogs: (logs: React.ReactNode[]) => void, setChangeLogs: (logs: React.ReactNode[]) => void) => void;
3
+ export declare const addLog: (log: React.ReactNode) => void;
4
+ export declare const addChangeLog: (log: React.ReactNode) => void;
5
+ export declare const clearLogs: () => void;
6
+ export declare const removeLastLog: () => void;
@@ -0,0 +1,36 @@
1
+ import { render } from 'ink';
2
+ import React from 'react';
3
+ import { Logs } from './logs.js';
4
+ let currentLogs = [];
5
+ let currentChangeLogs = [];
6
+ let setLogsCallback = null;
7
+ let setChangeLogsCallback = null;
8
+ const ensureLoggingInstance = () => {
9
+ if (!setLogsCallback) {
10
+ render(React.createElement(Logs));
11
+ }
12
+ };
13
+ export const setLoggingCallbacks = (setLogs, setChangeLogs) => {
14
+ setLogsCallback = setLogs;
15
+ setChangeLogsCallback = setChangeLogs;
16
+ };
17
+ export const addLog = (log) => {
18
+ ensureLoggingInstance();
19
+ currentLogs = [...currentLogs, log];
20
+ setLogsCallback?.(currentLogs);
21
+ };
22
+ export const addChangeLog = (log) => {
23
+ ensureLoggingInstance();
24
+ currentChangeLogs = [...currentChangeLogs, log];
25
+ setChangeLogsCallback?.(currentChangeLogs);
26
+ };
27
+ export const clearLogs = () => {
28
+ ensureLoggingInstance();
29
+ currentLogs = [];
30
+ setLogsCallback?.(currentLogs);
31
+ };
32
+ export const removeLastLog = () => {
33
+ ensureLoggingInstance();
34
+ currentLogs = currentLogs.slice(0, -1);
35
+ setLogsCallback?.(currentLogs);
36
+ };
package/dist/logs.d.ts CHANGED
@@ -38,7 +38,3 @@ export declare const RenamedLog: ({ before, after }: {
38
38
  after: string;
39
39
  }) => import("react/jsx-runtime").JSX.Element;
40
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 CHANGED
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { Box, Text } from 'ink';
3
3
  import Spinner from 'ink-spinner';
4
4
  import { useState, useEffect } from 'react';
5
+ import { setLoggingCallbacks } from './logging-state.js';
5
6
  export const EmptyLineLog = () => _jsx(Text, { children: " " });
6
7
  export const LaunchLog = ({ localUrl, networkUrl }) => {
7
8
  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, {})] }));
@@ -36,7 +37,7 @@ export const DeletedLog = ({ filename }) => {
36
37
  export const BrokenLinksLog = ({ brokenLinksByFile, }) => {
37
38
  const totalBrokenLinks = Object.values(brokenLinksByFile).reduce((acc, arr) => acc + arr.length, 0);
38
39
  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
+ 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)))] }));
40
41
  };
41
42
  export const RenamedLog = ({ before, after }) => {
42
43
  return (_jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: "success" }), _jsxs(Text, { children: [' ', "renamed ", before, " to ", after] })] }));
@@ -45,22 +46,7 @@ export const Logs = () => {
45
46
  const [logs, setLogs] = useState([]);
46
47
  const [changeLogs, setChangeLogs] = useState([]);
47
48
  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));
49
+ setLoggingCallbacks(setLogs, setChangeLogs);
52
50
  }, []);
53
51
  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
52
  };
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
- };