forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundler.js
79 lines (65 loc) · 2.21 KB
/
bundler.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
const fs = require('fs')
const appPaths = require('../app-paths')
const getPackage = require('../helpers/get-package')
const { log, warn, fatal } = require('../helpers/logger')
const versions = {
packager: '14.1.1',
builder: '22.4.0'
}
function isValidName (bundlerName) {
return ['packager', 'builder'].includes(bundlerName)
}
function installBundler (bundlerName) {
const { spawnSync } = require('../helpers/spawn')
const nodePackager = require('../helpers/node-packager')
const cmdParam = nodePackager === 'npm'
? ['install', '--save-dev']
: ['add', '--dev']
log(`Installing required Electron bundler (electron-${bundlerName})...`)
spawnSync(
nodePackager,
cmdParam.concat([`electron-${bundlerName}@${'^' + versions[bundlerName]}`]),
{ cwd: appPaths.appDir, env: { ...process.env, NODE_ENV: 'development' } },
() => warn(`Failed to install electron-${bundlerName}`)
)
}
function bundlerIsInstalled (bundlerName) {
const appPkg = require(appPaths.resolve.app('package.json'))
const pgkName = `electron-${bundlerName}`
return (
(appPkg.devDependencies && appPkg.devDependencies[pgkName])
|| (appPkg.dependencies && appPkg.dependencies[pgkName])
) !== void 0
}
module.exports.bundlerIsInstalled = bundlerIsInstalled
module.exports.ensureInstall = function (bundlerName) {
if (!isValidName(bundlerName)) {
fatal(`Unknown bundler "${ bundlerName }" for Electron\n`)
}
if (!bundlerIsInstalled(bundlerName)) {
installBundler(bundlerName)
}
}
module.exports.getDefaultName = function () {
if (bundlerIsInstalled('packager')) {
return 'packager'
}
if (bundlerIsInstalled('builder')) {
return 'builder'
}
return 'packager'
}
module.exports.getBundler = function (bundlerName) {
return getPackage(`electron-${bundlerName}`)
}
module.exports.ensureBuilderCompatibility = function () {
if (fs.existsSync(appPaths.resolve.electron('icons/linux-256x256.png'))) {
console.log()
console.log(`\n ⚠️ electron-builder requires a change to your src-electron/icons folder:
* replace linux-256x256.png with a 512x512 px png file named "linux-512x512.png"
* make sure to delete the old linux-256x256.png file
`)
console.log()
process.exit(1)
}
}