@@ -7,6 +7,7 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
7
7
BUILD_DIR = 'build/' ,
8
8
BUILD_TARGET = BUILD_DIR + 'pdf.js' ,
9
9
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/' ,
10
+ CHROME_BUILD_DIR = BUILD_DIR + '/chrome/' ,
10
11
EXTENSION_SRC_DIR = 'extensions/' ,
11
12
LOCALE_SRC_DIR = 'l10n/' ,
12
13
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 ) ;
@@ -256,6 +259,7 @@ target.pagesrepo = function() {
256
259
mkdir ( '-p' , GH_PAGES_DIR + '/web/images' ) ;
257
260
mkdir ( '-p' , GH_PAGES_DIR + BUILD_DIR ) ;
258
261
mkdir ( '-p' , GH_PAGES_DIR + EXTENSION_SRC_DIR + '/firefox' ) ;
262
+ mkdir ( '-p' , GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chrome' ) ;
259
263
} ;
260
264
261
265
@@ -556,6 +560,70 @@ target.chrome = function() {
556
560
]
557
561
} ;
558
562
builder . build ( setup ) ;
563
+
564
+ // Bundle the files to a Chrome extension file .crx if path to key is set
565
+ var pem = env [ 'PDFJS_CHROME_KEY' ] ;
566
+ if ( ! pem ) {
567
+ return ;
568
+ }
569
+
570
+ echo ( ) ;
571
+ echo ( '### Bundling .crx extension into ' + CHROME_BUILD_DIR ) ;
572
+
573
+ if ( ! test ( '-f' , pem ) ) {
574
+ echo ( 'Incorrect PDFJS_CHROME_KEY path' ) ;
575
+ exit ( 1 ) ;
576
+ }
577
+
578
+ var browserManifest = env [ 'PDF_BROWSERS' ] ||
579
+ 'test/resources/browser_manifests/browser_manifest.json' ;
580
+
581
+ if ( ! test ( '-f' , browserManifest ) ) {
582
+ echo ( 'Browser manifest file ' + browserManifest + ' does not exist.' ) ;
583
+ echo ( 'Try copying one of the examples in test/resources/browser_manifests' ) ;
584
+ exit ( 1 ) ;
585
+ }
586
+
587
+ try {
588
+ var manifest = JSON . parse ( cat ( browserManifest ) ) ;
589
+ } catch ( e ) {
590
+ echo ( 'Malformed browser manifest file' ) ;
591
+ echo ( e . message ) ;
592
+ exit ( 1 ) ;
593
+ }
594
+
595
+ var executable ;
596
+ manifest . forEach ( function ( browser ) {
597
+ if ( browser . name === 'chrome' ) {
598
+ executable = browser . path ;
599
+ }
600
+ } ) ;
601
+
602
+ // If there was no chrome entry in the browser manifest, exit
603
+ if ( ! executable ) {
604
+ echo ( 'There was no \'chrome\' entry in the browser manifest' ) ;
605
+ exit ( 1 ) ;
606
+ }
607
+
608
+ // If we're on a Darwin (Mac) OS, then let's check for an .app path
609
+ if ( process . platform === 'darwin' && executable . indexOf ( '.app' ) !== - 1 ) {
610
+ executable = path . join ( executable , 'Contents' , 'MacOS' , 'Google Chrome' ) ;
611
+ }
612
+
613
+ // If the chrome executable doesn't exist
614
+ if ( ! test ( '-f' , executable ) ) {
615
+ echo ( 'Incorrect executable path to chrome' ) ;
616
+ exit ( 1 ) ;
617
+ }
618
+
619
+ // Let chrome pack the extension for us
620
+ exec ( '"' + executable + '"' +
621
+ ' --no-message-box' +
622
+ ' "--pack-extension=' + ROOT_DIR + CHROME_BUILD_DIR + '"' +
623
+ ' "--pack-extension-key=' + pem + '"' ) ;
624
+
625
+ // Rename to pdf.js.crx
626
+ mv ( BUILD_DIR + 'chrome.crx' , CHROME_BUILD_DIR + 'pdf.js.crx' ) ;
559
627
} ;
560
628
561
629
0 commit comments