forked from nwutils/nw-updater
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gruntfile.js
160 lines (147 loc) · 4.36 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var exec = require('child_process').exec;
var ncp = require('ncp');
var fs = require('fs');
var isWin = /^win/.test(process.platform);
var isMac = /^darwin/.test(process.platform);
var isLinux = /^linux/.test(process.platform);
var is32 = process.arch == 'ia32';
var is64 = process.arch == 'x64';
var platforms = [];
if(isMac) platforms.push('osx');
if(isWin) platforms.push('win');
if(isLinux && is32) platforms.push('linux32');
if(isLinux && is64) platforms.push('linux64');
///^win/.test(process.platform)?'win':/^darwin/.test(process.platform)?'mac':process.arch == 'ia32'?'linux32':'linux64';
module.exports = function(grunt){
var dest = grunt.option('dest') || './deploy';
var src = grunt.option('src') || './app';
grunt.initConfig({
clean:{
main: ['test/app']
},
compress:{
mac:{
options: {
mode: 'zip',
archive: dest + '/updapp/osx/updapp.zip'
},
expand: true,
cwd: dest + '/updapp/osx/',
src: ['**/**'],
dest: '/updapp'
},
win:{
options: {
mode: 'zip',
archive: dest + '/updapp/win/updapp.zip'
},
expand: true,
cwd: dest + '/updapp/win/',
src: ['**/**'],
dest: '/updapp'
},
linux32:{
options: {
mode: 'tgz',
archive: dest + '/updapp/linux32/updapp.tar.gz'
},
expand: true,
cwd: dest + '/updapp/linux32/',
src: ['**/**'],
dest: 'updapp/'
},
linux64:{
options: {
mode: 'tgz',
archive: dest + '/updapp/linux64/updapp.tar.gz'
},
expand: true,
cwd: dest + '/updapp/linux64/',
src: ['**/**'],
dest: 'updapp/'
}
},
nodewebkit: {
options: {
buildDir: dest, // Where the build version of my node-webkit app is saved
platforms: platforms,
version: '0.9.2',
toolbar: false,
frame: false
},
src: [ src + '/**/*'] // Your node-wekit app
},
mochaTest:{
test:{
options: {
reporter: 'spec'
},
src: ['test/**/*.spec.js']
}
},
copy:{
win:{
src: 'tools/*',
dest: dest + '/win/'
}
},
jsdoc2md: {
withOptions: {
options: {
index: false,
template: "docs/README.hbs"
},
src: "app/updater.js",
dest: "README.md"
}
}
});
grunt.loadNpmTasks('grunt-node-webkit-builder');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-jsdoc-to-markdown');
grunt.registerTask('packageMacZip', function(){
var done = this.async();
fs.mkdirSync(dest + '/updapp/osx/updapp');
ncp(dest + '/updapp/osx/updapp.app', dest + '/updapp/osx/updapp/updapp.app', function(err){
exec('zip -r updapp.zip updapp',{cwd: dest + '/updapp/osx'},function(error, stdout, stderr){
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
done()
})
})
});
grunt.registerTask('packageMac', function(){
var done = this.async();
console.log('packaging...', 'hdiutil create -format UDZO -srcfolder ' + dest + '/releases/updapp/mac/updapp.app ' + dest + '/releases/updapp/mac/updapp.dmg');
exec('hdiutil create -format UDZO -srcfolder ' + dest + '/updapp/osx/updapp.app ' + dest + '/updapp/osx/updapp.dmg',function(error, stdout, stderr){
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
done()
})
});
grunt.registerTask('version', function(){
var ver = grunt.option('ver');
customizePackageJson({version: ver}, './app/package.json');
function customizePackageJson(obj, path){
var json = require(path);
for(var i in obj){
json[i] = obj[i];
}
fs.writeFileSync(path, JSON.stringify(json, null, 4));
}
});
var buildFlow = ['nodewebkit'];
if(isWin) buildFlow.push('copy:win');
grunt.registerTask('buildapp', buildFlow);
grunt.registerTask('docs', 'jsdoc2md');
grunt.registerTask('default', 'mochaTest');
};