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) {
|
2017-03-06 23:42:48 +09:00
|
|
|
throw new Error('ShellJS is not installed. Run "npm install" to install ' +
|
|
|
|
'all dependencies.');
|
2015-04-05 02:24:06 +09:00
|
|
|
}
|
|
|
|
|
2012-03-05 11:26:57 +09:00
|
|
|
var ROOT_DIR = __dirname + '/', // absolute path to project's root
|
2017-04-19 04:00:53 +09:00
|
|
|
BUILD_DIR = 'build/';
|
2016-04-23 07:20:47 +09:00
|
|
|
|
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
|
|
|
//
|
|
|
|
// make generic
|
|
|
|
// Builds the generic production viewer that should be compatible with most
|
|
|
|
// modern HTML5 browsers.
|
|
|
|
//
|
|
|
|
target.generic = function() {
|
2017-02-04 23:19:46 +09:00
|
|
|
execGulp('generic');
|
2012-08-02 03:29:13 +09:00
|
|
|
};
|
|
|
|
|
2014-10-01 02:22:38 +09:00
|
|
|
target.components = function() {
|
2017-02-04 23:19:46 +09:00
|
|
|
execGulp('components');
|
2014-10-01 02:22:38 +09:00
|
|
|
};
|
|
|
|
|
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() {
|
2017-04-15 04:28:46 +09:00
|
|
|
execGulp('web');
|
2014-04-11 02:01:51 +09:00
|
|
|
};
|
2012-03-05 11:26:57 +09:00
|
|
|
|
2014-04-11 02:01:51 +09:00
|
|
|
target.dist = function() {
|
2017-04-19 04:00:53 +09:00
|
|
|
execGulp('dist');
|
2014-09-23 08:06:34 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
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() {
|
2017-01-11 02:50:38 +09:00
|
|
|
execGulp('locale');
|
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 () {
|
2017-01-11 02:50:38 +09:00
|
|
|
execGulp('cmaps');
|
2014-03-15 03:22:02 +09:00
|
|
|
};
|
|
|
|
|
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() {
|
2017-02-04 23:19:46 +09:00
|
|
|
execGulp('singlefile');
|
2013-12-20 00:18:47 +09:00
|
|
|
};
|
|
|
|
|
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() {
|
2017-02-07 23:53:33 +09:00
|
|
|
execGulp('minified');
|
|
|
|
};
|
2014-09-11 01:10:04 +09:00
|
|
|
|
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() {
|
2017-02-07 23:53:33 +09:00
|
|
|
execGulp('firefox');
|
2012-05-09 00:23:55 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// make mozcentral
|
|
|
|
//
|
|
|
|
target.mozcentral = function() {
|
2017-02-07 23:53:33 +09:00
|
|
|
execGulp('mozcentral');
|
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() {
|
2017-02-07 23:53:33 +09:00
|
|
|
execGulp('chromium');
|
|
|
|
};
|
2014-03-15 03:22:02 +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() {
|
2017-02-22 07:24:07 +09:00
|
|
|
execGulp('baseline');
|
2012-11-03 07:23:49 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
//
|
2017-01-20 00:26:32 +09:00
|
|
|
// make importl10n
|
2014-03-23 00:40:59 +09:00
|
|
|
//
|
|
|
|
target.importl10n = function() {
|
2016-10-17 22:47:05 +09:00
|
|
|
execGulp('importl10n');
|
2014-03-23 00:40:59 +09:00
|
|
|
};
|