forked from mozilla/pdf.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.js
1543 lines (1312 loc) · 44.4 KB
/
make.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
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint node:true */
/* globals cat, cd, cp, echo, env, exec, exit, find, ls, mkdir, mv, process, rm,
sed, target, test */
'use strict';
try {
require('shelljs/make');
} catch (e) {
console.log('ShellJS is not installed. Run "npm install" to install ' +
'all dependencies.');
return;
}
var builder = require('./external/builder/builder.js');
var crlfchecker = require('./external/crlfchecker/crlfchecker.js');
var path = require('path');
var fs = require('fs');
var CONFIG_FILE = 'pdfjs.config';
var config = JSON.parse(fs.readFileSync(CONFIG_FILE));
// Defined by buildnumber target.
var BUILD_NUMBER,
VERSION;
var ROOT_DIR = __dirname + '/', // absolute path to project's root
BUILD_DIR = 'build/',
SRC_DIR = 'src/',
BUILD_TARGET = BUILD_DIR + 'pdf.js',
BUILD_WORKER_TARGET = BUILD_DIR + 'pdf.worker.js',
BUILD_TARGETS = [BUILD_TARGET, BUILD_WORKER_TARGET],
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/',
CHROME_BUILD_DIR = BUILD_DIR + '/chromium/',
B2G_BUILD_DIR = BUILD_DIR + '/b2g/',
JSDOC_DIR = BUILD_DIR + 'jsdoc',
EXTENSION_SRC_DIR = 'extensions/',
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/',
LOCALE_SRC_DIR = 'l10n/',
GH_PAGES_DIR = BUILD_DIR + 'gh-pages/',
GENERIC_DIR = BUILD_DIR + 'generic/',
MINIFIED_DIR = BUILD_DIR + 'minified/',
SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/',
COMPONENTS_DIR = BUILD_DIR + 'components/',
REPO = '[email protected]:mozilla/pdf.js.git',
MOZCENTRAL_PREF_PREFIX = 'pdfjs',
FIREFOX_PREF_PREFIX = '[email protected]',
MOZCENTRAL_STREAM_CONVERTER_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2291',
FIREFOX_STREAM_CONVERTER_ID = '6457a96b-2d68-439a-bcfa-44465fbcdbb1',
MOZCENTRAL_STREAM_CONVERTER2_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2292',
FIREFOX_STREAM_CONVERTER2_ID = '6457a96b-2d68-439a-bcfa-44465fbcdbb2';
var DEFINES = {
PRODUCTION: true,
// The main build targets:
GENERIC: false,
FIREFOX: false,
MOZCENTRAL: false,
CHROME: false,
MINIFIED: false,
SINGLE_FILE: false,
COMPONENTS: false
};
//
// make all
//
target.all = function() {
// Don't do anything by default
echo('Please specify a target. Available targets:');
for (var t in target) {
if (t !== 'all') {
echo(' ' + t);
}
}
};
////////////////////////////////////////////////////////////////////////////////
//
// Production stuff
//
// Files that need to be included in every build.
var COMMON_WEB_FILES =
['web/images',
'web/debugger.js'],
COMMON_WEB_FILES_PREPROCESS =
['web/viewer.js',
'web/viewer.html'],
COMMON_FIREFOX_FILES_PREPROCESS =
[FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm',
FIREFOX_CONTENT_DIR + 'PdfjsContentUtils.jsm',
FIREFOX_CONTENT_DIR + 'PdfjsChromeUtils.jsm',
FIREFOX_CONTENT_DIR + 'PdfRedirector.jsm'];
//
// make generic
// Builds the generic production viewer that should be compatible with most
// modern HTML5 browsers.
//
target.generic = function() {
target.bundle({});
target.locale();
cd(ROOT_DIR);
echo();
echo('### Creating generic viewer');
rm('-rf', GENERIC_DIR);
mkdir('-p', GENERIC_DIR);
mkdir('-p', GENERIC_DIR + BUILD_DIR);
mkdir('-p', GENERIC_DIR + '/web');
mkdir('-p', GENERIC_DIR + '/web/cmaps');
var defines = builder.merge(DEFINES, {GENERIC: true});
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, GENERIC_DIR + '/web'],
['LICENSE', GENERIC_DIR],
['external/webL10n/l10n.js', GENERIC_DIR + '/web'],
['web/compatibility.js', GENERIC_DIR + '/web'],
['web/compressed.tracemonkey-pldi-09.pdf', GENERIC_DIR + '/web'],
['external/bcmaps/*', GENERIC_DIR + '/web/cmaps/'],
['web/locale', GENERIC_DIR + '/web']
],
preprocess: [
[BUILD_TARGETS, GENERIC_DIR + BUILD_DIR],
[COMMON_WEB_FILES_PREPROCESS, GENERIC_DIR + '/web']
],
preprocessCSS: [
['generic', 'web/viewer.css',
GENERIC_DIR + '/web/viewer.css']
]
};
builder.build(setup);
cleanupJSSource(GENERIC_DIR + '/web/viewer.js');
cleanupCSSSource(GENERIC_DIR + '/web/viewer.css');
};
target.components = function() {
cd(ROOT_DIR);
echo();
echo('### Creating generic components');
rm('-rf', COMPONENTS_DIR);
mkdir('-p', COMPONENTS_DIR);
mkdir('-p', COMPONENTS_DIR + 'images');
var defines = builder.merge(DEFINES, {COMPONENTS: true});
var COMPONENTS_IMAGES = [
'web/images/annotation-*.svg',
'web/images/loading-icon.gif',
'web/images/shadow.png',
'web/images/texture.png',
];
var setup = {
defines: defines,
copy: [
[COMPONENTS_IMAGES, COMPONENTS_DIR + 'images'],
['web/compatibility.js', COMPONENTS_DIR],
],
preprocess: [
['web/pdf_viewer.component.js', COMPONENTS_DIR + 'pdf_viewer.js'],
],
preprocessCSS: [
['components', 'web/pdf_viewer.css', COMPONENTS_DIR + 'pdf_viewer.css'],
]
};
builder.build(setup);
cleanupJSSource(COMPONENTS_DIR + 'pdf_viewer.js');
cleanupCSSSource(COMPONENTS_DIR + 'pdf_viewer.css');
};
target.jsdoc = function() {
echo();
echo('### Generating jsdoc');
var JSDOC_FILES = [
'src/doc_helper.js',
'src/display/api.js',
'src/shared/util.js',
'src/core/annotation.js'
];
if (test('-d', JSDOC_DIR)) {
rm('-rf', JSDOC_DIR);
}
mkdir('-p',JSDOC_DIR);
exec('"node_modules/.bin/jsdoc" -d "' + JSDOC_DIR + '" ' +
JSDOC_FILES.join(' '));
echo();
};
//
// make web
// Generates the website for the project, by checking out the gh-pages branch
// underneath the build directory, and then moving the various viewer files
// into place.
//
target.web = function() {
target.generic();
target.extension();
target.b2g();
target.jsdoc();
echo();
echo('### Creating web site');
if (test('-d', GH_PAGES_DIR)) {
rm('-rf', GH_PAGES_DIR);
}
mkdir('-p', GH_PAGES_DIR + '/web');
mkdir('-p', GH_PAGES_DIR + '/web/images');
mkdir('-p', GH_PAGES_DIR + BUILD_DIR);
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/firefox');
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chromium');
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/b2g');
mkdir('-p', GH_PAGES_DIR + '/api/draft/');
mkdir('-p', GH_PAGES_DIR + '/examples/');
cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR);
cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf',
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/');
cp(CHROME_BUILD_DIR + '/*.crx', FIREFOX_BUILD_DIR + '/*.rdf',
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chromium/');
cp('-R', 'test/features', GH_PAGES_DIR);
cp('-R', 'examples/learning', GH_PAGES_DIR + '/examples/');
cp('-R', B2G_BUILD_DIR, GH_PAGES_DIR + EXTENSION_SRC_DIR + 'b2g/');
cp('-R', JSDOC_DIR + '/*', GH_PAGES_DIR + '/api/draft/');
var wintersmith = require('wintersmith');
var env = wintersmith('docs/config.json');
env.build(GH_PAGES_DIR, function (error) {
if (error) {
throw error;
}
sed('-i', /STABLE_VERSION/g, config.stableVersion,
GH_PAGES_DIR + '/getting_started/index.html');
sed('-i', /BETA_VERSION/g, config.betaVersion,
GH_PAGES_DIR + '/getting_started/index.html');
echo('Done building with wintersmith.');
cd(GH_PAGES_DIR);
exec('git init');
exec('git remote add origin ' + REPO);
exec('git add -A');
exec('git commit -am "gh-pages site created via make.js script"');
exec('git branch -m gh-pages');
echo();
echo('Website built in ' + GH_PAGES_DIR);
});
};
target.dist = function() {
target.generic();
target.singlefile();
target.components();
var DIST_DIR = BUILD_DIR + 'dist/';
var DIST_REPO_URL = 'https://github.com/mozilla/pdfjs-dist';
cd(ROOT_DIR);
echo();
echo('### Cloning baseline distribution');
rm('-rf', DIST_DIR);
mkdir('-p', DIST_DIR);
exec('git clone --depth 1 ' + DIST_REPO_URL + ' ' + DIST_DIR);
echo();
echo('### Overwriting all files');
rm('-rf', DIST_DIR + '*');
cp('-R', ROOT_DIR + 'external/dist/*', DIST_DIR);
cp('-R', GENERIC_DIR + 'LICENSE', DIST_DIR);
cp('-R', GENERIC_DIR + 'web/cmaps', DIST_DIR);
mkdir('-p', DIST_DIR + 'build/');
cp('-R', [
GENERIC_DIR + 'build/pdf.js',
GENERIC_DIR + 'build/pdf.worker.js',
SINGLE_FILE_DIR + 'build/pdf.combined.js',
], DIST_DIR + 'build/');
mkdir('-p', DIST_DIR + 'web/');
cp('-R', [
COMPONENTS_DIR + '*',
], DIST_DIR + 'web/');
echo();
echo('### Rebuilding manifests');
var DIST_NAME = 'pdfjs-dist';
var DIST_DESCRIPTION = 'Generic build of Mozilla\'s PDF.js library.';
var DIST_KEYWORDS = ['Mozilla', 'pdf', 'pdf.js'];
var DIST_HOMEPAGE = 'http://mozilla.github.io/pdf.js/';
var DIST_BUGS_URL = 'https://github.com/mozilla/pdf.js/issues';
var DIST_LICENSE = 'Apache-2.0';
var npmManifest = {
name: DIST_NAME,
version: VERSION,
description: DIST_DESCRIPTION,
keywords: DIST_KEYWORDS,
homepage: DIST_HOMEPAGE,
bugs: DIST_BUGS_URL,
license: DIST_LICENSE,
repository: {
type: 'git',
url: DIST_REPO_URL
},
};
fs.writeFileSync(DIST_DIR + 'package.json',
JSON.stringify(npmManifest, null, 2));
var bowerManifest = {
name: DIST_NAME,
version: VERSION,
main: [
'build/pdf.js',
'build/pdf.worker.js',
],
ignore: [],
keywords: DIST_KEYWORDS,
};
fs.writeFileSync(DIST_DIR + 'bower.json',
JSON.stringify(bowerManifest, null, 2));
echo();
echo('### Commiting changes');
cd(DIST_DIR);
var message = 'PDF.js version ' + VERSION;
exec('git add *');
exec('git commit -am \"' + message + '\"');
exec('git tag -a v' + VERSION + ' -m \"' + message + '\"');
cd(ROOT_DIR);
echo();
echo('Done. Push with');
echo(' cd ' + DIST_DIR + '; git push --tags ' + DIST_REPO_URL + ' master');
echo();
};
target.publish = function() {
target.generic();
config.stableVersion = config.betaVersion;
config.betaVersion = VERSION;
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
cd(GENERIC_DIR);
var distFilename = 'pdfjs-' + VERSION + '-dist.zip';
exec('zip -r ' + ROOT_DIR + BUILD_DIR + distFilename + ' *');
echo('Built distribution file: ' + distFilename);
cd(ROOT_DIR);
};
//
// make locale
// Creates localized resources for the viewer and extension.
//
target.locale = function() {
var METADATA_OUTPUT = 'extensions/firefox/metadata.inc';
var CHROME_MANIFEST_OUTPUT = 'extensions/firefox/chrome.manifest.inc';
var EXTENSION_LOCALE_OUTPUT = 'extensions/firefox/locale';
var VIEWER_LOCALE_OUTPUT = 'web/locale/';
cd(ROOT_DIR);
echo();
echo('### Building localization files');
rm('-rf', EXTENSION_LOCALE_OUTPUT);
mkdir('-p', EXTENSION_LOCALE_OUTPUT);
rm('-rf', VIEWER_LOCALE_OUTPUT);
mkdir('-p', VIEWER_LOCALE_OUTPUT);
var subfolders = ls(LOCALE_SRC_DIR);
subfolders.sort();
var metadataContent = '';
var chromeManifestContent = '';
var viewerOutput = '';
for (var i = 0; i < subfolders.length; i++) {
var locale = subfolders[i];
var path = LOCALE_SRC_DIR + locale;
if (!test('-d', path)) {
continue;
}
if (!/^[a-z][a-z]([a-z])?(-[A-Z][A-Z])?$/.test(locale)) {
echo('Skipping invalid locale: ' + locale);
continue;
}
mkdir('-p', EXTENSION_LOCALE_OUTPUT + '/' + locale);
mkdir('-p', VIEWER_LOCALE_OUTPUT + '/' + locale);
chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' +
locale + '/\n';
if (test('-f', path + '/viewer.properties')) {
viewerOutput += '[' + locale + ']\n' +
'@import url(' + locale + '/viewer.properties)\n\n';
cp(path + '/viewer.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale);
cp(path + '/viewer.properties', VIEWER_LOCALE_OUTPUT + '/' + locale);
}
if (test('-f', path + '/chrome.properties')) {
cp(path + '/chrome.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale);
}
if (test('-f', path + '/metadata.inc')) {
var metadata = cat(path + '/metadata.inc');
metadataContent += metadata;
}
}
viewerOutput.to(VIEWER_LOCALE_OUTPUT + 'locale.properties');
metadataContent.to(METADATA_OUTPUT);
chromeManifestContent.to(CHROME_MANIFEST_OUTPUT);
};
//
// make cmaps
// Compresses cmap files. Ensure that Adobe cmap download and uncompressed at
// ./external/cmaps location.
//
target.cmaps = function (args) {
var CMAP_INPUT = 'external/cmaps';
var VIEWER_CMAP_OUTPUT = 'external/bcmaps';
cd(ROOT_DIR);
echo();
echo('### Building cmaps');
// testing a file that usually present
if (!test('-f', CMAP_INPUT + '/UniJIS-UCS2-H')) {
echo('./external/cmaps has no cmap files, please download them from:');
echo(' https://github.com/adobe-type-tools/cmap-resources');
exit(1);
}
rm(VIEWER_CMAP_OUTPUT + '*.bcmap');
var compressCmaps =
require('./external/cmapscompress/compress.js').compressCmaps;
compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true);
};
//
// make bundle
// Bundles all source files into one wrapper 'pdf.js' file, in the given order.
//
target.bundle = function(args) {
args = args || {};
var defines = args.defines || DEFINES;
var excludes = args.excludes || [];
target.buildnumber();
cd(ROOT_DIR);
echo();
echo('### Bundling files into ' + BUILD_TARGET);
function bundle(filename, outfilename, SRC_FILES, EXT_SRC_FILES) {
for (var i = 0, length = excludes.length; i < length; ++i) {
var exclude = excludes[i];
var index = SRC_FILES.indexOf(exclude);
if (index >= 0) {
SRC_FILES.splice(index, 1);
}
}
var bundleContent = cat(SRC_FILES),
bundleVersion = VERSION,
bundleBuild = exec('git log --format="%h" -n 1',
{silent: true}).output.replace('\n', '');
crlfchecker.checkIfCrlfIsPresent(SRC_FILES);
// Prepend a newline because stripCommentHeaders only strips comments that
// follow a line feed. The file where bundleContent is inserted already
// contains a license header, so the header of bundleContent can be removed.
bundleContent = stripCommentHeaders('\n' + bundleContent);
// Append external files last since we don't want to modify them.
bundleContent += cat(EXT_SRC_FILES);
// This just preprocesses the empty pdf.js file, we don't actually want to
// preprocess everything yet since other build targets use this file.
builder.preprocess(filename, outfilename, builder.merge(defines,
{BUNDLE: bundleContent,
BUNDLE_VERSION: bundleVersion,
BUNDLE_BUILD: bundleBuild}));
}
if (!test('-d', BUILD_DIR)) {
mkdir(BUILD_DIR);
}
var SHARED_SRC_FILES = [
'shared/util.js',
];
var MAIN_SRC_FILES = SHARED_SRC_FILES.concat([
'display/api.js',
'display/metadata.js',
'display/canvas.js',
'display/webgl.js',
'display/pattern_helper.js',
'display/font_loader.js',
'display/annotation_helper.js',
'display/svg.js'
]);
var srcFiles = builder.getWorkerSrcFiles('src/worker_loader.js');
var WORKER_SRC_FILES = srcFiles.srcFiles;
if (!defines.SINGLE_FILE) {
// We want shared_src_files in both pdf.js and pdf.worker.js
// unless it's being built in singlefile mode.
WORKER_SRC_FILES = SHARED_SRC_FILES.concat(WORKER_SRC_FILES);
} else {
// In singlefile mode, all of the src files will be bundled into
// the main pdf.js outuput.
MAIN_SRC_FILES = MAIN_SRC_FILES.concat(WORKER_SRC_FILES);
}
var EXT_SRC_FILES = srcFiles.externalSrcFiles;
cd(SRC_DIR);
bundle('pdf.js', ROOT_DIR + BUILD_TARGET, MAIN_SRC_FILES, []);
var srcCopy = ROOT_DIR + BUILD_DIR + 'pdf.worker.js.temp';
cp('pdf.js', srcCopy);
bundle(srcCopy, ROOT_DIR + BUILD_WORKER_TARGET, WORKER_SRC_FILES,
EXT_SRC_FILES);
rm(srcCopy);
};
//
// make singlefile
// Concatenates pdf.js and pdf.worker.js into one big pdf.combined.js, and
// flags the script loader to not attempt to load the separate worker JS file.
//
target.singlefile = function() {
cd(ROOT_DIR);
echo();
echo('### Creating singlefile build');
var SINGLE_FILE_TARGET = BUILD_DIR + 'pdf.combined.js';
var defines = builder.merge(DEFINES, {SINGLE_FILE: true});
target.bundle({defines: defines});
cd(ROOT_DIR);
rm('-rf', SINGLE_FILE_DIR);
mkdir('-p', SINGLE_FILE_DIR);
mkdir('-p', SINGLE_FILE_DIR + BUILD_DIR);
var setup = {
defines: defines,
copy: [],
preprocess: [
[BUILD_TARGETS, SINGLE_FILE_DIR + BUILD_DIR]
]
};
builder.build(setup);
cd(SINGLE_FILE_DIR);
echo();
echo('### Moving pdf.js to pdf.combined.js');
var pdfJs = cat(BUILD_TARGET);
pdfJs.to(SINGLE_FILE_TARGET);
rm(BUILD_TARGET);
rm(BUILD_WORKER_TARGET);
};
function stripCommentHeaders(content, filename) {
// Strip out all the vim/license headers.
var notEndOfComment = '(?:[^*]|\\*(?!/))+';
var reg = new RegExp(
'\n/\\* -\\*- Mode' + notEndOfComment + '\\*/\\s*' +
'(?:/\\*' + notEndOfComment + '\\*/\\s*|//(?!#).*\n\\s*)+' +
'\'use strict\';', 'g');
content = content.replace(reg, '');
return content;
}
function cleanupJSSource(file) {
var content = cat(file);
content = stripCommentHeaders(content, file);
content.to(file);
}
function cleanupCSSSource(file) {
var content = cat(file);
// Strip out all license headers in the middle.
var reg = /\n\/\* Copyright(.|\n)*?Mozilla Foundation(.|\n)*?\*\//g;
content = content.replace(reg, '');
content.to(file);
}
//
// make minified
// Builds the minified production viewer that should be compatible with most
// modern HTML5 browsers. Requires Google Closure Compiler.
//
target.minified = function() {
var compilerPath = process.env['CLOSURE_COMPILER'];
if (!compilerPath) {
echo('### Closure Compiler is not set. Specify CLOSURE_COMPILER variable');
exit(1);
}
target.bundle({});
target.locale();
cd(ROOT_DIR);
echo();
echo('### Creating minified viewer');
rm('-rf', MINIFIED_DIR);
mkdir('-p', MINIFIED_DIR);
mkdir('-p', MINIFIED_DIR + BUILD_DIR);
mkdir('-p', MINIFIED_DIR + '/web');
mkdir('-p', MINIFIED_DIR + '/web/cmaps');
var defines = builder.merge(DEFINES, {GENERIC: true, MINIFIED: true});
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, MINIFIED_DIR + '/web'],
['web/compressed.tracemonkey-pldi-09.pdf', MINIFIED_DIR + '/web'],
['external/bcmaps/*', MINIFIED_DIR + '/web/cmaps'],
['web/locale', MINIFIED_DIR + '/web']
],
preprocess: [
[BUILD_TARGETS, MINIFIED_DIR + BUILD_DIR],
[COMMON_WEB_FILES_PREPROCESS, MINIFIED_DIR + '/web']
],
preprocessCSS: [
['minified', 'web/viewer.css',
MINIFIED_DIR + '/web/viewer.css']
]
};
builder.build(setup);
cleanupCSSSource(MINIFIED_DIR + '/web/viewer.css');
var viewerFiles = [
'web/compatibility.js',
'external/webL10n/l10n.js',
MINIFIED_DIR + BUILD_DIR + 'pdf.js',
MINIFIED_DIR + '/web/viewer.js'
];
var cmdPrefix = 'java -jar \"' + compilerPath + '\" ' +
'--language_in ECMASCRIPT5 ' +
'--warning_level QUIET ' +
'--compilation_level SIMPLE_OPTIMIZATIONS ';
echo();
echo('### Minifying js files');
exec(cmdPrefix + viewerFiles.map(function(s) {
return '--js \"' + s + '\"';
}).join(' ') +
' --js_output_file \"' + MINIFIED_DIR + '/web/pdf.viewer.js\"');
exec(cmdPrefix + '--js \"' + MINIFIED_DIR + '/build/pdf.js' + '\" ' +
'--js_output_file \"' + MINIFIED_DIR + '/build/pdf.min.js' + '\"');
exec(cmdPrefix + '--js \"' + MINIFIED_DIR + '/build/pdf.worker.js' + '\" ' +
'--js_output_file \"' + MINIFIED_DIR + '/build/pdf.worker.min.js' + '\"');
echo();
echo('### Cleaning js files');
rm(MINIFIED_DIR + '/web/viewer.js');
rm(MINIFIED_DIR + '/web/debugger.js');
rm(MINIFIED_DIR + '/build/pdf.js');
rm(MINIFIED_DIR + '/build/pdf.worker.js');
mv(MINIFIED_DIR + '/build/pdf.min.js',
MINIFIED_DIR + '/build/pdf.js');
mv(MINIFIED_DIR + '/build/pdf.worker.min.js',
MINIFIED_DIR + '/build/pdf.worker.js');
};
////////////////////////////////////////////////////////////////////////////////
//
// Extension stuff
//
//
// make extension
//
target.extension = function() {
cd(ROOT_DIR);
echo();
echo('### Building extensions');
target.locale();
target.firefox();
target.chromium();
};
target.buildnumber = function() {
cd(ROOT_DIR);
echo();
echo('### Getting extension build number');
var lines = exec('git log --format=oneline ' +
config.baseVersion + '..', {silent: true}).output;
// Build number is the number of commits since base version
BUILD_NUMBER = lines ? lines.match(/\n/g).length : 0;
echo('Extension build number: ' + BUILD_NUMBER);
VERSION = config.versionPrefix + BUILD_NUMBER;
};
//
// make firefox
//
target.firefox = function() {
cd(ROOT_DIR);
echo();
echo('### Building Firefox extension');
var defines = builder.merge(DEFINES, {FIREFOX: true});
var FIREFOX_BUILD_CONTENT_DIR = FIREFOX_BUILD_DIR + '/content/',
FIREFOX_EXTENSION_DIR = 'extensions/firefox/',
FIREFOX_EXTENSION_FILES_TO_COPY =
['*.js',
'*.rdf',
'*.svg',
'*.png',
'*.manifest',
'locale',
'chrome',
'../../LICENSE'],
FIREFOX_EXTENSION_FILES =
['bootstrap.js',
'install.rdf',
'chrome.manifest',
'icon.png',
'icon64.png',
'content',
'chrome',
'locale',
'LICENSE'],
FIREFOX_EXTENSION_NAME = 'pdf.js.xpi',
FIREFOX_AMO_EXTENSION_NAME = 'pdf.js.amo.xpi';
target.locale();
target.bundle({ excludes: ['core/network.js'], defines: defines });
cd(ROOT_DIR);
// Clear out everything in the firefox extension build directory
rm('-rf', FIREFOX_BUILD_DIR);
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR);
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR);
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + '/web');
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + '/web/cmaps');
cp(FIREFOX_CONTENT_DIR + 'PdfJs-stub.jsm',
FIREFOX_BUILD_CONTENT_DIR + 'PdfJs.jsm');
cp(FIREFOX_CONTENT_DIR + 'PdfJsTelemetry-addon.jsm',
FIREFOX_BUILD_CONTENT_DIR + 'PdfJsTelemetry.jsm');
// Copy extension files
cd(FIREFOX_EXTENSION_DIR);
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY, ROOT_DIR + FIREFOX_BUILD_DIR);
cd(ROOT_DIR);
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, FIREFOX_BUILD_CONTENT_DIR + '/web'],
['web/compatibility.js', FIREFOX_BUILD_CONTENT_DIR + '/web'],
['external/bcmaps/*', FIREFOX_BUILD_CONTENT_DIR + '/web/cmaps'],
[FIREFOX_EXTENSION_DIR + 'tools/l10n.js',
FIREFOX_BUILD_CONTENT_DIR + '/web']
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'],
[BUILD_TARGETS, FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR],
[COMMON_FIREFOX_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR],
[SRC_DIR + 'core/network.js', FIREFOX_BUILD_CONTENT_DIR],
[FIREFOX_EXTENSION_DIR + 'bootstrap.js', FIREFOX_BUILD_DIR]
],
preprocessCSS: [
['firefox', 'web/viewer.css',
FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.css']
]
};
builder.build(setup);
cleanupJSSource(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.js');
cleanupJSSource(FIREFOX_BUILD_DIR + 'bootstrap.js');
cleanupJSSource(FIREFOX_BUILD_CONTENT_DIR + 'PdfjsChromeUtils.jsm');
cleanupCSSSource(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.css');
// Remove '.DS_Store' and other hidden files
find(FIREFOX_BUILD_DIR).forEach(function(file) {
if (file.match(/^\./)) {
rm('-f', file);
}
});
// Update the build version number
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
FIREFOX_BUILD_DIR + '/install.rdf');
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
FIREFOX_BUILD_DIR + '/update.rdf');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, FIREFOX_STREAM_CONVERTER_ID,
FIREFOX_BUILD_CONTENT_DIR + 'PdfStreamConverter.jsm');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER2_ID/, FIREFOX_STREAM_CONVERTER2_ID,
FIREFOX_BUILD_CONTENT_DIR + 'PdfStreamConverter.jsm');
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, FIREFOX_PREF_PREFIX,
FIREFOX_BUILD_CONTENT_DIR + 'PdfStreamConverter.jsm');
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'false',
FIREFOX_BUILD_CONTENT_DIR + 'PdfStreamConverter.jsm');
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, FIREFOX_PREF_PREFIX,
FIREFOX_BUILD_CONTENT_DIR + 'PdfjsChromeUtils.jsm');
// Update localized metadata
var localizedMetadata = cat(EXTENSION_SRC_DIR + '/firefox/metadata.inc');
sed('-i', /.*PDFJS_LOCALIZED_METADATA.*\n/, localizedMetadata,
FIREFOX_BUILD_DIR + '/install.rdf');
var chromeManifest = cat(EXTENSION_SRC_DIR + '/firefox/chrome.manifest.inc');
sed('-i', /.*PDFJS_SUPPORTED_LOCALES.*\n/, chromeManifest,
FIREFOX_BUILD_DIR + '/chrome.manifest');
// Create the xpi
cd(FIREFOX_BUILD_DIR);
exec('zip -r ' + FIREFOX_EXTENSION_NAME + ' ' +
FIREFOX_EXTENSION_FILES.join(' '));
echo('extension created: ' + FIREFOX_EXTENSION_NAME);
cd(ROOT_DIR);
// Build the amo extension too (remove the updateUrl)
cd(FIREFOX_BUILD_DIR);
sed('-i', /.*updateURL.*\n/, '', 'install.rdf');
exec('zip -r ' + FIREFOX_AMO_EXTENSION_NAME + ' ' +
FIREFOX_EXTENSION_FILES.join(' '));
echo('AMO extension created: ' + FIREFOX_AMO_EXTENSION_NAME);
cd(ROOT_DIR);
};
//
// make mozcentral
//
target.mozcentral = function() {
cd(ROOT_DIR);
echo();
echo('### Building mozilla-central extension');
var defines = builder.merge(DEFINES, {MOZCENTRAL: true});
var MOZCENTRAL_DIR = BUILD_DIR + 'mozcentral/',
MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + 'browser/extensions/pdfjs/',
MOZCENTRAL_CONTENT_DIR = MOZCENTRAL_EXTENSION_DIR + 'content/',
MOZCENTRAL_L10N_DIR = MOZCENTRAL_DIR + 'browser/locales/en-US/pdfviewer/',
MOZCENTRAL_TEST_DIR = MOZCENTRAL_EXTENSION_DIR + 'test/',
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/',
FIREFOX_EXTENSION_FILES_TO_COPY =
['*.svg',
'*.png',
'*.manifest',
'README.mozilla',
'../../LICENSE'],
DEFAULT_LOCALE_FILES =
[LOCALE_SRC_DIR + 'en-US/viewer.properties',
LOCALE_SRC_DIR + 'en-US/chrome.properties'],
FIREFOX_MC_EXCLUDED_FILES =
['icon.png',
'icon64.png'];
target.bundle({ excludes: ['core/network.js'], defines: defines });
cd(ROOT_DIR);
// Clear out everything in the firefox extension build directory
rm('-rf', MOZCENTRAL_DIR);
mkdir('-p', MOZCENTRAL_CONTENT_DIR);
mkdir('-p', MOZCENTRAL_L10N_DIR);
mkdir('-p', MOZCENTRAL_CONTENT_DIR + BUILD_DIR);
mkdir('-p', MOZCENTRAL_CONTENT_DIR + '/web');
mkdir('-p', MOZCENTRAL_CONTENT_DIR + '/web/cmaps');
cp(FIREFOX_CONTENT_DIR + 'PdfJsTelemetry.jsm', MOZCENTRAL_CONTENT_DIR);
// Copy extension files
cd('extensions/firefox');
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY,
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR);
mv('-f', ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome-mozcentral.manifest',
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome.manifest');
cd(ROOT_DIR);
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, MOZCENTRAL_CONTENT_DIR + '/web'],
['external/bcmaps/*', MOZCENTRAL_CONTENT_DIR + '/web/cmaps'],
['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'],
[FIREFOX_CONTENT_DIR + 'pdfjschildbootstrap.js', MOZCENTRAL_CONTENT_DIR],
[BUILD_TARGETS, MOZCENTRAL_CONTENT_DIR + BUILD_DIR],
[SRC_DIR + 'core/network.js', MOZCENTRAL_CONTENT_DIR],
[COMMON_FIREFOX_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR],
[FIREFOX_CONTENT_DIR + 'PdfJs.jsm', MOZCENTRAL_CONTENT_DIR]
],
preprocessCSS: [
['mozcentral',
'web/viewer.css',
MOZCENTRAL_CONTENT_DIR + '/web/viewer.css']
]
};
builder.build(setup);
cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/web/viewer.js');
cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/PdfJs.jsm');
cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/PdfjsChromeUtils.jsm');
cleanupCSSSource(MOZCENTRAL_CONTENT_DIR + '/web/viewer.css');
// Remove '.DS_Store' and other hidden files
find(MOZCENTRAL_DIR).forEach(function(file) {
if (file.match(/^\./)) {
rm('-f', file);
}
});
// Remove excluded files
cd(MOZCENTRAL_EXTENSION_DIR);
FIREFOX_MC_EXCLUDED_FILES.forEach(function(file) {
if (test('-f', file)) {
rm('-r', file);
}
});
cd(ROOT_DIR);
// Copy default localization files
cp(DEFAULT_LOCALE_FILES, MOZCENTRAL_L10N_DIR);
// Update the build version number
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
MOZCENTRAL_EXTENSION_DIR + 'README.mozilla');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, MOZCENTRAL_STREAM_CONVERTER_ID,
MOZCENTRAL_CONTENT_DIR + 'PdfStreamConverter.jsm');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER2_ID/, MOZCENTRAL_STREAM_CONVERTER2_ID,
MOZCENTRAL_CONTENT_DIR + 'PdfStreamConverter.jsm');
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, MOZCENTRAL_PREF_PREFIX,
MOZCENTRAL_CONTENT_DIR + 'PdfStreamConverter.jsm');
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'true',
MOZCENTRAL_CONTENT_DIR + 'PdfStreamConverter.jsm');
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, MOZCENTRAL_PREF_PREFIX,
MOZCENTRAL_CONTENT_DIR + 'PdfjsChromeUtils.jsm');
// Copy test files
mkdir('-p', MOZCENTRAL_TEST_DIR);
cp('-Rf', 'test/mozcentral/*', MOZCENTRAL_TEST_DIR);
};
target.b2g = function() {
target.generic();
target.components();