Skip to content

Commit 710aad6

Browse files
author
User
committed
added Global API
1 parent ef44630 commit 710aad6

File tree

5 files changed

+119
-4
lines changed

5 files changed

+119
-4
lines changed

API.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const G_C = require('./apis/globalconfig')
2+
const G_API = require('./apis/globalapi')
23

34
const GlobalConfig = [
45
G_C.SILENT,
@@ -12,7 +13,12 @@ const GlobalConfig = [
1213
G_C.PRODUCTION_TIP
1314
]
1415

16+
const GlobalAPI = [
17+
G_API.EXTEND
18+
]
19+
1520

1621
module.exports = {
17-
GlobalConfig
22+
GlobalConfig,
23+
GlobalAPI
1824
}

apis/globalapi.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const chalk = require('chalk')
2+
const custom = require('../customcolors')
3+
const colorComment = custom.colorComment
4+
const colorPrimitive = custom.colorPrimitive
5+
const colorError = custom.colorError
6+
const colorArgs = custom.colorArgs
7+
8+
const EXTEND = {
9+
category: 'Global API',
10+
name: 'Vue.extend(options)',
11+
arguments: [
12+
`{Object} options`
13+
],
14+
usage: `Create a "subclass" of the base Vue constructor. The argument should be
15+
an object containing component options. The special case to
16+
note here is the ${colorArgs('data')} options - it must be a
17+
function when used with ${colorArgs('Vue.extend()')}.`,
18+
example: ` ${colorComment('// in template')}
19+
${chalk.blue('<div id=')}${chalk.green('"mount-point"')}${chalk.blue('></div>')}
20+
${colorComment('// create constructor')}
21+
${colorArgs('var')} Profile = Vue.extend({
22+
template: ${chalk.green("'<p>{{firstName}} {{lastName}} aka {{alias}}</p>'")}
23+
data: ${chalk.blue('function')} () {
24+
${colorArgs('return')} {
25+
firstName: ${chalk.green("'Walter'")},
26+
lastName: ${chalk.green("'White'")},
27+
alias: ${chalk.green("'Heisenberg'")}
28+
}
29+
}
30+
})
31+
${colorComment('// create an instance of Profile and mount it on an element')}
32+
${colorArgs('new')} Profile().$mount(${chalk.green("'#mount-point'")})
33+
Will result in:
34+
${chalk.blue('<p>')}Walter White aka Heisenberg${chalk.blue('</p>')}`
35+
}
36+
37+
const NEXT_TICK = {
38+
39+
}
40+
41+
const SET = {
42+
43+
}
44+
45+
const DELETE = {
46+
47+
}
48+
49+
const DIRECTIVE = {
50+
51+
}
52+
53+
const FILTER = {
54+
55+
}
56+
57+
const COMPONENT = {
58+
59+
}
60+
61+
const USE = {
62+
63+
}
64+
65+
const MIXIN = {
66+
67+
}
68+
69+
const COMPILE = {
70+
71+
}
72+
73+
const VERSION = {
74+
75+
}
76+
77+
module.exports = {
78+
EXTEND
79+
}

customcolors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ const chalk = require('chalk')
33
module.exports = {
44
colorComment: comment => chalk.gray(comment),
55
colorPrimitive: primitive => chalk.magentaBright(primitive),
6-
colorError: err => chalk.red(err)
6+
colorError: err => chalk.red(err),
7+
colorArgs: args => chalk.rgb(255,165,0)(args)
78
}

logfunctions/logglobalapi.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const chalk = require('chalk')
2+
const custom = require('../customcolors')
3+
const args = custom.colorArgs
4+
module.exports = {
5+
logGlobalAPI: function(obj){
6+
return(
7+
`
8+
${chalk.green('Category:')} ${obj.category}
9+
${chalk.green('Name:')} ${obj.name + '\n'}
10+
* Arguments:
11+
${obj.arguments.map(arg => {
12+
return `* ${args(arg)}`
13+
})}
14+
15+
* Usage: ${obj.usage}
16+
* Example: ${obj.example}
17+
`
18+
)
19+
}
20+
}

vue-help.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const V = require('vorpal')()
22
const LGC = require('./logfunctions/logglobalconfig')
3+
const LGA = require('./logfunctions/logglobalapi')
34
const api = require('./API')
45
const gc = api.GlobalConfig
5-
6+
const ga = api.GlobalAPI
67

78
V.delimiter('vue-help$').show()
89

9-
// Global Config API
10+
// Global Config
1011

1112
V.command('silent', 'Outputs "Global Config: #silent"').action(function(args, callback){
1213
const silent= gc[0]
@@ -60,4 +61,12 @@ V.command('productionTip', 'Outputs "Global Config: #productionTip"').action(fun
6061
const prod = gc[8]
6162
this.log(LGC.logGlobalConfig(prod))
6263
callback()
64+
})
65+
66+
// Global API
67+
68+
V.command('extend', 'Outputs "Global API: #Vue.extend(options)"').action(function(args, callback){
69+
const ex = ga[0]
70+
this.log(LGA.logGlobalAPI(ex))
71+
callback()
6372
})

0 commit comments

Comments
 (0)