forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (61 loc) · 2.1 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
const { installedBrowsers } = require('@vue/cli-shared-utils')
const applyTS = module.exports.applyTS = (api, invoking) => {
api.extendPackage({
devDependencies: {
'@types/mocha': '^8.0.1'
}
})
// inject types to tsconfig.json
if (invoking) {
api.render(files => {
const tsconfig = files['tsconfig.json']
if (tsconfig) {
const parsed = JSON.parse(tsconfig)
const types = parsed.compilerOptions.types
if (types) {
for (const t of ['mocha', '@wdio/mocha-framework', '@wdio/sync']) {
if (!types.includes(t)) {
types.push(t)
}
}
}
files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + '\n'
}
})
}
}
module.exports = (api, { webdrivers }, rootOptions, invoking) => {
api.render('./template', {
hasTS: api.hasPlugin('typescript'),
hasESLint: api.hasPlugin('eslint')
})
const devDependencies = {}
// Use devDependencies to store latest version number so as to automate update
const pluginDeps = require('../package.json').devDependencies
if (api.hasPlugin('typescript')) {
devDependencies['ts-node'] = pluginDeps['ts-node']
}
if (webdrivers && webdrivers.includes('firefox')) {
devDependencies.geckodriver = pluginDeps.geckodriver
devDependencies['wdio-geckodriver-service'] = pluginDeps['wdio-geckodriver-service']
}
if (webdrivers && webdrivers.includes('chrome')) {
// chromedriver major version bumps every 6 weeks following Chrome
// so there may be a mismatch between
// user's installed browser version and the default provided version
// fallback to the devDependencies version in case detection fails
devDependencies['wdio-chromedriver-service'] = pluginDeps['wdio-chromedriver-service']
devDependencies.chromedriver = installedBrowsers.chrome
? installedBrowsers.chrome.match(/^(\d+)\./)[1]
: pluginDeps.chromedriver
}
api.extendPackage({
scripts: {
'test:e2e': 'vue-cli-service test:e2e'
},
devDependencies
})
if (api.hasPlugin('typescript')) {
applyTS(api, invoking)
}
}