forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode-electron.js
84 lines (68 loc) · 2.1 KB
/
mode-electron.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
const fs = require('fs')
const fse = require('fs-extra')
const appPaths = require('../app-paths')
const { log, warn } = require('../helpers/logger')
const { spawnSync } = require('../helpers/spawn')
const nodePackager = require('../helpers/node-packager')
const { bundlerIsInstalled } = require('../electron/bundler')
const electronDeps = {
'electron': '^9.0.0',
'electron-debug': '^3.0.1',
'electron-devtools-installer': '^3.0.0',
'devtron': '^1.4.0'
}
class Mode {
get isInstalled () {
return fs.existsSync(appPaths.electronDir)
}
add () {
if (this.isInstalled) {
warn(`Electron support detected already. Aborting.`)
return
}
const cmdParam = nodePackager === 'npm'
? ['install', '--save-dev']
: ['add', '--dev']
log(`Installing Electron dependencies...`)
spawnSync(
nodePackager,
cmdParam.concat(Object.keys(electronDeps).map(dep => {
return `${dep}@${electronDeps[dep]}`
})),
{ cwd: appPaths.appDir, env: { ...process.env, NODE_ENV: 'development' } },
() => warn('Failed to install Electron dependencies')
)
log(`Creating Electron source folder...`)
fse.copySync(
appPaths.resolve.cli('templates/electron'),
appPaths.electronDir
)
log(`Electron support was added`)
}
remove () {
if (!this.isInstalled) {
warn(`No Electron support detected. Aborting.`)
return
}
log(`Removing Electron source folder`)
fse.removeSync(appPaths.electronDir)
const cmdParam = nodePackager === 'npm'
? ['uninstall', '--save-dev']
: ['remove']
const deps = Object.keys(electronDeps)
;['packager', 'builder'].forEach(bundlerName => {
if (bundlerIsInstalled(bundlerName)) {
deps.push(`electron-${bundlerName}`)
}
})
log(`Uninstalling Electron dependencies...`)
spawnSync(
nodePackager,
cmdParam.concat(deps),
{ cwd: appPaths.appDir, env: { ...process.env, NODE_ENV: 'development' } },
() => warn('Failed to uninstall Electron dependencies')
)
log(`Electron support was removed`)
}
}
module.exports = Mode