Using ShellJS
This commit is contained in:
parent
6c24a75340
commit
f6ba3843bd
26
external/shelljs/LICENSE
vendored
Normal file
26
external/shelljs/LICENSE
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
Copyright (c) 2012, Artur Adib <aadib@mozilla.com>
|
||||
All rights reserved.
|
||||
|
||||
You may use this project under the terms of the New BSD license as follows:
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of Artur Adib nor the
|
||||
names of the contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
316
external/shelljs/README.md
vendored
Normal file
316
external/shelljs/README.md
vendored
Normal file
@ -0,0 +1,316 @@
|
||||
# ShellJS - Unix shell commands for Node.js [![Build Status](https://secure.travis-ci.org/arturadib/shelljs.png)](http://travis-ci.org/arturadib/shelljs)
|
||||
|
||||
ShellJS is a **portable** (Windows included) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands.
|
||||
|
||||
The project is both [unit-tested](http://travis-ci.org/arturadib/shelljs) and battle-tested at Mozilla's [pdf.js](http://github.com/mozilla/pdf.js).
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
require('shelljs/global');
|
||||
|
||||
// Copy files to release dir
|
||||
mkdir('-p', 'out/Release');
|
||||
cp('-R', 'lib/*.js', 'out/Release');
|
||||
|
||||
// Replace macros in each .js file
|
||||
cd('lib');
|
||||
for (file in ls('*.js')) {
|
||||
sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
|
||||
sed('-i', /.*REMOVE_THIS_LINE.*\n/, '', file);
|
||||
sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file);
|
||||
}
|
||||
cd('..');
|
||||
|
||||
// Run external tool synchronously
|
||||
if (exec('git commit -am "Auto-commit"').code !== 0) {
|
||||
echo('Error: Git commit failed');
|
||||
exit(1);
|
||||
}
|
||||
```
|
||||
|
||||
### Global vs. Local
|
||||
|
||||
The example above uses the convenience script `shelljs/global` to reduce verbosity. If polluting your global namespace is not desirable, simply require `shelljs`.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var shell = require('shelljs');
|
||||
shell.echo('hello world');
|
||||
```
|
||||
|
||||
### Make tool
|
||||
|
||||
A convenience script `shelljs/make` is also provided to mimic the behavior of a Unix Makefile. In this case all shell objects are global, and command line arguments will cause the script to execute only the corresponding function in the global `target` object. To avoid redundant calls, target functions are executed only once per script.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
//
|
||||
// Example file: make.js
|
||||
//
|
||||
require('shelljs/make');
|
||||
|
||||
target.all = function() {
|
||||
target.bundle();
|
||||
target.docs();
|
||||
}
|
||||
|
||||
// Bundle JS files
|
||||
target.bundle = function() {
|
||||
cd(__dirname);
|
||||
mkdir('build');
|
||||
cd('lib');
|
||||
cat('*.js').to('../build/output.js');
|
||||
}
|
||||
|
||||
// Generate docs
|
||||
target.docs = function() {
|
||||
cd(__dirname);
|
||||
mkdir('docs');
|
||||
cd('lib');
|
||||
for (file in ls('*.js')) {
|
||||
var text = grep('//@', file); // extract special comments
|
||||
text.replace('//@', ''); // remove comment tags
|
||||
text.to('docs/my_docs.md');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To run the target `all`, call the above script without arguments: `$ node make`. To run the target `docs`: `$ node make docs`, and so on.
|
||||
|
||||
### Installing
|
||||
|
||||
Via npm:
|
||||
|
||||
```bash
|
||||
$ npm install shelljs
|
||||
```
|
||||
|
||||
Or simply copy `shell.js` into your project's directory, and `require()` accordingly.
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
DO NOT MODIFY BEYOND THIS POINT - IT'S AUTOMATICALLY GENERATED
|
||||
|
||||
-->
|
||||
|
||||
|
||||
# Command reference
|
||||
|
||||
|
||||
All commands run synchronously, unless otherwise stated.
|
||||
|
||||
|
||||
#### cd('dir')
|
||||
Changes to directory `dir` for the duration of the script
|
||||
|
||||
#### pwd()
|
||||
Returns the current directory.
|
||||
|
||||
#### ls([options ,] path [,path ...])
|
||||
#### ls([options ,] path_array)
|
||||
Available options:
|
||||
|
||||
+ `-R`: recursive
|
||||
+ `-a`: all files (include files beginning with `.`)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
ls('projs/*.js');
|
||||
ls('-R', '/users/me', '/tmp');
|
||||
ls('-R', ['/users/me', '/tmp']); // same as above
|
||||
```
|
||||
|
||||
Returns list of files in the given path, or in current directory if no path provided.
|
||||
For convenient iteration via `for (file in ls())`, the format returned is a hash object:
|
||||
`{ 'file1':null, 'dir1/file2':null, ...}`.
|
||||
|
||||
#### cp('[options ,] source [,source ...], dest')
|
||||
#### cp('[options ,] source_array, dest')
|
||||
Available options:
|
||||
|
||||
+ `-f`: force
|
||||
+ `-r, -R`: recursive
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
cp('file1', 'dir1');
|
||||
cp('-Rf', '/tmp/*', '/usr/local/*', '/home/tmp');
|
||||
cp('-Rf', ['/tmp/*', '/usr/local/*'], '/home/tmp'); // same as above
|
||||
```
|
||||
|
||||
Copies files. The wildcard `*` is accepted.
|
||||
|
||||
#### rm([options ,] file [, file ...])
|
||||
#### rm([options ,] file_array)
|
||||
Available options:
|
||||
|
||||
+ `-f`: force
|
||||
+ `-r, -R`: recursive
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
rm('-rf', '/tmp/*');
|
||||
rm('some_file.txt', 'another_file.txt');
|
||||
rm(['some_file.txt', 'another_file.txt']); // same as above
|
||||
```
|
||||
|
||||
Removes files. The wildcard `*` is accepted.
|
||||
|
||||
#### mv(source [, source ...], dest')
|
||||
#### mv(source_array, dest')
|
||||
Available options:
|
||||
|
||||
+ `f`: force
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
mv('-f', 'file', 'dir/');
|
||||
mv('file1', 'file2', 'dir/');
|
||||
mv(['file1', 'file2'], 'dir/'); // same as above
|
||||
```
|
||||
|
||||
Moves files. The wildcard `*` is accepted.
|
||||
|
||||
#### mkdir([options ,] dir [, dir ...])
|
||||
#### mkdir([options ,] dir_array)
|
||||
Available options:
|
||||
|
||||
+ `p`: full path (will create intermediate dirs if necessary)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
mkdir('-p', '/tmp/a/b/c/d', '/tmp/e/f/g');
|
||||
mkdir('-p', ['/tmp/a/b/c/d', '/tmp/e/f/g']); // same as above
|
||||
```
|
||||
|
||||
Creates directories.
|
||||
|
||||
#### cat(file [, file ...])
|
||||
#### cat(file_array)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var str = cat('file*.txt');
|
||||
var str = cat('file1', 'file2');
|
||||
var str = cat(['file1', 'file2']); // same as above
|
||||
```
|
||||
|
||||
Returns a string containing the given file, or a concatenated string
|
||||
containing the files if more than one file is given (a new line character is
|
||||
introduced between each file). Wildcard `*` accepted.
|
||||
|
||||
#### 'string'.to(file)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
cat('input.txt').to('output.txt');
|
||||
```
|
||||
|
||||
Analogous to the redirection operator `>` in Unix, but works with JavaScript strings (such as
|
||||
those returned by `cat`, `grep`, etc). _Like Unix redirections, `to()` will overwrite any existing file!_
|
||||
|
||||
#### sed([options ,] search_regex, replace_str, file)
|
||||
Available options:
|
||||
|
||||
+ `-i`: Replace contents of 'file' in-place. _Note that no backups will be created!_
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
sed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js');
|
||||
sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js');
|
||||
```
|
||||
|
||||
Reads an input string from `file` and performs a JavaScript `replace()` on the input
|
||||
using the given search regex and replacement string. Returns the new string after replacement.
|
||||
|
||||
#### grep(regex_filter, file [, file ...])
|
||||
#### grep(regex_filter, file_array)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
grep('GLOBAL_VARIABLE', '*.js');
|
||||
```
|
||||
|
||||
Reads input string from given files and returns a string containing all lines of the
|
||||
file that match the given `regex_filter`. Wildcard `*` accepted.
|
||||
|
||||
#### which(command)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var nodeExec = which('node');
|
||||
```
|
||||
|
||||
Searches for `command` in the system's PATH. On Windows looks for `.exe`, `.cmd`, and `.bat` extensions.
|
||||
Returns string containing the absolute path to the command.
|
||||
|
||||
#### echo(string [,string ...])
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
echo('hello world');
|
||||
var str = echo('hello world');
|
||||
```
|
||||
|
||||
Prints string to stdout, and returns string with additional utility methods
|
||||
like `.to()`.
|
||||
|
||||
#### exit(code)
|
||||
Exits the current process with the given exit code.
|
||||
|
||||
#### env['VAR_NAME']
|
||||
Object containing environment variables (both getter and setter). Shortcut to process.env.
|
||||
|
||||
#### exec(command [, options] [, callback])
|
||||
Available options (all `false` by default):
|
||||
|
||||
+ `async`: Asynchronous execution. Needs callback.
|
||||
+ `silent`: Do not echo program output to console.
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var version = exec('node --version', {silent:true}).output;
|
||||
```
|
||||
|
||||
Executes the given `command` _synchronously_, unless otherwise specified.
|
||||
When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's
|
||||
`output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the
|
||||
arguments `(code, output)`.
|
||||
|
||||
## Non-Unix commands
|
||||
|
||||
|
||||
#### tempdir()
|
||||
Searches and returns string containing a writeable, platform-dependent temporary directory.
|
||||
Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
|
||||
|
||||
#### exists(path [, path ...])
|
||||
#### exists(path_array)
|
||||
Returns true if all the given paths exist.
|
||||
|
||||
#### error()
|
||||
Tests if error occurred in the last command. Returns `null` if no error occurred,
|
||||
otherwise returns string explaining the error
|
||||
|
||||
#### verbose()
|
||||
Enables all output (default)
|
||||
|
||||
#### silent()
|
||||
Suppresses all output, except for explict `echo()` calls
|
3
external/shelljs/global.js
vendored
Normal file
3
external/shelljs/global.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
var shell = require('./shell.js');
|
||||
for (cmd in shell)
|
||||
global[cmd] = shell[cmd];
|
46
external/shelljs/make.js
vendored
Normal file
46
external/shelljs/make.js
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
require('./global');
|
||||
|
||||
global.target = {};
|
||||
|
||||
// This ensures we only execute the script targets after the entire script has
|
||||
// been evaluated
|
||||
var args = process.argv.slice(2);
|
||||
setTimeout(function() {
|
||||
|
||||
if (args.length === 1 && args[0] === '--help') {
|
||||
console.log('Available targets:');
|
||||
for (t in target)
|
||||
console.log(' ' + t);
|
||||
return;
|
||||
}
|
||||
|
||||
// Wrap targets to prevent duplicate execution
|
||||
for (t in target) {
|
||||
(function(t, oldTarget){
|
||||
|
||||
// Wrap it
|
||||
target[t] = function(force) {
|
||||
if (oldTarget.done && !force)
|
||||
return;
|
||||
oldTarget.done = true;
|
||||
return oldTarget(arguments);
|
||||
}
|
||||
|
||||
})(t, target[t]);
|
||||
}
|
||||
|
||||
// Execute desired targets
|
||||
if (args.length > 0) {
|
||||
args.forEach(function(arg) {
|
||||
if (arg in target)
|
||||
target[arg]();
|
||||
else {
|
||||
console.log('no such target: ' + arg);
|
||||
exit(1);
|
||||
}
|
||||
});
|
||||
} else if ('all' in target) {
|
||||
target.all();
|
||||
}
|
||||
|
||||
}, 0);
|
12
external/shelljs/package.json
vendored
Normal file
12
external/shelljs/package.json
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{ "name": "shelljs"
|
||||
, "version": "0.0.2pre1"
|
||||
, "author": "Artur Adib <aadib@mozilla.com>"
|
||||
, "description": "Portable Unix shell commands for Node.js"
|
||||
, "keywords": ["unix", "shell", "makefile", "make", "jake", "synchronous"]
|
||||
, "repository": "git://github.com/arturadib/shelljs"
|
||||
, "homepage": "http://github.com/arturadib/shelljs"
|
||||
, "main": "./shell.js"
|
||||
, "scripts": {
|
||||
"test": "node scripts/run-tests"
|
||||
}
|
||||
}
|
1207
external/shelljs/shell.js
vendored
Normal file
1207
external/shelljs/shell.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
401
make.js
Executable file
401
make.js
Executable file
@ -0,0 +1,401 @@
|
||||
#!/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/',
|
||||
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.extension();
|
||||
target.pagesrepo();
|
||||
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Creating web site');
|
||||
|
||||
cp(BUILD_TARGET, GH_PAGES_DIR+BUILD_TARGET);
|
||||
cp('-R', 'web/*', 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 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',
|
||||
'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'];
|
||||
|
||||
if (!exists(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 <script> tags in our web viewer to use only 'pdf.js'.
|
||||
// Produces 'viewer-production.html'
|
||||
//
|
||||
target.viewer = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Generating production-level viewer');
|
||||
|
||||
cd('web');
|
||||
// Remove development lines
|
||||
sed(/.*PDFJSSCRIPT_REMOVE_CORE.*\n/g, '', 'viewer.html').to('viewer-production.html');
|
||||
// Introduce snippet
|
||||
sed('-i', /.*PDFJSSCRIPT_INCLUDE_BUILD.*\n/g, cat('viewer-snippet.html'), 'viewer-production.html');
|
||||
}
|
||||
|
||||
//
|
||||
// make pagesrepo
|
||||
//
|
||||
// This target clones the gh-pages repo into the build directory. It deletes the current contents
|
||||
// of the repo, since we overwrite everything with data from the master repo. The 'make web' target
|
||||
// then uses 'git add -A' to track additions, modifications, moves, and deletions.
|
||||
target.pagesrepo = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Creating fresh clone of gh-pages');
|
||||
|
||||
if (!exists(BUILD_DIR))
|
||||
mkdir(BUILD_DIR);
|
||||
|
||||
if (!exists(GH_PAGES_DIR)) {
|
||||
echo();
|
||||
echo('Cloning project repo...');
|
||||
echo('(This operation can take a while, depending on network conditions)');
|
||||
exec('git clone -b gh-pages --depth=1 '+REPO+' '+GH_PAGES_DIR, {silent:true});
|
||||
echo('Done.');
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Extension stuff
|
||||
//
|
||||
|
||||
var EXTENSION_WEB_FILES =
|
||||
['web/images',
|
||||
'web/viewer.css',
|
||||
'web/viewer.js',
|
||||
'web/viewer.html',
|
||||
'web/viewer-production.html'],
|
||||
EXTENSION_BASE_VERSION = '4bb289ec499013de66eb421737a4dbb4a9273eda',
|
||||
EXTENSION_BUILD_NUMBER;
|
||||
|
||||
//
|
||||
// make extension
|
||||
//
|
||||
target.extension = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Building extensions');
|
||||
|
||||
target.production();
|
||||
target.firefox();
|
||||
target.chrome();
|
||||
}
|
||||
|
||||
target.buildnumber = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Getting extension build number');
|
||||
|
||||
// Build number is the number of commits since base version
|
||||
EXTENSION_BUILD_NUMBER = exec('git log --format=oneline '+EXTENSION_BASE_VERSION+'..', {silent:true})
|
||||
.output.match(/\n/g).length; // get # of lines in git output
|
||||
|
||||
echo('Extension build number: ' + EXTENSION_BUILD_NUMBER);
|
||||
}
|
||||
|
||||
//
|
||||
// make firefox
|
||||
//
|
||||
target.firefox = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Building Firefox extension');
|
||||
|
||||
var FIREFOX_BUILD_CONTENT_DIR = FIREFOX_BUILD_DIR+'/content/',
|
||||
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR+'/firefox/content/',
|
||||
FIREFOX_EXTENSION_FILES_TO_COPY =
|
||||
['*.js',
|
||||
'*.rdf',
|
||||
'components'];
|
||||
FIREFOX_EXTENSION_FILES =
|
||||
['content',
|
||||
'*.js',
|
||||
'install.rdf',
|
||||
'components',
|
||||
'content'];
|
||||
FIREFOX_EXTENSION_NAME = 'pdf.js.xpi',
|
||||
FIREFOX_AMO_EXTENSION_NAME = 'pdf.js.amo.xpi';
|
||||
|
||||
target.production();
|
||||
target.buildnumber();
|
||||
cd(ROOT_DIR);
|
||||
|
||||
// Clear out everything in the firefox extension build directory
|
||||
rm('-rf', FIREFOX_BUILD_DIR);
|
||||
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR);
|
||||
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR+BUILD_DIR);
|
||||
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR+'/web');
|
||||
|
||||
// Copy extension files
|
||||
cd('extensions/firefox');
|
||||
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY, ROOT_DIR+FIREFOX_BUILD_DIR);
|
||||
cd(ROOT_DIR);
|
||||
|
||||
// Copy a standalone version of pdf.js inside the content directory
|
||||
cp(BUILD_TARGET, FIREFOX_BUILD_CONTENT_DIR+BUILD_DIR);
|
||||
cp('-R', EXTENSION_WEB_FILES, FIREFOX_BUILD_CONTENT_DIR+'/web');
|
||||
rm(FIREFOX_BUILD_CONTENT_DIR+'/web/viewer-production.html');
|
||||
|
||||
// Copy over the firefox extension snippet so we can inline pdf.js in it
|
||||
cp('web/viewer-snippet-firefox-extension.html', FIREFOX_BUILD_CONTENT_DIR+'/web');
|
||||
|
||||
// Modify the viewer so it does all the extension-only stuff.
|
||||
cd(FIREFOX_BUILD_CONTENT_DIR+'/web');
|
||||
sed('-i', /.*PDFJSSCRIPT_INCLUDE_BUNDLE.*\n/, cat(ROOT_DIR+BUILD_TARGET), 'viewer-snippet-firefox-extension.html');
|
||||
sed('-i', /.*PDFJSSCRIPT_REMOVE_CORE.*\n/g, '', 'viewer.html');
|
||||
sed('-i', /.*PDFJSSCRIPT_REMOVE_FIREFOX_EXTENSION.*\n/g, '', 'viewer.html');
|
||||
sed('-i', /.*PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION.*\n/, cat('viewer-snippet-firefox-extension.html'), 'viewer.html');
|
||||
cd(ROOT_DIR);
|
||||
|
||||
// We don't need pdf.js anymore since its inlined
|
||||
rm('-Rf', FIREFOX_BUILD_CONTENT_DIR+BUILD_DIR);
|
||||
|
||||
// Update the build version number
|
||||
sed('-i', /PDFJSSCRIPT_BUILD/, EXTENSION_BUILD_NUMBER, FIREFOX_BUILD_DIR+'/install.rdf');
|
||||
sed('-i', /PDFJSSCRIPT_BUILD/, EXTENSION_BUILD_NUMBER, FIREFOX_BUILD_DIR+'/update.rdf');
|
||||
|
||||
// Create the xpi
|
||||
cd(FIREFOX_BUILD_DIR);
|
||||
exec('zip -r '+FIREFOX_EXTENSION_NAME+' '+FIREFOX_EXTENSION_FILES.join(' '));
|
||||
echo('extension created: ' + FIREFOX_EXTENSION_NAME);
|
||||
cd(ROOT_DIR);
|
||||
|
||||
// Build the amo extension too (remove the updateUrl)
|
||||
cd(FIREFOX_BUILD_DIR);
|
||||
sed('-i', /.*updateURL.*\n/, '', 'install.rdf');
|
||||
exec('zip -r '+FIREFOX_AMO_EXTENSION_NAME+' '+FIREFOX_EXTENSION_FILES.join(' '));
|
||||
echo('AMO extension created: ' + FIREFOX_AMO_EXTENSION_NAME);
|
||||
cd(ROOT_DIR);
|
||||
}
|
||||
|
||||
//
|
||||
// make chrome
|
||||
//
|
||||
target.chrome = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Building Chrome extension');
|
||||
|
||||
var CHROME_BUILD_DIR = BUILD_DIR+'/chrome/',
|
||||
CHROME_CONTENT_DIR = EXTENSION_SRC_DIR+'/chrome/content/',
|
||||
CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR+'/content/',
|
||||
CHROME_EXTENSION_FILES =
|
||||
['extensions/chrome/*.json',
|
||||
'extensions/chrome/*.html'];
|
||||
|
||||
target.production();
|
||||
target.buildnumber();
|
||||
cd(ROOT_DIR);
|
||||
|
||||
// Clear out everything in the chrome extension build directory
|
||||
rm('-Rf', CHROME_BUILD_DIR);
|
||||
mkdir('-p', CHROME_BUILD_CONTENT_DIR);
|
||||
mkdir('-p', CHROME_BUILD_CONTENT_DIR+BUILD_DIR);
|
||||
mkdir('-p', CHROME_BUILD_CONTENT_DIR+'/web');
|
||||
|
||||
// Copy extension files
|
||||
cp('-R', CHROME_EXTENSION_FILES, CHROME_BUILD_DIR);
|
||||
|
||||
// Copy a standalone version of pdf.js inside the content directory
|
||||
cp(BUILD_TARGET, CHROME_BUILD_CONTENT_DIR+BUILD_DIR);
|
||||
cp('-R', EXTENSION_WEB_FILES, CHROME_BUILD_CONTENT_DIR+'/web');
|
||||
mv('-f', CHROME_BUILD_CONTENT_DIR+'/web/viewer-production.html', CHROME_BUILD_CONTENT_DIR+'/web/viewer.html');
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Test stuff
|
||||
//
|
||||
|
||||
//
|
||||
// make test
|
||||
//
|
||||
target.test = function() {
|
||||
target.browsertest();
|
||||
target.unittest();
|
||||
}
|
||||
|
||||
//
|
||||
// make browsertest
|
||||
//
|
||||
target.browsertest = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Running browser tests');
|
||||
|
||||
var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json',
|
||||
PDF_BROWSERS = env['PDF_BROWSERS'] || 'resources/browser_manifests/browser_manifest.json';
|
||||
|
||||
if (!exists('test/'+PDF_BROWSERS)) {
|
||||
echo('Browser manifest file test/'+PDF_BROWSERS+' does not exist.');
|
||||
echo('Try copying one of the examples in test/resources/browser_manifests/');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cd('test');
|
||||
exec(PYTHON_BIN+' test.py --reftest --browserManifestFile='+PDF_BROWSERS+' --manifestFile='+PDF_TEST, {async:true});
|
||||
}
|
||||
|
||||
//
|
||||
// make unittest
|
||||
//
|
||||
target.unittest = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Running unit tests');
|
||||
|
||||
cd('test/unit');
|
||||
exec('make', {async:true});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Other
|
||||
//
|
||||
|
||||
//
|
||||
// make server
|
||||
//
|
||||
target.server = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Starting local server');
|
||||
|
||||
cd('test');
|
||||
exec(PYTHON_BIN+' -u test.py --port=8888', {async:true});
|
||||
}
|
||||
|
||||
//
|
||||
// make lint
|
||||
//
|
||||
target.lint = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Linting JS files (this can take a while!)');
|
||||
|
||||
var LINT_FILES = 'src/*.js \
|
||||
web/*.js \
|
||||
test/*.js \
|
||||
test/unit/*.js \
|
||||
extensions/firefox/*.js \
|
||||
extensions/firefox/components/*.js \
|
||||
extensions/chrome/*.js';
|
||||
|
||||
exec('gjslint --nojsdoc '+LINT_FILES);
|
||||
}
|
||||
|
||||
//
|
||||
// make clean
|
||||
//
|
||||
target.clean = function() {
|
||||
cd(ROOT_DIR);
|
||||
echo();
|
||||
echo('### Cleaning up project builds');
|
||||
|
||||
rm('-rf', BUILD_DIR);
|
||||
}
|
Loading…
Reference in New Issue
Block a user