Skip to content

Commit a98787e

Browse files
committed
Merge pull request mozilla#1825 from saebekassebil/crxbuild
Add support for building .crx file
2 parents d9e2367 + 1548676 commit a98787e

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

make.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
66
BUILD_DIR = 'build/',
77
BUILD_TARGET = BUILD_DIR + 'pdf.js',
88
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/',
9+
CHROME_BUILD_DIR = BUILD_DIR + '/chrome/',
910
EXTENSION_SRC_DIR = 'extensions/',
1011
LOCALE_SRC_DIR = 'l10n/',
1112
GH_PAGES_DIR = BUILD_DIR + 'gh-pages/',
@@ -107,6 +108,8 @@ target.web = function() {
107108
cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR);
108109
cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf',
109110
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/');
110113
cp('web/index.html.template', GH_PAGES_DIR + '/index.html');
111114

112115
cd(GH_PAGES_DIR);
@@ -258,6 +261,7 @@ target.pagesrepo = function() {
258261
mkdir('-p', GH_PAGES_DIR + '/web/images');
259262
mkdir('-p', GH_PAGES_DIR + BUILD_DIR);
260263
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/firefox');
264+
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chrome');
261265
};
262266

263267

@@ -574,6 +578,70 @@ target.chrome = function() {
574578
]
575579
};
576580
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');
577645
};
578646

579647

0 commit comments

Comments
 (0)