@@ -6,6 +6,7 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
6
6
BUILD_DIR = 'build/' ,
7
7
BUILD_TARGET = BUILD_DIR + 'pdf.js' ,
8
8
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/' ,
9
+ CHROME_BUILD_DIR = BUILD_DIR + '/chrome/' ,
9
10
EXTENSION_SRC_DIR = 'extensions/' ,
10
11
LOCALE_SRC_DIR = 'l10n/' ,
11
12
GH_PAGES_DIR = BUILD_DIR + 'gh-pages/' ,
@@ -107,6 +108,8 @@ target.web = function() {
107
108
cp ( '-R' , GENERIC_DIR + '/*' , GH_PAGES_DIR ) ;
108
109
cp ( FIREFOX_BUILD_DIR + '/*.xpi' , FIREFOX_BUILD_DIR + '/*.rdf' ,
109
110
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/' ) ;
111
+ cp ( CHROME_BUILD_DIR + '/*.crx' , FIREFOX_BUILD_DIR + '/*.rdf' ,
112
+ GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chrome/' ) ;
110
113
cp ( 'web/index.html.template' , GH_PAGES_DIR + '/index.html' ) ;
111
114
112
115
cd ( GH_PAGES_DIR ) ;
@@ -258,6 +261,7 @@ target.pagesrepo = function() {
258
261
mkdir ( '-p' , GH_PAGES_DIR + '/web/images' ) ;
259
262
mkdir ( '-p' , GH_PAGES_DIR + BUILD_DIR ) ;
260
263
mkdir ( '-p' , GH_PAGES_DIR + EXTENSION_SRC_DIR + '/firefox' ) ;
264
+ mkdir ( '-p' , GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chrome' ) ;
261
265
} ;
262
266
263
267
@@ -574,6 +578,70 @@ target.chrome = function() {
574
578
]
575
579
} ;
576
580
builder . build ( setup ) ;
581
+
582
+ // Bundle the files to a Chrome extension file .crx if path to key is set
583
+ var pem = env [ 'PDFJS_CHROME_KEY' ] ;
584
+ if ( ! pem ) {
585
+ return ;
586
+ }
587
+
588
+ echo ( ) ;
589
+ echo ( '### Bundling .crx extension into ' + CHROME_BUILD_DIR ) ;
590
+
591
+ if ( ! test ( '-f' , pem ) ) {
592
+ echo ( 'Incorrect PDFJS_CHROME_KEY path' ) ;
593
+ exit ( 1 ) ;
594
+ }
595
+
596
+ var browserManifest = env [ 'PDF_BROWSERS' ] ||
597
+ 'test/resources/browser_manifests/browser_manifest.json' ;
598
+
599
+ if ( ! test ( '-f' , browserManifest ) ) {
600
+ echo ( 'Browser manifest file ' + browserManifest + ' does not exist.' ) ;
601
+ echo ( 'Try copying one of the examples in test/resources/browser_manifests' ) ;
602
+ exit ( 1 ) ;
603
+ }
604
+
605
+ try {
606
+ var manifest = JSON . parse ( cat ( browserManifest ) ) ;
607
+ } catch ( e ) {
608
+ echo ( 'Malformed browser manifest file' ) ;
609
+ echo ( e . message ) ;
610
+ exit ( 1 ) ;
611
+ }
612
+
613
+ var executable ;
614
+ manifest . forEach ( function ( browser ) {
615
+ if ( browser . name === 'chrome' ) {
616
+ executable = browser . path ;
617
+ }
618
+ } ) ;
619
+
620
+ // If there was no chrome entry in the browser manifest, exit
621
+ if ( ! executable ) {
622
+ echo ( 'There was no \'chrome\' entry in the browser manifest' ) ;
623
+ exit ( 1 ) ;
624
+ }
625
+
626
+ // If we're on a Darwin (Mac) OS, then let's check for an .app path
627
+ if ( process . platform === 'darwin' && executable . indexOf ( '.app' ) !== - 1 ) {
628
+ executable = executable + '/Contents/MacOS/Google Chrome' ) ;
629
+ }
630
+
631
+ // If the chrome executable doesn't exist
632
+ if ( ! test ( '-f' , executable ) ) {
633
+ echo ( 'Incorrect executable path to chrome' ) ;
634
+ exit ( 1 ) ;
635
+ }
636
+
637
+ // Let chrome pack the extension for us
638
+ exec ( '"' + executable + '"' +
639
+ ' --no-message-box' +
640
+ ' "--pack-extension=' + ROOT_DIR + CHROME_BUILD_DIR + '"' +
641
+ ' "--pack-extension-key=' + pem + '"' ) ;
642
+
643
+ // Rename to pdf.js.crx
644
+ mv ( BUILD_DIR + 'chrome.crx' , CHROME_BUILD_DIR + 'pdf.js.crx' ) ;
577
645
} ;
578
646
579
647
0 commit comments