Skip to content

Commit ec48369

Browse files
committed
[skip ci] feat(generator): allow user to select electron version
1 parent ed0bcb8 commit ec48369

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

generator/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs')
22

3-
module.exports = api => {
3+
module.exports = (api, options = {}) => {
44
const usesTS = api.hasPlugin('typescript')
55
const hasBackground =
66
fs.existsSync(api.resolve(`./src/background.ts`)) ||
@@ -72,15 +72,18 @@ module.exports = api => {
7272
// Create new postinstall script
7373
postinstallScript = 'electron-builder install-app-deps'
7474
}
75+
const devDependencies = {}
76+
if (options.electronBuilder && options.electronBuilder.electronVersion) {
77+
// Use provided electron version
78+
devDependencies.electron = options.electronBuilder.electronVersion
79+
}
7580
api.extendPackage({
7681
scripts: {
7782
'electron:build': 'vue-cli-service electron:build',
7883
'electron:serve': 'vue-cli-service electron:serve',
7984
postinstall: postinstallScript
8085
},
81-
devDependencies: {
82-
electron: '^2.0.2'
83-
},
86+
devDependencies,
8487
main: 'background.js'
8588
})
8689
}

prompts.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const path = require('path')
2+
3+
module.exports = [
4+
{
5+
name: 'electronBuilder.electronVersion',
6+
type: 'list',
7+
message: 'Choose Electron Version',
8+
choices: [
9+
{
10+
name: '^2.0.0 (stable)',
11+
value: '^2.0.0',
12+
short: '^2.0.0'
13+
},
14+
{
15+
name: '^3.0.0 (may have small issues)',
16+
value: '^3.0.0',
17+
short: '^3.0.0'
18+
}
19+
],
20+
when: () => {
21+
try {
22+
// Attempt to read package.json
23+
const pkg = require(path.join(process.cwd(), 'package.json'))
24+
// Don't show if electron version is already set
25+
return !pkg.devDependencies.electron
26+
} catch (e) {
27+
console.log('Unable to read package.json')
28+
return true
29+
}
30+
}
31+
}
32+
]

0 commit comments

Comments
 (0)