2013-02-03 07:49:19 +09:00
|
|
|
/* 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.
|
|
|
|
*/
|
Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.*
ESLint has a number of advantageous properties, compared to JSHint. Among those are:
- The ability to find subtle bugs, thanks to more rules (e.g. PR 7881).
- Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint.
- Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary).
- The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage.
- More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead.
By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want.
Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much.
I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations.
Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%).
A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible:
- `comma-dangle`, controls trailing commas in Objects and Arrays (among others).
- `object-curly-spacing`, controls spacing inside of Objects.
- `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.)
Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed.
Useful links:
- http://eslint.org/docs/user-guide/configuring
- http://eslint.org/docs/rules/
2016-12-15 23:52:29 +09:00
|
|
|
/* eslint-env node, shelljs */
|
2012-08-31 20:51:25 +09:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-04-05 02:24:06 +09:00
|
|
|
try {
|
|
|
|
require('shelljs/make');
|
|
|
|
} catch (e) {
|
|
|
|
console.log('ShellJS is not installed. Run "npm install" to install ' +
|
|
|
|
'all dependencies.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-02 06:27:42 +09:00
|
|
|
var builder = require('./external/builder/builder.js');
|
2014-04-11 02:01:51 +09:00
|
|
|
var fs = require('fs');
|
|
|
|
|
|
|
|
var CONFIG_FILE = 'pdfjs.config';
|
|
|
|
var config = JSON.parse(fs.readFileSync(CONFIG_FILE));
|
|
|
|
|
2012-03-05 11:26:57 +09:00
|
|
|
var ROOT_DIR = __dirname + '/', // absolute path to project's root
|
2012-03-04 04:01:31 +09:00
|
|
|
BUILD_DIR = 'build/',
|
2013-02-07 08:19:29 +09:00
|
|
|
SRC_DIR = 'src/',
|
2012-03-05 11:26:57 +09:00
|
|
|
BUILD_TARGET = BUILD_DIR + 'pdf.js',
|
2013-08-13 02:48:06 +09:00
|
|
|
BUILD_WORKER_TARGET = BUILD_DIR + 'pdf.worker.js',
|
|
|
|
BUILD_TARGETS = [BUILD_TARGET, BUILD_WORKER_TARGET],
|
2012-03-05 11:26:57 +09:00
|
|
|
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/',
|
2013-08-22 01:54:59 +09:00
|
|
|
CHROME_BUILD_DIR = BUILD_DIR + '/chromium/',
|
2014-04-14 05:54:24 +09:00
|
|
|
JSDOC_DIR = BUILD_DIR + 'jsdoc',
|
2012-03-04 04:01:31 +09:00
|
|
|
EXTENSION_SRC_DIR = 'extensions/',
|
2014-09-18 06:14:04 +09:00
|
|
|
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/',
|
2012-05-12 04:39:11 +09:00
|
|
|
LOCALE_SRC_DIR = 'l10n/',
|
2012-03-05 11:26:57 +09:00
|
|
|
GH_PAGES_DIR = BUILD_DIR + 'gh-pages/',
|
2012-08-02 03:29:13 +09:00
|
|
|
GENERIC_DIR = BUILD_DIR + 'generic/',
|
2014-01-18 01:50:54 +09:00
|
|
|
MINIFIED_DIR = BUILD_DIR + 'minified/',
|
2016-11-24 01:31:46 +09:00
|
|
|
DIST_DIR = BUILD_DIR + 'dist/',
|
2014-10-01 02:22:38 +09:00
|
|
|
SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/',
|
|
|
|
COMPONENTS_DIR = BUILD_DIR + 'components/',
|
2012-03-04 04:01:31 +09:00
|
|
|
REPO = 'git@github.com:mozilla/pdf.js.git',
|
2012-05-24 07:57:14 +09:00
|
|
|
MOZCENTRAL_PREF_PREFIX = 'pdfjs',
|
|
|
|
FIREFOX_PREF_PREFIX = 'extensions.uriloader@pdf.js',
|
|
|
|
MOZCENTRAL_STREAM_CONVERTER_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2291',
|
2015-07-03 02:59:17 +09:00
|
|
|
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';
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2012-08-02 03:29:13 +09:00
|
|
|
var DEFINES = {
|
|
|
|
PRODUCTION: true,
|
|
|
|
// The main build targets:
|
|
|
|
GENERIC: false,
|
|
|
|
FIREFOX: false,
|
|
|
|
MOZCENTRAL: false,
|
2013-12-20 00:18:47 +09:00
|
|
|
CHROME: false,
|
2014-01-18 01:50:54 +09:00
|
|
|
MINIFIED: false,
|
2014-10-01 02:22:38 +09:00
|
|
|
SINGLE_FILE: false,
|
|
|
|
COMPONENTS: false
|
2012-08-02 03:29:13 +09:00
|
|
|
};
|
|
|
|
|
2016-04-23 07:20:47 +09:00
|
|
|
function getCurrentVersion() {
|
|
|
|
// The 'build/version.json' file is created by 'buildnumber' task.
|
|
|
|
return JSON.parse(fs.readFileSync(ROOT_DIR + 'build/version.json').toString())
|
|
|
|
.version;
|
|
|
|
}
|
|
|
|
|
2016-10-17 22:47:05 +09:00
|
|
|
function execGulp(cmd) {
|
|
|
|
var result = exec('gulp ' + cmd);
|
|
|
|
if (result.code) {
|
|
|
|
echo('ERROR: gulp exited with ' + result.code);
|
|
|
|
exit(result.code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
// make all
|
|
|
|
//
|
2012-03-05 11:26:57 +09:00
|
|
|
target.all = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('default');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
|
2013-02-03 07:49:19 +09:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
// Production stuff
|
|
|
|
//
|
|
|
|
|
2012-08-02 03:29:13 +09:00
|
|
|
// Files that need to be included in every build.
|
2012-08-02 04:05:03 +09:00
|
|
|
var COMMON_WEB_FILES =
|
2013-07-10 07:14:21 +09:00
|
|
|
['web/images',
|
2012-08-02 03:29:13 +09:00
|
|
|
'web/debugger.js'],
|
|
|
|
COMMON_WEB_FILES_PREPROCESS =
|
2016-04-09 02:34:27 +09:00
|
|
|
['web/viewer.html'],
|
2014-09-18 06:14:04 +09:00
|
|
|
COMMON_FIREFOX_FILES_PREPROCESS =
|
|
|
|
[FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm',
|
2016-10-15 00:57:53 +09:00
|
|
|
FIREFOX_CONTENT_DIR + 'PdfJsNetwork.jsm',
|
2014-09-18 06:14:04 +09:00
|
|
|
FIREFOX_CONTENT_DIR + 'PdfjsContentUtils.jsm',
|
2015-08-07 00:38:45 +09:00
|
|
|
FIREFOX_CONTENT_DIR + 'PdfjsChromeUtils.jsm'];
|
2012-08-02 03:29:13 +09:00
|
|
|
//
|
|
|
|
// make generic
|
|
|
|
// Builds the generic production viewer that should be compatible with most
|
|
|
|
// modern HTML5 browsers.
|
|
|
|
//
|
|
|
|
target.generic = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bundle-generic');
|
2016-04-23 07:20:47 +09:00
|
|
|
|
2012-08-02 03:29:13 +09:00
|
|
|
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');
|
2014-03-18 03:20:24 +09:00
|
|
|
mkdir('-p', GENERIC_DIR + '/web/cmaps');
|
2012-08-02 03:29:13 +09:00
|
|
|
|
2012-08-02 06:27:42 +09:00
|
|
|
var defines = builder.merge(DEFINES, {GENERIC: true});
|
2012-08-02 03:29:13 +09:00
|
|
|
|
|
|
|
var setup = {
|
|
|
|
defines: defines,
|
|
|
|
copy: [
|
2016-04-23 07:20:47 +09:00
|
|
|
[BUILD_TARGETS, GENERIC_DIR + BUILD_DIR],
|
|
|
|
[BUILD_DIR + 'viewer.js', GENERIC_DIR + '/web'],
|
2012-08-02 03:29:13 +09:00
|
|
|
[COMMON_WEB_FILES, GENERIC_DIR + '/web'],
|
2014-04-11 02:01:51 +09:00
|
|
|
['LICENSE', GENERIC_DIR],
|
2012-08-02 03:29:13 +09:00
|
|
|
['external/webL10n/l10n.js', GENERIC_DIR + '/web'],
|
|
|
|
['web/compatibility.js', GENERIC_DIR + '/web'],
|
|
|
|
['web/compressed.tracemonkey-pldi-09.pdf', GENERIC_DIR + '/web'],
|
2014-03-18 03:20:24 +09:00
|
|
|
['external/bcmaps/*', GENERIC_DIR + '/web/cmaps/'],
|
2012-11-30 05:02:33 +09:00
|
|
|
['web/locale', GENERIC_DIR + '/web']
|
2012-08-02 03:29:13 +09:00
|
|
|
],
|
|
|
|
preprocess: [
|
|
|
|
[COMMON_WEB_FILES_PREPROCESS, GENERIC_DIR + '/web']
|
2014-09-11 01:10:04 +09:00
|
|
|
],
|
|
|
|
preprocessCSS: [
|
|
|
|
['generic', 'web/viewer.css',
|
|
|
|
GENERIC_DIR + '/web/viewer.css']
|
2012-08-02 03:29:13 +09:00
|
|
|
]
|
|
|
|
};
|
2012-08-02 06:27:42 +09:00
|
|
|
builder.build(setup);
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2015-12-22 04:46:50 +09:00
|
|
|
cleanupJSSource(GENERIC_DIR + '/build/pdf.js');
|
2013-06-19 01:05:55 +09:00
|
|
|
cleanupJSSource(GENERIC_DIR + '/web/viewer.js');
|
2014-09-11 01:10:04 +09:00
|
|
|
cleanupCSSSource(GENERIC_DIR + '/web/viewer.css');
|
2012-08-02 03:29:13 +09:00
|
|
|
};
|
|
|
|
|
2014-10-01 02:22:38 +09:00
|
|
|
target.components = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bundle-components');
|
2016-04-23 07:20:47 +09:00
|
|
|
|
2014-10-01 02:22:38 +09:00
|
|
|
cd(ROOT_DIR);
|
|
|
|
echo();
|
|
|
|
echo('### Creating generic components');
|
|
|
|
|
|
|
|
rm('-rf', COMPONENTS_DIR);
|
|
|
|
mkdir('-p', COMPONENTS_DIR);
|
|
|
|
mkdir('-p', COMPONENTS_DIR + 'images');
|
|
|
|
|
2016-04-09 02:34:27 +09:00
|
|
|
var defines = builder.merge(DEFINES, {COMPONENTS: true, GENERIC: true});
|
|
|
|
|
2014-10-01 02:22:38 +09:00
|
|
|
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: [
|
2016-04-23 07:20:47 +09:00
|
|
|
[BUILD_DIR + 'pdf_viewer.js', COMPONENTS_DIR],
|
2014-10-01 02:22:38 +09:00
|
|
|
[COMPONENTS_IMAGES, COMPONENTS_DIR + 'images'],
|
|
|
|
['web/compatibility.js', COMPONENTS_DIR],
|
|
|
|
],
|
2016-04-23 07:20:47 +09:00
|
|
|
preprocess: [],
|
2014-10-01 02:22:38 +09:00
|
|
|
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');
|
|
|
|
};
|
|
|
|
|
2014-04-14 05:54:24 +09:00
|
|
|
target.jsdoc = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('jsdoc');
|
2014-04-14 05:54:24 +09:00
|
|
|
};
|
|
|
|
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
// make web
|
2012-08-23 03:34:34 +09:00
|
|
|
// 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.
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
target.web = function() {
|
2012-08-02 03:29:13 +09:00
|
|
|
target.generic();
|
2012-03-04 04:01:31 +09:00
|
|
|
target.extension();
|
2014-04-14 05:54:24 +09:00
|
|
|
target.jsdoc();
|
2012-03-05 11:26:57 +09:00
|
|
|
|
2016-10-17 22:47:05 +09:00
|
|
|
cd(ROOT_DIR);
|
2012-03-04 04:01:31 +09:00
|
|
|
echo();
|
|
|
|
echo('### Creating web site');
|
|
|
|
|
2014-03-15 00:18:08 +09:00
|
|
|
if (test('-d', GH_PAGES_DIR)) {
|
2012-09-13 01:10:30 +09:00
|
|
|
rm('-rf', GH_PAGES_DIR);
|
2014-03-15 00:18:08 +09:00
|
|
|
}
|
2012-09-13 01:10:30 +09:00
|
|
|
|
|
|
|
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');
|
2013-08-22 05:27:13 +09:00
|
|
|
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chromium');
|
2014-04-14 05:54:24 +09:00
|
|
|
mkdir('-p', GH_PAGES_DIR + '/api/draft/');
|
2014-09-16 23:24:48 +09:00
|
|
|
mkdir('-p', GH_PAGES_DIR + '/examples/');
|
2012-09-13 01:10:30 +09:00
|
|
|
|
2012-08-02 03:29:13 +09:00
|
|
|
cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR);
|
2012-03-05 11:26:57 +09:00
|
|
|
cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf',
|
2012-08-02 03:29:13 +09:00
|
|
|
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/');
|
2012-08-23 06:16:29 +09:00
|
|
|
cp(CHROME_BUILD_DIR + '/*.crx', FIREFOX_BUILD_DIR + '/*.rdf',
|
2013-08-22 01:54:59 +09:00
|
|
|
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chromium/');
|
2012-12-03 06:47:41 +09:00
|
|
|
cp('-R', 'test/features', GH_PAGES_DIR);
|
2014-09-16 23:24:48 +09:00
|
|
|
cp('-R', 'examples/learning', GH_PAGES_DIR + '/examples/');
|
2014-04-14 05:54:24 +09:00
|
|
|
cp('-R', JSDOC_DIR + '/*', GH_PAGES_DIR + '/api/draft/');
|
2012-08-02 03:29:13 +09:00
|
|
|
|
2014-04-11 09:42:48 +09:00
|
|
|
var wintersmith = require('wintersmith');
|
2014-04-11 02:01:51 +09:00
|
|
|
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.');
|
|
|
|
|
2016-04-23 07:20:47 +09:00
|
|
|
var VERSION = getCurrentVersion();
|
2015-10-24 00:56:40 +09:00
|
|
|
var reason = process.env['PDFJS_UPDATE_REASON'];
|
2014-04-11 02:01:51 +09:00
|
|
|
cd(GH_PAGES_DIR);
|
|
|
|
exec('git init');
|
|
|
|
exec('git remote add origin ' + REPO);
|
|
|
|
exec('git add -A');
|
2015-10-24 00:56:40 +09:00
|
|
|
exec('git commit -am "gh-pages site created via make.js script" -m ' +
|
|
|
|
'"PDF.js version ' + VERSION + (reason ? ' - ' + reason : '') + '"');
|
2014-04-11 02:01:51 +09:00
|
|
|
exec('git branch -m gh-pages');
|
|
|
|
|
|
|
|
echo();
|
|
|
|
echo('Website built in ' + GH_PAGES_DIR);
|
|
|
|
});
|
|
|
|
};
|
2012-03-05 11:26:57 +09:00
|
|
|
|
2014-04-11 02:01:51 +09:00
|
|
|
target.dist = function() {
|
2014-09-23 08:06:34 +09:00
|
|
|
target.generic();
|
|
|
|
target.singlefile();
|
2014-10-01 02:22:38 +09:00
|
|
|
target.components();
|
2016-11-24 01:31:46 +09:00
|
|
|
target.minified();
|
2014-09-23 08:06:34 +09:00
|
|
|
|
|
|
|
var DIST_REPO_URL = 'https://github.com/mozilla/pdfjs-dist';
|
2016-04-23 07:20:47 +09:00
|
|
|
var VERSION = getCurrentVersion();
|
2014-09-23 08:06:34 +09:00
|
|
|
|
|
|
|
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 + '*');
|
|
|
|
|
2014-09-24 21:10:09 +09:00
|
|
|
cp('-R', ROOT_DIR + 'external/dist/*', DIST_DIR);
|
2014-09-23 08:06:34 +09:00
|
|
|
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',
|
2016-04-13 22:24:25 +09:00
|
|
|
SRC_DIR + 'pdf.worker.entry.js',
|
2014-09-23 08:06:34 +09:00
|
|
|
], DIST_DIR + 'build/');
|
2016-11-24 01:31:46 +09:00
|
|
|
cp(MINIFIED_DIR + 'build/pdf.js', DIST_DIR + 'build/pdf.min.js');
|
|
|
|
cp(MINIFIED_DIR + 'build/pdf.worker.js',
|
|
|
|
DIST_DIR + 'build/pdf.worker.min.js');
|
2014-09-23 08:06:34 +09:00
|
|
|
|
|
|
|
mkdir('-p', DIST_DIR + 'web/');
|
|
|
|
cp('-R', [
|
2014-10-01 02:22:38 +09:00
|
|
|
COMPONENTS_DIR + '*',
|
2014-09-23 08:06:34 +09:00
|
|
|
], 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,
|
2015-12-22 04:46:50 +09:00
|
|
|
main: 'build/pdf.js',
|
2014-09-23 08:06:34 +09:00
|
|
|
description: DIST_DESCRIPTION,
|
|
|
|
keywords: DIST_KEYWORDS,
|
|
|
|
homepage: DIST_HOMEPAGE,
|
|
|
|
bugs: DIST_BUGS_URL,
|
|
|
|
license: DIST_LICENSE,
|
2016-04-13 22:24:25 +09:00
|
|
|
dependencies: {
|
|
|
|
'node-ensure': '^0.0.0' // shim for node for require.ensure
|
|
|
|
},
|
|
|
|
browser: {
|
2016-04-05 01:32:01 +09:00
|
|
|
'node-ensure': false
|
|
|
|
},
|
2016-04-08 01:52:56 +09:00
|
|
|
format: 'amd', // to not allow system.js to choose 'cjs'
|
2014-09-23 08:06:34 +09:00
|
|
|
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();
|
2016-07-17 21:33:41 +09:00
|
|
|
echo('### Committing changes');
|
2014-09-23 08:06:34 +09:00
|
|
|
|
|
|
|
cd(DIST_DIR);
|
2015-10-24 00:56:40 +09:00
|
|
|
var reason = process.env['PDFJS_UPDATE_REASON'];
|
|
|
|
var message = 'PDF.js version ' + VERSION + (reason ? ' - ' + reason : '');
|
2014-09-23 08:06:34 +09:00
|
|
|
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() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('publish');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2012-05-02 22:51:52 +09:00
|
|
|
//
|
|
|
|
// make locale
|
|
|
|
// Creates localized resources for the viewer and extension.
|
|
|
|
//
|
|
|
|
target.locale = function() {
|
|
|
|
var METADATA_OUTPUT = 'extensions/firefox/metadata.inc';
|
2012-05-12 04:39:11 +09:00
|
|
|
var CHROME_MANIFEST_OUTPUT = 'extensions/firefox/chrome.manifest.inc';
|
|
|
|
var EXTENSION_LOCALE_OUTPUT = 'extensions/firefox/locale';
|
2012-11-30 05:02:33 +09:00
|
|
|
var VIEWER_LOCALE_OUTPUT = 'web/locale/';
|
2012-05-02 22:51:52 +09:00
|
|
|
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
echo();
|
|
|
|
echo('### Building localization files');
|
|
|
|
|
2012-05-12 04:39:11 +09:00
|
|
|
rm('-rf', EXTENSION_LOCALE_OUTPUT);
|
|
|
|
mkdir('-p', EXTENSION_LOCALE_OUTPUT);
|
2012-11-30 05:02:33 +09:00
|
|
|
rm('-rf', VIEWER_LOCALE_OUTPUT);
|
|
|
|
mkdir('-p', VIEWER_LOCALE_OUTPUT);
|
2012-05-12 04:39:11 +09:00
|
|
|
|
|
|
|
var subfolders = ls(LOCALE_SRC_DIR);
|
2012-05-02 22:51:52 +09:00
|
|
|
subfolders.sort();
|
|
|
|
var metadataContent = '';
|
2012-05-12 04:39:11 +09:00
|
|
|
var chromeManifestContent = '';
|
2012-05-02 22:51:52 +09:00
|
|
|
var viewerOutput = '';
|
|
|
|
for (var i = 0; i < subfolders.length; i++) {
|
|
|
|
var locale = subfolders[i];
|
2012-05-12 04:39:11 +09:00
|
|
|
var path = LOCALE_SRC_DIR + locale;
|
2014-03-15 00:18:08 +09:00
|
|
|
if (!test('-d', path)) {
|
2012-05-02 22:51:52 +09:00
|
|
|
continue;
|
2014-03-15 00:18:08 +09:00
|
|
|
}
|
2014-03-23 00:40:59 +09:00
|
|
|
if (!/^[a-z][a-z]([a-z])?(-[A-Z][A-Z])?$/.test(locale)) {
|
2012-05-02 22:51:52 +09:00
|
|
|
echo('Skipping invalid locale: ' + locale);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-05-12 04:39:11 +09:00
|
|
|
mkdir('-p', EXTENSION_LOCALE_OUTPUT + '/' + locale);
|
2012-11-30 05:02:33 +09:00
|
|
|
mkdir('-p', VIEWER_LOCALE_OUTPUT + '/' + locale);
|
2012-08-23 03:34:34 +09:00
|
|
|
chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' +
|
|
|
|
locale + '/\n';
|
2012-05-12 04:39:11 +09:00
|
|
|
|
2012-05-02 22:51:52 +09:00
|
|
|
if (test('-f', path + '/viewer.properties')) {
|
2012-11-30 05:02:33 +09:00
|
|
|
viewerOutput += '[' + locale + ']\n' +
|
|
|
|
'@import url(' + locale + '/viewer.properties)\n\n';
|
2012-05-12 04:39:11 +09:00
|
|
|
cp(path + '/viewer.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale);
|
2012-11-30 05:02:33 +09:00
|
|
|
cp(path + '/viewer.properties', VIEWER_LOCALE_OUTPUT + '/' + locale);
|
2012-05-02 22:51:52 +09:00
|
|
|
}
|
|
|
|
|
2012-05-16 02:33:01 +09:00
|
|
|
if (test('-f', path + '/chrome.properties')) {
|
|
|
|
cp(path + '/chrome.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale);
|
2012-05-02 22:51:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (test('-f', path + '/metadata.inc')) {
|
|
|
|
var metadata = cat(path + '/metadata.inc');
|
|
|
|
metadataContent += metadata;
|
|
|
|
}
|
|
|
|
}
|
2012-11-30 05:02:33 +09:00
|
|
|
viewerOutput.to(VIEWER_LOCALE_OUTPUT + 'locale.properties');
|
2012-05-02 22:51:52 +09:00
|
|
|
metadataContent.to(METADATA_OUTPUT);
|
2012-05-12 04:39:11 +09:00
|
|
|
chromeManifestContent.to(CHROME_MANIFEST_OUTPUT);
|
2012-05-02 22:51:52 +09:00
|
|
|
};
|
|
|
|
|
2014-03-15 03:22:02 +09:00
|
|
|
//
|
|
|
|
// make cmaps
|
2014-03-18 03:20:24 +09:00
|
|
|
// Compresses cmap files. Ensure that Adobe cmap download and uncompressed at
|
|
|
|
// ./external/cmaps location.
|
2014-03-15 03:22:02 +09:00
|
|
|
//
|
2015-12-17 06:31:30 +09:00
|
|
|
target.cmaps = function () {
|
2014-03-15 03:22:02 +09:00
|
|
|
var CMAP_INPUT = 'external/cmaps';
|
2014-03-18 03:20:24 +09:00
|
|
|
var VIEWER_CMAP_OUTPUT = 'external/bcmaps';
|
|
|
|
|
2014-03-15 03:22:02 +09:00
|
|
|
cd(ROOT_DIR);
|
|
|
|
echo();
|
|
|
|
echo('### Building cmaps');
|
|
|
|
|
2014-03-18 03:20:24 +09:00
|
|
|
// 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:');
|
2015-06-30 16:33:25 +09:00
|
|
|
echo(' https://github.com/adobe-type-tools/cmap-resources');
|
2014-03-18 03:20:24 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rm(VIEWER_CMAP_OUTPUT + '*.bcmap');
|
2014-03-15 03:22:02 +09:00
|
|
|
|
|
|
|
var compressCmaps =
|
|
|
|
require('./external/cmapscompress/compress.js').compressCmaps;
|
|
|
|
compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true);
|
|
|
|
};
|
|
|
|
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
// make bundle
|
|
|
|
// Bundles all source files into one wrapper 'pdf.js' file, in the given order.
|
|
|
|
//
|
2013-02-07 08:19:29 +09:00
|
|
|
target.bundle = function(args) {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bundle');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2013-12-20 00:18:47 +09:00
|
|
|
//
|
|
|
|
// 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');
|
|
|
|
|
2016-04-23 07:20:47 +09:00
|
|
|
var SINGLE_FILE_BUILD_DIR = SINGLE_FILE_DIR + 'build/';
|
2013-12-20 00:18:47 +09:00
|
|
|
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bundle-singlefile');
|
2013-12-20 00:18:47 +09:00
|
|
|
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
|
|
|
rm('-rf', SINGLE_FILE_DIR);
|
|
|
|
mkdir('-p', SINGLE_FILE_DIR);
|
2016-04-23 07:20:47 +09:00
|
|
|
mkdir('-p', SINGLE_FILE_BUILD_DIR);
|
2013-12-20 00:18:47 +09:00
|
|
|
|
2016-04-23 07:20:47 +09:00
|
|
|
cp(BUILD_DIR + 'pdf.combined.js', SINGLE_FILE_BUILD_DIR);
|
2013-12-20 00:18:47 +09:00
|
|
|
};
|
|
|
|
|
2015-12-17 06:31:30 +09:00
|
|
|
function stripCommentHeaders(content) {
|
2015-07-09 06:49:14 +09:00
|
|
|
var notEndOfComment = '(?:[^*]|\\*(?!/))+';
|
|
|
|
var reg = new RegExp(
|
2015-11-22 02:45:06 +09:00
|
|
|
'\n/\\* Copyright' + notEndOfComment + '\\*/\\s*' +
|
|
|
|
'(?:/\\*' + notEndOfComment + '\\*/\\s*|//(?!#).*\n\\s*)*' +
|
|
|
|
'\\s*\'use strict\';', 'g');
|
2015-07-09 06:49:14 +09:00
|
|
|
content = content.replace(reg, '');
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2013-06-19 01:05:55 +09:00
|
|
|
function cleanupJSSource(file) {
|
|
|
|
var content = cat(file);
|
|
|
|
|
2015-12-17 06:31:30 +09:00
|
|
|
content = stripCommentHeaders(content);
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2013-06-19 01:05:55 +09:00
|
|
|
content.to(file);
|
|
|
|
}
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2014-09-11 01:10:04 +09:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-01-18 01:50:54 +09:00
|
|
|
//
|
|
|
|
// make minified
|
|
|
|
// Builds the minified production viewer that should be compatible with most
|
2015-07-01 13:47:15 +09:00
|
|
|
// modern HTML5 browsers.
|
2014-01-18 01:50:54 +09:00
|
|
|
//
|
|
|
|
target.minified = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bundle-minified');
|
2014-01-18 01:50:54 +09:00
|
|
|
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');
|
2014-03-18 03:20:24 +09:00
|
|
|
mkdir('-p', MINIFIED_DIR + '/web/cmaps');
|
2014-01-18 01:50:54 +09:00
|
|
|
|
|
|
|
var defines = builder.merge(DEFINES, {GENERIC: true, MINIFIED: true});
|
|
|
|
|
|
|
|
var setup = {
|
|
|
|
defines: defines,
|
|
|
|
copy: [
|
2016-04-23 07:20:47 +09:00
|
|
|
[BUILD_TARGETS, MINIFIED_DIR + BUILD_DIR],
|
|
|
|
[BUILD_DIR + 'viewer.js', MINIFIED_DIR + '/web'],
|
2014-01-18 01:50:54 +09:00
|
|
|
[COMMON_WEB_FILES, MINIFIED_DIR + '/web'],
|
|
|
|
['web/compressed.tracemonkey-pldi-09.pdf', MINIFIED_DIR + '/web'],
|
2014-03-18 03:20:24 +09:00
|
|
|
['external/bcmaps/*', MINIFIED_DIR + '/web/cmaps'],
|
2014-01-18 01:50:54 +09:00
|
|
|
['web/locale', MINIFIED_DIR + '/web']
|
|
|
|
],
|
|
|
|
preprocess: [
|
|
|
|
[COMMON_WEB_FILES_PREPROCESS, MINIFIED_DIR + '/web']
|
2014-09-11 01:10:04 +09:00
|
|
|
],
|
|
|
|
preprocessCSS: [
|
|
|
|
['minified', 'web/viewer.css',
|
|
|
|
MINIFIED_DIR + '/web/viewer.css']
|
2014-01-18 01:50:54 +09:00
|
|
|
]
|
|
|
|
};
|
|
|
|
builder.build(setup);
|
|
|
|
|
2014-09-11 01:10:04 +09:00
|
|
|
cleanupCSSSource(MINIFIED_DIR + '/web/viewer.css');
|
|
|
|
|
2014-01-18 01:50:54 +09:00
|
|
|
var viewerFiles = [
|
|
|
|
'web/compatibility.js',
|
|
|
|
'external/webL10n/l10n.js',
|
|
|
|
MINIFIED_DIR + BUILD_DIR + 'pdf.js',
|
|
|
|
MINIFIED_DIR + '/web/viewer.js'
|
|
|
|
];
|
|
|
|
|
|
|
|
echo();
|
|
|
|
echo('### Minifying js files');
|
|
|
|
|
2015-07-01 13:47:15 +09:00
|
|
|
var UglifyJS = require('uglify-js');
|
|
|
|
// V8 chokes on very long sequences. Works around that.
|
|
|
|
var optsForHugeFile = {compress: {sequences: false}};
|
|
|
|
|
|
|
|
UglifyJS.minify(viewerFiles).code
|
|
|
|
.to(MINIFIED_DIR + '/web/pdf.viewer.js');
|
|
|
|
UglifyJS.minify(MINIFIED_DIR + '/build/pdf.js').code
|
|
|
|
.to(MINIFIED_DIR + '/build/pdf.min.js');
|
|
|
|
UglifyJS.minify(MINIFIED_DIR + '/build/pdf.worker.js', optsForHugeFile).code
|
|
|
|
.to(MINIFIED_DIR + '/build/pdf.worker.min.js');
|
2014-01-18 01:50:54 +09:00
|
|
|
|
|
|
|
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');
|
|
|
|
};
|
|
|
|
|
2013-02-03 07:49:19 +09:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
// Extension stuff
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// make extension
|
|
|
|
//
|
|
|
|
target.extension = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('extension');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
target.buildnumber = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('buildnumber');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
//
|
|
|
|
// make firefox
|
|
|
|
//
|
|
|
|
target.firefox = function() {
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
echo();
|
|
|
|
echo('### Building Firefox extension');
|
2012-08-02 06:27:42 +09:00
|
|
|
var defines = builder.merge(DEFINES, {FIREFOX: true});
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2012-03-05 11:26:57 +09:00
|
|
|
var FIREFOX_BUILD_CONTENT_DIR = FIREFOX_BUILD_DIR + '/content/',
|
2012-08-02 03:29:13 +09:00
|
|
|
FIREFOX_EXTENSION_DIR = 'extensions/firefox/',
|
2012-03-04 04:01:31 +09:00
|
|
|
FIREFOX_EXTENSION_FILES_TO_COPY =
|
|
|
|
['*.js',
|
|
|
|
'*.rdf',
|
2012-05-09 00:23:55 +09:00
|
|
|
'*.svg',
|
2012-03-21 07:25:02 +09:00
|
|
|
'*.png',
|
2012-05-12 04:39:11 +09:00
|
|
|
'*.manifest',
|
|
|
|
'locale',
|
2014-09-18 06:14:04 +09:00
|
|
|
'chrome',
|
2012-05-09 00:23:55 +09:00
|
|
|
'../../LICENSE'],
|
2012-03-04 04:01:31 +09:00
|
|
|
FIREFOX_EXTENSION_FILES =
|
2012-03-14 10:31:53 +09:00
|
|
|
['bootstrap.js',
|
2012-03-04 04:01:31 +09:00
|
|
|
'install.rdf',
|
2012-05-12 04:39:11 +09:00
|
|
|
'chrome.manifest',
|
2012-03-21 07:25:02 +09:00
|
|
|
'icon.png',
|
|
|
|
'icon64.png',
|
2012-03-14 10:31:53 +09:00
|
|
|
'content',
|
2014-09-18 06:14:04 +09:00
|
|
|
'chrome',
|
2012-05-12 04:39:11 +09:00
|
|
|
'locale',
|
2012-05-09 00:23:55 +09:00
|
|
|
'LICENSE'],
|
2016-08-03 21:44:18 +09:00
|
|
|
FIREFOX_EXTENSION_NAME = 'pdf.js.xpi';
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2012-05-12 08:12:48 +09:00
|
|
|
target.locale();
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bundle-firefox');
|
2012-03-04 04:01:31 +09:00
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
|
|
|
// Clear out everything in the firefox extension build directory
|
|
|
|
rm('-rf', FIREFOX_BUILD_DIR);
|
|
|
|
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR);
|
2012-03-05 11:26:57 +09:00
|
|
|
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR);
|
|
|
|
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + '/web');
|
2014-03-18 03:20:24 +09:00
|
|
|
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + '/web/cmaps');
|
2012-03-05 11:26:57 +09:00
|
|
|
|
2012-08-23 03:34:34 +09:00
|
|
|
cp(FIREFOX_CONTENT_DIR + 'PdfJs-stub.jsm',
|
|
|
|
FIREFOX_BUILD_CONTENT_DIR + 'PdfJs.jsm');
|
2012-08-20 03:07:31 +09:00
|
|
|
|
2013-08-16 23:53:05 +09:00
|
|
|
cp(FIREFOX_CONTENT_DIR + 'PdfJsTelemetry-addon.jsm',
|
|
|
|
FIREFOX_BUILD_CONTENT_DIR + 'PdfJsTelemetry.jsm');
|
|
|
|
|
2012-03-05 11:26:57 +09:00
|
|
|
// Copy extension files
|
2012-09-02 19:05:05 +09:00
|
|
|
cd(FIREFOX_EXTENSION_DIR);
|
2012-03-05 11:26:57 +09:00
|
|
|
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY, ROOT_DIR + FIREFOX_BUILD_DIR);
|
2012-03-04 04:01:31 +09:00
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
2012-08-02 03:29:13 +09:00
|
|
|
var setup = {
|
|
|
|
defines: defines,
|
|
|
|
copy: [
|
2016-04-23 07:20:47 +09:00
|
|
|
[BUILD_TARGETS, FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR],
|
|
|
|
[BUILD_DIR + 'viewer.js', FIREFOX_BUILD_CONTENT_DIR + '/web'],
|
2012-08-02 03:29:13 +09:00
|
|
|
[COMMON_WEB_FILES, FIREFOX_BUILD_CONTENT_DIR + '/web'],
|
2014-03-18 03:20:24 +09:00
|
|
|
['external/bcmaps/*', FIREFOX_BUILD_CONTENT_DIR + '/web/cmaps'],
|
2012-09-02 19:05:05 +09:00
|
|
|
[FIREFOX_EXTENSION_DIR + 'tools/l10n.js',
|
2014-03-22 07:16:03 +09:00
|
|
|
FIREFOX_BUILD_CONTENT_DIR + '/web']
|
2012-08-02 03:29:13 +09:00
|
|
|
],
|
|
|
|
preprocess: [
|
2012-10-30 04:44:18 +09:00
|
|
|
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'],
|
2014-09-18 06:14:04 +09:00
|
|
|
[COMMON_FIREFOX_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR],
|
2014-03-22 07:16:03 +09:00
|
|
|
[SRC_DIR + 'core/network.js', FIREFOX_BUILD_CONTENT_DIR],
|
|
|
|
[FIREFOX_EXTENSION_DIR + 'bootstrap.js', FIREFOX_BUILD_DIR]
|
2013-07-10 07:14:21 +09:00
|
|
|
],
|
|
|
|
preprocessCSS: [
|
|
|
|
['firefox', 'web/viewer.css',
|
|
|
|
FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.css']
|
2012-08-02 03:29:13 +09:00
|
|
|
]
|
|
|
|
};
|
2012-08-02 06:27:42 +09:00
|
|
|
builder.build(setup);
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2013-06-19 01:05:55 +09:00
|
|
|
cleanupJSSource(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.js');
|
2014-03-22 07:16:03 +09:00
|
|
|
cleanupJSSource(FIREFOX_BUILD_DIR + 'bootstrap.js');
|
2014-09-19 04:55:04 +09:00
|
|
|
cleanupJSSource(FIREFOX_BUILD_CONTENT_DIR + 'PdfjsChromeUtils.jsm');
|
2014-09-11 01:10:04 +09:00
|
|
|
cleanupCSSSource(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.css');
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2012-03-15 06:50:49 +09:00
|
|
|
// Remove '.DS_Store' and other hidden files
|
2012-03-27 05:33:00 +09:00
|
|
|
find(FIREFOX_BUILD_DIR).forEach(function(file) {
|
2014-03-15 00:18:08 +09:00
|
|
|
if (file.match(/^\./)) {
|
2012-03-15 06:50:49 +09:00
|
|
|
rm('-f', file);
|
2014-03-15 00:18:08 +09:00
|
|
|
}
|
2012-03-27 05:33:00 +09:00
|
|
|
});
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
// Update the build version number
|
2016-04-23 07:20:47 +09:00
|
|
|
var VERSION = getCurrentVersion();
|
2014-04-11 02:01:51 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
|
2012-08-23 03:34:34 +09:00
|
|
|
FIREFOX_BUILD_DIR + '/install.rdf');
|
2014-04-11 02:01:51 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
|
2012-08-23 03:34:34 +09:00
|
|
|
FIREFOX_BUILD_DIR + '/update.rdf');
|
|
|
|
|
|
|
|
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, FIREFOX_STREAM_CONVERTER_ID,
|
2014-02-28 07:11:39 +09:00
|
|
|
FIREFOX_BUILD_CONTENT_DIR + 'PdfStreamConverter.jsm');
|
2015-07-03 02:59:17 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER2_ID/, FIREFOX_STREAM_CONVERTER2_ID,
|
|
|
|
FIREFOX_BUILD_CONTENT_DIR + 'PdfStreamConverter.jsm');
|
2012-08-23 03:34:34 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, FIREFOX_PREF_PREFIX,
|
2014-02-28 07:11:39 +09:00
|
|
|
FIREFOX_BUILD_CONTENT_DIR + 'PdfStreamConverter.jsm');
|
2012-08-23 03:34:34 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'false',
|
2014-02-28 07:11:39 +09:00
|
|
|
FIREFOX_BUILD_CONTENT_DIR + 'PdfStreamConverter.jsm');
|
2014-09-18 08:14:00 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, FIREFOX_PREF_PREFIX,
|
|
|
|
FIREFOX_BUILD_CONTENT_DIR + 'PdfjsChromeUtils.jsm');
|
2012-05-24 07:57:14 +09:00
|
|
|
|
2012-05-02 22:51:52 +09:00
|
|
|
// Update localized metadata
|
|
|
|
var localizedMetadata = cat(EXTENSION_SRC_DIR + '/firefox/metadata.inc');
|
2012-08-23 03:34:34 +09:00
|
|
|
sed('-i', /.*PDFJS_LOCALIZED_METADATA.*\n/, localizedMetadata,
|
|
|
|
FIREFOX_BUILD_DIR + '/install.rdf');
|
2012-05-12 04:39:11 +09:00
|
|
|
var chromeManifest = cat(EXTENSION_SRC_DIR + '/firefox/chrome.manifest.inc');
|
2012-08-23 03:34:34 +09:00
|
|
|
sed('-i', /.*PDFJS_SUPPORTED_LOCALES.*\n/, chromeManifest,
|
|
|
|
FIREFOX_BUILD_DIR + '/chrome.manifest');
|
2012-05-02 22:51:52 +09:00
|
|
|
|
2015-07-21 23:29:12 +09:00
|
|
|
// Set timezone to UTC before calling zip to get reproducible results.
|
|
|
|
process.env.TZ = 'UTC';
|
|
|
|
|
2012-03-04 04:01:31 +09:00
|
|
|
// Create the xpi
|
|
|
|
cd(FIREFOX_BUILD_DIR);
|
2012-08-23 03:34:34 +09:00
|
|
|
exec('zip -r ' + FIREFOX_EXTENSION_NAME + ' ' +
|
|
|
|
FIREFOX_EXTENSION_FILES.join(' '));
|
2012-03-04 04:01:31 +09:00
|
|
|
echo('extension created: ' + FIREFOX_EXTENSION_NAME);
|
|
|
|
cd(ROOT_DIR);
|
2012-05-09 00:23:55 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// make mozcentral
|
|
|
|
//
|
|
|
|
target.mozcentral = function() {
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
echo();
|
|
|
|
echo('### Building mozilla-central extension');
|
2012-08-02 06:27:42 +09:00
|
|
|
var defines = builder.merge(DEFINES, {MOZCENTRAL: true});
|
2012-05-09 00:23:55 +09:00
|
|
|
|
2012-05-12 04:39:11 +09:00
|
|
|
var MOZCENTRAL_DIR = BUILD_DIR + 'mozcentral/',
|
2012-05-23 07:56:12 +09:00
|
|
|
MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + 'browser/extensions/pdfjs/',
|
2012-05-12 04:39:11 +09:00
|
|
|
MOZCENTRAL_CONTENT_DIR = MOZCENTRAL_EXTENSION_DIR + 'content/',
|
|
|
|
MOZCENTRAL_L10N_DIR = MOZCENTRAL_DIR + 'browser/locales/en-US/pdfviewer/',
|
2012-05-09 00:23:55 +09:00
|
|
|
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/',
|
|
|
|
FIREFOX_EXTENSION_FILES_TO_COPY =
|
2012-11-03 07:23:49 +09:00
|
|
|
['*.svg',
|
2012-05-09 00:23:55 +09:00
|
|
|
'*.png',
|
2012-05-12 04:39:11 +09:00
|
|
|
'*.manifest',
|
2012-05-09 00:23:55 +09:00
|
|
|
'README.mozilla',
|
|
|
|
'../../LICENSE'],
|
|
|
|
DEFAULT_LOCALE_FILES =
|
2012-05-16 03:38:38 +09:00
|
|
|
[LOCALE_SRC_DIR + 'en-US/viewer.properties',
|
2014-01-18 02:32:30 +09:00
|
|
|
LOCALE_SRC_DIR + 'en-US/chrome.properties'],
|
|
|
|
FIREFOX_MC_EXCLUDED_FILES =
|
|
|
|
['icon.png',
|
|
|
|
'icon64.png'];
|
2012-05-09 00:23:55 +09:00
|
|
|
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bundle-mozcentral');
|
2012-05-09 00:23:55 +09:00
|
|
|
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');
|
2014-03-18 03:20:24 +09:00
|
|
|
mkdir('-p', MOZCENTRAL_CONTENT_DIR + '/web/cmaps');
|
2012-05-09 00:23:55 +09:00
|
|
|
|
2013-08-16 23:53:05 +09:00
|
|
|
cp(FIREFOX_CONTENT_DIR + 'PdfJsTelemetry.jsm', MOZCENTRAL_CONTENT_DIR);
|
2012-06-01 03:16:06 +09:00
|
|
|
|
2012-05-09 00:23:55 +09:00
|
|
|
// Copy extension files
|
|
|
|
cd('extensions/firefox');
|
2012-08-23 03:34:34 +09:00
|
|
|
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY,
|
|
|
|
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR);
|
2012-05-23 07:56:12 +09:00
|
|
|
mv('-f', ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome-mozcentral.manifest',
|
2012-08-23 03:34:34 +09:00
|
|
|
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome.manifest');
|
2012-05-09 00:23:55 +09:00
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
2012-08-02 03:29:13 +09:00
|
|
|
var setup = {
|
|
|
|
defines: defines,
|
|
|
|
copy: [
|
2016-04-23 07:20:47 +09:00
|
|
|
[BUILD_TARGETS, MOZCENTRAL_CONTENT_DIR + BUILD_DIR],
|
|
|
|
[BUILD_DIR + 'viewer.js', MOZCENTRAL_CONTENT_DIR + '/web'],
|
2012-08-02 03:29:13 +09:00
|
|
|
[COMMON_WEB_FILES, MOZCENTRAL_CONTENT_DIR + '/web'],
|
2014-03-18 03:20:24 +09:00
|
|
|
['external/bcmaps/*', MOZCENTRAL_CONTENT_DIR + '/web/cmaps'],
|
2014-03-22 07:16:03 +09:00
|
|
|
['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
|
2012-08-02 03:29:13 +09:00
|
|
|
],
|
|
|
|
preprocess: [
|
2012-10-30 04:44:18 +09:00
|
|
|
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'],
|
2014-09-20 06:00:13 +09:00
|
|
|
[FIREFOX_CONTENT_DIR + 'pdfjschildbootstrap.js', MOZCENTRAL_CONTENT_DIR],
|
2014-03-22 07:16:03 +09:00
|
|
|
[SRC_DIR + 'core/network.js', MOZCENTRAL_CONTENT_DIR],
|
2014-09-18 06:14:04 +09:00
|
|
|
[COMMON_FIREFOX_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR],
|
2014-03-22 07:16:03 +09:00
|
|
|
[FIREFOX_CONTENT_DIR + 'PdfJs.jsm', MOZCENTRAL_CONTENT_DIR]
|
2013-07-10 07:14:21 +09:00
|
|
|
],
|
|
|
|
preprocessCSS: [
|
2014-02-11 06:06:03 +09:00
|
|
|
['mozcentral',
|
|
|
|
'web/viewer.css',
|
|
|
|
MOZCENTRAL_CONTENT_DIR + '/web/viewer.css']
|
2012-08-02 03:29:13 +09:00
|
|
|
]
|
|
|
|
};
|
2012-08-02 06:27:42 +09:00
|
|
|
builder.build(setup);
|
2012-05-09 00:23:55 +09:00
|
|
|
|
2013-06-19 01:05:55 +09:00
|
|
|
cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/web/viewer.js');
|
2014-03-22 07:16:03 +09:00
|
|
|
cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/PdfJs.jsm');
|
2014-09-19 04:55:04 +09:00
|
|
|
cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/PdfjsChromeUtils.jsm');
|
2014-09-11 01:10:04 +09:00
|
|
|
cleanupCSSSource(MOZCENTRAL_CONTENT_DIR + '/web/viewer.css');
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2012-05-09 00:23:55 +09:00
|
|
|
// Remove '.DS_Store' and other hidden files
|
|
|
|
find(MOZCENTRAL_DIR).forEach(function(file) {
|
2014-03-15 00:18:08 +09:00
|
|
|
if (file.match(/^\./)) {
|
2012-05-09 00:23:55 +09:00
|
|
|
rm('-f', file);
|
2014-03-15 00:18:08 +09:00
|
|
|
}
|
2012-05-09 00:23:55 +09:00
|
|
|
});
|
|
|
|
|
2014-01-18 02:32:30 +09:00
|
|
|
// Remove excluded files
|
|
|
|
cd(MOZCENTRAL_EXTENSION_DIR);
|
|
|
|
FIREFOX_MC_EXCLUDED_FILES.forEach(function(file) {
|
|
|
|
if (test('-f', file)) {
|
|
|
|
rm('-r', file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
2012-05-09 00:23:55 +09:00
|
|
|
// Copy default localization files
|
|
|
|
cp(DEFAULT_LOCALE_FILES, MOZCENTRAL_L10N_DIR);
|
|
|
|
|
|
|
|
// Update the build version number
|
2016-04-23 07:20:47 +09:00
|
|
|
var VERSION = getCurrentVersion();
|
2014-04-11 02:01:51 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
|
2012-08-23 03:34:34 +09:00
|
|
|
MOZCENTRAL_EXTENSION_DIR + 'README.mozilla');
|
2012-03-14 10:31:53 +09:00
|
|
|
|
2012-08-23 03:34:34 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, MOZCENTRAL_STREAM_CONVERTER_ID,
|
2014-02-28 07:11:39 +09:00
|
|
|
MOZCENTRAL_CONTENT_DIR + 'PdfStreamConverter.jsm');
|
2015-07-03 02:59:17 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER2_ID/, MOZCENTRAL_STREAM_CONVERTER2_ID,
|
|
|
|
MOZCENTRAL_CONTENT_DIR + 'PdfStreamConverter.jsm');
|
2012-08-23 03:34:34 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, MOZCENTRAL_PREF_PREFIX,
|
2014-02-28 07:11:39 +09:00
|
|
|
MOZCENTRAL_CONTENT_DIR + 'PdfStreamConverter.jsm');
|
2012-08-23 03:34:34 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'true',
|
2014-02-28 07:11:39 +09:00
|
|
|
MOZCENTRAL_CONTENT_DIR + 'PdfStreamConverter.jsm');
|
2014-09-18 08:14:00 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, MOZCENTRAL_PREF_PREFIX,
|
|
|
|
MOZCENTRAL_CONTENT_DIR + 'PdfjsChromeUtils.jsm');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
//
|
|
|
|
// make chrome
|
|
|
|
//
|
2013-08-22 02:22:43 +09:00
|
|
|
target.chromium = function() {
|
2014-03-15 03:22:02 +09:00
|
|
|
target.locale();
|
|
|
|
|
2012-03-04 04:01:31 +09:00
|
|
|
cd(ROOT_DIR);
|
|
|
|
echo();
|
2013-08-22 02:22:43 +09:00
|
|
|
echo('### Building Chromium extension');
|
2012-08-02 06:27:42 +09:00
|
|
|
var defines = builder.merge(DEFINES, {CHROME: true});
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2013-08-22 01:54:59 +09:00
|
|
|
var CHROME_BUILD_DIR = BUILD_DIR + '/chromium/',
|
2012-08-02 03:29:13 +09:00
|
|
|
CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + '/content/';
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bundle-chromium');
|
2012-03-04 04:01:31 +09:00
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
|
|
|
// Clear out everything in the chrome extension build directory
|
|
|
|
rm('-Rf', CHROME_BUILD_DIR);
|
|
|
|
mkdir('-p', CHROME_BUILD_CONTENT_DIR);
|
2012-03-05 11:26:57 +09:00
|
|
|
mkdir('-p', CHROME_BUILD_CONTENT_DIR + BUILD_DIR);
|
|
|
|
mkdir('-p', CHROME_BUILD_CONTENT_DIR + '/web');
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2012-08-02 03:29:13 +09:00
|
|
|
var setup = {
|
|
|
|
defines: defines,
|
|
|
|
copy: [
|
2016-04-23 07:20:47 +09:00
|
|
|
[BUILD_TARGETS, CHROME_BUILD_CONTENT_DIR + BUILD_DIR],
|
|
|
|
[BUILD_DIR + 'viewer.js', CHROME_BUILD_CONTENT_DIR + '/web'],
|
2012-08-02 03:29:13 +09:00
|
|
|
[COMMON_WEB_FILES, CHROME_BUILD_CONTENT_DIR + '/web'],
|
2013-08-22 01:54:59 +09:00
|
|
|
[['extensions/chromium/*.json',
|
|
|
|
'extensions/chromium/*.html',
|
|
|
|
'extensions/chromium/*.js',
|
|
|
|
'extensions/chromium/*.css',
|
2016-12-11 03:58:36 +09:00
|
|
|
'extensions/chromium/icon*.png'],
|
2012-08-23 03:34:34 +09:00
|
|
|
CHROME_BUILD_DIR],
|
2014-08-23 06:00:39 +09:00
|
|
|
['extensions/chromium/pageAction/*.*', CHROME_BUILD_DIR + '/pageAction'],
|
2015-01-07 02:22:35 +09:00
|
|
|
['extensions/chromium/options/*.*', CHROME_BUILD_DIR + '/options'],
|
2012-11-30 05:02:33 +09:00
|
|
|
['external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web'],
|
2014-03-18 03:20:24 +09:00
|
|
|
['external/bcmaps/*', CHROME_BUILD_CONTENT_DIR + '/web/cmaps'],
|
2012-11-30 05:02:33 +09:00
|
|
|
['web/locale', CHROME_BUILD_CONTENT_DIR + '/web']
|
2012-08-02 03:29:13 +09:00
|
|
|
],
|
|
|
|
preprocess: [
|
2012-11-30 05:02:33 +09:00
|
|
|
[COMMON_WEB_FILES_PREPROCESS, CHROME_BUILD_CONTENT_DIR + '/web']
|
2014-09-11 01:10:04 +09:00
|
|
|
],
|
|
|
|
preprocessCSS: [
|
|
|
|
['chrome', 'web/viewer.css',
|
|
|
|
CHROME_BUILD_CONTENT_DIR + '/web/viewer.css']
|
2012-08-02 03:29:13 +09:00
|
|
|
]
|
|
|
|
};
|
2012-08-02 06:27:42 +09:00
|
|
|
builder.build(setup);
|
2012-08-23 06:16:29 +09:00
|
|
|
|
2013-06-19 01:05:55 +09:00
|
|
|
cleanupJSSource(CHROME_BUILD_CONTENT_DIR + '/web/viewer.js');
|
2014-09-11 01:10:04 +09:00
|
|
|
cleanupCSSSource(CHROME_BUILD_CONTENT_DIR + '/web/viewer.css');
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2012-09-07 00:33:07 +09:00
|
|
|
// Update the build version number
|
2016-04-23 07:20:47 +09:00
|
|
|
var VERSION = getCurrentVersion();
|
2014-04-11 02:01:51 +09:00
|
|
|
sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
|
2012-09-07 00:33:07 +09:00
|
|
|
CHROME_BUILD_DIR + '/manifest.json');
|
|
|
|
|
2013-04-04 07:28:45 +09:00
|
|
|
// Allow PDF.js resources to be loaded by adding the files to
|
|
|
|
// the "web_accessible_resources" section.
|
|
|
|
var file_list = ls('-RA', CHROME_BUILD_CONTENT_DIR);
|
|
|
|
var public_chrome_files = file_list.reduce(function(war, file) {
|
|
|
|
// Exclude directories (naive: Exclude paths without dot)
|
|
|
|
if (file.indexOf('.') !== -1) {
|
2014-03-15 00:18:08 +09:00
|
|
|
// Only add a comma after the first file
|
|
|
|
if (war) {
|
|
|
|
war += ',\n';
|
|
|
|
}
|
|
|
|
war += JSON.stringify('content/' + file);
|
2013-04-04 07:28:45 +09:00
|
|
|
}
|
|
|
|
return war;
|
|
|
|
}, '');
|
|
|
|
sed('-i', /"content\/\*"/, public_chrome_files,
|
|
|
|
CHROME_BUILD_DIR + '/manifest.json');
|
|
|
|
|
2012-08-23 06:16:29 +09:00
|
|
|
// Bundle the files to a Chrome extension file .crx if path to key is set
|
|
|
|
var pem = env['PDFJS_CHROME_KEY'];
|
|
|
|
if (!pem) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo();
|
|
|
|
echo('### Bundling .crx extension into ' + CHROME_BUILD_DIR);
|
|
|
|
|
|
|
|
if (!test('-f', pem)) {
|
|
|
|
echo('Incorrect PDFJS_CHROME_KEY path');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
var browserManifest = env['PDF_BROWSERS'] ||
|
|
|
|
'test/resources/browser_manifests/browser_manifest.json';
|
|
|
|
|
|
|
|
if (!test('-f', browserManifest)) {
|
|
|
|
echo('Browser manifest file ' + browserManifest + ' does not exist.');
|
2015-04-04 04:21:54 +09:00
|
|
|
echo('Copy and adjust the example in test/resources/browser_manifests.');
|
2012-08-23 06:16:29 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-02-01 08:43:13 +09:00
|
|
|
var manifest;
|
2012-08-23 06:16:29 +09:00
|
|
|
try {
|
2013-02-01 08:43:13 +09:00
|
|
|
manifest = JSON.parse(cat(browserManifest));
|
2012-08-23 06:16:29 +09:00
|
|
|
} catch (e) {
|
|
|
|
echo('Malformed browser manifest file');
|
|
|
|
echo(e.message);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
var executable;
|
|
|
|
manifest.forEach(function(browser) {
|
|
|
|
if (browser.name === 'chrome') {
|
|
|
|
executable = browser.path;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// If there was no chrome entry in the browser manifest, exit
|
2012-08-28 04:23:42 +09:00
|
|
|
if (!executable) {
|
2012-08-23 06:16:29 +09:00
|
|
|
echo('There was no \'chrome\' entry in the browser manifest');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're on a Darwin (Mac) OS, then let's check for an .app path
|
|
|
|
if (process.platform === 'darwin' && executable.indexOf('.app') !== -1) {
|
2012-08-28 01:09:33 +09:00
|
|
|
executable = executable + '/Contents/MacOS/Google Chrome';
|
2012-08-23 06:16:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the chrome executable doesn't exist
|
2012-08-28 04:23:42 +09:00
|
|
|
if (!test('-f', executable)) {
|
2012-08-23 06:16:29 +09:00
|
|
|
echo('Incorrect executable path to chrome');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let chrome pack the extension for us
|
|
|
|
exec('"' + executable + '"' +
|
|
|
|
' --no-message-box' +
|
|
|
|
' "--pack-extension=' + ROOT_DIR + CHROME_BUILD_DIR + '"' +
|
|
|
|
' "--pack-extension-key=' + pem + '"');
|
|
|
|
|
|
|
|
// Rename to pdf.js.crx
|
|
|
|
mv(BUILD_DIR + 'chrome.crx', CHROME_BUILD_DIR + 'pdf.js.crx');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
|
2013-02-03 07:49:19 +09:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
// Test stuff
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// make test
|
|
|
|
//
|
|
|
|
target.test = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('test');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2012-03-29 06:06:41 +09:00
|
|
|
//
|
|
|
|
// make bottest
|
|
|
|
// (Special tests for the Github bot)
|
|
|
|
//
|
|
|
|
target.bottest = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('bottest');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
//
|
|
|
|
// make browsertest
|
|
|
|
//
|
2012-03-29 06:06:41 +09:00
|
|
|
target.browsertest = function(options) {
|
2016-05-02 23:58:29 +09:00
|
|
|
if (options && options.noreftest) {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('browsertest-noreftest');
|
2016-05-02 23:58:29 +09:00
|
|
|
} else {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('browsertest');
|
2012-03-04 04:01:31 +09:00
|
|
|
}
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
//
|
|
|
|
// make unittest
|
|
|
|
//
|
2012-04-20 04:32:24 +09:00
|
|
|
target.unittest = function(options, callback) {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('unittest');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2012-11-02 08:10:47 +09:00
|
|
|
//
|
|
|
|
// make fonttest
|
|
|
|
//
|
|
|
|
target.fonttest = function(options, callback) {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('fonttest');
|
2012-11-02 08:10:47 +09:00
|
|
|
};
|
|
|
|
|
2012-03-30 04:04:12 +09:00
|
|
|
//
|
|
|
|
// make botmakeref
|
|
|
|
//
|
|
|
|
target.botmakeref = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('botmakeref');
|
2012-03-27 05:33:00 +09:00
|
|
|
};
|
|
|
|
|
2012-11-03 07:23:49 +09:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Baseline operation
|
|
|
|
//
|
|
|
|
target.baseline = function() {
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
|
|
|
echo();
|
|
|
|
echo('### Creating baseline environment');
|
|
|
|
|
|
|
|
var baselineCommit = env['BASELINE'];
|
|
|
|
if (!baselineCommit) {
|
|
|
|
echo('Baseline commit is not provided. Please specify BASELINE variable');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2014-03-15 00:18:08 +09:00
|
|
|
if (!test('-d', BUILD_DIR)) {
|
2012-11-03 07:23:49 +09:00
|
|
|
mkdir(BUILD_DIR);
|
2014-03-15 00:18:08 +09:00
|
|
|
}
|
2012-11-03 07:23:49 +09:00
|
|
|
|
|
|
|
var BASELINE_DIR = BUILD_DIR + 'baseline';
|
|
|
|
if (test('-d', BASELINE_DIR)) {
|
|
|
|
cd(BASELINE_DIR);
|
|
|
|
exec('git fetch origin');
|
|
|
|
} else {
|
|
|
|
cd(BUILD_DIR);
|
|
|
|
exec('git clone .. baseline');
|
|
|
|
cd(ROOT_DIR + BASELINE_DIR);
|
|
|
|
}
|
|
|
|
exec('git checkout ' + baselineCommit);
|
|
|
|
};
|
|
|
|
|
|
|
|
target.mozcentralbaseline = function() {
|
|
|
|
target.baseline();
|
|
|
|
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
|
|
|
echo();
|
|
|
|
echo('### Creating mozcentral baseline environment');
|
|
|
|
|
|
|
|
var BASELINE_DIR = BUILD_DIR + 'baseline';
|
|
|
|
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline';
|
2014-03-15 00:18:08 +09:00
|
|
|
if (test('-d', MOZCENTRAL_BASELINE_DIR)) {
|
2012-11-03 07:23:49 +09:00
|
|
|
rm('-rf', MOZCENTRAL_BASELINE_DIR);
|
2014-03-15 00:18:08 +09:00
|
|
|
}
|
2012-11-03 07:23:49 +09:00
|
|
|
|
|
|
|
cd(BASELINE_DIR);
|
2014-03-15 00:18:08 +09:00
|
|
|
if (test('-d', 'build')) {
|
2012-11-03 07:23:49 +09:00
|
|
|
rm('-rf', 'build');
|
2014-03-15 00:18:08 +09:00
|
|
|
}
|
2016-03-13 23:23:41 +09:00
|
|
|
exec('node make mozcentral');
|
2012-11-03 07:23:49 +09:00
|
|
|
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
mkdir(MOZCENTRAL_BASELINE_DIR);
|
|
|
|
cp('-Rf', BASELINE_DIR + '/build/mozcentral/*', MOZCENTRAL_BASELINE_DIR);
|
|
|
|
// fixing baseline
|
|
|
|
if (test('-f', MOZCENTRAL_BASELINE_DIR +
|
|
|
|
'/browser/extensions/pdfjs/PdfStreamConverter.js')) {
|
|
|
|
rm(MOZCENTRAL_BASELINE_DIR +
|
|
|
|
'/browser/extensions/pdfjs/PdfStreamConverter.js');
|
|
|
|
}
|
|
|
|
|
|
|
|
cd(MOZCENTRAL_BASELINE_DIR);
|
|
|
|
exec('git init');
|
|
|
|
exec('git add .');
|
|
|
|
exec('git commit -m "mozcentral baseline"');
|
|
|
|
};
|
|
|
|
|
|
|
|
target.mozcentraldiff = function() {
|
|
|
|
target.mozcentral();
|
|
|
|
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
|
|
|
echo();
|
|
|
|
echo('### Creating mozcentral diff');
|
|
|
|
|
|
|
|
var MOZCENTRAL_DIFF = BUILD_DIR + 'mozcentral.diff';
|
2014-03-15 00:18:08 +09:00
|
|
|
if (test('-f', MOZCENTRAL_DIFF)) {
|
2012-11-03 07:23:49 +09:00
|
|
|
rm(MOZCENTRAL_DIFF);
|
2014-03-15 00:18:08 +09:00
|
|
|
}
|
2012-11-03 07:23:49 +09:00
|
|
|
|
|
|
|
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline';
|
|
|
|
if (!test('-d', MOZCENTRAL_BASELINE_DIR)) {
|
|
|
|
echo('mozcentral baseline was not found');
|
2016-03-05 04:30:36 +09:00
|
|
|
echo('Please build one using "gulp mozcentralbaseline"');
|
2012-11-03 07:23:49 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
cd(MOZCENTRAL_BASELINE_DIR);
|
|
|
|
exec('git reset --hard');
|
|
|
|
cd(ROOT_DIR); rm('-rf', MOZCENTRAL_BASELINE_DIR + '/*'); // trying to be safe
|
|
|
|
cd(MOZCENTRAL_BASELINE_DIR);
|
|
|
|
cp('-Rf', '../mozcentral/*', '.');
|
|
|
|
exec('git add -A');
|
|
|
|
exec('git diff --binary --cached --unified=8', {silent: true}).output.
|
|
|
|
to('../mozcentral.diff');
|
|
|
|
|
|
|
|
echo('Result diff can be found at ' + MOZCENTRAL_DIFF);
|
|
|
|
};
|
|
|
|
|
|
|
|
target.mozcentralcheck = function() {
|
|
|
|
cd(ROOT_DIR);
|
|
|
|
|
|
|
|
echo();
|
|
|
|
echo('### Checking mozcentral changes');
|
|
|
|
|
|
|
|
var mcPath = env['MC_PATH'];
|
|
|
|
if (!mcPath) {
|
|
|
|
echo('mozilla-central path is not provided.');
|
|
|
|
echo('Please specify MC_PATH variable');
|
|
|
|
exit(1);
|
|
|
|
}
|
2014-08-02 05:26:27 +09:00
|
|
|
if ((mcPath[0] !== '/' && mcPath[0] !== '~' && mcPath[1] !== ':') ||
|
2012-11-03 07:23:49 +09:00
|
|
|
!test('-d', mcPath)) {
|
|
|
|
echo('mozilla-central path is not in absolute form or does not exist.');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
var MOZCENTRAL_DIFF = BUILD_DIR + 'mozcentral_changes.diff';
|
|
|
|
if (test('-f', MOZCENTRAL_DIFF)) {
|
|
|
|
rm(MOZCENTRAL_DIFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline';
|
|
|
|
if (!test('-d', MOZCENTRAL_BASELINE_DIR)) {
|
|
|
|
echo('mozcentral baseline was not found');
|
2016-03-05 04:30:36 +09:00
|
|
|
echo('Please build one using "gulp mozcentralbaseline"');
|
2012-11-03 07:23:49 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
cd(MOZCENTRAL_BASELINE_DIR);
|
|
|
|
exec('git reset --hard');
|
|
|
|
cd(ROOT_DIR); rm('-rf', MOZCENTRAL_BASELINE_DIR + '/*'); // trying to be safe
|
|
|
|
cd(MOZCENTRAL_BASELINE_DIR);
|
|
|
|
mkdir('browser');
|
|
|
|
cd('browser');
|
|
|
|
mkdir('-p', 'extensions/pdfjs');
|
|
|
|
cp('-Rf', mcPath + '/browser/extensions/pdfjs/*', 'extensions/pdfjs');
|
|
|
|
mkdir('-p', 'locales/en-US/pdfviewer');
|
|
|
|
cp('-Rf', mcPath + '/browser/locales/en-US/pdfviewer/*',
|
|
|
|
'locales/en-US/pdfviewer');
|
|
|
|
// Remove '.DS_Store' and other hidden files
|
|
|
|
find('.').forEach(function(file) {
|
|
|
|
if (file.match(/^\.\w|~$/)) {
|
|
|
|
rm('-f', file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
cd('..');
|
|
|
|
exec('git add -A');
|
|
|
|
var diff = exec('git diff --binary --cached --unified=8',
|
|
|
|
{silent: true}).output;
|
|
|
|
|
|
|
|
if (diff) {
|
|
|
|
echo('There were changes found at mozilla-central.');
|
|
|
|
diff.to('../mozcentral_changes.diff');
|
|
|
|
echo('Result diff can be found at ' + MOZCENTRAL_DIFF);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo('Success: there are no changes at mozilla-central');
|
|
|
|
};
|
|
|
|
|
2012-03-04 04:01:31 +09:00
|
|
|
|
2013-02-03 07:49:19 +09:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
// Other
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// make server
|
|
|
|
//
|
2016-03-05 00:36:46 +09:00
|
|
|
target.server = function () {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('server');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-03-04 04:01:31 +09:00
|
|
|
|
|
|
|
//
|
|
|
|
// make lint
|
|
|
|
//
|
|
|
|
target.lint = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('lint');
|
2013-02-01 08:29:37 +09:00
|
|
|
};
|
|
|
|
|
2012-03-04 04:01:31 +09:00
|
|
|
//
|
|
|
|
// make clean
|
|
|
|
//
|
|
|
|
target.clean = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('clean');
|
2012-03-05 11:26:57 +09:00
|
|
|
};
|
2012-08-19 05:01:01 +09:00
|
|
|
|
2012-08-28 04:17:29 +09:00
|
|
|
//
|
|
|
|
// make makefile
|
|
|
|
//
|
2016-03-05 00:36:46 +09:00
|
|
|
target.makefile = function () {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('makefile');
|
2012-08-28 04:17:29 +09:00
|
|
|
};
|
2014-03-23 00:40:59 +09:00
|
|
|
|
|
|
|
//
|
|
|
|
//make importl10n
|
|
|
|
//
|
|
|
|
target.importl10n = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('importl10n');
|
2014-03-23 00:40:59 +09:00
|
|
|
};
|
2016-04-23 07:20:47 +09:00
|
|
|
|
|
|
|
exports.stripCommentHeaders = stripCommentHeaders;
|
|
|
|
exports.builder = builder;
|