@mintlify/previewing 4.0.957 → 4.0.959

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.
@@ -1,9 +1,10 @@
1
- import { findAndRemoveImports, stringifyTree, topologicalSort, hasImports, optionallyAddLeadingSlash, optionallyRemoveLeadingSlash, resolveImportPath, } from '@mintlify/common';
1
+ import { findAndRemoveImports, replaceVariables, stringifyTree, topologicalSort, hasImports, optionallyAddLeadingSlash, optionallyRemoveLeadingSlash, resolveImportPath, } from '@mintlify/common';
2
2
  import { outputFile } from 'fs-extra';
3
3
  import { join } from 'path';
4
4
  import { NEXT_PUBLIC_PATH } from '../../constants.js';
5
5
  import { getOriginalSnippets } from './getSnippets.js';
6
6
  import { resolveAllImports } from './resolveAllImports.js';
7
+ import { getCurrentVariables } from './utils.js';
7
8
  const findAllDependents = async (initialFileWithSlash, allSnippets, processedDataCache) => {
8
9
  const affected = new Set([initialFileWithSlash]);
9
10
  const queue = [initialFileWithSlash];
@@ -35,7 +36,11 @@ const findAllDependents = async (initialFileWithSlash, allSnippets, processedDat
35
36
  };
36
37
  export const generateDependentSnippets = async (changedFilename, newImportData) => {
37
38
  const processedDataCache = new Map();
38
- const allOriginalSnippets = await getOriginalSnippets();
39
+ const [allOriginalSnippets, variables] = await Promise.all([
40
+ getOriginalSnippets(),
41
+ getCurrentVariables(),
42
+ ]);
43
+ const vars = variables ?? {};
39
44
  const updatedSnippetFileKey = optionallyAddLeadingSlash(changedFilename);
40
45
  const affectedSnippets = await findAllDependents(updatedSnippetFileKey, allOriginalSnippets, processedDataCache);
41
46
  const snippetPromises = Array.from(affectedSnippets).map(async (filename) => {
@@ -82,7 +87,9 @@ export const generateDependentSnippets = async (changedFilename, newImportData)
82
87
  }
83
88
  const targetFilename = optionallyRemoveLeadingSlash(currentSnippet.filename);
84
89
  const targetPath = join(NEXT_PUBLIC_PATH, targetFilename);
85
- await outputFile(targetPath, stringifyTree(processedTree), { flag: 'w' });
90
+ await outputFile(targetPath, replaceVariables(stringifyTree(processedTree), vars), {
91
+ flag: 'w',
92
+ });
86
93
  processedSnippets.push(targetFilename);
87
94
  }
88
95
  return processedSnippets;
@@ -201,7 +201,9 @@ const onUpdateEvent = async (filename, callback, options = {}) => {
201
201
  break;
202
202
  }
203
203
  case 'snippet': {
204
- await fse.copy(filePath, targetPath);
204
+ const variables = await getCurrentVariables();
205
+ const rawContent = (await readFile(filePath)).toString();
206
+ await fse.outputFile(targetPath, replaceVariables(rawContent, variables), { flag: 'w' });
205
207
  break;
206
208
  }
207
209
  case 'snippet-v2': {