-
-
Notifications
You must be signed in to change notification settings - Fork 417
/
index.js
101 lines (90 loc) · 2.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const vsg = require('vue-styleguidist')
const merge = require('webpack-merge')
const configSchemaImport = require('vue-styleguidist/lib/scripts/schemas/config')
const configSchema = configSchemaImport.default || configSchemaImport
const styleguidist = vsg.default || vsg
module.exports = (api, options) => {
api.configureWebpack(() => ({
// make sure that the docs blocks
// are ignored during normal serve & build
module: {
rules: [
{
resourceQuery: /blockType=docs/,
loader: 'null-loader'
}
]
}
}))
api.registerCommand(
'styleguidist:build',
{
description: 'build the styleguidist website',
usage: 'vue-cli-service styleguidist:build [options]',
options: {
'--config': 'path to the config file'
}
},
args => {
getStyleguidist(args, api, options).binutils.build()
}
)
api.registerCommand(
'styleguidist',
{
description: 'launch the styleguidist dev server',
usage: 'vue-cli-service styleguidist [options]',
options: {
'--config': 'path to the config file'
}
},
args => {
const server = getStyleguidist(args, api, options).binutils.server(args.open).app
// in order to avoid ghosted threads at the end of tests
;['SIGINT', 'SIGTERM'].forEach(signal => {
process.on(signal, () => {
server.close(() => {
process.exit(0)
})
})
})
// in tests, killing the process with SIGTERM causes execa to
// throw
if (process.env.VUE_CLI_TEST) {
process.stdin.on('data', data => {
if (data.toString() === 'close') {
// eslint-disable-next-line no-console
console.log('got close signal!')
server.close(() => {
process.exit(0)
})
}
})
}
}
)
}
function getStyleguidist(args, api, options) {
const conf = api.resolve(args.config || './styleguide.config.js')
const sgConf = conf && conf.length ? require(conf) : {}
const userWebpackConfig = sgConf.webpackConfig
options.outputDir = sgConf.styleguideDir || configSchema.styleguideDir.default
const cliWebpackConfig = getConfig(api)
return styleguidist(
conf,
config => (config.webpackConfig = merge(cliWebpackConfig, userWebpackConfig))
)
}
/**
* Make webpackConfig for styleguidist
* @param {Object} api
*/
function getConfig(api) {
const conf = api.resolveChainableWebpackConfig()
// because we are dealing with hot replacement in vsg
// remove duplicate hot module reload plugin
conf.plugins.delete('hmr')
// remove the double compiled successfully message
conf.plugins.delete('friendly-errors')
return api.resolveWebpackConfig(conf)
}