Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Render custom icons
Browse files Browse the repository at this point in the history
This closes #5
  • Loading branch information
leo committed Feb 8, 2018
1 parent af1e848 commit 1fa33eb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
17 changes: 13 additions & 4 deletions lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const getDependencies = async cwd => {
return new Set(list.filter(Boolean))
}

module.exports = async (workingDir, outputDir, { name, asar, slug }) => {
module.exports = async (workingDir, outputDir, config) => {
spinner.create(`Bundling application for ${os}`)

const include = [
Expand All @@ -77,11 +77,11 @@ module.exports = async (workingDir, outputDir, { name, asar, slug }) => {
]

const isWin = process.platform === 'win32'
const main = join(outputDir, isWin ? 'electron' : `${name}.app`)
const main = join(outputDir, isWin ? 'electron' : `${config.name}.app`)
const parent = join(main, isWin ? 'resources' : 'Contents/Resources')
const target = join(parent, asar ? 'app.asar' : 'app')
const target = join(parent, config.asar ? 'app.asar' : 'app')

if (asar) {
if (config.asar) {
// The items within this collection won't be walked. Not their
// contents will be included – only their actual representation
// in the file system.
Expand All @@ -107,6 +107,15 @@ module.exports = async (workingDir, outputDir, { name, asar, slug }) => {
await Promise.all(copiers)
}

if (!isWin) {
const icon = {
origin: config.macOS.icon,
target: join(parent, `${config.slug}.icns`)
}

await fs.copy(icon.origin, icon.target)
}

// Remove any useless files from the bundle
await clear(parent, remove)

Expand Down
4 changes: 2 additions & 2 deletions lib/build/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ const createDMG = (outputDir, appPath, config) => new Promise(resolve => {
})

const createEXE = (outputDirectory, appDirectory, config) => {
const { name: title, slug, version } = config
const { name: title, slug, version, windows } = config

return generateEXE({
appDirectory,
outputDirectory,
iconUrl: join(process.cwd(), 'windows.ico'),
iconUrl: windows.icon,
authors: 'ACME, Inc.',
version,
noMsi: true,
Expand Down
49 changes: 27 additions & 22 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Native
const { join } = require('path')
const { join, resolve } = require('path')

// Packages
const { pathExists, readJSON } = require('fs-extra')
Expand All @@ -17,40 +17,45 @@ module.exports = async cwd => {
return
}

let version
let neutron
let name
const defaultConfig = {
asar: true,
macOS: {
icon: './main/static/mac.icns'
},
windows: {
icon: './main/static/windows.ico'
}
}

let packageConfig

try {
({ name, version, neutron } = await readJSON(location))
packageConfig = await readJSON(location)
} catch (err) {
spinner.fail('Not able to read the `package.json` file')
return
}

if (!neutron) {
neutron = {}
if (!packageConfig.version) {
spinner.fail('Please specify `version` inside `package.json`')
return
}

if (!neutron.name && name) {
neutron.name = capitalize.words(name.replace('-', ' '))
} else if (!name) {
const config = Object.assign(defaultConfig, packageConfig.neutron || {}, {
version: packageConfig.version
})

if (!config.name && packageConfig.name) {
config.name = capitalize.words(packageConfig.name.replace('-', ' '))
} else if (!packageConfig.name) {
spinner.fail('Please set `name` or `neutron.name` inside `package.json`')
return
}

if (!version) {
spinner.fail('Please specify `version` inside `package.json`')
return
}
config.slug = dashify(config.name)

if (typeof neutron.asar === 'undefined') {
neutron.asar = true
}
config.macOS.icon = resolve(cwd, config.macOS.icon)
config.windows.icon = resolve(cwd, config.windows.icon)

return {
...neutron,
slug: dashify(neutron.name ? neutron.name : name),
version
}
return config
}
Binary file added template/main/static/mac.icns
Binary file not shown.
Binary file added template/main/static/windows.ico
Binary file not shown.

0 comments on commit 1fa33eb

Please sign in to comment.