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

vuepress / vuepress-next / 7163313360

11 Dec 2023 05:25AM CUT coverage: 67.837% (-1.3%) from 69.176%
7163313360

Pull #1449

github

web-flow
Merge 4941993a9 into b82d48e1e
Pull Request #1449: feat: remove vuepress-vite and vuepress-webpack package and support --bundler option, close #1446

325 of 462 branches covered (0.0%)

Branch coverage included in aggregate %.

2 of 26 new or added lines in 4 files covered. (7.69%)

1 existing line in 1 file now uncovered.

641 of 962 relevant lines covered (66.63%)

47.76 hits per line

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

3.7
/packages/cli/src/commands/dev/createDev.ts
1
import process from 'node:process'
2
import { createDevApp } from '@vuepress/core'
3
import type { AppConfig } from '@vuepress/core'
4
import { debug, fs, logger, withSpinner } from '@vuepress/utils'
5
import type { FSWatcher } from 'chokidar'
6
import {
7
  loadUserConfig,
8
  resolveAppConfig,
9
  resolveCliAppConfig,
10
  resolveUserConfigConventionalPath,
11
  resolveUserConfigPath,
12
  transformUserConfigToPlugin,
13
} from '../../config/index.js'
14
import type { DevCommand } from './types.js'
15
import { watchPageFiles } from './watchPageFiles.js'
16
import { watchUserConfigFile } from './watchUserConfigFile.js'
17

18
const log = debug('vuepress:cli/dev')
3✔
19

20
export const createDev = (defaultAppConfig: Partial<AppConfig>): DevCommand => {
3✔
21
  const dev: DevCommand = async (
×
22
    sourceDir = '.',
×
23
    commandOptions = {},
×
24
  ): Promise<void> => {
25
    log(`commandOptions:`, commandOptions)
×
26

27
    if (process.env.NODE_ENV === undefined) {
×
28
      process.env.NODE_ENV = 'development'
×
29
    }
30

31
    // resolve app config from cli options
NEW
32
    const cliAppConfig = await resolveCliAppConfig(sourceDir, commandOptions)
×
33

34
    // resolve user config file
35
    const userConfigPath = commandOptions.config
×
36
      ? resolveUserConfigPath(commandOptions.config)
37
      : resolveUserConfigConventionalPath(cliAppConfig.source)
38
    log(`userConfigPath:`, userConfigPath)
×
39
    const { userConfig, userConfigDependencies } =
40
      await loadUserConfig(userConfigPath)
×
41

42
    // resolve the final app config to use
43
    const appConfig = resolveAppConfig({
×
44
      defaultAppConfig,
45
      cliAppConfig,
46
      userConfig,
47
    })
48
    if (appConfig === null) {
×
49
      return
×
50
    }
51

52
    // create vuepress app
53
    const app = createDevApp(appConfig)
×
54

55
    // use user-config plugin
56
    app.use(transformUserConfigToPlugin(userConfig, cliAppConfig.source))
×
57

58
    // clean temp and cache
59
    if (commandOptions.cleanTemp === true) {
×
60
      await withSpinner('Cleaning temp')(() => {
×
61
        return fs.remove(app.dir.temp())
×
62
      })
63
    }
64
    if (commandOptions.cleanCache === true) {
×
65
      await withSpinner('Cleaning cache')(() => {
×
66
        return fs.remove(app.dir.cache())
×
67
      })
68
    }
69

70
    // initialize and prepare
71
    await withSpinner('Initializing and preparing data')(async () => {
×
72
      await app.init()
×
73
      await app.prepare()
×
74
    })
75

76
    // start dev server
77
    const close = await app.dev()
×
78

79
    // do not watch files if `watch` is set to `false`
80
    if (commandOptions.watch === false) {
×
81
      return
×
82
    }
83

84
    // all watchers
85
    const watchers: FSWatcher[] = []
×
86

87
    // restart dev command
88
    const restart = async (): Promise<void> => {
×
89
      await Promise.all([
×
90
        // close all watchers
91
        ...watchers.map((item) => item.close()),
×
92
        // close current dev server
93
        close(),
94
      ])
95
      // restart dev command
96
      await dev(sourceDir, {
×
97
        ...commandOptions,
98
        // do not clean cache and temp on restart
99
        cleanCache: false,
100
        cleanTemp: false,
101
      })
102
      logger.tip(`dev server has restarted, please refresh your browser`)
×
103
    }
104

105
    // watch page files
106
    watchers.push(...watchPageFiles(app))
×
107

108
    // watch user config file
109
    if (userConfigPath) {
×
110
      watchers.push(
×
111
        ...watchUserConfigFile({
112
          userConfigPath,
113
          userConfigDependencies,
114
          restart,
115
        }),
116
      )
117
    }
118

119
    await app.pluginApi.hooks.onWatched.process(app, watchers, restart)
×
120
  }
121

122
  return dev
×
123
}
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