-
Notifications
You must be signed in to change notification settings - Fork 182
/
Gruntfile.js
1229 lines (1150 loc) · 41 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
/* jshint node: true */
/* jshint esversion: 6 */
module.exports = function(grunt) {
'use strict';
require('time-grunt')(grunt);
const _ = require('lodash');
const fs = require('fs');
const rules = require('./build/tools/common-grunt-rules');
const path = require('path');
//-------------------------------------------------------------------------
// Location of where src is copied into and compiled
const devBuildPath = 'build/src';
const distBuildPath = 'build/dist';
// Location of where to copy/build third_party source/libs.
const thirdPartyBuildPath = 'build/third_party';
// Setup our build rules/tools
const Rule = new rules.Rule({
// The path where code in this repository should be built in.
devBuildPath: devBuildPath,
// The path from where third party libraries should be copied. e.g. as used by
// sample apps.
thirdPartyBuildPath: thirdPartyBuildPath
});
//-------------------------------------------------------------------------
const chromeExtDevPath = path.join(devBuildPath, 'chrome/extension/');
const chromeAppDevPath = path.join(devBuildPath, 'chrome/app/');
const firefoxDevPath = path.join(devBuildPath, 'firefox/');
const ccaDevPath = path.join(devBuildPath, 'cca/');
const androidDevPath = path.join(devBuildPath, 'android/');
const genericPath = path.join(devBuildPath, 'generic/');
//-------------------------------------------------------------------------
function browserifyIntegrationTest(path) {
return Rule.browserifySpec(path, {
browserifyOptions: {
standalone: 'browserified_exports'
}
});
}
//-------------------------------------------------------------------------
const basePath = process.cwd();
const ccaPath = path.join(basePath, 'node_modules/cca/');
const freedomForChromePath = path.dirname(require.resolve('freedom-for-chrome/package.json'));
//-------------------------------------------------------------------------
// TODO: Move more file lists here.
const FILES = {
jasmine_helpers: [
// Help Jasmine's PhantomJS understand promises.
'node_modules/es6-promise/dist/promise-*.js',
'!node_modules/es6-promise/dist/promise-*amd.js',
'!node_modules/es6-promise/dist/promise-*.min.js'
],
// Files which are required at run-time everywhere
uproxy_common: [
'generic/network-options.js',
'generic/version.js'
],
thirdPartyUi: [
'platform/platform.js',
'polymer/polymer.html',
'polymer/polymer.js',
'webcomponentsjs/**.min.js'
]
};
//-------------------------------------------------------------------------
function finishVulcanized(basePath, baseFilename) {
return {
files: [{
src: path.join(basePath, baseFilename + '.html'),
dest: path.join(basePath, baseFilename + '.html')
}],
options: {
replacements: [
{
pattern: baseFilename + '.js',
replacement: baseFilename + '.static.js'
}, {
pattern: /<script src=\"[a-zA-Z_.\/]+third_party\/bower\/([^"]+)"><\/script>/,
replacement: '<script src="../lib/$1"></script>'
}
]
}
};
}
function readJSONFile(file) {
return JSON.parse(fs.readFileSync(file, 'utf8'));
}
function getWithBasePath(files, base) {
base = base || '';
return files.map((file) => {
if (file[0] === '!') {
return '!' + path.join(base, file.slice(1));
} else {
return path.join(base, file);
}
});
}
const backendThirdPartyBuildPaths = ['bower', 'sha1'];
const backendFreedomModulePaths = [
'lib/loggingprovider',
'lib/churn-pipe',
'lib/cloud/social'
];
const uiDistFiles = [
'generic_ui/*.html',
'generic_ui/style/*.css',
'generic_ui/polymer/vulcanized*.{html,js}',
'generic_ui/fonts/*',
'generic_ui/icons/*',
'generic_ui/scripts/get_logs.js',
'generic_ui/scripts/content_digitalocean.js'
];
const coreDistFiles = [
'fonts/*',
'*.html', // technically does not exist in Firefox
'freedomjs-anonymized-metrics/anonmetrics.json',
'freedomjs-anonymized-metrics/metric.js',
'freedom-social-github/social.github.json',
'freedom-social-github/github-social-provider.js',
'freedom-social-firebase/social.firebase-facebook.json',
'freedom-social-firebase/social.firebase-google.json',
'freedom-social-firebase/firebase-shims.js',
'freedom-social-firebase/firebase.js',
'freedom-social-firebase/firebase-social-provider.js',
'freedom-social-firebase/facebook-social-provider.js',
'freedom-social-firebase/google-social-provider.js',
'freedom-social-firebase/google-auth.js',
'freedom-social-quiver/socketio.quiver.json',
'freedom-social-quiver/socketio.quiver.js',
'freedom-port-control/port-control.js',
'freedom-port-control/port-control.json',
'freedom-pgp-e2e/end-to-end.compiled.js',
'freedom-pgp-e2e/googstorage.js',
'freedom-pgp-e2e/hex2words.js',
'freedom-pgp-e2e/e2e.js',
'freedom-pgp-e2e/pgpapi.json',
'forge-min/forge.min.js', // For cloud social provider
'**/freedom-module.json',
'**/*.static.js'
];
// This should always be added to arrays of files to copy last
const universalDistFiles = [
'icons/**/*',
'bower/webcomponentsjs/webcomponents.min.js',
'bower/polymer/polymer.js',
'!generic_core/freedom-module.json',
'!generic_ui/polymer/vulcanized*inline.html',
'!generic_ui/polymer/vulcanized.js',
'!**/*spec*'
];
const extraFilesForCoreBuilds = [
'freedomjs-anonymized-metrics',
'freedom-social-firebase',
'freedom-social-github',
'freedom-social-wechat',
'freedom-social-quiver',
'freedom-pgp-e2e',
'freedom-port-control'
];
function getExtraFilesForCoreBuild(basePath) {
return extraFilesForCoreBuilds.map((spec) => {
return {
expand: true,
cwd: path.join('node_modules', spec, 'dist'),
src: ['**'],
dest: path.join(basePath, spec)
};
});
}
grunt.initConfig({
pkg: readJSONFile('package.json'),
pkgs: {
freedom: readJSONFile('node_modules/freedom/package.json'),
freedomchrome: readJSONFile('node_modules/freedom-for-chrome/package.json'),
freedomfirefox: readJSONFile('node_modules/freedom-for-firefox/package.json'),
freedomfirebase: readJSONFile('node_modules/freedom-social-firebase/package.json'),
freedomGitHub: readJSONFile('node_modules/freedom-social-github/package.json'),
freedomwechat: readJSONFile('node_modules/freedom-social-wechat/package.json'),
freedomquiver: readJSONFile('node_modules/freedom-social-quiver/package.json')
},
clean: [devBuildPath, distBuildPath, '.tscache'],
//-------------------------------------------------------------------------
// Import global names into config name space.
ccaJsPath: path.join(ccaPath, 'src/cca.js'),
androidDevPath: androidDevPath,
ccaDevPath: ccaDevPath,
// Create commands to run in different directories.
ccaPlatformAndroidCmd: '<%= ccaJsPath %> platform add android',
ccaAddPluginsCmd: '<%= ccaJsPath %> plugin add cordova-plugin-splashscreen cordova-custom-config https://github.com/Initsogar/cordova-webintent.git https://github.com/uProxy/cordova-plugin-tun2socks.git',
exec: {
makeChromeWebStoreZips: {
command: 'tools/makechromezips.sh'
},
// Pipe 'no' into any CCA command which asks on first run whether to send usage stats.
// It's slightly annoying on your workstation, potentially fatal on Docker and Travis.
ccaCreate: {
command: 'echo no | <%= ccaJsPath %> create <%= androidDevPath %> org.uproxy.uProxy "uProxy" --link-to=<%= ccaDevPath %>'
},
ccaPlatformAndroid: {
cwd: '<%= androidDevPath %>',
command: '<%= ccaPlatformAndroidCmd %>'
},
ccaAddPluginsAndroid: {
cwd: '<%= androidDevPath %>',
command: '<%= ccaAddPluginsCmd %>'
},
// Note: The fixed crosswalk version here is pinned in order to maintain
// compatibility with the modified libxwalkcore.so that provides obfuscated WebRTC.
ccaBuildAndroidDev: {
cwd: '<%= androidDevPath %>',
command: 'echo no | <%= ccaJsPath %> build android --debug [email protected]:xwalk_core_library_beta:22.52.561.2'
},
ccaBuildAndroidRelease: {
cwd: '<%= androidDevPath %>',
command: 'echo no | <%= ccaJsPath %> build android --release [email protected]:xwalk_core_library_beta:22.52.561.2'
},
ccaEmulateAndroid: {
cwd: '<%= androidDevPath %>',
command: '<%= ccaJsPath %> run android --emulator'
},
cleanAndroid: {
command: 'rm -rf <%= androidDevPath %>'
},
androidReplaceXwalkDev: {
command: './replace_xwalk_in_apk.sh debug'
},
androidReplaceXwalkRelease: {
command: './replace_xwalk_in_apk.sh release'
},
installFreedomForNodeForZork: {
// This allows our Docker containers, which do not have access to the
// git repo's "top-level" node_modules/ folder find freedom-for-node.
cwd: 'build/src/lib/samples/zork-node',
command: 'yarn add freedom-for-node'
},
xpi: {
command: 'yarn run jpm -- --addon-dir build/dist/firefox xpi'
}
},
copy: {
// Copy releveant non-typescript src files to dev build.
resources: {
files: [
{
nonull: true,
expand: true,
cwd: 'src/',
src: ['**/*', '!**/*.ts', '!generic_core/dist_build/*', '!generic_core/dev_build/*'],
dest: devBuildPath,
onlyIf: 'modified'
}
]
},
i18nMessages: {
files: [{
nonull: false, expand: true,
cwd: 'src',
src: ['generic_ui/locales/**/*.json'],
dest: devBuildPath
}]
},
devGenericCore: {
files: [
{
nonull: true,
src: 'src/generic_core/dev_build/freedom-module.json',
dest: devBuildPath + '/generic_core/freedom-module.json',
onlyIf: 'modified'
}
]
},
// Copy releveant files for distribution.
dist: {
files: [
{ // Chrome extension
expand: true,
cwd: chromeExtDevPath,
src: [
'manifest.json',
'_locales/**',
'generic_ui/scripts/copypaste.js',
'scripts/context.static.js',
'scripts/background.static.js'
].concat(uiDistFiles, universalDistFiles),
dest: 'build/dist/chrome/extension'
},
{ // Chrome app
expand: true,
cwd: chromeAppDevPath,
src: [
'manifest.json',
'managed_policy_schema.json',
'_locales/**',
'polymer/vulcanized.{html,js}',
'freedom-for-chrome/freedom-for-chrome.js'
].concat(coreDistFiles, universalDistFiles),
dest: 'build/dist/chrome/app'
},
{ // Chrome app freedom-module
expand: true,
cwd: 'src/generic_core/dist_build/',
src: ['*'],
dest: 'build/dist/chrome/app/generic_core'
},
{ // Firefox
expand: true,
cwd: firefoxDevPath,
src: [
'package.json',
// Addon sdk scripts
'lib/**/*.js',
'data/scripts/content-proxy.js',
'data/freedom-for-firefox/freedom-for-firefox.jsm'
].concat(
getWithBasePath(uiDistFiles, 'data'),
getWithBasePath(coreDistFiles, 'data'),
getWithBasePath(universalDistFiles, 'data')),
dest: 'build/dist/firefox'
},
{ // Firefox freedom-module
expand: true,
cwd: 'src/generic_core/dist_build/',
src: ['*'],
dest: 'build/dist/firefox/data/generic_core/'
}
]
},
cca_splash: {
files: [
{
expand: true,
cwd: 'src/cca',
src: ['splashscreen.png'],
dest: path.join(androidDevPath, 'platforms/android/res/drawable-port-xhdpi')
}
]
},
// uproxy-lib sample apps.
libsForZorkChromeApp: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome'],
pathsFromDevBuild: ['lib/churn-pipe', 'lib/loggingprovider', 'lib/zork'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/zork-chromeapp/'
}),
libsForZorkFirefoxApp: Rule.copyLibs({
npmLibNames: ['freedom-for-firefox'],
pathsFromDevBuild: ['lib/churn-pipe', 'lib/loggingprovider', 'lib/zork'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/zork-firefoxapp/data/'
}),
libsForZorkNode: Rule.copyLibs({
pathsFromDevBuild: ['lib/churn-pipe', 'lib/loggingprovider', 'lib/zork'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/zork-node/'
}),
libsForEchoServerChromeApp: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome'],
pathsFromDevBuild: ['lib/echo', 'lib/loggingprovider'],
localDestPath: 'lib/samples/echo-server-chromeapp/'
}),
libsForEchoServerFirefoxApp: Rule.copyLibs({
npmLibNames: ['freedom-for-firefox'],
pathsFromDevBuild: ['lib/echo', 'lib/loggingprovider'],
localDestPath: 'lib/samples/echo-server-firefoxapp/data/'
}),
libsForEchoServerNode: Rule.copyLibs({
npmLibNames: ['freedom-for-node'],
pathsFromDevBuild: ['lib/echo', 'lib/loggingprovider'],
localDestPath: 'lib/samples/echo-server-node/'
}),
libsForCopypasteChatChromeApp: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome'],
pathsFromDevBuild: ['lib/copypaste-chat', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/copypaste-chat-chromeapp/'
}),
libsForCopypasteChatFirefoxApp: Rule.copyLibs({
npmLibNames: ['freedom-for-firefox'],
pathsFromDevBuild: ['lib/copypaste-chat', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/copypaste-chat-firefoxapp/data'
}),
libsForCopypasteChatWebApp: Rule.copyLibs({
npmLibNames: ['freedom'],
pathsFromDevBuild: ['lib/copypaste-chat', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/copypaste-chat-webapp/'
}),
libsForSimpleSocksChromeApp: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome'],
pathsFromDevBuild: ['lib/simple-socks', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/simple-socks-chromeapp/'
}),
libsForSimpleSocksFirefoxApp: Rule.copyLibs({
npmLibNames: ['freedom-for-firefox'],
pathsFromDevBuild: ['lib/simple-socks', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/simple-socks-firefoxapp/data/'
}),
libsForSimpleSocksNode: Rule.copyLibs({
npmLibNames: ['freedom-for-node'],
pathsFromDevBuild: ['lib/simple-socks', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['uproxy-obfuscators', 'freedom-port-control'],
localDestPath: 'lib/samples/simple-socks-node/'
}),
libsForSimpleChatChromeApp: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome'],
pathsFromDevBuild: ['lib/simple-chat', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/simple-chat-chromeapp/'
}),
libsForSimpleChatFirefoxApp: Rule.copyLibs({
npmLibNames: ['freedom-for-firefox'],
pathsFromDevBuild: ['lib/simple-chat', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/simple-chat-firefoxapp/data'
}),
// While neither churn-pipe nor freedom-port-control can be used in a
// regular web page environment, they are included so that obfuscation
// may be easily enabled in the Chrome and Firefox samples.
libsForSimpleChatWebApp: Rule.copyLibs({
npmLibNames: ['freedom'],
pathsFromDevBuild: ['lib/simple-chat', 'lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/samples/simple-chat-webapp/'
}),
libsForUprobeChromeApp: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome'],
pathsFromDevBuild: ['lib/uprobe', 'lib/loggingprovider'],
localDestPath: 'lib/samples/uprobe-chromeapp/'
}),
libsForUprobeFirefoxApp: Rule.copyLibs({
npmLibNames: ['freedom-for-firefox'],
pathsFromDevBuild: ['lib/uprobe', 'lib/loggingprovider'],
localDestPath: 'lib/samples/uprobe-firefoxapp/data/'
}),
// uproxy-lib integration tests.
libsForIntegrationTcp: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome'],
pathsFromDevBuild: ['lib/loggingprovider'],
localDestPath: 'lib/integration-tests/tcp'
}),
libsForIntegrationSocksEcho: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome'],
pathsFromDevBuild: ['lib/churn-pipe', 'lib/loggingprovider'],
pathsFromThirdPartyBuild: ['freedom-port-control'],
localDestPath: 'lib/integration-tests/socks-echo'
})
},
symlink: {
cca_keys: {
files: [
{
expand: true,
cwd: 'keys',
src: [
'android-release-keys.properties',
'play_store_keys.p12'
],
dest: androidDevPath
}
]
}
},
//-------------------------------------------------------------------------
'string-replace': {
version: {
files: [{
src: path.join(devBuildPath, 'generic/version.js'),
dest: path.join(devBuildPath, 'generic/version.js')
}],
options: {
replacements: [{
pattern: /\"___VERSION_TEMPLATE___\"/g,
replacement: JSON.stringify({
version: '<%= pkg.version %>',
gitcommit: '<%= gitinfo.local.branch.current.SHA %>',
freedom: '<%= pkgs.freedom.version %>',
'freedom-for-chrome': '<%= pkgs.freedomchrome.version %>',
'freedom-for-firefox': '<%= pkgs.freedomfirefox.version %>',
'freedom-social-firebase': '<%= pkgs.freedomfirebase.version %>',
'freedom-social-github': '<%= pkgs.freedomGitHub.version %>',
'freedom-social-wechat': '<%= pkgs.freedomwechat.version %>',
'freedom-social-quiver': '<%= pkgs.freedomquiver.version %>'
})
}]
}
}
},
ts: {
default: {
tsconfig: {
tsconfig: 'tsconfig.json',
passThrough: true
}
}
},
browserify: {
chromeExtensionCoreConnector: Rule.browserify('chrome/extension/scripts/chrome_core_connector'),
chromeExtensionCoreConnectorSpec: Rule.browserifySpec('chrome/extension/scripts/chrome_core_connector'),
genericCoreFirewall: Rule.browserify('generic_core/firewall'),
genericCoreFreedomModule: Rule.browserify('generic_core/freedom-module'),
// uproxy-lib
loggingProvider: Rule.browserify('lib/loggingprovider/freedom-module'),
churnPipeFreedomModule: Rule.browserify('lib/churn-pipe/freedom-module'),
cloudSocialProviderFreedomModule: Rule.browserify('lib/cloud/social/freedom-module'),
// uproxy-lib sample apps.
copypasteChatFreedomModule: Rule.browserify('lib/copypaste-chat/freedom-module'),
echoServerFreedomModule: Rule.browserify('lib/echo/freedom-module'),
simpleChatFreedomModule: Rule.browserify('lib/simple-chat/freedom-module'),
simpleSocksFreedomModule: Rule.browserify('lib/simple-socks/freedom-module'),
uprobeFreedomModule: Rule.browserify('lib/uprobe/freedom-module'),
zorkFreedomModule: Rule.browserify('lib/zork/freedom-module'),
// uproxy-lib sample apps (with UI).
copypasteChatMain: Rule.browserify('lib/copypaste-chat/main.core-env'),
simpleChatMain: Rule.browserify('lib/simple-chat/main.core-env'),
integrationTcpFreedomModule: Rule.browserify('lib/integration-tests/tcp/freedom-module'),
integrationTcpSpec: browserifyIntegrationTest('lib/integration-tests/tcp/tcp.core-env'),
integrationSocksEchoFreedomModule: Rule.browserify('lib/integration-tests/socks-echo/freedom-module'),
integrationSocksEchoChurnSpec: browserifyIntegrationTest('lib/integration-tests/socks-echo/churn.core-env'),
integrationSocksEchoNochurnSpec: browserifyIntegrationTest('lib/integration-tests/socks-echo/nochurn.core-env'),
integrationSocksEchoSlowSpec: browserifyIntegrationTest('lib/integration-tests/socks-echo/slow.core-env')
},
tslint: {
options: {
configuration: 'src/tslint.json'
},
files: {
src: ['src/**/*.ts']
}
},
jshint: {
firefox: {
options: {
moz: true
},
src: ['src/firefox/lib/*.js']
}
},
watch: {
resources: {
files: ['src/**/*', '!src/**/*.ts'],
tasks: ['copy:resources']
},
typescript: {
files: ['src/**/*.ts'],
tasks: ['compileTypescript']
},
browserify: {
files: ['build/**/*.js', '!build/**/*.static.js'],
tasks: ['browserify:chromeAppMainCoreEnv', 'browserify:chromeExtBackground']
},
chromeExt: {
files: ['src/**/*'],
tasks: ['chromeExtRoot']
}
},
//-------------------------------------------------------------------------
jasmine: {
chrome_core_connector: Rule.jasmineSpec('chrome/extension/scripts/chrome_core_connector', [
path.join('build/src/mocks/chrome_mocks.js')
])
},
jasmine_chromeapp: {
tcp: {
files: [
{
cwd: devBuildPath + '/lib/integration-tests/tcp/',
src: ['**/*', '!jasmine_chromeapp/**/*'],
dest: './',
expand: true
}
],
scripts: [
'freedom-for-chrome/freedom-for-chrome.js',
'tcp.core-env.spec.static.js'
],
options: {
outDir: devBuildPath + '/lib/integration-tests/tcp/jasmine_chromeapp/',
keepRunner: false
}
},
socksEcho: {
files: [
{
cwd: devBuildPath + '/lib/integration-tests/socks-echo/',
src: ['**/*', '!jasmine_chromeapp*/**'],
dest: './',
expand: true
}
],
scripts: [
'freedom-for-chrome/freedom-for-chrome.js',
'churn.core-env.spec.static.js',
'nochurn.core-env.spec.static.js'
],
options: {
outDir: devBuildPath + '/lib/integration-tests/socks-echo/jasmine_chromeapp/',
keepRunner: false
}
},
socksEchoSlow: {
files: [
{
cwd: devBuildPath + '/lib/integration-tests/socks-echo/',
src: ['**/*', '!jasmine_chromeapp*/**'],
dest: './',
expand: true
}
],
scripts: [
'freedom-for-chrome/freedom-for-chrome.js',
'slow.core-env.spec.static.js'
],
options: {
outDir: devBuildPath + '/lib/integration-tests/socks-echo/jasmine_chromeapp_slow/',
keepRunner: true
}
}
}
});
//-------------------------------------------------------------------------
// Helper functions for different components
function fullyVulcanize(basePath, srcFilename, destFilename, browserify) {
browserify = !!browserify;
let tasks = [];
// this adds the rule to the task to the grunt object as well as
// adding the text needed to run it in a rule to the list of rules that will be
// returned
function addTask(component, task, rule) {
grunt.config.set(component + '.' + task, rule);
return tasks.push(component + ':' + task);
}
const realBasePath = path.join(devBuildPath, basePath);
const srcFile = path.join(realBasePath, srcFilename + '.html');
const destFile = path.join(realBasePath, destFilename + '.html');
const taskName = path.join(realBasePath, destFilename);
// The basic vulcanize tasks, we do both steps in order to get all the
// javascript into a separate file
addTask('vulcanize', taskName, {
options: {
inline: true,
csp: destFilename + '.js',
excludes: { scripts: ['polymer.js'] }
},
files: [{ src: srcFile, dest: destFile }]
});
if (browserify) {
// If we need to brewserify the file, there also needs to be a step to replace
// some of the strings in the vulcanized html file to refer to the static version
const browserifyPath = path.join(basePath, destFilename);
addTask('string-replace', taskName + 'Vulcanized', finishVulcanized(realBasePath, destFilename));
addTask('browserify', browserifyPath, Rule.browserify(browserifyPath, {}));
}
return tasks;
}
// Returns a task name that will run the input task only once if
// called multiple times.
function makeRunOnce(taskName) {
return 'run-once:' + taskName;
}
// Register a task, making sure subtasks only run once.
// Description is optional.
function registerTask(grunt, taskName, description, subTasks) {
if (!subTasks) {
subTasks = description;
return grunt.registerTask(taskName, subTasks.map(makeRunOnce));
}
return grunt.registerTask(taskName, description, subTasks.map(makeRunOnce));
}
registerTask(grunt, 'default', ['build']);
// Builds all code, including the "dist" build, but skips Android as well as
// ts-linting and testing which can be annoying and slow.
// We added jshint here because catches hard syntax errors, etc.
registerTask(grunt, 'build', [
'build_chrome',
'build_firefox',
'build_cca',
'jshint',
'copy:dist',
'exec:xpi',
'exec:makeChromeWebStoreZips'
]);
// This is run prior to releasing uProxy and, in addition to
// building, tests and lints all code.
registerTask(grunt, 'dist', [
'build',
'test'
]);
registerTask(grunt, 'compileTypescript', 'Compiles all the Typescript code', [
'copy:i18nMessages', 'ts', 'version_file'
]);
registerTask(grunt, 'version_file', [
'gitinfo',
'string-replace:version'
]);
registerTask(grunt, 'base', [
'copy:resources',
'copy:devGenericCore',
'compileTypescript',
'browserify:genericCoreFreedomModule',
'browserify:loggingProvider',
'browserify:churnPipeFreedomModule',
'browserify:cloudSocialProviderFreedomModule'
]);
registerTask(grunt, 'echoServer', [
'base',
'browserify:echoServerFreedomModule',
'copy:libsForEchoServerChromeApp',
'copy:libsForEchoServerFirefoxApp',
'copy:libsForEchoServerNode'
]);
registerTask(grunt, 'copypasteChat', [
'base',
'browserify:copypasteChatFreedomModule',
'browserify:copypasteChatMain',
'copy:libsForCopypasteChatChromeApp',
'copy:libsForCopypasteChatFirefoxApp',
'copy:libsForCopypasteChatWebApp'
]);
registerTask(grunt, 'deployer', [
'base',
'browserify:deployerFreedomModule',
'copy:libsForDeployerChromeApp',
'copy:libsForDeployerFirefoxApp'
]);
registerTask(grunt, 'simpleChat', [
'base',
'browserify:simpleChatFreedomModule',
'browserify:simpleChatMain',
'copy:libsForSimpleChatChromeApp',
'copy:libsForSimpleChatFirefoxApp',
'copy:libsForSimpleChatWebApp'
]);
registerTask(grunt, 'simpleSocks', [
'base',
'browserify:simpleSocksFreedomModule',
'copy:libsForSimpleSocksChromeApp',
'copy:libsForSimpleSocksFirefoxApp',
'copy:libsForSimpleSocksNode'
]);
registerTask(grunt, 'uprobe', [
'base',
'browserify:uprobeFreedomModule',
'copy:libsForUprobeChromeApp',
'copy:libsForUprobeFirefoxApp'
]);
registerTask(grunt, 'zork', [
'base',
'browserify:zorkFreedomModule',
'copy:libsForZorkChromeApp',
'copy:libsForZorkFirefoxApp',
'copy:libsForZorkNode',
'exec:installFreedomForNodeForZork'
]);
// Chrome
registerTask(grunt, 'build_chrome', [
'build_chrome_app',
'build_chrome_ext'
]);
// =========================================================================
// Chrome App
// =========================================================================
registerTask(grunt, 'build_chrome_app', [
'base',
'chromeAppMainCoreEnv',
'chromeAppExtMissing',
'copy:chromeApp',
]);
registerTask(grunt, 'chromeAppMainCoreEnv',
'Builds build/dist/chrome/app/scripts/main.core-env.static.js', [
'compileTypescript',
'browserify:chromeAppMainCoreEnv'
]);
registerTask(grunt, 'chromeAppExtMissing',
'Builds build/src/chrome/app/polymer/vulcanized.{html,js}', [
'compileTypescript',
'copy:resources',
'copy:chromeAppBower',
].concat(fullyVulcanize('chrome/app/polymer', 'ext-missing', 'vulcanized')));
grunt.config.merge({
browserify: {
chromeAppMainCoreEnv: Rule.browserify('chrome/app/scripts/main.core-env'),
},
copy: {
chromeApp: Rule.copyLibs({
npmLibNames: ['freedom-for-chrome', 'forge-min'],
pathsFromDevBuild: [
'generic_core'
].concat(backendFreedomModulePaths),
pathsFromThirdPartyBuild: backendThirdPartyBuildPaths,
files: getExtraFilesForCoreBuild(chromeAppDevPath).concat({
expand: true, cwd: 'src/',
src: ['icons/128_online.png', 'fonts/*'],
dest: chromeAppDevPath
}),
localDestPath: 'chrome/app/'
}),
chromeAppBower: {
expand: true, cwd: 'third_party',
src: ['bower/**/*'],
dest: chromeAppDevPath
},
}
});
// =========================================================================
// Chrome Extension
// =========================================================================
registerTask(grunt, 'build_chrome_ext', [
'chromeExtBackground',
'chromeExtContext',
'chromeExtRoot',
'copy:chromeExt',
'copy:chromeExtAdditional',
]);
registerTask(grunt, 'chromeExtBackground',
'Builds build/src/chrome/extension/scripts/background.static.js', [
'compileTypescript',
'browserify:chromeExtBackground'
]);
registerTask(grunt, 'chromeExtContext',
'Builds build/src/chrome/extension/scripts/context.static.js', [
'compileTypescript',
'browserify:chromeExtContext'
]);
registerTask(grunt, 'chromeExtRoot',
'Builds build/src/chrome/extension/generic_ui/polymer/vulcanized.{html,static.js}', [
'compileTypescript',
'copy:resources',
'copy:chromeExt',
'copy:chromeExtAdditional',
].concat(fullyVulcanize('chrome/extension/generic_ui/polymer', 'root', 'vulcanized', true)));
grunt.config.merge({
browserify: {
chromeExtBackground: Rule.browserify('chrome/extension/scripts/background', {
browserifyOptions: {
standalone: 'ui_context'
}
}),
chromeExtContext: Rule.browserify('chrome/extension/scripts/context', {
browserifyOptions: {
standalone: 'ui_context'
}
}),
},
copy: {
chromeExt: Rule.copyLibs({
npmLibNames: [],
pathsFromDevBuild: ['generic_ui', 'interfaces', 'icons', 'fonts'],
pathsFromThirdPartyBuild: ['bower'],
files: [
{
expand: true, cwd: devBuildPath, flatten: true,
src: FILES.uproxy_common,
dest: chromeExtDevPath + '/generic_ui/scripts'
}, {
expand: true, cwd: devBuildPath, flatten: true,
src: FILES.uproxy_common,
dest: chromeExtDevPath + '/scripts'
}, {
expand: true, cwd: devBuildPath, flatten: true,
src: FILES.uproxy_common,
dest: chromeExtDevPath + '/generic'
}
],
localDestPath: 'chrome/extension'
}),
chromeExtAdditional: {
files: [
{ // Copy chrome extension panel components from the background
expand: true,
cwd: chromeExtDevPath,
src: ['polymer/*', 'scripts/*', 'icons/*', 'fonts/*', '*.html'],
dest: chromeExtDevPath + '/generic_ui'
}
]
}
},
});
// =========================================================================
// Firefox
// =========================================================================
registerTask(grunt, 'build_firefox', [
'base',
'firefoxContext',
'firefoxRoot',
'copy:firefox',
'copy:firefox_additional',
]);
registerTask(grunt, 'firefoxContext',
'Builds build/src/firefox/data/scripts/context.static.js', [
'compileTypescript',
'browserify:firefoxContext'
])
registerTask(grunt, 'firefoxRoot',
'Builds build/src/firefox/data/generic_ui/polymer/vulcanized.{html,static.js}', [
'compileTypescript',
'copy:resources',
'copy:firefox',
'copy:firefox_additional',
].concat(fullyVulcanize('firefox/data/generic_ui/polymer', 'root', 'vulcanized', true)));
grunt.config.merge({
browserify: {
firefoxContext: {
src: [firefoxDevPath + '/data/scripts/background.js'],
dest: firefoxDevPath + '/data/scripts/context.static.js',
options: {
browserifyOptions: {
standalone: 'ui_context'
}
}
},
},
copy: {
firefox: Rule.copyLibs({
npmLibNames: [
'freedom-for-firefox',
'forge-min'
],
pathsFromDevBuild: [
'generic_core',
'generic_ui',
'interfaces',
'icons',
'fonts'
].concat(backendFreedomModulePaths),
pathsFromThirdPartyBuild: backendThirdPartyBuildPaths,
files: getExtraFilesForCoreBuild(path.join(firefoxDevPath, 'data')).concat({
expand: true,
cwd: devBuildPath,
src: ['interfaces/*.js'],
dest: firefoxDevPath + '/lib'
}),
localDestPath: 'firefox/data'
}),
firefox_additional: {
files: [
{ // Copy chrome extension panel components from the background.