Skip to content

Commit

Permalink
Convert more code to use electron-installer-common (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored Jan 4, 2019
1 parent 4ce638e commit a8e399d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@
"nyc": "^13.1.0"
},
"dependencies": {
"asar": "^0.14.6",
"cross-spawn-promise": "^0.10.1",
"debug": "^4.1.1",
"electron-installer-common": "^0.4.0",
"electron-installer-common": "^0.4.2",
"fs-extra": "^7.0.1",
"js-yaml": "^3.10.0",
"lodash.filter": "^4.6.0",
Expand Down
36 changes: 5 additions & 31 deletions src/default_args.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
/*
Copyright 2017 Mark Lee and contributors
Copyright 2017, 2018, 2019 Mark Lee and contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

const asar = require('asar')
const debug = require('debug')('electron-installer-snap:default_args')
const fs = require('fs-extra')
const path = require('path')
const { readMeta } = require('electron-installer-common')

function defaultArgsFromPackageJSON (packageJSON) {
return {
Expand All @@ -29,31 +27,7 @@ function defaultArgsFromPackageJSON (packageJSON) {
}
}

function defaultArgsFromAsar (asarFilename) {
const packageJSON = JSON.parse(asar.extractFile(asarFilename, 'package.json'))
return defaultArgsFromPackageJSON(packageJSON)
module.exports = function defaultArgsFromApp (packageDir) {
return readMeta({ src: packageDir, logger: debug })
.then(defaultArgsFromPackageJSON)
}

function defaultArgsFromPackageJSONFile (packageDir, resourcesDir) {
return fs.readJson(path.join(resourcesDir, 'app', 'package.json'))
.catch(err => {
throw new Error(`Could not find, read, or parse package.json in packaged app '${packageDir}':\n${err.message}`)
}).then(packageJSON => defaultArgsFromPackageJSON(packageJSON))
}

function defaultArgsFromApp (packageDir) {
const resourcesDir = path.resolve(packageDir, 'resources')
const asarFilename = path.join(resourcesDir, 'app.asar')
return fs.pathExists(asarFilename)
.then(asarExists => {
if (asarExists) {
debug('Loading package.json defaults from', asarFilename)
return defaultArgsFromAsar(asarFilename)
} else {
debug('Loading package.json defaults from', packageDir)
return defaultArgsFromPackageJSONFile(packageDir, resourcesDir)
}
})
}

module.exports = defaultArgsFromApp
13 changes: 6 additions & 7 deletions src/yaml.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
/*
Copyright 2017 Mark Lee and contributors
Copyright 2017, 2018, 2019 Mark Lee and contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,12 +16,11 @@ limitations under the License.
*/

const debug = require('debug')('electron-installer-snap:yaml')
const dependencies = require('electron-installer-common/src/dependencies')
const common = require('electron-installer-common')
const fs = require('fs-extra')
const merge = require('lodash.merge')
const path = require('path')
const pull = require('lodash.pull')
const readElectronVersion = require('electron-installer-common/src/readelectronversion')
const yaml = require('js-yaml')

const { createDesktopLaunchCommand } = require('./launcher')
Expand Down Expand Up @@ -158,14 +157,14 @@ class SnapcraftYAML {
this.parts.organize = {}
this.parts.organize[path.basename(packageDir)] = this.data.name

return readElectronVersion(packageDir)
return common.readElectronVersion(packageDir)
.then(version => this.updateDependencies(version))
}

updateDependencies (version) {
this.parts.after[0] = dependencies.getGTKDepends(version, DEPENDENCY_MAP)
this.parts['stage-packages'] = this.parts['stage-packages'].concat(dependencies.getGConfDepends(version, DEPENDENCY_MAP))
.concat(dependencies.getUUIDDepends(version, DEPENDENCY_MAP))
this.parts.after[0] = common.getGTKDepends(version, DEPENDENCY_MAP)
this.parts['stage-packages'] = this.parts['stage-packages'].concat(common.getGConfDepends(version, DEPENDENCY_MAP))
.concat(common.getUUIDDepends(version, DEPENDENCY_MAP))

return this.data
}
Expand Down

0 comments on commit a8e399d

Please sign in to comment.