Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate make.js to gulpfile.js #8349

Merged
merged 4 commits into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 85 additions & 51 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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/';
Expand All @@ -58,6 +59,7 @@ var COMMON_WEB_FILES = [
'web/images/*.{png,svg,gif,cur}',
'web/debugger.js'
];
var MOZCENTRAL_DIFF_FILE = 'mozcentral.diff';

var REPO = '[email protected]:mozilla/pdf.js.git';
var DIST_REPO_URL = 'https://github.com/mozilla/pdfjs-dist';
Expand All @@ -81,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 () {
Expand Down Expand Up @@ -677,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');
Expand Down Expand Up @@ -1042,10 +1059,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');
});
Expand Down Expand Up @@ -1222,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);
Expand All @@ -1245,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');
Expand Down Expand Up @@ -1333,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');
Expand All @@ -1347,38 +1360,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);
}

Object.keys(gulp.tasks).forEach(function (taskName) {
var oldTask = global.target[taskName] || function () {
gulp.run(taskName);
};
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);
mkdirp.sync(MOZCENTRAL_BASELINE_DIR);

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();
});
});

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.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();
});
});
});
Loading