-
Notifications
You must be signed in to change notification settings - Fork 93
/
Gruntfile.js
2213 lines (2005 loc) · 81.9 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
var LIVERELOAD_PORT = 35729;
var SERVER_PORT = 8000;
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var serveStatic = require('serve-static');
var serveIndex = require('serve-index');
var mountFolder = function (dir) {
return serveStatic(
require('path').resolve(dir),
{
// We need to specify a file that will be displayed in place of
// index.html. _.html is used because it is unlikely to exist.
index: '_.html',
setHeaders: setHeaders
}
);
};
var mountDirectory = function(dir) {
return serveIndex(
require('path').resolve(dir),
{
icons: true,
}
);
};
var setHeaders = function(res, path) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.setHeader('Cross-Origin-Embedder-Policy', 'credentialless');
res.setHeader('Cross-Origin-Opener-Policy', 'cross-origin');
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
res.setHeader('Content-Security-Policy',`frame-ancestors 'self' http://localhost:${SERVER_PORT} http://localhost:${LIVERELOAD_PORT}`);
res.setHeader('X-Content-Type-Options', '');
}
var postHandler = function(req, res, next) {
if (req.method === 'POST') {
//debugger;
console.log('received a POST request');
var mkdirp = require('mkdirp');
var fs = require('fs');
//var Buffer = require('buffer/').Buffer;
// We don't want the leading /, or else the file system will think
// we're writing to root, which we don't have permission to. Should
// really be dealing with the path more gracefully.
var path = req.url.substring(1);
// First make sure the directory exists, or else the following call to
// createWriteStream fails. We don't want to include the file name as
// part of the directory, or else our post will be trying to change the
// directory to become a file with content, which will fail.
var lastDelimiter = path.lastIndexOf('/');
if (lastDelimiter >= 0) {
var directories = path.substring(0, lastDelimiter);
mkdirp.sync(directories);
}
var file;
if (req.headers['content-type'] === 'application/octet-stream') {
var {Base64Decode} = require('base64-stream');
file = fs.createWriteStream(path);
req.pipe(new Base64Decode()).pipe(file);
file.on('error', function(err) {
res.write('error uploading the file');
res.write(JSON.stringify(err));
res.statusCode = 500;
console.log('POST error ' + JSON.stringify(err));
});
req.on('end', function() {
res.write('uploaded file!');
res.end();
});
} else {
file = fs.createWriteStream(path);
req.pipe(file);
file.on('error', function(err) {
res.write('error uploading the file');
res.write(JSON.stringify(err));
res.statusCode = 500;
});
req.on('end', function() {
res.write('uploaded file!');
res.end();
});
}
} else {
// We only want to hand this off to the other middleware if this
// is not a POST, as we're expecting to be the only ones to
// handle POSTs.
return next();
}
};
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to match all subfolders:
// 'test/spec/**/*.js'
// templateFramework: 'lodash'
module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
// load all grunt tasks
require('load-grunt-tasks')(grunt);
// passing in port as input
SERVER_PORT = grunt.option('port') || 8000;
// We do not want the default behavior of serving only the app folder.
// Instead we want to serve the base repo directory, as this will give us
// access to the test dir as well. Further, if you don't have a homescreen
// defined, it doesn't really make sense to have a single index.html.
var baseDirForServer = '';
var tablesConfig = {
// The base app directory. Note that if you modify this you should
// also modify the other properties in this object that refer to
// app
appDir: 'app',
appName: 'default',
// The mount point of the device. Should allow adb push/pull.
deviceMount: '/sdcard/opendatakit',
// The mount point of the device for odk collect forms.
formMount: '/sdcard/odk/forms',
assetsDir: 'app/config/assets',
// The directory where the 'tables' directory containing the tableId
// directories lives.
tablesDir: 'app/config/tables',
dataDir: 'app/data',
// Where the templates for a new tableId folder lives. i.e. if you want
// to add a table, the contents of this directory would be copied to
// tablesDir/tableId.
tableTemplateDir: 'grunttemplates/table/default',
// tableIdStr will be what we replace in the table template with the
// provided tableId. E.g. '../%TABLE_ID%_list.html' will become
// '../myTableId_list.html'
tableIdStr: '%TABLE_ID%',
// The string we need to replace with the app name.
appStr: '%APP%',
// The output directory
outputDbDir: 'output/db',
// The directory where csvs are output.
outputCsvDir: 'output/csv',
// The directory where the device.properties and app.properties objects are stored
outputPropsDir: 'output/props',
// The directory where logs are output
outputLogsDir: 'output/logging',
// The directory where the debug objects are output.
outputDebugDir: 'output/debug',
// The db directory path on the phone. %APP% should be replaced by app name
// We use write-ahead-logging, so we need to pull both sqlite.db and sqlite.wal
deviceDbDirectoryPath: '/sdcard/opendatakit/%APP%/data/webDb',
xlsxDir: 'xlsxconverter'
};
var surveyConfig = {
// The base app directory. Note that if you modify this you should
// also modify the other properties in this object that refer to
// app
appDir: 'app',
appName: 'survey',
// The mount point of the device. Should allow adb push/pull.
deviceMount: '/sdcard/opendatakit',
xlsxDir: 'xlsxconverter'
};
grunt.initConfig({
// Here we have to set the objects for the exec task. We are using
// grunt-exec to execute the adb push and adb pull commands.
// cmd is the command that is run when calling this task with the
// target and must return a string.
exec: {
adbpush: {
cmd: function(src, dest) {
return 'adb push ' + src + ' ' + dest;
}
},
adbpull: {
cmd: function(src, dest) {
return 'adb pull ' + src + ' ' + dest;
}
},
adbshell: {
cmd: function(str) {
return 'adb shell ' + str;
}
},
macGenConvert: {
cmd: function(str, formDefFile) {
return 'node macGenConverter.js ' + str + ' > ' + formDefFile;
}
}
},
tables: tablesConfig,
watch: {
options: {
nospawn: true,
livereload: true
},
livereload: {
options: {
livereload: LIVERELOAD_PORT
},
files: [
'devEnv/*.html',
'devEnv/*.js',
'<%= tables.appDir %>/*.html',
'<%= tables.appDir %>/system/**',
]
},
test: {
files: ['test/spec/**/*.js'],
tasks: ['test']
}
},
connect: {
server: {
options: {
setHeaders: setHeaders
}
},
options: {
port: SERVER_PORT,
// change this to '0.0.0.0' to access the server from outside
hostname: 'localhost'
},
livereload: {
options: {
middleware: function(connect, options, middlewares) {
// Add the middleware for setting headers
middlewares.unshift(function(req, res, next) {
setHeaders(res);
next();
});
middlewares.unshift(postHandler);
middlewares.unshift(lrSnippet);
middlewares.unshift(mountFolder(baseDirForServer));
middlewares.unshift(mountDirectory(baseDirForServer));
return middlewares;
}
}
},
test: {
options: {
port: 8001,
middleware: [
postHandler,
lrSnippet,
mountFolder('test'),
mountFolder(baseDirForServer),
mountDirectory(baseDirForServer)
]
}
}
},
open: {
server: {
path: 'http://localhost:<%= connect.options.port %>/index.html',
app: {app: (function() {
var platform = require('os').platform();
// windows: *win*
// mac: darwin
if (platform.search('win') >= 0 &&
platform.search('darwin') < 0) {
// Windows expects chrome.
grunt.log.writeln('detected Windows environment');
return 'chrome';
} else {
// Mac (and maybe others--add as discovered), expects
// Google Chrome
grunt.log.writeln('detected non-Windows environment');
return 'Google Chrome';
}
})()
}
}
},
});
// We need grunt-exec to run adb commands from within grunt.
grunt.loadNpmTasks('grunt-exec');
// Just an alias task--shorthand for doing all the pullings
grunt.registerTask(
'adbpull',
'Perform all the adbpull tasks',
['adbpull-debug', 'adbpull-db', 'adbpull-csv', 'adbpull-logs']);
// Just an alias task--shorthand for doing all the pushings
grunt.registerTask(
'adbpush',
'Perform all the adbpush tasks',
["adbpull-props", "remove-folders", 'adbpush-collect', 'adbpush-default-app', "adbpush-props"]);
grunt.registerTask(
'clean',
'wipe the device',
["adbpull-props", "remove-folders", "adbpush-props", "setup"]);
grunt.registerTask(
'adbpull-debug',
'Pull the debug output objects from the device',
function() {
var src = tablesConfig.deviceMount + '/' + tablesConfig.appName +
'/' + tablesConfig.outputDebugDir;
var dest = tablesConfig.appDir + '/' + tablesConfig.outputDebugDir;
grunt.log.writeln('adb pull ' + src + ' ' + dest);
grunt.task.run('exec:adbpull:' + src + ':' + dest);
});
grunt.registerTask(
'adbpull-db',
'Pull the db from the device',
function() {
var dbPath = tablesConfig.deviceDbDirectoryPath;
dbPath = dbPath.replace(tablesConfig.appStr, tablesConfig.appName);
var src = dbPath;
var dest = tablesConfig.appDir + '/' + tablesConfig.outputDbDir;
grunt.log.writeln('adb pull ' + src + ' ' + dest);
grunt.task.run('exec:adbpull:' + src + ':' + dest);
});
grunt.registerTask(
'adbpull-csv',
'Pull any exported csv files from the device',
function() {
var src = tablesConfig.deviceMount + '/' + tablesConfig.appName +
'/' + tablesConfig.outputCsvDir;
var dest = tablesConfig.appDir + '/' + tablesConfig.outputCsvDir;
grunt.log.writeln('adb pull ' + src + ' ' + dest);
grunt.task.run('exec:adbpull:' + src + ':' + dest);
});
grunt.registerTask(
'adbpull-logs',
'Pull any logs stored in the device for debugging purposes',
function() {
var src = tablesConfig.deviceMount + '/' + tablesConfig.appName + '/' + tablesConfig.outputLogsDir;
var dest = tablesConfig.appDir + '/' + tablesConfig.outputLogsDir;
grunt.log.writeln('adb pull ' + src + ' ' + dest);
grunt.task.run('exec:adbpull:' + src + ':' + dest);
});
grunt.registerTask(
'xlsx-convert-all',
'Run the XLSX converter on all form definitions',
function() {
var platform = require('os').platform();
var isWindows = (platform.search('win') >= 0 &&
platform.search('darwin') < 0);
var dirs = grunt.file.expand(
{filter: function(path) {
if ( !path.endsWith(".xlsx") ) {
return false;
}
var cells = path.split((isWindows ? "\\" : "/"));
return (cells.length >= 6) &&
( cells[cells.length-1] === cells[cells.length-2] + ".xlsx" );
},
cwd: 'app' },
'**/*.xlsx',
'!**/~$*.xlsx'
);
// Now run these files through macGenConvert.js
dirs.forEach(function(fileName) {
// fileName uses forward slashes on all platforms
var xlsFile;
var formDefFile;
var cells;
xlsFile = 'app/' + fileName;
cells = xlsFile.split('/');
cells[cells.length-1] = 'formDef.json';
formDefFile = cells.join('/');
grunt.log.writeln('macGenConvert: ' + xlsFile + ' > ' + formDefFile);
grunt.task.run('exec:macGenConvert:' + xlsFile + ':' + formDefFile);
});
});
var zipAllFiles = function( destZipFile, filesList, completionFn ) {
// create a file to stream archive data to.
var fs = require('fs');
var archiver = require('archiver');
var output = fs.createWriteStream(destZipFile);
var archive = archiver('zip', {
store: true // Sets the compression method to STORE.
});
// listen for all archive data to be written
output.on('close', function() {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
completionFn(true);
});
// good practice to catch this error explicitly
archive.on('error', function(err) {
throw err;
});
// pipe archive data to the file
archive.pipe(output);
filesList.forEach(function(fileName) {
// Have to add app back into the file name for the adb push
var src = tablesConfig.appDir + '/' + fileName;
grunt.log.writeln('archive.file(' + src + ', {name: ' + fileName + '} )');
archive.file(src, {name: fileName }, function(err) {
if(err) {
grunt.log.writeln('error ' + err + ' adding ' + src + ' to file ' + destZipFile);
}} );
});
// finalize the archive (ie we are done appending files but streams have to finish yet)
archive.finalize();
};
grunt.registerTask(
'build-zips',
'BROKEN: does not compress and last file is not terminated properly. Construct the configzip and systemzip for survey and tables',
function() {
var done = this.async();
var buildDir = 'build' +
'/zips';
grunt.file.delete(buildDir + '/');
grunt.file.mkdir(buildDir);
grunt.file.mkdir(buildDir + '/survey/');
grunt.file.mkdir(buildDir + '/tables/');
var surveySystemZipFiles = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'system/survey/templates/**',
'system/survey/js/**',
'system/libs/**',
'system/js/**',
'system/index.html',
'!**/.DS_Store',
'!**/~$*.xlsx');
var surveyConfigZipFiles = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'config/assets/framework/**',
'config/assets/commonDefinitions.js',
'config/assets/img/play.png',
'config/assets/img/form_logo.png',
'config/assets/img/backup.png',
'config/assets/img/advance.png',
'config/assets/css/odk-survey.css',
'!**/.DS_Store',
'!**/~$*.xlsx');
var tablesSystemZipFiles = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'system/tables/test/**',
'system/tables/js/**',
'system/libs/**',
'system/js/**',
'!**/.DS_Store',
'!**/~$*.xlsx');
var tablesConfigZipFiles = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'config/assets/libs/jquery*',
'config/assets/libs/d3*',
'config/assets/libs/d3-amd/**',
'config/assets/commonDefinitions.js',
'config/assets/img/little_arrow.png',
'!**/.DS_Store',
'!**/~$*.xlsx');
zipAllFiles(buildDir + '/survey/systemzip', surveySystemZipFiles,
function(outcome) {
if ( outcome ) {
zipAllFiles(buildDir + '/survey/configzip', surveyConfigZipFiles,
function(outcome) {
if ( outcome ) {
zipAllFiles(buildDir + '/tables/systemzip', tablesSystemZipFiles,
function(outcome) {
if ( outcome ) {
zipAllFiles(buildDir + '/tables/configzip', tablesConfigZipFiles,
function(outcome) {
if ( outcome ) {
grunt.log.writeln('success!');
done(true);
} else {
done('failing on /tables/configzip with error: ' + outcome);
}
});
} else {
done('failing on /tables/systemzip with error: ' + outcome);
}
});
} else {
done('failing on /survey/configzip with error: ' + outcome);
}
});
} else {
done('failing on /survey/systemzip with error: ' + outcome);
}
});
});
grunt.registerTask(
'adbpush-default-app',
'Push everything in the app directory (except system) to the device',
function() {
// Do not push any system, data or output files.
// The first parameter is an options object where we specify that
// we only want files--this is important because otherwise when
// we get directory names adb will push everything in the directory
// name, effectively pushing everything twice. We also specify that we
// want everything returned to be relative to 'app' by using 'cwd'.
var dirs = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'.nomedia',
'**',
'system/**',
'!data/**',
'!output/**',
'!**/~$*.xlsx');
// Now push these files to the phone.
dirs.forEach(function(fileName) {
// Have to add app back into the file name for the adb push
var src = tablesConfig.appDir + '/' + fileName;
var dest =
tablesConfig.deviceMount +
'/' +
tablesConfig.appName +
'/' +
fileName;
grunt.log.writeln('adb push ' + src + ' ' + dest);
grunt.task.run('exec:adbpush:' + src + ':' + dest);
});
});
grunt.registerTask(
'adbpush-tables',
'Push everything for tables only to the device',
function() {
// We do not need any system, data or output files.
// The first parameter is an options object where we specify that
// we only want files--this is important because otherwise when
// we get directory names adb will push everything in the directory
// name, effectively pushing everything twice. We also specify that we
// want everything returned to be relative to 'app' by using 'cwd'.
var dirs = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'.nomedia',
'**',
'!system/**',
'!data/**',
'!output/**',
'!**/~$*.xlsx');
// Now push these files to the phone.
dirs.forEach(function(fileName) {
// Have to add app back into the file name for the adb push
var src = tablesConfig.appDir + '/' + fileName;
var dest =
tablesConfig.deviceMount +
'/' +
tablesConfig.appName +
'/' +
fileName;
grunt.log.writeln('adb push ' + src + ' ' + dest);
grunt.task.run('exec:adbpush:' + src + ':' + dest);
});
// And then we want to put the collect forms in the right place.
// This will push the collect forms for ALL the tables, but since
// only the files used in the Tables demo follows the convention
// required by the adbpush-collect task, that is ok.
grunt.task.run('adbpush-collect');
});
grunt.registerTask(
'adbpush-systemjs',
'Push everything for tables only to the device',
function() {
// We do not need any system, data or output files.
// The first parameter is an options object where we specify that
// we only want files--this is important because otherwise when
// we get directory names adb will push everything in the directory
// name, effectively pushing everything twice. We also specify that we
// want everything returned to be relative to 'app' by using 'cwd'.
var dirs = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'.nomedia',
'**',
'!system/**',
'system/tables/js/**',
'system/survey/**',
'!data/**',
'!output/**',
'!config/**',
'!**/~$*.xlsx');
// Now push these files to the phone.
dirs.forEach(function(fileName) {
// Have to add app back into the file name for the adb push
var src = tablesConfig.appDir + '/' + fileName;
var dest =
tablesConfig.deviceMount +
'/' +
tablesConfig.appName +
'/' +
fileName;
grunt.log.writeln('adb push ' + src + ' ' + dest);
grunt.task.run('exec:adbpush:' + src + ':' + dest);
});
// And then we want to put the collect forms in the right place.
// This will push the collect forms for ALL the tables, but since
// only the files used in the Tables demo follows the convention
// required by the adbpush-collect task, that is ok.
grunt.task.run('adbpush-collect');
});
grunt.registerTask(
'adbpush-tables-demo-alpha2',
'Push everything for tables demo to the device',
function() {
// In the alpha demo we want Tables and Survey. For the alpha2,
// it had needed a push of the system files, but we won't do that
// here. We only want a subset of the app/tables files,
// however. So, we are going to get everything except that
// directory and then add back in the ones that we want.
// The first parameter is an options object where we specify that
// we only want files--this is important because otherwise when
// we get directory names adb will push everything in the directory
// name, effectively pushing everything twice. We also specify that we
// want everything returned to be relative to 'app' by using 'cwd'.
var dirs = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'.nomedia',
'**',
'!system/**',
'!data/**',
'!output/**',
'!config/tables/**',
'config/tables/geotagger/**',
'config/tables/Tea_houses/**',
'config/tables/Tea_types/**',
'config/tables/Tea_inventory/**',
'config/tables/Tea_houses_editable/**',
'config/tables/household/**',
'config/tables/household_member/**');
// Now push these files to the phone.
dirs.forEach(function(fileName) {
// Have to add app back into the file name for the adb push
var src = tablesConfig.appDir + '/' + fileName;
var dest =
tablesConfig.deviceMount +
'/' +
tablesConfig.appName +
'/' +
fileName;
grunt.log.writeln('adb push ' + src + ' ' + dest);
grunt.task.run('exec:adbpush:' + src + ':' + dest);
});
// And then we want to put the collect forms in the right place.
// This will push the collect forms for ALL the tables, but since
// only the files used in the Tables demo follows the convention
// required by the adbpush-collect task, that is ok.
grunt.task.run('adbpush-collect');
});
grunt.registerTask(
'adbpush-tables-demo-JGI',
'Push everything for tables JGI demo to the device',
function() {
// In the alpha demo we want Tables and Survey. For this demo,
// it had needed a push of the system files, but we won't do that
// here. We only want a subset of the app/tables files,
// however. So, we are going to get everything except that
// directory and then add back in the ones that we want.
// The first parameter is an options object where we specify that
// we only want files--this is important because otherwise when
// we get directory names adb will push everything in the directory
// name, effectively pushing everything twice. We also specify that we
// want everything returned to be relative to 'app' by using 'cwd'.
var dirs = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'.nomedia',
'**',
'!system/**',
'!data/**',
'!output/**',
'!config/tables/**',
'config/tables/follow/**',
'config/tables/follow_arrival/**',
'config/tables/follow_map_position/**',
'config/tables/follow_map_time/**',
'config/tables/food_bout/**',
'config/tables/groom_bout/**',
'config/tables/mating_event/**',
'config/tables/other_species/**');
// Now push these files to the phone.
dirs.forEach(function(fileName) {
// Have to add app back into the file name for the adb push
var src = tablesConfig.appDir + '/' + fileName;
var dest =
tablesConfig.deviceMount +
'/' +
tablesConfig.appName +
'/' +
fileName;
grunt.log.writeln('adb push ' + src + ' ' + dest);
grunt.task.run('exec:adbpush:' + src + ':' + dest);
});
});
grunt.registerTask(
'adbpush-scan',
'Push everything for scan tables to the device',
function() {
// In the alpha demo we want Tables and Survey. For this demo,
// it had needed a push of the system files, but we won't do that
// here. We only want a subset of the app/tables files,
// however. So, we are going to get everything except that
// directory and then add back in the ones that we want.
// The first parameter is an options object where we specify that
// we only want files--this is important because otherwise when
// we get directory names adb will push everything in the directory
// name, effectively pushing everything twice. We also specify that we
// want everything returned to be relative to 'app' by using 'cwd'.
var dirs = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'.nomedia',
'**',
'!system/**',
'!data/**',
'!output/**',
'!config/assets/**',
'!config/tables/**',
'config/tables/scan_example/**',
'!**/~$*.xlsx');
// Now push these files to the phone.
dirs.forEach(function(fileName) {
// Have to add app back into the file name for the adb push
var src = tablesConfig.appDir + '/' + fileName;
var dest =
tablesConfig.deviceMount +
'/' +
tablesConfig.appName +
'/' +
fileName;
grunt.log.writeln('adb push ' + src + ' ' + dest);
grunt.task.run('exec:adbpush:' + src + ':' + dest);
});
});
//
// returns a function that will handle the copying of files into the
// build/ + infix.substr(1) folder with any files containing ".infix."
// stripped of that infix and any folders ending in ".infix" also stripped.
//
var infixRenameCopier = function(demoInfix, offsetDir) {
return function(fileName) {
// Have to add app back into the file name for the adb push
var src;
if ( offsetDir !== undefined && offsetDir !== null && offsetDir !== "" ) {
src = offsetDir +
'/' +
fileName;
} else {
src = fileName;
}
var isInfixed = false;
// need to handle infixed directories and files
var destFileName = fileName;
var idx = destFileName.indexOf(demoInfix + ".");
while ( idx >= 0 ) {
// file...
isInfixed = true;
destFileName = destFileName.substring(0,idx) + destFileName.substring(idx+demoInfix.length);
idx = destFileName.indexOf(demoInfix + ".");
}
var idxDir = destFileName.indexOf(demoInfix + "/");
while ( idxDir >= 0 ) {
// directory...
isInfixed = true;
destFileName = destFileName.substring(0,idxDir) + destFileName.substring(idxDir+demoInfix.length);
idxDir = destFileName.indexOf(demoInfix + "/");
}
var buildDir = 'build' +
'/' +
demoInfix.substring(1);
var baseDir = buildDir;
if ( offsetDir !== undefined && offsetDir !== null && offsetDir !== "" ) {
baseDir = baseDir +
'/' +
offsetDir;
}
var dest;
if ( isInfixed ) {
// copy the original so that, e.g, grunt adbpush-tables-tablesdemo will work
dest = baseDir +
'/' +
fileName;
grunt.log.writeln('file copy ' + src + ' ' + dest);
grunt.file.copy(src, dest);
}
// and copy the renamed destination file so that
// grunt adbpush will also work.
dest = baseDir +
'/' +
destFileName;
grunt.log.writeln('file copy ' + src + ' ' + dest);
grunt.file.copy(src, dest);
};
};
//
// returns a function that will handle the adb push of files onto the
// device with any files containing ".infix." stripped of that infix
// and any folders ending in ".infix" also stripped.
//
var infixRenameAdbPusher = function(demoInfix, offsetDir) {
// Now push these files to the phone.
return function(fileName) {
// Have to add app back into the file name for the adb push
var src;
if ( offsetDir !== undefined && offsetDir !== null && offsetDir !== "" ) {
src = offsetDir +
'/' +
fileName;
} else {
src = fileName;
}
var isInfixed = false;
// need to handle infixed directories and files
var destFileName = fileName;
var idx = destFileName.indexOf(demoInfix + ".");
while ( idx >= 0 ) {
// file...
isInfixed = true;
destFileName = destFileName.substring(0,idx) + destFileName.substring(idx+demoInfix.length);
idx = destFileName.indexOf(demoInfix + ".");
}
var idxDir = destFileName.indexOf(demoInfix + "/");
while ( idxDir >= 0 ) {
// directory...
isInfixed = true;
destFileName = destFileName.substring(0,idxDir) + destFileName.substring(idxDir+demoInfix.length);
idxDir = destFileName.indexOf(demoInfix + "/");
}
var dest =
tablesConfig.deviceMount +
'/' +
tablesConfig.appName +
'/' +
destFileName;
grunt.log.writeln('adb push ' + src + ' ' + dest);
grunt.task.run('exec:adbpush:' + src + ':' + dest);
};
};
var largeDataSetFiles = function(grunt) {
// We only want a subset of the app/tables files,
// however. So, we are going to get everything except that
// directory and then add back in the ones that we want.
// The first parameter is an options object where we specify that
// we only want files--this is important because otherwise when
// we get directory names adb will push everything in the directory
// name, effectively pushing everything twice. We also specify that we
// want everything returned to be relative to 'app' by using 'cwd'.
var dirs = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'.nomedia',
'**',
'!system/**',
'!data/**',
'!output/**',
'!config/tables/**',
'config/assets/**',
'config/tables/large_dataset/**',
'config/tables/testRun/**');
return dirs;
};
grunt.registerTask(
'adbpush-largeDataSet500',
'Push everything for large data set to the device',
function() {
var dirs = largeDataSetFiles(grunt);
// Now push these files to the phone.
dirs.forEach(infixRenameAdbPusher(".largeDataSet500", tablesConfig.appDir));
}
);
grunt.registerTask(
'adbpush-largeDataSet3000',
'Push everything for large data set to the device',
function() {
var dirs = largeDataSetFiles(grunt);
// Now push these files to the phone.
dirs.forEach(infixRenameAdbPusher(".largeDataSet3000", tablesConfig.appDir));
}
);
var gatesDemoFiles072216 = function(grunt) {
// We only want a subset of the app/tables files,
// however. So, we are going to get everything except that
// directory and then add back in the ones that we want.
// The first parameter is an options object where we specify that
// we only want files--this is important because otherwise when
// we get directory names adb will push everything in the directory
// name, effectively pushing everything twice. We also specify that we
// want everything returned to be relative to 'app' by using 'cwd'.
var dirs = grunt.file.expand(
{filter: 'isFile',
cwd: 'app' },
'.nomedia',
'**',
'!system/**',
'!data/**',
'!output/**',
'!config/tables/**',
'config/assets/**',
'config/tables/child_coverage/**',
'config/tables/femaleClients/**',
'config/tables/follow/**',
'config/tables/follow_arrival/**',
'config/tables/follow_map_position/**',
'config/tables/follow_map_time/**',
'config/tables/food_bout/**',
'config/tables/graphExample/**',
'config/tables/gridScreen/**',
'config/tables/geopoints/**',
'config/tables/geotagger/**',
'config/tables/groom_bout/**',
'config/tables/household/**',
'config/tables/household_member/**',
'config/tables/maleClients/**',
'config/tables/mating_event/**',
'config/tables/other_species/**',
'config/tables/plot/**',
'config/tables/Tea_houses/**',
'config/tables/Tea_houses_editable/**',
'config/tables/Tea_inventory/**',
'config/tables/Tea_types/**',
'config/tables/visit/**');
return dirs;
};
grunt.registerTask(