File size: 2,132 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { readFileSync, writeFileSync } from 'node:fs'
import { generateReferenceDocs } from '@tanstack/config/typedoc'
import { glob } from 'tinyglobby'

const __dirname = fileURLToPath(new URL('.', import.meta.url))

await generateReferenceDocs({
  packages: [
    {
      name: 'angular-query-experimental',
      entryPoints: [
        resolve(
          __dirname,
          '../packages/angular-query-experimental/src/index.ts',
        ),
      ],
      tsconfig: resolve(
        __dirname,
        '../packages/angular-query-experimental/tsconfig.json',
      ),
      outputDir: resolve(__dirname, '../docs/framework/angular/reference'),
      exclude: ['./packages/query-core/**/*'],
    },
    {
      name: 'svelte-query',
      entryPoints: [
        resolve(__dirname, '../packages/svelte-query/src/index.ts'),
      ],
      tsconfig: resolve(__dirname, '../packages/svelte-query/tsconfig.json'),
      outputDir: resolve(__dirname, '../docs/framework/svelte/reference'),
      exclude: ['./packages/query-core/**/*'],
    },
  ],
})

// Define the pattern to match all generated markdown files
const markdownFilesPattern = 'docs/framework/{angular,svelte}/reference/**/*.md'

// Find all markdown files matching the pattern
const markdownFiles = await glob(markdownFilesPattern)

console.log(`Found ${markdownFiles.length} markdown files to process\n`)

// Process each markdown file
markdownFiles.forEach((file) => {
  const content = readFileSync(file, 'utf-8')
  let updatedContent = content
  updatedContent = updatedContent.replaceAll(/\]\(\.\.\//gm, '](../../')
  // updatedContent = content.replaceAll(/\]\(\.\//gm, '](../')
  updatedContent = updatedContent.replaceAll(
    /\]\((?!https?:\/\/|\/\/|\/|\.\/|\.\.\/|#)([^)]+)\)/gm,
    (match, p1) => `](../${p1})`,
  )

  // Write the updated content back to the file
  if (updatedContent !== content) {
    writeFileSync(file, updatedContent, 'utf-8')
    console.log(`Processed file: ${file}`)
  }
})

console.log('\n✅ All markdown files have been processed!')

process.exit(0)