Skip to content

Commit 658ea75

Browse files
committed
refactor: unify code style.
1 parent 01fa9af commit 658ea75

21 files changed

+308
-39
lines changed

packages/@vuepress/core/lib/build.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
module.exports = async function build (sourceDir, cliOptions = {}) {
24
process.env.NODE_ENV = 'production'
35

packages/@vuepress/core/lib/dev.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
module.exports = async function dev (sourceDir, cliOptions = {}) {
24
const path = require('path')
35
const webpack = require('webpack')

packages/@vuepress/core/lib/eject.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
const path = require('path')
24
const { chalk, fs, logger } = require('@vuepress/shared-utils')
35

packages/@vuepress/core/lib/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
exports.dev = require('./dev')
24
exports.build = require('./build')
35
exports.eject = require('./eject')

packages/@vuepress/core/lib/plugin-api/abstract/AsyncOption.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ const { logger, chalk, datatypes: { isFunction }} = require('@vuepress/shared-ut
88
const Option = require('./Option')
99

1010
/**
11-
* Expose Asynchronous Option.
11+
* Expose asynchronous option class.
1212
*/
1313

1414
class AsyncOption extends Option {
1515
/**
1616
* Asynchronous serial running
17+
*
1718
* @param args
1819
* @param {Array<AsyncFunction>} args
20+
* @api public
1921
*/
2022

2123
async asyncApply (...args) {
@@ -42,8 +44,10 @@ class AsyncOption extends Option {
4244

4345
/**
4446
* Asynchronous serial running
47+
*
4548
* @param args
4649
* @param {Array<AsyncFunction>} args
50+
* @api public
4751
*/
4852

4953
async parallelApply (...args) {
@@ -72,8 +76,10 @@ class AsyncOption extends Option {
7276

7377
/**
7478
* Process a value via a pipeline.
79+
*
7580
* @param input
76-
* @returns {*}
81+
* @returns {any}
82+
* @api public
7783
*/
7884

7985
async pipeline (input) {

packages/@vuepress/core/lib/plugin-api/abstract/Option.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const { logger, chalk, compose, datatypes: { isFunction }} = require('@vuepress/shared-utils')
88

99
/**
10-
* Expose Option.
10+
* Expose synchronous option class.
1111
*/
1212

1313
class Option {
@@ -18,8 +18,10 @@ class Option {
1818

1919
/**
2020
* Set value with name.
21+
*
2122
* @param {string} name
2223
* @param {T} value
24+
* @api public
2325
*/
2426

2527
add (name, value) {
@@ -31,7 +33,9 @@ class Option {
3133

3234
/**
3335
* Delete value with name.
36+
*
3437
* @param {string} name
38+
* @api public
3539
*/
3640

3741
delete (name) {
@@ -44,7 +48,9 @@ class Option {
4448

4549
/**
4650
* Clean option store
51+
*
4752
* @param {string} name
53+
* @api public
4854
*/
4955

5056
clear (name) {
@@ -53,25 +59,31 @@ class Option {
5359

5460
/**
5561
* Get values.
62+
*
5663
* @returns {any<T>}
64+
* @api public
5765
*/
5866

5967
get values () {
6068
return this.items.map(item => item.value)
6169
}
6270

6371
/**
72+
* Get applied values
6473
*
6574
* @returns {Array|*|any[]}
75+
* @api public
6676
*/
6777

6878
get appliedValues () {
6979
return this.appliedItems && this.appliedItems.map(item => item.value)
7080
}
7181

7282
/**
73-
* Get values.
83+
* Get entries.
84+
*
7485
* @returns {any<T>}
86+
* @api public
7587
*/
7688

7789
get entries () {
@@ -80,7 +92,9 @@ class Option {
8092

8193
/**
8294
* Synchronous running
95+
*
8396
* @param {Array<Function>} args
97+
* @api public
8498
*/
8599

86100
syncApply (...args) {

packages/@vuepress/core/lib/plugin-api/index.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ module.exports = class PluginAPI {
2323
this.options = {}
2424
this._pluginContext = context
2525
this._pluginQueue = []
26-
this._initializeOptions(PLUGIN_OPTION_MAP)
26+
this.initializeOptions(PLUGIN_OPTION_MAP)
2727
}
2828

2929
/**
3030
* Get enabled plugins
31+
*
3132
* @returns {array}
33+
* @api public
3234
*/
3335

3436
get enabledPlugins () {
@@ -37,7 +39,9 @@ module.exports = class PluginAPI {
3739

3840
/**
3941
* Get disabled plugins
42+
*
4043
* @returns {array}
44+
* @api public
4145
*/
4246

4347
get disabledPlugins () {
@@ -46,6 +50,8 @@ module.exports = class PluginAPI {
4650

4751
/**
4852
* apply plugin.
53+
*
54+
* @api public
4955
*/
5056

5157
apply () {
@@ -60,9 +66,11 @@ module.exports = class PluginAPI {
6066

6167
/**
6268
* Normalize plugin and push it to the plugin queue.
69+
*
6370
* @param {object} pluginRaw
6471
* @param {object} pluginOptions
6572
* @returns {module.PluginAPI}
73+
* @api public
6674
*/
6775

6876
use (pluginRaw, pluginOptions = {}) {
@@ -84,8 +92,10 @@ module.exports = class PluginAPI {
8492

8593
/**
8694
* Use plugin by config.
95+
*
8796
* @param pluginsConfig
8897
* @returns {module.PluginAPI}
98+
* @api public
8999
*/
90100

91101
useByPluginsConfig (pluginsConfig) {
@@ -98,9 +108,11 @@ module.exports = class PluginAPI {
98108

99109
/**
100110
* initialize plugin options.
111+
*
112+
* @api private
101113
*/
102114

103-
_initializeOptions () {
115+
initializeOptions () {
104116
Object.keys(PLUGIN_OPTION_MAP).forEach(key => {
105117
const option = PLUGIN_OPTION_MAP[key]
106118
this.options[option.name] = instantiateOption(option.name)
@@ -109,10 +121,12 @@ module.exports = class PluginAPI {
109121

110122
/**
111123
* Register plugin option.
124+
*
112125
* @param {string} key
113126
* @param {any} value
114127
* @param {string} pluginName
115128
* @returns {module.PluginAPI}
129+
* @api private
116130
*/
117131

118132
registerOption (key, value, pluginName) {
@@ -132,6 +146,8 @@ module.exports = class PluginAPI {
132146

133147
/**
134148
* apply plugin.
149+
*
150+
* @api private
135151
*/
136152

137153
applyPlugin ({

packages/@vuepress/core/lib/plugin-api/override/EnhanceAppFilesOption.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
'use strict'
32

43
/**

packages/@vuepress/core/lib/prepare/AppContext.js

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
'use strict'
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
17
const path = require('path')
28
const createMarkdown = require('../markdown/index')
39
const loadConfig = require('./loadConfig')
@@ -8,17 +14,23 @@ const Page = require('./Page')
814
const I18n = require('./I18n')
915
const PluginAPI = require('../plugin-api/index')
1016

17+
/**
18+
* Expose AppContext.
19+
*/
20+
1121
module.exports = class AppContext {
1222
/**
1323
* Instantiate the app context with a new API
14-
* @param { string } sourceDir
24+
*
25+
* @param {string} sourceDir
1526
* @param {{
1627
* isProd: boolean,
1728
* plugins: pluginsConfig,
1829
* theme: themeNameConfig
1930
* temp: string
2031
* }} options
2132
*/
33+
2234
constructor (sourceDir, cliOptions = {}, isProd) {
2335
this.sourceDir = sourceDir
2436
this.cliOptions = cliOptions
@@ -47,8 +59,11 @@ module.exports = class AppContext {
4759

4860
/**
4961
* Load pages, load plugins, apply plugins / plugin options, etc.
62+
*
5063
* @returns {Promise<void>}
64+
* @api private
5165
*/
66+
5267
async process () {
5368
this.normalizeHeadTagUrls()
5469
this.markdown = createMarkdown(this.siteConfig)
@@ -72,7 +87,10 @@ module.exports = class AppContext {
7287

7388
/**
7489
* Apply internal and user plugins
90+
*
91+
* @api private
7592
*/
93+
7694
resolvePlugins () {
7795
const themeConfig = this.themeConfig
7896
const siteConfig = this.siteConfig
@@ -111,7 +129,10 @@ module.exports = class AppContext {
111129

112130
/**
113131
* normalize head tag urls for base
132+
*
133+
* @api private
114134
*/
135+
115136
normalizeHeadTagUrls () {
116137
if (this.base !== '/' && this.siteConfig.head) {
117138
this.siteConfig.head.forEach(tag => {
@@ -132,7 +153,10 @@ module.exports = class AppContext {
132153

133154
/**
134155
* Make template configurable
156+
*
157+
* @api private
135158
*/
159+
136160
resolveTemplates () {
137161
let { ssrTemplate, devTemplate } = this.siteConfig
138162
const templateDir = path.resolve(this.vuepressDir, 'templates')
@@ -156,8 +180,11 @@ module.exports = class AppContext {
156180

157181
/**
158182
* Find all page source files located in sourceDir
183+
*
159184
* @returns {Promise<void>}
185+
* @api private
160186
*/
187+
161188
async resolvePages () {
162189
// resolve pageFiles
163190
const patterns = ['**/*.md', '!.vuepress', '!node_modules']
@@ -179,8 +206,11 @@ module.exports = class AppContext {
179206

180207
/**
181208
* Add a page
182-
* @returns { Promise<void> }
209+
*
210+
* @returns {Promise<void>}
211+
* @api public
183212
*/
213+
184214
async addPage (options) {
185215
options.permalinkPattern = this.siteConfig.permalink
186216
const page = new Page(options)
@@ -194,15 +224,19 @@ module.exports = class AppContext {
194224

195225
/**
196226
* Resolve theme
197-
* @returns { Promise<void> }
227+
*
228+
* @returns {Promise<void>}
229+
* @api private
198230
*/
231+
199232
async resolveTheme () {
200233
const theme = this.siteConfig.theme || this.cliOptions.theme
201234
Object.assign(this, (await loadTheme(theme, this.sourceDir, this.vuepressDir)))
202235
}
203236

204237
/**
205238
* Get the data to be delivered to the client.
239+
*
206240
* @returns {{
207241
* title: string,
208242
* description: string,
@@ -211,7 +245,9 @@ module.exports = class AppContext {
211245
* themeConfig: ThemeConfig,
212246
* locales: Locales
213247
* }}
248+
* @api public
214249
*/
250+
215251
getSiteData () {
216252
return {
217253
title: this.siteConfig.title || '',
@@ -233,6 +269,7 @@ module.exports = class AppContext {
233269
* tempPath: string
234270
* }}
235271
*/
272+
236273
function createTemp (tempPath) {
237274
if (!tempPath) {
238275
tempPath = path.resolve(__dirname, '../../.temp')

0 commit comments

Comments
 (0)