Remove make.js and the target fetching in gulpfile.js

Note that we have to use `fs.writeFileSync` since `.to()` is not
available anymore. Moreover, introduce `safeSpawnSync` to make sure that
we check the return codes of the spawned processes properly.
This commit is contained in:
Tim van der Meij 2017-04-27 23:21:26 +02:00
parent 145c0cea39
commit f748407b26
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
2 changed files with 41 additions and 326 deletions

View File

@ -83,6 +83,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 () {
@ -679,12 +693,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');
@ -1220,14 +1235,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);
@ -1243,7 +1258,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');
@ -1331,10 +1346,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');
@ -1351,7 +1366,10 @@ gulp.task('mozcentralbaseline', ['baseline'], function (done) {
// Create a mozcentral build.
rimraf.sync(BASELINE_DIR + BUILD_DIR);
spawnSync('gulp', ['mozcentral', '--cwd', BASELINE_DIR], {env: process.env});
var workingDirectory = path.resolve(process.cwd(), BASELINE_DIR);
safeSpawnSync('gulp', ['mozcentral'],
{env: process.env, cwd: workingDirectory, stdio: 'inherit'});
// Copy the mozcentral build to the mozcentral baseline directory.
rimraf.sync(MOZCENTRAL_BASELINE_DIR);
@ -1361,10 +1379,10 @@ gulp.task('mozcentralbaseline', ['baseline'], function (done) {
.pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR))
.on('end', function () {
// Commit the mozcentral baseline.
spawnSync('git', ['init'], {cwd: MOZCENTRAL_BASELINE_DIR});
spawnSync('git', ['add', '.'], {cwd: MOZCENTRAL_BASELINE_DIR});
spawnSync('git', ['commit', '-m', 'mozcentral baseline'],
{cwd: MOZCENTRAL_BASELINE_DIR});
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();
});
});
@ -1384,8 +1402,8 @@ gulp.task('mozcentraldiff', ['mozcentral', 'mozcentralbaseline'],
gulp.src([BUILD_DIR + 'mozcentral/**/*'])
.pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR))
.on('end', function () {
spawnSync('git', ['add', '-A'], {cwd: MOZCENTRAL_BASELINE_DIR});
var diff = spawnSync('git',
safeSpawnSync('git', ['add', '-A'], {cwd: MOZCENTRAL_BASELINE_DIR});
var diff = safeSpawnSync('git',
['diff', '--binary', '--cached', '--unified=8'],
{cwd: MOZCENTRAL_BASELINE_DIR}).stdout;
@ -1398,39 +1416,3 @@ gulp.task('mozcentraldiff', ['mozcentral', 'mozcentralbaseline'],
});
});
});
// Getting all shelljs registered tasks and register them with gulp
require('./make.js');
var gulpContext = false;
for (var taskName in global.target) {
if (taskName in gulp.tasks) {
continue;
}
var task = (function (shellJsTask) {
return function () {
gulpContext = true;
try {
shellJsTask.call(global.target);
} finally {
gulpContext = false;
}
};
})(global.target[taskName]);
gulp.task(taskName, task);
}
Object.keys(gulp.tasks).forEach(function (taskName) {
var oldTask = global.target[taskName] || function () {
gulp.run(taskName);
};
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);
}
};
});

267
make.js
View File

@ -1,267 +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) {
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() {
execGulp('mozcentralbaseline');
};
target.mozcentraldiff = function() {
execGulp('mozcentraldiff');
};
////////////////////////////////////////////////////////////////////////////////
//
// 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');
};