Skip to content

Commit ef44630

Browse files
author
User
committed
added Global Config APIs
1 parent 50c7d83 commit ef44630

File tree

4 files changed

+61
-64
lines changed

4 files changed

+61
-64
lines changed

API.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const G_C = require('./globalconfig/globalconfig')
1+
const G_C = require('./apis/globalconfig')
22

33
const GlobalConfig = [
44
G_C.SILENT,
@@ -7,7 +7,9 @@ const GlobalConfig = [
77
G_C.ERROR_HANDLER,
88
G_C.WARN_HANDLER,
99
G_C.IGNORED_ELEMENTS,
10-
G_C.KEY_CODES
10+
G_C.KEY_CODES,
11+
G_C.PERFORMANCE,
12+
G_C.PRODUCTION_TIP
1113
]
1214

1315

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const chalk = require('chalk')
2+
const custom = require('../customcolors')
3+
const colorComment = custom.colorComment
4+
const colorPrimitive = custom.colorPrimitive
5+
const colorError = custom.colorError
26

3-
colorComment = comment => chalk.gray(comment)
4-
5-
colorPrimitive = primitive => chalk.magentaBright(primitive)
67

78
const SILENT = {
89
category: 'Global Config',
@@ -18,12 +19,12 @@ const OPTION_MERGE_STRATEGIES = {
1819
type: '{ [key: string]: Function }',
1920
default: '{}',
2021
usage: `Vue.config.optionMergeStrategies._my_option = ${chalk.magentaBright('function')}(parent,child,vm){
21-
${chalk.magentaBright('return')} child + 1
22+
${chalk.magentaBright('return')} child + ${colorPrimitive('1')}
2223
}
2324
${chalk.magentaBright('const')} Profile = Vue.extend({
24-
_my_option: 1
25+
_my_option: ${colorPrimitive('1')}
2526
})
26-
// Profile.options._my_option = 2\n`,
27+
${colorComment("// Profile.options._my_option = 2")}\n`,
2728
details: `Define custom merging strategies for options.
2829
The merge strategy receives the value of that option defined
2930
on the parent and child instances as the first and second arguments,
@@ -34,7 +35,7 @@ const DEVTOOLS = {
3435
name: 'devtools',
3536
type: 'boolean',
3637
default: `true ${chalk.white('(')} false ${chalk.white('in production builds)')}`,
37-
usage: `// make sure to set this synchronously immediately after loading Vue
38+
usage: `${colorComment("// make sure to set this synchronously immediately after loading Vue")}
3839
Vue.config.devtools = ${chalk.magentaBright('true')}`,
3940
details: `Check whether to allow ${chalk.green('vue-devtools')} inspection.
4041
This option's default value is ${chalk.magentaBright('true')} in development builds and ${chalk.magentaBright('false')} in production builds.
@@ -46,9 +47,9 @@ const ERROR_HANDLER = {
4647
type: 'Function',
4748
default: 'undefined',
4849
usage: `Vue.config.errorHandler = ${chalk.magentaBright('function')}(err,vm,info){
49-
// handle error
50-
// 'info' is a Vue-specific error info, e.g. which lifecycle hook
51-
// the error was found in. Only available in 2.2.0+
50+
${colorComment("// handle error")}
51+
${colorComment("// 'info' is a Vue-specific error info, e.g. which lifecycle hook")}
52+
${colorComment("// the error was found in. Only available in 2.2.0+")}
5253
}`,
5354
details: `Assign a handler for uncaught errors during component render function
5455
and watchers. The handler gets called with the error and the Vue instance.`
@@ -59,8 +60,8 @@ const WARN_HANDLER = {
5960
name: 'warnHandler',
6061
type: 'Function',
6162
default: 'undefined',
62-
usage: `Vue.config.warnHandler = ${chalk.magentaBright('function')} (msg, vm, trace) {
63-
// trace is the component hierarchy trace
63+
usage: `Vue.config.warnHandler = ${chalk.magentaBright('function')}(msg,vm,trace){
64+
${colorComment("// trace is the component hierarchy trace")}
6465
}`,
6566
details: `Assign a custom handler for runtime Vue warnings. Note this only works
6667
during development and is ignored in production.`
@@ -75,7 +76,7 @@ const IGNORED_ELEMENTS = {
7576
]`,
7677
details: `Make Vue ignore custom elements defined outside of Vue
7778
(e.g., using the Web Components APIs). Otherwise, it will throw
78-
a warning about an ${chalk.magentaBright('Unknown custom element')}, assuming that you forgot to
79+
a warning about an ${colorError("Unknown custom element")}, assuming that you forgot to
7980
register a global component or misspelled a component name.`
8081
}
8182

@@ -99,53 +100,26 @@ const KEY_CODES = {
99100
details: 'Define custom key alias(es) for v-on.'
100101
}
101102

102-
/*const SILENT = {
103-
category: 'Global Config',
104-
name: '#silent',
105-
type: 'boolean',
106-
default: 'false',
107-
arguments: '',
108-
readOption: '',
109-
usage: `Vue.config.silent = ${chalk.magentaBright('true')}`,
110-
details: 'Suppress all Vue logs and warnings',
111-
example: ''
112-
}
113-
const SILENT = {
114-
category: 'Global Config',
115-
name: '#silent',
116-
type: 'boolean',
117-
default: 'false',
118-
arguments: '',
119-
readOption: '',
120-
usage: `Vue.config.silent = ${chalk.magentaBright('true')}`,
121-
details: 'Suppress all Vue logs and warnings',
122-
example: ''
123-
}
124-
125-
const SILENT = {
103+
const PERFORMANCE = {
126104
category: 'Global Config',
127-
name: '#silent',
105+
name: 'performance',
128106
type: 'boolean',
129-
default: 'false',
130-
arguments: '',
131-
readOption: '',
132-
usage: `Vue.config.silent = ${chalk.magentaBright('true')}`,
133-
details: 'Suppress all Vue logs and warnings',
134-
example: ''
107+
default: 'false (from 2.2.3)',
108+
usage: `Vue.config.performance = ${chalk.magentaBright('true')}`,
109+
details: `Set this to ${colorPrimitive("true")} to enable component init, compile,
110+
render, and patch performance in the browser devtool timeline.
111+
Only works in development mode and in browsers that support the
112+
${chalk.green("performance.mark")} API.`,
135113
}
136-
137-
const SILENT = {
114+
const PRODUCTION_TIP = {
138115
category: 'Global Config',
139-
name: '#silent',
116+
name: 'productionTip',
140117
type: 'boolean',
141-
default: 'false',
142-
arguments: '',
143-
readOption: '',
144-
usage: `Vue.config.silent = ${chalk.magentaBright('true')}`,
145-
details: 'Suppress all Vue logs and warnings',
146-
example: ''
118+
default: 'true',
119+
usage: `Vue.config.productionTip = ${chalk.magentaBright('false')}`,
120+
details: `Set this to ${colorPrimitive("false")} to prevent the production
121+
tip on Vue startup.`
147122
}
148-
*/
149123

150124
module.exports = {
151125
SILENT,
@@ -154,5 +128,7 @@ module.exports = {
154128
ERROR_HANDLER,
155129
WARN_HANDLER,
156130
IGNORED_ELEMENTS,
157-
KEY_CODES
131+
KEY_CODES,
132+
PERFORMANCE,
133+
PRODUCTION_TIP
158134
}

customcolors.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const chalk = require('chalk')
2+
3+
module.exports = {
4+
colorComment: comment => chalk.gray(comment),
5+
colorPrimitive: primitive => chalk.magentaBright(primitive),
6+
colorError: err => chalk.red(err)
7+
}

vue-help.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,56 @@ V.delimiter('vue-help$').show()
88

99
// Global Config API
1010

11-
V.command('silent', 'Outputs').action(function(args, callback){
11+
V.command('silent', 'Outputs "Global Config: #silent"').action(function(args, callback){
1212
const silent= gc[0]
1313
this.log(LGC.logGlobalConfig(silent))
1414
callback()
1515
})
1616

17-
V.command('optionMergeStrategies', 'Outputs').action(function(args, callback){
17+
V.command('optionMergeStrategies', 'Outputs "Global Config: #optionMergeStrategies"').action(function(args, callback){
1818
const optMergeStrat = gc[1]
1919
this.log(LGC.logGlobalConfig(optMergeStrat))
2020
callback()
2121
})
2222

23-
V.command('devtools', 'Outputs').action(function(args, callback){
23+
V.command('devtools', 'Outputs "Global Config: #devtools"').action(function(args, callback){
2424
const devtools = gc[2]
2525
this.log(LGC.logGlobalConfig(devtools))
2626
callback()
2727
})
2828

29-
V.command('errorHandler', 'Outputs').action(function(args, callback){
29+
V.command('errorHandler', 'Outputs "Global Config: #errorHandler"').action(function(args, callback){
3030
const errorHandler = gc[3]
3131
this.log(LGC.logGlobalConfig(errorHandler))
3232
callback()
3333
})
3434

35-
V.command('warnHandler', 'Outputs').action(function(args, callback){
35+
V.command('warnHandler', 'Outputs "Global Config: #warnHandler"').action(function(args, callback){
3636
const warnHandler = gc[4]
3737
this.log(LGC.logGlobalConfig(warnHandler))
3838
callback()
3939
})
4040

41-
V.command('ignoredElements', 'Outputs').action(function(args, callback){
41+
V.command('ignoredElements', 'Outputs "Global Config: #ignoredElements"').action(function(args, callback){
4242
const ignoredElements = gc[5]
4343
this.log(LGC.logGlobalConfig(ignoredElements))
4444
callback()
4545
})
4646

47-
V.command('keyCodes', 'Outputs').action(function(args, callback){
47+
V.command('keyCodes', 'Outputs "Global Config: #keyCodes"').action(function(args, callback){
4848
const keyCodes = gc[6]
4949
this.log(LGC.logGlobalConfig(keyCodes))
5050
callback()
51+
})
52+
53+
V.command('performance', 'Outputs "Global Config: #performance"').action(function(args, callback){
54+
const perf = gc[7]
55+
this.log(LGC.logGlobalConfig(perf))
56+
callback()
57+
})
58+
59+
V.command('productionTip', 'Outputs "Global Config: #productionTip"').action(function(args, callback){
60+
const prod = gc[8]
61+
this.log(LGC.logGlobalConfig(prod))
62+
callback()
5163
})

0 commit comments

Comments
 (0)