diff --git a/gulpfile.js b/gulpfile.js index fce122e4e4c8a..d4f32bcfdcaad 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -30,14 +30,15 @@ var runSequence = require('run-sequence'); var stream = require('stream'); var exec = require('child_process').exec; var spawn = require('child_process').spawn; +var spawnSync = require('child_process').spawnSync; var streamqueue = require('streamqueue'); var merge = require('merge-stream'); var zip = require('gulp-zip'); var webpack2 = require('webpack'); var webpackStream = require('webpack-stream'); +var vinyl = require('vinyl-fs'); var BUILD_DIR = 'build/'; -var JSDOC_DIR = 'jsdoc/'; var L10N_DIR = 'l10n/'; var TEST_DIR = 'test/'; var EXTENSION_SRC_DIR = 'extensions/'; @@ -48,11 +49,16 @@ var COMPONENTS_DIR = BUILD_DIR + 'components/'; var SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/'; var MINIFIED_DIR = BUILD_DIR + 'minified/'; var FIREFOX_BUILD_DIR = BUILD_DIR + 'firefox/'; +var CHROME_BUILD_DIR = BUILD_DIR + 'chromium/'; +var JSDOC_BUILD_DIR = BUILD_DIR + 'jsdoc/'; +var GH_PAGES_DIR = BUILD_DIR + 'gh-pages/'; var COMMON_WEB_FILES = [ 'web/images/*.{png,svg,gif,cur}', 'web/debugger.js' ]; +var REPO = 'git@github.com:mozilla/pdf.js.git'; + var builder = require('./external/builder/builder.js'); var CONFIG_FILE = 'pdfjs.config'; @@ -287,6 +293,12 @@ function checkDir(path) { } } +function replaceInFile(path, find, replacement) { + var content = fs.readFileSync(path).toString(); + content = content.replace(find, replacement); + fs.writeFileSync(path, content); +} + function getTempFile(prefix, suffix) { mkdirp.sync(BUILD_DIR + 'tmp/'); var bytes = require('crypto').randomBytes(6).toString('hex'); @@ -926,10 +938,9 @@ gulp.task('jsdoc', function (done) { 'src/core/annotation.js' ]; - var directory = BUILD_DIR + JSDOC_DIR; - rimraf(directory, function () { - mkdirp(directory, function () { - var command = '"node_modules/.bin/jsdoc" -d ' + directory + ' ' + + rimraf(JSDOC_BUILD_DIR, function () { + mkdirp(JSDOC_BUILD_DIR, function () { + var command = '"node_modules/.bin/jsdoc" -d ' + JSDOC_BUILD_DIR + ' ' + JSDOC_FILES.join(' '); exec(command, done); }); @@ -1161,6 +1172,63 @@ gulp.task('importl10n', function(done) { locales.downloadL10n(L10N_DIR, done); }); +gulp.task('gh-pages-prepare', ['web-pre'], function () { + console.log(); + console.log('### Creating web site'); + + rimraf.sync(GH_PAGES_DIR); + + // 'vinyl' because web/viewer.html needs its BOM. + return merge([ + vinyl.src(GENERIC_DIR + '**/*', {base: GENERIC_DIR, stripBOM: false}) + .pipe(gulp.dest(GH_PAGES_DIR)), + gulp.src([FIREFOX_BUILD_DIR + '*.xpi', + FIREFOX_BUILD_DIR + '*.rdf']) + .pipe(gulp.dest(GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/')), + gulp.src(CHROME_BUILD_DIR + '*.crx') + .pipe(gulp.dest(GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chromium/')), + gulp.src('test/features/**/*', {base: 'test/'}) + .pipe(gulp.dest(GH_PAGES_DIR)), + gulp.src(JSDOC_BUILD_DIR + '**/*', {base: JSDOC_BUILD_DIR}) + .pipe(gulp.dest(GH_PAGES_DIR + 'api/draft/')), + ]); +}); + +gulp.task('wintersmith', ['gh-pages-prepare'], function (done) { + var wintersmith = require('wintersmith'); + var env = wintersmith('docs/config.json'); + env.build(GH_PAGES_DIR, function (error) { + if (error) { + return done(error); + } + replaceInFile(GH_PAGES_DIR + '/getting_started/index.html', + /STABLE_VERSION/g, config.stableVersion); + replaceInFile(GH_PAGES_DIR + '/getting_started/index.html', + /BETA_VERSION/g, config.betaVersion); + console.log('Done building with wintersmith.'); + done(); + }); +}); + +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', [ + '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}); + + console.log(); + console.log('Website built in ' + GH_PAGES_DIR); +}); + +gulp.task('web', ['gh-pages-prepare', 'wintersmith', 'gh-pages-git']); + // Getting all shelljs registered tasks and register them with gulp require('./make.js'); diff --git a/make.js b/make.js index 5dd9203bce0a4..17e396f7b5065 100644 --- a/make.js +++ b/make.js @@ -25,24 +25,15 @@ try { var fs = require('fs'); -var CONFIG_FILE = 'pdfjs.config'; -var config = JSON.parse(fs.readFileSync(CONFIG_FILE)); - var ROOT_DIR = __dirname + '/', // absolute path to project's root BUILD_DIR = 'build/', SRC_DIR = 'src/', - FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/', - CHROME_BUILD_DIR = BUILD_DIR + '/chromium/', - JSDOC_DIR = BUILD_DIR + 'jsdoc', - EXTENSION_SRC_DIR = 'extensions/', - GH_PAGES_DIR = BUILD_DIR + 'gh-pages/', GENERIC_DIR = BUILD_DIR + 'generic/', MINIFIED_DIR = BUILD_DIR + 'minified/', DIST_DIR = BUILD_DIR + 'dist/', SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/', COMPONENTS_DIR = BUILD_DIR + 'components/', - LIB_DIR = BUILD_DIR + 'lib/', - REPO = 'git@github.com:mozilla/pdf.js.git'; + LIB_DIR = BUILD_DIR + 'lib/'; function getCurrentVersion() { // The 'build/version.json' file is created by 'buildnumber' task. @@ -95,57 +86,7 @@ target.jsdoc = function() { // into place. // target.web = function() { - execGulp('web-pre'); - - cd(ROOT_DIR); - echo(); - echo('### Creating web site'); - - if (test('-d', GH_PAGES_DIR)) { - rm('-rf', GH_PAGES_DIR); - } - - 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'); - mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chromium'); - mkdir('-p', GH_PAGES_DIR + '/api/draft/'); - mkdir('-p', GH_PAGES_DIR + '/examples/'); - - cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR); - cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf', - GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/'); - cp(CHROME_BUILD_DIR + '/*.crx', FIREFOX_BUILD_DIR + '/*.rdf', - GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chromium/'); - cp('-R', 'test/features', GH_PAGES_DIR); - cp('-R', JSDOC_DIR + '/*', GH_PAGES_DIR + '/api/draft/'); - - var wintersmith = require('wintersmith'); - 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.'); - - var VERSION = getCurrentVersion(); - var reason = process.env['PDFJS_UPDATE_REASON']; - cd(GH_PAGES_DIR); - exec('git init'); - exec('git remote add origin ' + REPO); - exec('git add -A'); - exec('git commit -am "gh-pages site created via make.js script" -m ' + - '"PDF.js version ' + VERSION + (reason ? ' - ' + reason : '') + '"'); - exec('git branch -m gh-pages'); - - echo(); - echo('Website built in ' + GH_PAGES_DIR); - }); + execGulp('web'); }; target.dist = function() { diff --git a/package.json b/package.json index cc4f3352ad683..1ce96875f9539 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,9 @@ "streamqueue": "^1.1.1", "systemjs": "^0.20.7", "systemjs-plugin-babel": "0.0.21", - "typogr": "~0.6.5", + "typogr": "^0.6.6", "uglify-js": "^2.6.1", + "vinyl-fs": "^2.4.4", "webpack": "^2.2.1", "webpack-stream": "^3.2.0", "wintersmith": "^2.0.0",