#!/usr/bin/env node require('./external/shelljs/make'); var ROOT_DIR = __dirname + '/', // absolute path to project's root BUILD_DIR = 'build/', BUILD_TARGET = BUILD_DIR + 'pdf.js', FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/', EXTENSION_SRC_DIR = 'extensions/', LOCALE_SRC_DIR = 'l10n/', GH_PAGES_DIR = BUILD_DIR + 'gh-pages/', REPO = 'git@github.com:mozilla/pdf.js.git', PYTHON_BIN = 'python2.7'; // // make all // target.all = function() { // Don't do anything by default echo('Please specify a target. Available targets:'); for (t in target) if (t !== 'all') echo(' ' + t); }; /////////////////////////////////////////////////////////////////////////////////////////// // // Production stuff // // // 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() { target.production(); target.locale(); target.extension(); target.pagesrepo(); cd(ROOT_DIR); echo(); echo('### Creating web site'); var GH_PAGES_SRC_FILES = [ 'web/*', 'external/webL10n/l10n.js' ]; cp(BUILD_TARGET, GH_PAGES_DIR + BUILD_TARGET); cp('-R', GH_PAGES_SRC_FILES, GH_PAGES_DIR + '/web'); cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf', GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/'); cp(GH_PAGES_DIR + '/web/index.html.template', GH_PAGES_DIR + '/index.html'); mv('-f', GH_PAGES_DIR + '/web/viewer-production.html', GH_PAGES_DIR + '/web/viewer.html'); cd(GH_PAGES_DIR); exec('git add -A'); echo(); echo("Website built in " + GH_PAGES_DIR); echo("Don't forget to cd into " + GH_PAGES_DIR + " and issue 'git commit' to push changes."); }; // // make locale // Creates localized resources for the viewer and extension. // target.locale = function() { var METADATA_OUTPUT = 'extensions/firefox/metadata.inc'; var CHROME_MANIFEST_OUTPUT = 'extensions/firefox/chrome.manifest.inc'; var EXTENSION_LOCALE_OUTPUT = 'extensions/firefox/locale'; var VIEWER_OUTPUT = 'web/locale.properties'; var DEFAULT_LOCALE = 'en-US'; cd(ROOT_DIR); echo(); echo('### Building localization files'); rm('-rf', EXTENSION_LOCALE_OUTPUT); mkdir('-p', EXTENSION_LOCALE_OUTPUT); var subfolders = ls(LOCALE_SRC_DIR); subfolders.sort(); var metadataContent = ''; var chromeManifestContent = ''; var viewerOutput = ''; for (var i = 0; i < subfolders.length; i++) { var locale = subfolders[i]; var path = LOCALE_SRC_DIR + locale; if (!test('-d', path)) continue; if (!/^[a-z][a-z](-[A-Z][A-Z])?$/.test(locale)) { echo('Skipping invalid locale: ' + locale); continue; } mkdir('-p', EXTENSION_LOCALE_OUTPUT + '/' + locale); chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' + locale + '/\n'; if (test('-f', path + '/viewer.properties')) { var properties = cat(path + '/viewer.properties'); viewerOutput += '[' + locale + ']\n' + properties + '\n'; cp(path + '/viewer.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale); } if (test('-f', path + '/chrome.properties')) { cp(path + '/chrome.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale); } if (test('-f', path + '/metadata.inc')) { var metadata = cat(path + '/metadata.inc'); metadataContent += metadata; } } viewerOutput.to(VIEWER_OUTPUT); metadataContent.to(METADATA_OUTPUT); chromeManifestContent.to(CHROME_MANIFEST_OUTPUT); }; // // make production // Creates production output (pdf.js, and corresponding changes to web/ files) // target.production = function() { target.bundle(); target.viewer(); }; // // make bundle // Bundles all source files into one wrapper 'pdf.js' file, in the given order. // target.bundle = function() { cd(ROOT_DIR); echo(); echo('### Bundling files into ' + BUILD_TARGET); // File order matters var SRC_FILES = ['core.js', 'util.js', 'api.js', 'canvas.js', 'obj.js', 'function.js', 'charsets.js', 'cidmaps.js', 'colorspace.js', 'crypto.js', 'evaluator.js', 'fonts.js', 'glyphlist.js', 'image.js', 'metrics.js', 'parser.js', 'pattern.js', 'stream.js', 'worker.js', '../external/jpgjs/jpg.js', 'jpx.js', 'bidi.js', 'metadata.js']; if (!test('-d', BUILD_DIR)) mkdir(BUILD_DIR); cd('src'); var bundle = cat(SRC_FILES), bundleVersion = exec('git log --format="%h" -n 1', {silent: true}).output.replace('\n', ''); sed(/.*PDFJSSCRIPT_INCLUDE_ALL.*\n/, bundle, 'pdf.js') .to(ROOT_DIR + BUILD_TARGET); sed('-i', 'PDFJSSCRIPT_BUNDLE_VER', bundleVersion, ROOT_DIR + BUILD_TARGET); }; // // make viewer // Changes development