Merge pull request #8349 from timvandermeij/remove-make
Migrate `make.js` to `gulpfile.js`
This commit is contained in:
commit
0c99429291
134
gulpfile.js
134
gulpfile.js
@ -44,6 +44,7 @@ var TEST_DIR = 'test/';
|
||||
var EXTENSION_SRC_DIR = 'extensions/';
|
||||
|
||||
var BASELINE_DIR = BUILD_DIR + 'baseline/';
|
||||
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline/';
|
||||
var GENERIC_DIR = BUILD_DIR + 'generic/';
|
||||
var COMPONENTS_DIR = BUILD_DIR + 'components/';
|
||||
var SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/';
|
||||
@ -59,6 +60,7 @@ var COMMON_WEB_FILES = [
|
||||
'web/images/*.{png,svg,gif,cur}',
|
||||
'web/debugger.js'
|
||||
];
|
||||
var MOZCENTRAL_DIFF_FILE = 'mozcentral.diff';
|
||||
|
||||
var REPO = 'git@github.com:mozilla/pdf.js.git';
|
||||
var DIST_REPO_URL = 'https://github.com/mozilla/pdfjs-dist';
|
||||
@ -82,6 +84,20 @@ var DEFINES = {
|
||||
PDFJS_NEXT: false,
|
||||
};
|
||||
|
||||
function safeSpawnSync(command, parameters, options) {
|
||||
// Execute all commands in a shell.
|
||||
options = options || {};
|
||||
options.shell = true;
|
||||
|
||||
var result = spawnSync(command, parameters, options);
|
||||
if (result.status !== 0) {
|
||||
console.log('Error: command "' + command + '" with parameters "' +
|
||||
parameters + '" exited with code ' + result.status);
|
||||
process.exit(result.status);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function createStringSource(filename, content) {
|
||||
var source = stream.Readable({ objectMode: true });
|
||||
source._read = function () {
|
||||
@ -678,12 +694,13 @@ gulp.task('minified-post', ['minified-pre'], function () {
|
||||
// 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');
|
||||
fs.writeFileSync(MINIFIED_DIR + '/web/pdf.viewer.js',
|
||||
UglifyJS.minify(viewerFiles).code);
|
||||
fs.writeFileSync(MINIFIED_DIR + '/build/pdf.min.js',
|
||||
UglifyJS.minify(MINIFIED_DIR + '/build/pdf.js').code);
|
||||
fs.writeFileSync(MINIFIED_DIR + '/build/pdf.worker.min.js',
|
||||
UglifyJS.minify(MINIFIED_DIR + '/build/pdf.worker.js',
|
||||
optsForHugeFile).code);
|
||||
|
||||
console.log();
|
||||
console.log('### Cleaning js files');
|
||||
@ -1043,10 +1060,6 @@ gulp.task('browsertest', function () {
|
||||
return createTestSource('browser');
|
||||
});
|
||||
|
||||
gulp.task('browsertest-noreftest', function () {
|
||||
return createTestSource('browser (no reftest)');
|
||||
});
|
||||
|
||||
gulp.task('unittest', function () {
|
||||
return createTestSource('unit');
|
||||
});
|
||||
@ -1223,14 +1236,14 @@ gulp.task('gh-pages-git', ['gh-pages-prepare', 'wintersmith'], function () {
|
||||
var VERSION = getVersionJSON().version;
|
||||
var reason = process.env['PDFJS_UPDATE_REASON'];
|
||||
|
||||
spawnSync('git', ['init'], {cwd: GH_PAGES_DIR});
|
||||
spawnSync('git', ['remote', 'add', 'origin', REPO], {cwd: GH_PAGES_DIR});
|
||||
spawnSync('git', ['add', '-A'], {cwd: GH_PAGES_DIR});
|
||||
spawnSync('git', [
|
||||
safeSpawnSync('git', ['init'], {cwd: GH_PAGES_DIR});
|
||||
safeSpawnSync('git', ['remote', 'add', 'origin', REPO], {cwd: GH_PAGES_DIR});
|
||||
safeSpawnSync('git', ['add', '-A'], {cwd: GH_PAGES_DIR});
|
||||
safeSpawnSync('git', [
|
||||
'commit', '-am', 'gh-pages site created via gulpfile.js script',
|
||||
'-m', 'PDF.js version ' + VERSION + (reason ? ' - ' + reason : '')
|
||||
], {cwd: GH_PAGES_DIR});
|
||||
spawnSync('git', ['branch', '-m', 'gh-pages'], {cwd: GH_PAGES_DIR});
|
||||
safeSpawnSync('git', ['branch', '-m', 'gh-pages'], {cwd: GH_PAGES_DIR});
|
||||
|
||||
console.log();
|
||||
console.log('Website built in ' + GH_PAGES_DIR);
|
||||
@ -1246,7 +1259,7 @@ gulp.task('dist-repo-prepare', ['dist-pre'], function () {
|
||||
|
||||
rimraf.sync(DIST_DIR);
|
||||
mkdirp.sync(DIST_DIR);
|
||||
spawnSync('git', ['clone', '--depth', '1', DIST_REPO_URL, DIST_DIR]);
|
||||
safeSpawnSync('git', ['clone', '--depth', '1', DIST_REPO_URL, DIST_DIR]);
|
||||
|
||||
console.log();
|
||||
console.log('### Overwriting all files');
|
||||
@ -1334,10 +1347,10 @@ gulp.task('dist-repo-git', ['dist-repo-prepare'], function () {
|
||||
|
||||
var reason = process.env['PDFJS_UPDATE_REASON'];
|
||||
var message = 'PDF.js version ' + VERSION + (reason ? ' - ' + reason : '');
|
||||
spawnSync('git', ['add', '*'], {cwd: DIST_DIR});
|
||||
spawnSync('git', ['commit', '-am', message], {cwd: DIST_DIR});
|
||||
spawnSync('git', ['tag', '-a', 'v' + VERSION, '-m', message],
|
||||
{cwd: DIST_DIR});
|
||||
safeSpawnSync('git', ['add', '*'], {cwd: DIST_DIR});
|
||||
safeSpawnSync('git', ['commit', '-am', message], {cwd: DIST_DIR});
|
||||
safeSpawnSync('git', ['tag', '-a', 'v' + VERSION, '-m', message],
|
||||
{cwd: DIST_DIR});
|
||||
|
||||
console.log();
|
||||
console.log('Done. Push with');
|
||||
@ -1348,38 +1361,59 @@ gulp.task('dist-repo-git', ['dist-repo-prepare'], function () {
|
||||
|
||||
gulp.task('dist', ['dist-repo-git']);
|
||||
|
||||
// Getting all shelljs registered tasks and register them with gulp
|
||||
require('./make.js');
|
||||
gulp.task('mozcentralbaseline', ['baseline'], function (done) {
|
||||
console.log();
|
||||
console.log('### Creating mozcentral baseline environment');
|
||||
|
||||
var gulpContext = false;
|
||||
for (var taskName in global.target) {
|
||||
if (taskName in gulp.tasks) {
|
||||
continue;
|
||||
}
|
||||
// Create a mozcentral build.
|
||||
rimraf.sync(BASELINE_DIR + BUILD_DIR);
|
||||
|
||||
var task = (function (shellJsTask) {
|
||||
return function () {
|
||||
gulpContext = true;
|
||||
try {
|
||||
shellJsTask.call(global.target);
|
||||
} finally {
|
||||
gulpContext = false;
|
||||
}
|
||||
};
|
||||
})(global.target[taskName]);
|
||||
gulp.task(taskName, task);
|
||||
}
|
||||
var workingDirectory = path.resolve(process.cwd(), BASELINE_DIR);
|
||||
safeSpawnSync('gulp', ['mozcentral'],
|
||||
{env: process.env, cwd: workingDirectory, stdio: 'inherit'});
|
||||
|
||||
Object.keys(gulp.tasks).forEach(function (taskName) {
|
||||
var oldTask = global.target[taskName] || function () {
|
||||
gulp.run(taskName);
|
||||
};
|
||||
// Copy the mozcentral build to the mozcentral baseline directory.
|
||||
rimraf.sync(MOZCENTRAL_BASELINE_DIR);
|
||||
mkdirp.sync(MOZCENTRAL_BASELINE_DIR);
|
||||
|
||||
global.target[taskName] = function (args) {
|
||||
// The require('shelljs/make') import in make.js will try to execute tasks
|
||||
// listed in arguments, guarding with gulpContext
|
||||
if (gulpContext) {
|
||||
oldTask.call(global.target, args);
|
||||
}
|
||||
};
|
||||
gulp.src([BASELINE_DIR + BUILD_DIR + 'mozcentral/**/*'])
|
||||
.pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR))
|
||||
.on('end', function () {
|
||||
// Commit the mozcentral baseline.
|
||||
safeSpawnSync('git', ['init'], {cwd: MOZCENTRAL_BASELINE_DIR});
|
||||
safeSpawnSync('git', ['add', '.'], {cwd: MOZCENTRAL_BASELINE_DIR});
|
||||
safeSpawnSync('git', ['commit', '-m', '"mozcentral baseline"'],
|
||||
{cwd: MOZCENTRAL_BASELINE_DIR});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('mozcentraldiff', ['mozcentral', 'mozcentralbaseline'],
|
||||
function (done) {
|
||||
console.log();
|
||||
console.log('### Creating mozcentral diff');
|
||||
|
||||
// Create the diff between the current mozcentral build and the
|
||||
// baseline mozcentral build, which both exist at this point.
|
||||
// The mozcentral baseline directory is a Git repository, so we
|
||||
// remove all files and copy the current mozcentral build files
|
||||
// into it to create the diff.
|
||||
rimraf.sync(MOZCENTRAL_BASELINE_DIR + '*');
|
||||
|
||||
gulp.src([BUILD_DIR + 'mozcentral/**/*'])
|
||||
.pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR))
|
||||
.on('end', function () {
|
||||
safeSpawnSync('git', ['add', '-A'], {cwd: MOZCENTRAL_BASELINE_DIR});
|
||||
var diff = safeSpawnSync('git',
|
||||
['diff', '--binary', '--cached', '--unified=8'],
|
||||
{cwd: MOZCENTRAL_BASELINE_DIR}).stdout;
|
||||
|
||||
createStringSource(MOZCENTRAL_DIFF_FILE, diff)
|
||||
.pipe(gulp.dest(BUILD_DIR))
|
||||
.on('end', function () {
|
||||
console.log('Result diff can be found at ' + BUILD_DIR +
|
||||
MOZCENTRAL_DIFF_FILE);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
330
make.js
330
make.js
@ -1,330 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
/* eslint-env node, shelljs */
|
||||
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
require('shelljs/make');
|
||||
} catch (e) {
|
||||
throw new Error('ShellJS is not installed. Run "npm install" to install ' +
|
||||
'all dependencies.');
|
||||
}
|
||||
|
||||
var ROOT_DIR = __dirname + '/', // absolute path to project's root
|
||||
BUILD_DIR = 'build/';
|
||||
|
||||
function execGulp(cmd) {
|
||||
var result = exec('gulp ' + cmd);
|
||||
if (result.code) {
|
||||
echo('ERROR: gulp exited with ' + result.code);
|
||||
exit(result.code);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// make all
|
||||
//
|
||||
target.all = function() {
|
||||
execGulp('default');
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Production stuff
|
||||
//
|
||||
|
||||
//
|
||||
// make generic
|
||||
// Builds the generic production viewer that should be compatible with most
|
||||
// modern HTML5 browsers.
|
||||
//
|
||||
target.generic = function() {
|
||||
execGulp('generic');
|
||||
};
|
||||
|
||||
target.components = function() {
|
||||
execGulp('components');
|
||||
};
|
||||
|
||||
target.jsdoc = function() {
|
||||
execGulp('jsdoc');
|
||||
};
|
||||
|
||||
//
|
||||
// make web
|
||||
// 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.
|
||||
//
|
||||
target.web = function() {
|
||||
execGulp('web');
|
||||
};
|
||||
|
||||
target.dist = function() {
|
||||
execGulp('dist');
|
||||
};
|
||||
|
||||
target.publish = function() {
|
||||
execGulp('publish');
|
||||
};
|
||||
|
||||
//
|
||||
// make locale
|
||||
// Creates localized resources for the viewer and extension.
|
||||
//
|
||||
target.locale = function() {
|
||||
execGulp('locale');
|
||||
};
|
||||
|
||||
//
|
||||
// make cmaps
|
||||
// Compresses cmap files. Ensure that Adobe cmap download and uncompressed at
|
||||
// ./external/cmaps location.
|
||||
//
|
||||
target.cmaps = function () {
|
||||
execGulp('cmaps');
|
||||
};
|
||||
|
||||
//
|
||||
// make bundle
|
||||
// Bundles all source files into one wrapper 'pdf.js' file, in the given order.
|
||||
//
|
||||
target.bundle = function(args) {
|
||||
execGulp('bundle');
|
||||
};
|
||||
|
||||
//
|
||||
// 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() {
|
||||
execGulp('singlefile');
|
||||
};
|
||||
|
||||
//
|
||||
// make minified
|
||||
// Builds the minified production viewer that should be compatible with most
|
||||
// modern HTML5 browsers.
|
||||
//
|
||||
target.minified = function() {
|
||||
execGulp('minified');
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Extension stuff
|
||||
//
|
||||
|
||||
//
|
||||
// make extension
|
||||
//
|
||||
target.extension = function() {
|
||||
execGulp('extension');
|
||||
};
|
||||
|
||||
target.buildnumber = function() {
|
||||
execGulp('buildnumber');
|
||||
};
|
||||
|
||||
//
|
||||
// make firefox
|
||||
//
|
||||
target.firefox = function() {
|
||||
execGulp('firefox');
|
||||
};
|
||||
|
||||
//
|
||||
// make mozcentral
|
||||
//
|
||||
target.mozcentral = function() {
|
||||
execGulp('mozcentral');
|
||||
};
|
||||
|
||||
//
|
||||
// make chrome
|
||||
//
|
||||
target.chromium = function() {
|
||||
execGulp('chromium');
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Test stuff
|
||||
//
|
||||
|
||||
//
|
||||
// make test
|
||||
//
|
||||
target.test = function() {
|
||||
execGulp('test');
|
||||
};
|
||||
|
||||
//
|
||||
// make bottest
|
||||
// (Special tests for the Github bot)
|
||||
//
|
||||
target.bottest = function() {
|
||||
execGulp('bottest');
|
||||
};
|
||||
|
||||
//
|
||||
// make browsertest
|
||||
//
|
||||
target.browsertest = function(options) {
|
||||
if (options && options.noreftest) {
|
||||
execGulp('browsertest-noreftest');
|
||||
} else {
|
||||
execGulp('browsertest');
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// make unittest
|
||||
//
|
||||
target.unittest = function(options, callback) {
|
||||
execGulp('unittest');
|
||||
};
|
||||
|
||||
//
|
||||
// make fonttest
|
||||
//
|
||||
target.fonttest = function(options, callback) {
|
||||
execGulp('fonttest');
|
||||
};
|
||||
|
||||
//
|
||||
// make botmakeref
|
||||
//
|
||||
target.botmakeref = function() {
|
||||
execGulp('botmakeref');
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Baseline operation
|
||||
//
|
||||
target.baseline = function() {
|
||||
execGulp('baseline');
|
||||
};
|
||||
|
||||
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';
|
||||
if (test('-d', MOZCENTRAL_BASELINE_DIR)) {
|
||||
rm('-rf', MOZCENTRAL_BASELINE_DIR);
|
||||
}
|
||||
|
||||
cd(BASELINE_DIR);
|
||||
if (test('-d', 'build')) {
|
||||
rm('-rf', 'build');
|
||||
}
|
||||
exec('node make mozcentral');
|
||||
|
||||
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';
|
||||
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');
|
||||
echo('Please build one using "gulp mozcentralbaseline"');
|
||||
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);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Other
|
||||
//
|
||||
|
||||
//
|
||||
// make server
|
||||
//
|
||||
target.server = function () {
|
||||
execGulp('server');
|
||||
};
|
||||
|
||||
//
|
||||
// make lint
|
||||
//
|
||||
target.lint = function() {
|
||||
execGulp('lint');
|
||||
};
|
||||
|
||||
//
|
||||
// make clean
|
||||
//
|
||||
target.clean = function() {
|
||||
execGulp('clean');
|
||||
};
|
||||
|
||||
//
|
||||
// make makefile
|
||||
//
|
||||
target.makefile = function () {
|
||||
execGulp('makefile');
|
||||
};
|
||||
|
||||
//
|
||||
// make importl10n
|
||||
//
|
||||
target.importl10n = function() {
|
||||
execGulp('importl10n');
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user