1
1
const fs = require ( 'fs' )
2
+ const semver = require ( 'semver' )
2
3
3
4
module . exports = ( api , options = { } ) => {
4
5
if ( ! options . electronBuilder ) options . electronBuilder = { }
6
+ const electronVersion = options . electronBuilder . electronVersion
7
+ let pkg = fs . readFileSync ( api . resolve ( './package.json' ) , 'utf8' )
8
+ pkg = JSON . parse ( pkg )
5
9
const usesTS = api . hasPlugin ( 'typescript' )
6
10
const hasBackground =
7
11
fs . existsSync ( api . resolve ( `./src/background.ts` ) ) ||
8
12
fs . existsSync ( api . resolve ( `./src/background.js` ) )
13
+
9
14
if ( ! hasBackground ) {
10
15
// If user does not have a background file it should be created
11
- api . render ( './templates/base' )
16
+ api . render ( './templates/base' , {
17
+ // Scheme registration changed in Electron 5.0.0
18
+ newSchemeRegistrationFunction : semver . gte (
19
+ ( electronVersion || pkg . devDependencies . electron ) . replace ( '^' , '' ) ,
20
+ '5.0.0'
21
+ )
22
+ } )
12
23
}
13
24
// Add tests
14
25
let testFramework
@@ -44,7 +55,10 @@ module.exports = (api, options = {}) => {
44
55
/ p r o c e s s \. e n v \. W E B P A C K _ D E V _ S E R V E R _ U R L \s * ?\) $ / m,
45
56
'process.env.WEBPACK_DEV_SERVER_URL as string)'
46
57
)
47
- background = background . replace ( / l e t w i n \s * ?$ / m, 'let win: BrowserWindow | null' )
58
+ background = background . replace (
59
+ / l e t w i n \s * ?$ / m,
60
+ 'let win: BrowserWindow | null'
61
+ )
48
62
fs . writeFileSync ( api . resolve ( './src/background.ts' ) , background )
49
63
if ( api . hasPlugin ( 'router' ) ) {
50
64
console . log ( '\n' )
@@ -60,8 +74,6 @@ module.exports = (api, options = {}) => {
60
74
'electron:build' : 'vue-cli-service electron:build' ,
61
75
'electron:serve' : 'vue-cli-service electron:serve'
62
76
}
63
- let pkg = fs . readFileSync ( api . resolve ( './package.json' ) , 'utf8' )
64
- pkg = JSON . parse ( pkg )
65
77
const addScript = ( name , command ) => {
66
78
// Add on to existing script if it exists
67
79
if ( pkg . scripts && pkg . scripts [ name ] ) {
@@ -81,9 +93,9 @@ module.exports = (api, options = {}) => {
81
93
addScript ( 'postinstall' , 'electron-builder install-app-deps' )
82
94
addScript ( 'postuninstall' , 'electron-builder install-app-deps' )
83
95
const devDependencies = { }
84
- if ( options . electronBuilder . electronVersion ) {
96
+ if ( electronVersion ) {
85
97
// Use provided electron version
86
- devDependencies . electron = options . electronBuilder . electronVersion
98
+ devDependencies . electron = electronVersion
87
99
}
88
100
const dependencies = { }
89
101
if ( testFramework === 'mocha' ) {
0 commit comments