• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vuepress / vuepress-next / 3792858757

pending completion
3792858757

push

github

GitHub
fix(theme-default): preserve url params when switching language (#1211)

325 of 468 branches covered (69.44%)

Branch coverage included in aggregate %.

682 of 1002 relevant lines covered (68.06%)

42.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.35
/ecosystem/plugin-palette/src/node/palettePlugin.ts
1
import type { Plugin } from '@vuepress/core'
2
import chokidar from 'chokidar'
3
import { preparePaletteFile } from './preparePaletteFile.js'
4
import { prepareStyleFile } from './prepareStyleFile.js'
5
import { presetOptions } from './presetOptions.js'
6

7
/**
8
 * Options of @vuepress/plugin-palette
9
 */
10
export interface PalettePluginOptions {
11
  /**
12
   * Preset of the palette
13
   *
14
   * @default 'css'
15
   */
16
  preset?: 'css' | 'sass' | 'less' | 'stylus'
17

18
  /**
19
   * File path of the user palette file, relative to source directory
20
   */
21
  userPaletteFile?: string
22

23
  /**
24
   * File path of the generated palette temp file, relative to temp directory
25
   */
26
  tempPaletteFile?: string
27

28
  /**
29
   * File path of the user style file, relative to source directory
30
   */
31
  userStyleFile?: string
32

33
  /**
34
   * File path of the generated style temp file, relative to temp directory
35
   */
36
  tempStyleFile?: string
37

38
  /**
39
   * Function to generate import code
40
   */
41
  importCode?: (filePath: string) => string
42
}
43

44
export const palettePlugin = ({
2!
45
  preset = 'css',
×
46
  userPaletteFile = presetOptions[preset].userPaletteFile,
×
47
  tempPaletteFile = presetOptions[preset].tempPaletteFile,
×
48
  userStyleFile = presetOptions[preset].userStyleFile,
×
49
  tempStyleFile = presetOptions[preset].tempStyleFile,
×
50
  importCode = presetOptions[preset].importCode,
×
51
}: PalettePluginOptions = {}): Plugin => ({
×
52
  name: '@vuepress/plugin-palette',
53

54
  alias: (app) => ({
×
55
    '@vuepress/plugin-palette/palette': app.dir.temp(tempPaletteFile),
56
    '@vuepress/plugin-palette/style': app.dir.temp(tempStyleFile),
57
  }),
58

59
  onPrepared: async (app) => {
60
    await Promise.all([
×
61
      preparePaletteFile(app, {
62
        userPaletteFile,
63
        tempPaletteFile,
64
        importCode,
65
      }),
66
      prepareStyleFile(app, {
67
        userStyleFile,
68
        tempStyleFile,
69
        importCode,
70
      }),
71
    ])
72
  },
73

74
  onWatched: (app, watchers) => {
75
    const paletteWatcher = chokidar.watch(userPaletteFile, {
×
76
      cwd: app.dir.source(),
77
      ignoreInitial: true,
78
    })
79
    paletteWatcher.on('add', () => {
×
80
      preparePaletteFile(app, {
×
81
        userPaletteFile,
82
        tempPaletteFile,
83
        importCode,
84
      })
85
    })
86
    paletteWatcher.on('unlink', () => {
×
87
      preparePaletteFile(app, {
×
88
        userPaletteFile,
89
        tempPaletteFile,
90
        importCode,
91
      })
92
    })
93
    watchers.push(paletteWatcher)
×
94

95
    const styleWatcher = chokidar.watch(userStyleFile, {
×
96
      cwd: app.dir.source(),
97
      ignoreInitial: true,
98
    })
99
    styleWatcher.on('add', () => {
×
100
      prepareStyleFile(app, {
×
101
        userStyleFile,
102
        tempStyleFile,
103
        importCode,
104
      })
105
    })
106
    styleWatcher.on('unlink', () => {
×
107
      prepareStyleFile(app, {
×
108
        userStyleFile,
109
        tempStyleFile,
110
        importCode,
111
      })
112
    })
113
    watchers.push(styleWatcher)
×
114
  },
115
})
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc