Skip to content

Commit

Permalink
Build linux AppDir
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Apr 23, 2017
1 parent 6ff0298 commit d42cce2
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 16 deletions.
8 changes: 8 additions & 0 deletions scripts/appimage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -x

set +e

curl -L https://github.com/probonopd/AppImages/raw/master/functions.sh \
-o ./scripts/functions.sh

. ./scripts/functions.sh
89 changes: 74 additions & 15 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('shelljs/make')

const packager = require('electron-packager')
const release = require('../lib/common/release')
const { join, resolve } = require('path')
const { basename, extname, join, resolve, relative } = require('path')
const dir = resolve(__dirname, '..')
const res = join(dir, 'res')
const electron = require('electron/package')
Expand All @@ -13,16 +13,21 @@ target.all = (args = []) => {
const platform = args[0] || process.platform
const arch = args[1] || process.arch

const { author, channel, version, product } = release

const icon = platform === 'win32' ?
join(res, 'icons', release.channel, `${release.name}.ico`) :
join(res, 'icons', release.channel, `${release.name}.icns`)
join(res, 'icons', channel, `${release.name}.ico`) :
join(res, 'icons', channel, `${release.name}.icns`)

const out = join(dir, 'dist', release.channel)
const out = join(dir, 'dist', channel)

packager({
platform, arch, icon, out, dir,

name: release.product,
platform,
arch,
icon,
out,
dir,
name: product,
prune: true,
overwrite: true,

Expand All @@ -31,19 +36,19 @@ target.all = (args = []) => {
},

electronVersion: electron.version,
appVersion: release.version,
appVersion: version,
appBundleId: 'org.tropy.tropy',
helperBundleId: 'org.tropy.tropy-helper',
appCategoryType: 'public.app-category.productivity',
appCopyright:
`Copyright (c) 2015-${new Date().getFullYear()} ` +
`${release.author.name}. All rights not expressly granted are reserved.`,
`${author.name}. All rights not expressly granted are reserved.`,

extendInfo: join(res, 'ext.plist'),

win32metadata: {
CompanyName: release.author.name,
ProductName: release.product
CompanyName: author.name,
ProductName: product
},

extraResource: [
Expand All @@ -67,6 +72,7 @@ target.all = (args = []) => {
/^\/ext/,
/^\/res.icons/,
/^\/res.dmg/,
/^\/res.linux/,
/^\/res.ext\.plist/,
/^\/scripts/,
/^\/src/,
Expand All @@ -77,17 +83,70 @@ target.all = (args = []) => {

}, (err, dst) => {
if (err) return console.error(err)
console.log(`Saved to ${dst}`)
dst = String(dst)

switch (platform) {
case 'linux':
rename(String(dst), release.product, release.name)
console.log('Renamed executable')
case 'linux': {
const name = (channel === 'stable') ?
release.name : `${release.name}-${channel}`

console.log(`Renaming executable to ${name}...`)
rename(dst, product, name)

console.log('Creating .desktop file...')
desktop(name, release.product, name)
.to(join(dst, `${name}.desktop`))

console.log('Copying icons...')
copyIcons(dst, name)

console.log('Linking executable...')
const bin = join(dst, 'usr', 'bin')
mkdir('-p', bin)
cd(bin)
ln('-s', `../../${name}`, name)
cd('-')

break
}
}

console.log(`Saved package in ${relative(dir, dst)}`)
})
}

function rename(ctx, from, to) {
mv(join(ctx, from), join(ctx, to))
}

function desktop(exec, name, icon) {
return `#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=${name}
Exec=${exec} %f
Icon=${icon}
Categories=GTK;Graphics;2DGraphics;Viewer;Development;
MimeType=image/jpeg;application/x-tpy;
StartupWMClass=${name}`
}

function copyIcons(dst, name) {
const theme = resolve(dst, 'usr', 'share', 'icons', 'hicolor')
const icons = resolve(res, 'icons', release.channel, 'tropy')

for (let icon of ls(icons)) {
let ext = extname(icon)
let variant = basename(icon, ext)
let target = join(theme, variant, 'apps')

let file = (variant === 'symbolic') ?
`${name}-symbolic${ext}` : `${name}${ext}`

mkdir('-p', target)
cp(join(icons, icon), join(target, file))
}
}

17 changes: 16 additions & 1 deletion scripts/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ target.all = () => {
}


target.linux = () => {
assert(platform === 'linux', 'must be run on Linux')

const targets = ls('-d', join(dist, '*-linux-*'))
assert(targets.length, 'no targets found')

const appimage = join(__dirname, 'appimage.sh')
const name = (release.channel === 'stable') ?
release.name : `${release.name}-${release.channel}`

for (let target of targets) {
exec(`${appimage} ${name} ${target}`)
}
}

target.darwin = () => {
assert(platform === 'darwin', 'must be run on macOS')
}
Expand All @@ -22,8 +37,8 @@ target.win32 = async () => {
assert(platform === 'win32', 'must be run on Windows')

const { createWindowsInstaller } = require('electron-winstaller')
const targets = ls('-d', join(dist, '*-win32-*'))

const targets = ls('-d', join(dist, '*-win32-*'))
assert(targets.length, 'no targets found')

for (let target of targets) {
Expand Down

0 comments on commit d42cce2

Please sign in to comment.