@@ -67,6 +67,11 @@ module.exports = function (grunt) {
67
67
return exec ( "unzip -q " + src + " -d " + dest ) ;
68
68
}
69
69
70
+ function curl ( src , dest ) {
71
+ grunt . verbose . writeln ( "Downloading " + src ) ;
72
+ return exec ( "curl -o " + dest + " " + src ) ;
73
+ }
74
+
70
75
// task: cef
71
76
grunt . registerTask ( "cef" , "Download and setup CEF" , function ( ) {
72
77
var config = "cef-" + platform + common . arch ( ) ,
@@ -127,8 +132,50 @@ module.exports = function (grunt) {
127
132
grunt . task . run ( "curl-dir:" + grunt . config ( "cefConfig" ) ) ;
128
133
} ) ;
129
134
130
- function symbolFileLocation ( ) {
131
- return path . resolve ( process . cwd ( ) , "deps/cef/symbols/" ) ;
135
+ grunt . registerTask ( "curl-download" , function ( ) {
136
+ var downloadConfig = arguments [ 0 ] ,
137
+ downloadSource = grunt . config ( "curl-dir." + downloadConfig + ".src" ) ,
138
+ downloadDest = path . join ( process . cwd ( ) , grunt . config ( "curl-dir." + downloadConfig + ".dest" ) ) ,
139
+ downloadSourceURLS = downloadSource ,
140
+ done = this . async ( ) ;
141
+
142
+ if ( ! Array . isArray ( downloadSource ) ) {
143
+ downloadSourceURLS = [ ] ;
144
+ downloadSourceURLS . push ( downloadSource ) ;
145
+ }
146
+
147
+ var promises = downloadSourceURLS . map ( function ( srcUrl ) {
148
+ var filename = path . basename ( srcUrl ) ,
149
+ dest = path . join ( downloadDest , filename ) ;
150
+
151
+ grunt . verbose . writeln ( "Download " + srcUrl + " to " + dest ) ;
152
+ return curl ( srcUrl , dest ) ;
153
+ } ) ;
154
+
155
+ q . all ( promises ) . then ( done ) . catch ( function ( err ) {
156
+ done ( err ) ;
157
+ } ) ;
158
+ } ) ;
159
+
160
+ function cefFileLocation ( ) {
161
+ return path . resolve ( process . cwd ( ) , "deps/cef" ) ;
162
+ }
163
+
164
+ // Deduct the configuration (debug|release) from the zip file name
165
+ function symbolCompileConfiguration ( zipFileName ) {
166
+ if ( zipFileName ) {
167
+ var re = / \w + ?[ \d + \. \d + \. \d + ] + _ \w + ?_ ( \w + ?) _ \w + \. z i p / ;
168
+ var match = zipFileName . match ( re ) ;
169
+
170
+ if ( ! match ) {
171
+ grunt . log . error ( "File name doesn't match the pattern for cef symbols:" , zipFileName ) ;
172
+ return zipFileName ;
173
+ }
174
+
175
+ return match [ 1 ] ;
176
+ } else {
177
+ grunt . log . error ( "Please provide a zip file name" ) ;
178
+ }
132
179
}
133
180
134
181
grunt . registerTask ( "cef-symbols" , "Download and unpack the CEF symbols" , function ( ) {
@@ -146,7 +193,8 @@ module.exports = function (grunt) {
146
193
symbolSrcUrls . forEach ( function ( srcUrl ) {
147
194
var zipName = path . basename ( srcUrl ) ,
148
195
zipDest = path . resolve ( process . cwd ( ) , path . join ( grunt . config ( "curl-dir." + config + ".dest" ) , zipName ) ) ,
149
- txtName ;
196
+ txtName ,
197
+ _symbolFileLocation ;
150
198
151
199
// extract zip file name and set config property
152
200
grunt . config ( "cefConfig" , config ) ;
@@ -155,9 +203,11 @@ module.exports = function (grunt) {
155
203
txtName = path . basename ( zipName , ".zip" ) + ".txt" ;
156
204
157
205
// optionally download if CEF is not found
158
- if ( ! grunt . file . exists ( path . resolve ( path . join ( symbolFileLocation ( ) , txtName ) ) ) ) {
206
+ _symbolFileLocation = path . join ( cefFileLocation ( ) , symbolCompileConfiguration ( zipName ) ) ;
207
+
208
+ if ( ! grunt . file . exists ( path . resolve ( path . join ( _symbolFileLocation , txtName ) ) ) ) {
159
209
// pass the name of the zip file
160
- var zipDestSafe = zipDest . replace ( ":" , "|" ) ;
210
+ var zipDestSafe = zipDest . replace ( ":" , "|" ) ;
161
211
var cefTasks = [ "cef-symbols-extract" + ":" + zipDestSafe ] ;
162
212
163
213
if ( grunt . file . exists ( zipDest ) ) {
@@ -168,7 +218,7 @@ module.exports = function (grunt) {
168
218
169
219
grunt . task . run ( cefTasks ) ;
170
220
} else {
171
- grunt . verbose . writeln ( "Skipping CEF symbols download. Found deps/cef/symbols /" + txtName ) ;
221
+ grunt . verbose . writeln ( "Skipping CEF symbols download. Found " + _symbolFileLocation + " /" + txtName ) ;
172
222
}
173
223
} ) ;
174
224
}
@@ -183,11 +233,35 @@ module.exports = function (grunt) {
183
233
zipName = path . basename ( zipDest , '.zip' ) ,
184
234
unzipPromise ;
185
235
186
- // unzip to deps/cef/symbols/
187
- unzipPromise = unzip ( zipDest , symbolFileLocation ( ) ) ;
236
+ var symbolFileLocation = path . join ( cefFileLocation ( ) , symbolCompileConfiguration ( path . basename ( zipDest ) ) ) ;
237
+
238
+ // unzip to deps/cef
239
+ unzipPromise = unzip ( zipDest , symbolFileLocation ) ;
240
+
241
+ var symbolDir = path . join ( symbolFileLocation , zipName ) ;
188
242
189
243
unzipPromise . then ( function ( ) {
190
- var memo = path . resolve ( path . join ( symbolFileLocation ( ) , zipName + ".txt" ) ) ;
244
+ var rename = q . denodeify ( fs . rename ) ,
245
+ readdir = q . denodeify ( fs . readdir ) ;
246
+
247
+ return readdir ( symbolDir ) . then ( function ( files ) {
248
+ if ( files . length ) {
249
+ var promises = files . map ( function ( file ) {
250
+ return rename ( path . join ( symbolDir , file ) , path . join ( path . dirname ( symbolDir ) , file ) ) ;
251
+ } ) ;
252
+
253
+ return q . all ( promises ) ;
254
+ } else {
255
+ return ;
256
+ }
257
+ } , function ( err ) {
258
+ return err ;
259
+ } ) ;
260
+ } ) . then ( function ( ) {
261
+ var rmdir = q . denodeify ( fs . rmdir ) ;
262
+ return rmdir ( symbolDir ) ;
263
+ } ) . then ( function ( ) {
264
+ var memo = path . resolve ( path . join ( symbolFileLocation , zipName + ".txt" ) ) ;
191
265
192
266
// write empty file with zip file
193
267
grunt . file . write ( memo , "" ) ;
@@ -208,7 +282,8 @@ module.exports = function (grunt) {
208
282
grunt . log . writeln ( "Downloading " + downloadConfig + ". This may take a while..." ) ;
209
283
// curl doesn't give me the option to handle download errors on my own. If the requested file can't
210
284
// be found, curl will log an error to the console.
211
- grunt . task . run ( "curl-dir:" + downloadConfig ) ;
285
+ //grunt.task.run("curl-dir:" + downloadConfig);
286
+ grunt . task . run ( "curl-download:" + downloadConfig ) ;
212
287
} ) ;
213
288
214
289
// task: cef-extract
0 commit comments