-
Notifications
You must be signed in to change notification settings - Fork 9
/
Gruntfile.js
89 lines (79 loc) · 2.72 KB
/
Gruntfile.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
80
81
82
83
84
85
86
87
88
89
"use strict"
var version = require('fs').readFileSync('VERSION').toString().trim()
module.exports = function(grunt) {
grunt.initConfig({
nodewebkit: {
options: {
version: '0.9.2',
app_name: 'Remonit',
app_version: version,
linux32: true,
linux64: true,
mac_icns: './design/osx.icns',
linux_icon: './design/medium-48x48.png',
build_dir: './build'
},
src: ['./nw.release/**/*']
}
})
grunt.loadNpmTasks('grunt-node-webkit-builder')
grunt.registerTask('nwLinux', nwLinux(grunt))
grunt.registerTask('nw', ['nodewebkit', 'nwLinux'])
}
var fs = require('fs'),
path = require('path')
function nwLinux(grunt) {
return function() {
var config = grunt.config('nodewebkit.options')
;['linux32', 'linux64'].forEach(function(linux) {
if (!config[linux]) return
var buildDir = config.build_dir
var appName = config.app_name
var dir = path.join(buildDir, 'releases', appName, linux, appName)
var iconFile = config.linux_icon
if (iconFile) {
grunt.file.copy(iconFile, path.join(dir, 'icon.png'))
}
var binFile = path.join(dir, appName)
fs.renameSync(binFile, binFile + '-bin')
fs.chmodSync(binFile + '-bin', '755')
grunt.file.write(binFile, linuxWrapper(appName))
fs.chmodSync(binFile, '755')
})
}
}
function linuxWrapper(appName) {
return '#!/bin/bash\n' +
'\n' +
'MYAPP_NAME="' + appName + '"\n' +
'\n' +
'# script path\n' +
'export MYAPP_WRAPPER="`readlink -f "$0"`"\n' +
'HERE="`dirname "$MYAPP_WRAPPER"`"\n' +
'\n' +
'# link libudev.so.0\n' +
'if [ ! -f "$HERE/libudev.so.0" ]; then # if not linked yet\n' +
' udevDependent=`which udisks 2> /dev/null` # Ubuntu, Mint\n' +
' if [ -z "$udevDependent" ]; then\n' +
' udevDependent=`which systemd 2> /dev/null` # Fedora, SUSE\n' +
' fi\n' +
' if [ -z "$udevDependent" ]; then\n' +
' udevDependent=`which findmnt` # Arch\n' +
' fi\n' +
' udevso=`ldd $udevDependent | grep libudev.so | awk \'{print $3;}\'`\n' +
' if [ -e "$udevso" ]; then\n' +
' ln -sf "$udevso" "$HERE/libudev.so.0"\n' +
' fi\n' +
'fi\n' +
'\n' +
'# use script directory as lib path\n' +
'if [[ -n "$LD_LIBRARY_PATH" ]]; then\n' +
' LD_LIBRARY_PATH="$HERE:$HERE/lib:$LD_LIBRARY_PATH"\n' +
'else\n' +
' LD_LIBRARY_PATH="$HERE:$HERE/lib"\n' +
'fi\n' +
'export LD_LIBRARY_PATH\n' +
'\n' +
'# execute actual app\n' +
'exec -a "$0" "$HERE/$MYAPP_NAME-bin" "$@"\n'
}