-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
204 lines (191 loc) · 5.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*jshint camelcase: false*/
// Generated on 2013-08-01 using generator-chrome-extension 0.2.3
module.exports = function (grunt) {
'use strict';
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// configurable paths
var config = {
app: 'app',
dist: 'dist',
tmp: 'tmp',
resources: 'resources'
};
grunt.initConfig({
config: config,
clean: {
dist: {
files: [{
dot: true,
src: [
'<%= config.dist %>/*',
'<%= config.tmp %>/*'
]
}]
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
files: '<%= config.app %>/js/*.js'
},
copy: {
appLinux: {
files: [{
expand: true,
cwd: '<%= config.app %>',
dest: '<%= config.dist %>/app.nw',
src: '**'
}]
},
appMacos: {
files: [{
expand: true,
cwd: '<%= config.app %>',
dest: '<%= config.dist %>/node-webkit.app/Contents/Resources/app.nw',
src: '**'
},
{
expand: true,
cwd: '<%= config.resources %>/mac-files/',
dest: '<%= config.dist %>/node-webkit.app/Contents/',
filter: 'isFile',
src: '*.plist'
},
{
expand: true,
cwd: '<%= config.resources %>/mac-files/',
dest: '<%= config.dist %>/node-webkit.app/Contents/Resources/',
filter: 'isFile',
src: '*.icns'
}]
},
webkit: {
files: [{
expand: true,
cwd: '<%=config.resources %>/node-webkit/MacOS',
dest: '<%= config.dist %>/',
src: '**'
}]
},
copyWinToTmp: {
files: [{
expand: true,
cwd: '<%= config.resources %>/node-webkit/Windows/',
dest: '<%= config.tmp %>/',
src: '**'
}]
}
},
compress: {
appToTmp: {
options: {
archive: '<%= config.tmp %>/app.zip'
},
files: [
{
expand: true,
cwd:'<%= config.app %>',
src: ['**']
}
]
},
finalWindowsApp: {
options: {
archive: '<%= config.dist %>/saber.zip'
},
files: [
{
expand: true,
cwd:'<%= config.tmp %>',
src: ['**']
}
]
}
},
rename: {
app: {
files: [
{
src: '<%= config.dist %>/node-webkit.app',
dest: '<%= config.dist %>/saber.app'
}
]
},
zipToApp: {
files: [
{
src: '<%= config.tmp %>/app.zip',
dest: '<%= config.tmp %>/app.nw'
}
]
}
}
});
grunt.registerTask('chmod', 'Add lost Permissions.', function () {
var fs = require('fs');
fs.chmodSync('dist/saber.app/Contents/Frameworks/node-webkit Helper EH.app/Contents/MacOS/node-webkit Helper EH', '555');
fs.chmodSync('dist/saber.app/Contents/Frameworks/node-webkit Helper NP.app/Contents/MacOS/node-webkit Helper NP', '555');
fs.chmodSync('dist/saber.app/Contents/Frameworks/node-webkit Helper.app/Contents/MacOS/node-webkit Helper', '555');
fs.chmodSync('dist/saber.app/Contents/MacOS/node-webkit', '555');
});
grunt.registerTask('createLinuxApp', 'Create linux distribution.', function () {
var fs = require('fs');
var childProcess = require('child_process');
var exec = childProcess.exec;
exec('mkdir dist; cp resources/node-webkit/linux_ia64/nw.pak dist/ && cp resources/node-webkit/linux_ia64/nw dist/node-webkit && cp resources/linux/qq dist/qq && chmod a+x dist/qq; touch dist/ready', function (error, stdout, stderr) {
console.log(stderr, stdout, error);
});
while (!fs.existsSync('dist/ready')) {}
});
grunt.registerTask('createWindowsApp', 'Create windows distribution.', function () {
var fs = require('fs');
var childProcess = require('child_process');
var exec = childProcess.exec;
exec('copy /b tmp\\nw.exe+tmp\\app.nw tmp\\saber.exe && del tmp\\app.nw tmp\\nw.exe && echo.>tmp\\ready', function (error, stdout, stderr) {
console.log(stderr, stdout, error);
});
while (!fs.existsSync('tmp/ready')) {}
});
grunt.registerTask('setVersion', 'Set version to all needed files', function(version){
var config = grunt.config.get(['config']);
var appPath = config.app;
var resourcesPath = config.resources;
var mainPackageJSON = grunt.file.readJSON('package.json');
var appPackageJSON = grunt.file.readJSON(appPath + '/package.json');
var infoPlistTmp = grunt.file.read(resourcesPath + '/mac-files/Info.plist.tmp', {encoding: 'UTF8'});
var infoPlist = grunt.template.process(infoPlistTmp, {data: {version: version}});
mainPackageJSON.version = version;
appPackageJSON.version = version;
grunt.file.write('package.json', JSON.stringify(mainPackageJSON, null, 2), {encoding: 'UTF8'});
grunt.file.write(appPath + '/package.json', JSON.stringify(appPackageJSON, null, 2), {encoding: 'UTF8'});
grunt.file.write(resourcesPath + '/mac-files/Info.plist', infoPlist, {encoding: 'UTF8'});
});
grunt.registerTask('dist-linux', [
'jshint',
'clean:dist',
'copy:appLinux',
'createLinuxApp'
]);
grunt.registerTask('dist-win', [
//'jshint',
'clean:dist',
'copy:copyWinToTmp',
'compress:appToTmp',
'rename:zipToApp',
'createWindowsApp',
'compress:finalWindowsApp'
]);
grunt.registerTask('dist-mac', [
'jshint',
'clean:dist',
'copy:webkit',
'copy:appMacos',
'rename:app',
'chmod'
]);
grunt.registerTask('check', [
'jshint'
]);
};