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

vuepress / vuepress-next / 3860590913

pending completion
3860590913

Pull #1228

github

GitHub
Merge b04c6dafe into b4e313bb7
Pull Request #1228: feat(core): add markdownEnv to Page

325 of 468 branches covered (69.44%)

Branch coverage included in aggregate %.

683 of 1003 relevant lines covered (68.1%)

42.25 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
32
    const cliAppConfig = 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 } = await loadUserConfig(
×
40
      userConfigPath
41
    )
42

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

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

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

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

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

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

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

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

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

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

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

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

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