chore: update the npm package to use @electron/get (#18413)
* chore: update the npm package to use @electron/get * chore: update node requirement for got
This commit is contained in:
parent
cbc177708e
commit
a6637fbce9
2 changed files with 25 additions and 38 deletions
|
@ -1,14 +1,14 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var version = require('./package').version
|
const version = require('./package').version
|
||||||
|
|
||||||
var fs = require('fs')
|
const fs = require('fs')
|
||||||
var os = require('os')
|
const os = require('os')
|
||||||
var path = require('path')
|
const path = require('path')
|
||||||
var extract = require('extract-zip')
|
const extract = require('extract-zip')
|
||||||
var download = require('electron-download')
|
const { downloadArtifact } = require('@electron/get')
|
||||||
|
|
||||||
var installedVersion = null
|
let installedVersion = null
|
||||||
try {
|
try {
|
||||||
installedVersion = fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '')
|
installedVersion = fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '')
|
||||||
} catch (ignored) {
|
} catch (ignored) {
|
||||||
|
@ -19,28 +19,26 @@ if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
var platformPath = getPlatformPath()
|
const platformPath = getPlatformPath()
|
||||||
|
|
||||||
var electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath)
|
const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath)
|
||||||
|
|
||||||
if (installedVersion === version && fs.existsSync(electronPath)) {
|
if (installedVersion === version && fs.existsSync(electronPath)) {
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloads if not cached
|
// downloads if not cached
|
||||||
download({
|
downloadArtifact({
|
||||||
cache: process.env.electron_config_cache,
|
version,
|
||||||
version: version,
|
artifactName: 'electron',
|
||||||
platform: process.env.npm_config_platform,
|
|
||||||
arch: process.env.npm_config_arch,
|
|
||||||
strictSSL: process.env.npm_config_strict_ssl === 'true',
|
|
||||||
force: process.env.force_no_cache === 'true',
|
force: process.env.force_no_cache === 'true',
|
||||||
quiet: process.env.npm_config_loglevel === 'silent' || process.env.CI
|
cacheRoot: process.env.electron_config_cache,
|
||||||
}, extractFile)
|
platform: process.env.npm_config_platform || process.platform,
|
||||||
|
arch: process.env.npm_config_arch || process.arch
|
||||||
|
}).then((zipPath) => extractFile(zipPath)).catch((err) => onerror(err))
|
||||||
|
|
||||||
// unzips and makes path.txt point at the correct executable
|
// unzips and makes path.txt point at the correct executable
|
||||||
function extractFile (err, zipPath) {
|
function extractFile (zipPath) {
|
||||||
if (err) return onerror(err)
|
|
||||||
extract(zipPath, { dir: path.join(__dirname, 'dist') }, function (err) {
|
extract(zipPath, { dir: path.join(__dirname, 'dist') }, function (err) {
|
||||||
if (err) return onerror(err)
|
if (err) return onerror(err)
|
||||||
fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, function (err) {
|
fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, function (err) {
|
||||||
|
@ -54,7 +52,7 @@ function onerror (err) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlatformPath () {
|
function getPlatformPath () {
|
||||||
var platform = process.env.npm_config_platform || os.platform()
|
const platform = process.env.npm_config_platform || os.platform()
|
||||||
|
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
|
|
|
@ -1,29 +1,18 @@
|
||||||
{
|
{
|
||||||
"scripts": {
|
"main": "index.js",
|
||||||
"cache-clean": "rm -rf ~/.electron && rm -rf dist",
|
"types": "electron.d.ts",
|
||||||
"postinstall": "node install.js",
|
|
||||||
"pretest": "npm run cache-clean",
|
|
||||||
"test": "standard"
|
|
||||||
},
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"electron": "cli.js"
|
"electron": "cli.js"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"scripts": {
|
||||||
"types": "electron.d.ts",
|
"postinstall": "node install.js"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@electron/get": "^1.0.1",
|
||||||
"@types/node": "^10.12.18",
|
"@types/node": "^10.12.18",
|
||||||
"electron-download": "^4.1.0",
|
|
||||||
"extract-zip": "^1.0.3"
|
"extract-zip": "^1.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
|
||||||
"home-path": "^0.1.1",
|
|
||||||
"path-exists": "^2.0.0",
|
|
||||||
"standard": "^5.4.1"
|
|
||||||
},
|
|
||||||
"directories": {
|
|
||||||
"test": "test"
|
|
||||||
},
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 4.0"
|
"node": ">= 8.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue