You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/05/14 02:09:49 UTC
[07/24] git commit: CB-5816 add build --release
CB-5816 add build --release
Project: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/commit/a11ffb20
Tree: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/tree/a11ffb20
Diff: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/diff/a11ffb20
Branch: refs/heads/master
Commit: a11ffb2056c2952a5ded71d5229eb690936ac870
Parents: 650e29e
Author: braas <br...@steckelfisch.nl>
Authored: Tue Mar 18 14:50:24 2014 +0100
Committer: braas <br...@steckelfisch.nl>
Committed: Tue Mar 18 14:50:24 2014 +0100
----------------------------------------------------------------------
bin/lib/create.js | 30 +-
bin/templates/project/cordova/build | 30 +-
bin/templates/project/cordova/clean | 38 +
bin/templates/project/cordova/lib/build.js | 138 ++
bin/templates/project/cordova/lib/clean.js | 46 +
.../project/cordova/node_modules/.bin/shjs | 1 +
.../adm-zip/.idea/scopes/scope_settings.xml | 5 +
.../node_modules/adm-zip/MIT-LICENSE.txt | 21 +
.../cordova/node_modules/adm-zip/README.md | 64 +
.../cordova/node_modules/adm-zip/adm-zip.js | 404 +++++
.../node_modules/adm-zip/headers/entryHeader.js | 261 +++
.../node_modules/adm-zip/headers/index.js | 2 +
.../node_modules/adm-zip/headers/mainHeader.js | 80 +
.../node_modules/adm-zip/methods/deflater.js | 1578 ++++++++++++++++++
.../node_modules/adm-zip/methods/index.js | 2 +
.../node_modules/adm-zip/methods/inflater.js | 448 +++++
.../cordova/node_modules/adm-zip/package.json | 43 +
.../attributes_test/New folder/hidden.txt | 17 +
.../New folder/hidden_readonly.txt | 17 +
.../attributes_test/New folder/readonly.txt | 17 +
.../attributes_test/New folder/somefile.txt | 17 +
.../attributes_test/asd/New Text Document.txt | 0
.../test/assets/attributes_test/blank file.txt | 0
.../cordova/node_modules/adm-zip/test/index.js | 5 +
.../node_modules/adm-zip/util/constants.js | 84 +
.../cordova/node_modules/adm-zip/util/errors.js | 35 +
.../cordova/node_modules/adm-zip/util/fattr.js | 84 +
.../cordova/node_modules/adm-zip/util/index.js | 4 +
.../cordova/node_modules/adm-zip/util/utils.js | 145 ++
.../cordova/node_modules/adm-zip/zipEntry.js | 224 +++
.../cordova/node_modules/adm-zip/zipFile.js | 311 ++++
.../node_modules/shelljs/.documentup.json | 6 +
.../cordova/node_modules/shelljs/.jshintrc | 7 +
.../cordova/node_modules/shelljs/.npmignore | 2 +
.../cordova/node_modules/shelljs/.travis.yml | 5 +
.../cordova/node_modules/shelljs/LICENSE | 26 +
.../cordova/node_modules/shelljs/README.md | 552 ++++++
.../cordova/node_modules/shelljs/bin/shjs | 51 +
.../cordova/node_modules/shelljs/global.js | 3 +
.../cordova/node_modules/shelljs/make.js | 47 +
.../cordova/node_modules/shelljs/package.json | 44 +
.../shelljs/scripts/generate-docs.js | 21 +
.../node_modules/shelljs/scripts/run-tests.js | 50 +
.../cordova/node_modules/shelljs/shell.js | 153 ++
.../cordova/node_modules/shelljs/src/cat.js | 43 +
.../cordova/node_modules/shelljs/src/cd.js | 19 +
.../cordova/node_modules/shelljs/src/chmod.js | 208 +++
.../cordova/node_modules/shelljs/src/common.js | 189 +++
.../cordova/node_modules/shelljs/src/cp.js | 200 +++
.../cordova/node_modules/shelljs/src/dirs.js | 191 +++
.../cordova/node_modules/shelljs/src/echo.js | 20 +
.../cordova/node_modules/shelljs/src/error.js | 10 +
.../cordova/node_modules/shelljs/src/exec.js | 181 ++
.../cordova/node_modules/shelljs/src/find.js | 51 +
.../cordova/node_modules/shelljs/src/grep.js | 52 +
.../cordova/node_modules/shelljs/src/ls.js | 126 ++
.../cordova/node_modules/shelljs/src/mkdir.js | 68 +
.../cordova/node_modules/shelljs/src/mv.js | 80 +
.../cordova/node_modules/shelljs/src/popd.js | 1 +
.../cordova/node_modules/shelljs/src/pushd.js | 1 +
.../cordova/node_modules/shelljs/src/pwd.js | 11 +
.../cordova/node_modules/shelljs/src/rm.js | 145 ++
.../cordova/node_modules/shelljs/src/sed.js | 43 +
.../cordova/node_modules/shelljs/src/tempdir.js | 56 +
.../cordova/node_modules/shelljs/src/test.js | 85 +
.../cordova/node_modules/shelljs/src/to.js | 29 +
.../cordova/node_modules/shelljs/src/toEnd.js | 29 +
.../cordova/node_modules/shelljs/src/which.js | 79 +
68 files changed, 7032 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index a5905c1..07372d7 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -26,6 +26,26 @@ var fs = require('fs'),
ROOT = path.join(__dirname, '..', '..'),
check_reqs = require('./check_reqs');
+/*
+try {
+ require.resolve("shelljs");
+ create();
+} catch(e) {
+ console.log('Shelljs module was not found, running \'npm install\'.....');
+ var exec = require('child_process').exec;
+ var cwd = process.cwd();
+ process.chdir(__dirname);
+ exec('npm install', function (error, stdout, stderr) {
+ if (error !== null) {
+ console.error('ERROR : running \'npm install\' is npm installed? ' + error);
+ console.error(stderr);
+ process.exit(error.code);
+ }
+ process.chdir(cwd);
+ create();
+ });
+*/
+
exports.createProject = function(project_path,package_name,project_name){
var VERSION = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8');
@@ -53,14 +73,22 @@ exports.createProject = function(project_path,package_name,project_name){
//copy template folder
shjs.cp('-r', path.join(ROOT, 'bin', 'templates', 'project', 'www'), project_path);
+
+ //copy check_reqs file ,creat bin/lip if it does not exist yet
+ if(!fs.existsSync(path.join(project_path,'cordova', 'lib'))) {
+ shjs.mkdir('-p', path.join(project_path,'cordova', 'lib'));
+ }
+ shjs.cp( path.join(ROOT, 'bin', 'lib', 'check_reqs.js'), path.join(project_path,'cordova', 'lib'));
//copy cordova js file
- shjs.cp('-r', path.join(ROOT, 'cordova-lib', 'cordova.js'), path.join(project_path,'www'));
+ shjs.cp('-r', path.join(ROOT, 'cordova-lib', 'cordova.js'), path.join(project_path,'www'));
//copy cordova folder
shjs.cp('-r', path.join(ROOT, 'bin', 'templates', 'project', 'cordova'), project_path);
[
'run',
+ 'build',
+ 'clean',
'version',
].forEach(function(f) {
shjs.chmod(755, path.join(project_path, 'cordova', f));
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/build
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/build b/bin/templates/project/cordova/build
index 9e85301..fa7408c 100755
--- a/bin/templates/project/cordova/build
+++ b/bin/templates/project/cordova/build
@@ -20,7 +20,33 @@
*/
-// Build is not implemented
+var path = require('path'),
+ build = require('./lib/build'),
+ reqs = require('./lib/check_reqs'),
+ args = process.argv;
+
+// provide help
+if( args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
+ args[2] == 'help' || args[2] == '-help' || args[2] == '/help') {
+ build.help();
+ process.exit(0);
+}
+
+// check for the correct argument count, the correct options
+if( (args.length > 3)
+ || (args[2] && ( (args[2] != '--debug')
+ && (args[2] != '--release')))) {
+ console.error('please only use --debug or --release as argument');
+ build.help();
+ process.exit(2);
+} else {
+ var buildOpt = 'debug';
+ //var buildTypeOpt = 'web';
+ if(args[2] && args[2] == '--release') {
+ buildOpt = 'release'
+ }
+
+ build.buildProject(buildOpt);
+}
-process.exit(1);
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/clean
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/clean b/bin/templates/project/cordova/clean
new file mode 100644
index 0000000..bb161fe
--- /dev/null
+++ b/bin/templates/project/cordova/clean
@@ -0,0 +1,38 @@
+#!/usr/bin/env node
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+*/
+
+
+var path = require('path'),
+ clean = require('./lib/clean'),
+ reqs = require('./lib/check_reqs'),
+ args = process.argv;
+
+// Support basic help commands
+if(args.length > 2
+ || args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
+ args[2] == 'help' || args[2] == '-help' || args[2] == '/help') {
+ console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'clean')) );
+ process.exit(0);
+} else {
+ clean.cleanProject();
+}
+
+
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/build.js b/bin/templates/project/cordova/lib/build.js
new file mode 100644
index 0000000..a088d24
--- /dev/null
+++ b/bin/templates/project/cordova/lib/build.js
@@ -0,0 +1,138 @@
+#!/usr/bin/env node
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+var path = require('path'),
+ fs = require('fs'),
+ clean = require('./clean'),
+ shjs = require('shelljs'),
+ zip = require('adm-zip'),
+ check_reqs = require('./check_reqs'),
+ buildDirInMerge ='build--release';
+
+function hasCustomReleaseArtifactsDir() {
+ return fs.existsSync('platforms/firefoxos/www/'+buildDirInMerge);
+}
+
+function hasAllRequiredCustomReleaseArtifacts() {
+ if(!fs.existsSync('platforms/firefoxos/www/'+buildDirInMerge+'/manifest.webapp')) {
+ console.error('\nPlease provide <project>/merges/firefoxos/'+buildDirInMerge+'/manifest.webapp');
+ }
+
+ if(!fs.existsSync('platforms/firefoxos/www/'+buildDirInMerge+'/index.html')) {
+ console.error('\nPlease provide <project>/merges/firefoxos/'+buildDirInMerge+'/index.html');
+ }
+
+ return ( fs.existsSync('platforms/firefoxos/www/'+buildDirInMerge+'/manifest.webapp')
+ && fs.existsSync('platforms/firefoxos/www/'+buildDirInMerge+'/index.html') );
+}
+
+function mergeMiniManifest() {
+ // console.log('pwd: '+shjs.pwd());
+ console.log('Merge (mini-)manifest.webapp provided at \'merges/firefoxos/'+buildDirInMerge+'/\'');
+ shjs.mv('-f' ,'platforms/firefoxos/www/'+buildDirInMerge+'/manifest.webapp', 'platforms/firefoxos/build/manifest.webapp');
+}
+
+function mergeIndexHtml() {
+ // console.log('pwd: '+shjs.pwd());
+ console.log('Merge index.html provided at \'merges/firefoxos/'+buildDirInMerge+'/\'');
+ shjs.mv('-f', 'platforms/firefoxos/www/'+buildDirInMerge+'/index.html', 'platforms/firefoxos/build/index.html');
+}
+
+// cordova merges merge/firefoxos to platforms/firefoxos/www
+// this removes the ''build' directory
+function removeMergesFirefoxosBuildFromWWW() {
+ console.log('Remove '+buildDirInMerge+' from \'platforms/firefoxos/www\'');
+ if(fs.existsSync('platforms/firefoxos/www/'+buildDirInMerge)) {
+ shjs.rm('-r', 'platforms/firefoxos/www/'+buildDirInMerge);
+ }
+}
+
+
+/**
+ * buildProject
+ * --debug (default):
+ *
+ *
+ * --release
+ *
+ *
+ */
+exports.buildProject = function(buildTarget){
+
+ // Check that requirements are (stil) met
+ if(!check_reqs.run()) {
+ console.error('Please make sure you meet the software requirements in order to build a firefoxos cordova project');
+ process.exit(2);
+ }
+
+ clean.cleanProject(); // remove old build result
+
+ // if 'debug' (default), remove files we only need for 'release'
+ if(buildTarget == 'debug') {
+ // clean.cleanProject(); // remove old build result
+ if(hasCustomReleaseArtifactsDir()){
+ removeMergesFirefoxosBuildFromWWW();
+ }
+ process.exit(0);
+ }
+
+ if(buildTarget == 'release') {
+ console.log('Building Firefoxos project');
+ // clean.cleanProject(); // remove old build result
+
+ if(!hasAllRequiredCustomReleaseArtifacts()) {
+ console.error('Check \'https://developer.mozilla.org/en-US/Marketplace/Publishing/Packaged_apps\' for the required artifacts');
+ process.exit(2);
+
+ }
+
+ if(!fs.existsSync('platforms/firefoxos/build')) {
+ // first run, or project has been cleaned
+ fs.mkdir('platforms/firefoxos/build');
+ }
+
+ mergeMiniManifest();
+ mergeIndexHtml();
+ removeMergesFirefoxosBuildFromWWW();
+
+ // add the project in a zipfile
+ var zipFile = zip();
+ zipFile.addLocalFolder('platforms/firefoxos/www', '.');
+ zipFile.writeZip("platforms/firefoxos/build/package.zip");
+
+ process.exit(0);
+ }
+
+ // should never get here
+ console.error('Illegal target to build a firefoxos cordova project');
+ process.exit(2);
+
+}
+
+module.exports.help = function() {
+ console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'build')) + ' [build_type]');
+ console.log('Build Types : ');
+ console.log(' \'--debug\': Default build.');
+ console.log(' \'--release\': will build a zip-file of the project in \'platforms/firefoxos/build\'.');
+ console.log(' Please provide manifest.webapp and index.html in merges/firefoxos/'+buildDirInMerge);
+}
+
+
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/lib/clean.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/clean.js b/bin/templates/project/cordova/lib/clean.js
new file mode 100644
index 0000000..52bf0f3
--- /dev/null
+++ b/bin/templates/project/cordova/lib/clean.js
@@ -0,0 +1,46 @@
+#!/usr/bin/env node
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+var fs = require('fs'),
+ shjs = require('shelljs'),
+ check_reqs = require('./check_reqs');
+
+exports.cleanProject = function(){
+
+ // Check that requirements are (stil) met
+ if(!check_reqs.run()) {
+ console.error('Please make sure you meet the software requirements in order to clean an firefoxos cordova project');
+ process.exit(2);
+ }
+
+ console.log('Cleaning Firefoxos project');
+ try {
+ if(fs.existsSync('platforms/firefoxos/build')) {
+ shjs.rm('-r', 'platforms/firefoxos/build');
+ }
+ }
+ catch(err) {
+ console.log('could not remove platforms/firefoxos/build : '+err.message);
+ }
+
+
+}
+
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/node_modules/.bin/shjs
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/node_modules/.bin/shjs b/bin/templates/project/cordova/node_modules/.bin/shjs
new file mode 120000
index 0000000..a044997
--- /dev/null
+++ b/bin/templates/project/cordova/node_modules/.bin/shjs
@@ -0,0 +1 @@
+../shelljs/bin/shjs
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/node_modules/adm-zip/.idea/scopes/scope_settings.xml
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/node_modules/adm-zip/.idea/scopes/scope_settings.xml b/bin/templates/project/cordova/node_modules/adm-zip/.idea/scopes/scope_settings.xml
new file mode 100644
index 0000000..922003b
--- /dev/null
+++ b/bin/templates/project/cordova/node_modules/adm-zip/.idea/scopes/scope_settings.xml
@@ -0,0 +1,5 @@
+<component name="DependencyValidationManager">
+ <state>
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
+ </state>
+</component>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/node_modules/adm-zip/MIT-LICENSE.txt
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/node_modules/adm-zip/MIT-LICENSE.txt b/bin/templates/project/cordova/node_modules/adm-zip/MIT-LICENSE.txt
new file mode 100644
index 0000000..0124c8a
--- /dev/null
+++ b/bin/templates/project/cordova/node_modules/adm-zip/MIT-LICENSE.txt
@@ -0,0 +1,21 @@
+Copyright (c) 2012 Another-D-Mention Software and other contributors,
+http://www.another-d-mention.ro/
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/node_modules/adm-zip/README.md
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/node_modules/adm-zip/README.md b/bin/templates/project/cordova/node_modules/adm-zip/README.md
new file mode 100644
index 0000000..dd94d47
--- /dev/null
+++ b/bin/templates/project/cordova/node_modules/adm-zip/README.md
@@ -0,0 +1,64 @@
+# ADM-ZIP for NodeJS
+
+ADM-ZIP is a pure JavaScript implementation for zip data compression for [NodeJS](http://nodejs.org/).
+
+# Installation
+
+With [npm](http://npmjs.org) do:
+
+ $ npm install adm-zip
+
+## What is it good for?
+The library allows you to:
+
+* decompress zip files directly to disk or in memory buffers
+* compress files and store them to disk in .zip format or in compressed buffers
+* update content of/add new/delete files from an existing .zip
+
+# Dependencies
+There are no other nodeJS libraries that ADM-ZIP is dependent of
+
+# Examples
+
+## Basic usage
+```javascript
+
+ var AdmZip = require('adm-zip');
+
+ // reading archives
+ var zip = new AdmZip("./my_file.zip");
+ var zipEntries = zip.getEntries(); // an array of ZipEntry records
+
+ zipEntries.forEach(function(zipEntry) {
+ console.log(zipEntry.toString()); // outputs zip entries information
+ if (zipEntry.entryName == "my_file.txt") {
+ console.log(zipEntry.data.toString('utf8'));
+ }
+ });
+ // outputs the content of some_folder/my_file.txt
+ console.log(zip.readAsText("some_folder/my_file.txt"));
+ // extracts the specified file to the specified location
+ zip.extractEntryTo(/*entry name*/"some_folder/my_file.txt", /*target path*/"/home/me/tempfolder", /*maintainEntryPath*/false, /*overwrite*/true);
+ // extracts everything
+ zip.extractAllTo(/*target path*/"/home/me/zipcontent/", /*overwrite*/true);
+
+
+ // creating archives
+ var zip = new AdmZip();
+
+ // add file directly
+ zip.addFile("test.txt", new Buffer("inner content of the file"), "entry comment goes here");
+ // add local file
+ zip.addLocalFile("/home/me/some_picture.png");
+ // get everything as a buffer
+ var willSendthis = zip.toBuffer();
+ // or write everything to disk
+ zip.writeZip(/*target file name*/"/home/me/files.zip");
+
+
+ // ... more examples in the wiki
+```
+
+For more detailed information please check out the [wiki](https://github.com/cthackers/adm-zip/wiki).
+
+[![build status](https://secure.travis-ci.org/cthackers/adm-zip.png)](http://travis-ci.org/cthackers/adm-zip)
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/node_modules/adm-zip/adm-zip.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/node_modules/adm-zip/adm-zip.js b/bin/templates/project/cordova/node_modules/adm-zip/adm-zip.js
new file mode 100644
index 0000000..0a0c518
--- /dev/null
+++ b/bin/templates/project/cordova/node_modules/adm-zip/adm-zip.js
@@ -0,0 +1,404 @@
+var fs = require("fs"),
+ pth = require("path");
+
+fs.existsSync = fs.existsSync || pth.existsSync;
+
+var ZipEntry = require("./zipEntry"),
+ ZipFile = require("./zipFile"),
+ Utils = require("./util");
+
+module.exports = function(/*String*/input) {
+ var _zip = undefined,
+ _filename = "";
+
+ if (input && typeof input === "string") { // load zip file
+ if (fs.existsSync(input)) {
+ _filename = input;
+ _zip = new ZipFile(input, Utils.Constants.FILE);
+ } else {
+ throw Utils.Errors.INVALID_FILENAME;
+ }
+ } else if(input && Buffer.isBuffer(input)) { // load buffer
+ _zip = new ZipFile(input, Utils.Constants.BUFFER);
+ } else { // create new zip file
+ _zip = new ZipFile(null, Utils.Constants.NONE);
+ }
+
+ function getEntry(/*Object*/entry) {
+ if (entry && _zip) {
+ var item;
+ // If entry was given as a file name
+ if (typeof entry === "string")
+ item = _zip.getEntry(entry);
+ // if entry was given as a ZipEntry object
+ if (typeof entry === "object" && entry.entryName != undefined && entry.header != undefined)
+ item = _zip.getEntry(entry.entryName);
+
+ if (item) {
+ return item;
+ }
+ }
+ return null;
+ }
+
+ return {
+ /**
+ * Extracts the given entry from the archive and returns the content as a Buffer object
+ * @param entry ZipEntry object or String with the full path of the entry
+ *
+ * @return Buffer or Null in case of error
+ */
+ readFile : function(/*Object*/entry) {
+ var item = getEntry(entry);
+ return item && item.getData() || null;
+ },
+
+ /**
+ * Asynchronous readFile
+ * @param entry ZipEntry object or String with the full path of the entry
+ * @param callback
+ *
+ * @return Buffer or Null in case of error
+ */
+ readFileAsync : function(/*Object*/entry, /*Function*/callback) {
+ var item = getEntry(entry);
+ if (item) {
+ item.getDataAsync(callback);
+ } else {
+ callback(null,"getEntry failed for:" + entry)
+ }
+ },
+
+ /**
+ * Extracts the given entry from the archive and returns the content as plain text in the given encoding
+ * @param entry ZipEntry object or String with the full path of the entry
+ * @param encoding Optional. If no encoding is specified utf8 is used
+ *
+ * @return String
+ */
+ readAsText : function(/*Object*/entry, /*String - Optional*/encoding) {
+ var item = getEntry(entry);
+ if (item) {
+ var data = item.getData();
+ if (data && data.length) {
+ return data.toString(encoding || "utf8");
+ }
+ }
+ return "";
+ },
+
+ /**
+ * Asynchronous readAsText
+ * @param entry ZipEntry object or String with the full path of the entry
+ * @param callback
+ * @param encoding Optional. If no encoding is specified utf8 is used
+ *
+ * @return String
+ */
+ readAsTextAsync : function(/*Object*/entry, /*Function*/callback, /*String - Optional*/encoding) {
+ var item = getEntry(entry);
+ if (item) {
+ item.getDataAsync(function(data) {
+ if (data && data.length) {
+ callback(data.toString(encoding || "utf8"));
+ } else {
+ callback("");
+ }
+ })
+ } else {
+ callback("");
+ }
+ },
+
+ /**
+ * Remove the entry from the file or the entry and all it's nested directories and files if the given entry is a directory
+ *
+ * @param entry
+ */
+ deleteFile : function(/*Object*/entry) { // @TODO: test deleteFile
+ var item = getEntry(entry);
+ if (item) {
+ _zip.deleteEntry(item.entryName);
+ }
+ },
+
+ /**
+ * Adds a comment to the zip. The zip must be rewritten after adding the comment.
+ *
+ * @param comment
+ */
+ addZipComment : function(/*String*/comment) { // @TODO: test addZipComment
+ _zip.comment = comment;
+ },
+
+ /**
+ * Returns the zip comment
+ *
+ * @return String
+ */
+ getZipComment : function() {
+ return _zip.comment || '';
+ },
+
+ /**
+ * Adds a comment to a specified zipEntry. The zip must be rewritten after adding the comment
+ * The comment cannot exceed 65535 characters in length
+ *
+ * @param entry
+ * @param comment
+ */
+ addZipEntryComment : function(/*Object*/entry,/*String*/comment) {
+ var item = getEntry(entry);
+ if (item) {
+ item.comment = comment;
+ }
+ },
+
+ /**
+ * Returns the comment of the specified entry
+ *
+ * @param entry
+ * @return String
+ */
+ getZipEntryComment : function(/*Object*/entry) {
+ var item = getEntry(entry);
+ if (item) {
+ return item.comment || '';
+ }
+ return ''
+ },
+
+ /**
+ * Updates the content of an existing entry inside the archive. The zip must be rewritten after updating the content
+ *
+ * @param entry
+ * @param content
+ */
+ updateFile : function(/*Object*/entry, /*Buffer*/content) {
+ var item = getEntry(entry);
+ if (item) {
+ item.setData(content);
+ }
+ },
+
+ /**
+ * Adds a file from the disk to the archive
+ *
+ * @param localPath
+ */
+ addLocalFile : function(/*String*/localPath, /*String*/zipPath) {
+ if (fs.existsSync(localPath)) {
+ if(zipPath){
+ zipPath=zipPath.split("\\").join("/");
+ if(zipPath.charAt(zipPath.length - 1) != "/"){
+ zipPath += "/";
+ }
+ }else{
+ zipPath="";
+ }
+ var p = localPath.split("\\").join("/").split("/").pop();
+
+ this.addFile(zipPath+p, fs.readFileSync(localPath), "", 0)
+ } else {
+ throw Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath);
+ }
+ },
+
+ /**
+ * Adds a local directory and all its nested files and directories to the archive
+ *
+ * @param localPath
+ */
+ addLocalFolder : function(/*String*/localPath, /*String*/zipPath) {
+ if(zipPath){
+ zipPath=zipPath.split("\\").join("/");
+ if(zipPath.charAt(zipPath.length - 1) != "/"){
+ zipPath += "/";
+ }
+ }else{
+ zipPath="";
+ }
+ localPath = localPath.split("\\").join("/"); //windows fix
+ if (localPath.charAt(localPath.length - 1) != "/")
+ localPath += "/";
+
+ if (fs.existsSync(localPath)) {
+
+ var items = Utils.findFiles(localPath),
+ self = this;
+
+ if (items.length) {
+ items.forEach(function(path) {
+ var p = path.split("\\").join("/").replace(localPath, ""); //windows fix
+ if (p.charAt(p.length - 1) !== "/") {
+ self.addFile(zipPath+p, fs.readFileSync(path), "", 0)
+ } else {
+ self.addFile(zipPath+p, new Buffer(0), "", 0)
+ }
+ });
+ }
+ } else {
+ throw Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath);
+ }
+ },
+
+ /**
+ * Allows you to create a entry (file or directory) in the zip file.
+ * If you want to create a directory the entryName must end in / and a null buffer should be provided.
+ * Comment and attributes are optional
+ *
+ * @param entryName
+ * @param content
+ * @param comment
+ * @param attr
+ */
+ addFile : function(/*String*/entryName, /*Buffer*/content, /*String*/comment, /*Number*/attr) {
+ var entry = new ZipEntry();
+ entry.entryName = entryName;
+ entry.comment = comment || "";
+ entry.attr = attr || 438; //0666;
+ if (entry.isDirectory && content.length) {
+ // throw Utils.Errors.DIRECTORY_CONTENT_ERROR;
+ }
+ entry.setData(content);
+ _zip.setEntry(entry);
+ },
+
+ /**
+ * Returns an array of ZipEntry objects representing the files and folders inside the archive
+ *
+ * @return Array
+ */
+ getEntries : function() {
+ if (_zip) {
+ return _zip.entries;
+ } else {
+ return [];
+ }
+ },
+
+ /**
+ * Returns a ZipEntry object representing the file or folder specified by ``name``.
+ *
+ * @param name
+ * @return ZipEntry
+ */
+ getEntry : function(/*String*/name) {
+ return getEntry(name);
+ },
+
+ /**
+ * Extracts the given entry to the given targetPath
+ * If the entry is a directory inside the archive, the entire directory and it's subdirectories will be extracted
+ *
+ * @param entry ZipEntry object or String with the full path of the entry
+ * @param targetPath Target folder where to write the file
+ * @param maintainEntryPath If maintainEntryPath is true and the entry is inside a folder, the entry folder
+ * will be created in targetPath as well. Default is TRUE
+ * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true.
+ * Default is FALSE
+ *
+ * @return Boolean
+ */
+ extractEntryTo : function(/*Object*/entry, /*String*/targetPath, /*Boolean*/maintainEntryPath, /*Boolean*/overwrite) {
+ overwrite = overwrite || false;
+ maintainEntryPath = typeof maintainEntryPath == "undefined" ? true : maintainEntryPath;
+
+ var item = getEntry(entry);
+ if (!item) {
+ throw Utils.Errors.NO_ENTRY;
+ }
+
+ var target = pth.resolve(targetPath, maintainEntryPath ? item.entryName : pth.basename(item.entryName));
+
+ if (item.isDirectory) {
+ target = pth.resolve(target, "..");
+ var children = _zip.getEntryChildren(item);
+ children.forEach(function(child) {
+ if (child.isDirectory) return;
+ var content = child.getData();
+ if (!content) {
+ throw Utils.Errors.CANT_EXTRACT_FILE;
+ }
+ Utils.writeFileTo(pth.resolve(targetPath, maintainEntryPath ? child.entryName : child.entryName.substr(item.entryName.length)), content, overwrite);
+ });
+ return true;
+ }
+
+ var content = item.getData();
+ if (!content) throw Utils.Errors.CANT_EXTRACT_FILE;
+
+ if (fs.existsSync(targetPath) && !overwrite) {
+ throw Utils.Errors.CANT_OVERRIDE;
+ }
+ Utils.writeFileTo(target, content, overwrite);
+
+ return true;
+ },
+
+ /**
+ * Extracts the entire archive to the given location
+ *
+ * @param targetPath Target location
+ * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true.
+ * Default is FALSE
+ */
+ extractAllTo : function(/*String*/targetPath, /*Boolean*/overwrite) {
+ overwrite = overwrite || false;
+ if (!_zip) {
+ throw Utils.Errors.NO_ZIP;
+ }
+
+ _zip.entries.forEach(function(entry) {
+ if (entry.isDirectory) {
+ Utils.makeDir(pth.resolve(targetPath, entry.entryName.toString()));
+ return;
+ }
+ var content = entry.getData();
+ if (!content) {
+ throw Utils.Errors.CANT_EXTRACT_FILE + "2";
+ }
+ Utils.writeFileTo(pth.resolve(targetPath, entry.entryName.toString()), content, overwrite);
+ })
+ },
+
+ /**
+ * Writes the newly created zip file to disk at the specified location or if a zip was opened and no ``targetFileName`` is provided, it will overwrite the opened zip
+ *
+ * @param targetFileName
+ * @param callback
+ */
+ writeZip : function(/*String*/targetFileName, /*Function*/callback) {
+ if (arguments.length == 1) {
+ if (typeof targetFileName == "function") {
+ callback = targetFileName;
+ targetFileName = "";
+ }
+ }
+
+ if (!targetFileName && _filename) {
+ targetFileName = _filename;
+ }
+ if (!targetFileName) return;
+
+ var zipData = _zip.compressToBuffer();
+ if (zipData) {
+ Utils.writeFileTo(targetFileName, zipData, true);
+ }
+ },
+
+ /**
+ * Returns the content of the entire zip file as a Buffer object
+ *
+ * @return Buffer
+ */
+ toBuffer : function(/*Function*/onSuccess,/*Function*/onFail,/*Function*/onItemStart,/*Function*/onItemEnd) {
+ this.valueOf = 2;
+ if (typeof onSuccess == "function") {
+ _zip.toAsyncBuffer(onSuccess,onFail,onItemStart,onItemEnd);
+ return null;
+ }
+ return _zip.compressToBuffer()
+ }
+ }
+};
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/node_modules/adm-zip/headers/entryHeader.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/node_modules/adm-zip/headers/entryHeader.js b/bin/templates/project/cordova/node_modules/adm-zip/headers/entryHeader.js
new file mode 100644
index 0000000..9a0e1bd
--- /dev/null
+++ b/bin/templates/project/cordova/node_modules/adm-zip/headers/entryHeader.js
@@ -0,0 +1,261 @@
+var Utils = require("../util"),
+ Constants = Utils.Constants;
+
+/* The central directory file header */
+module.exports = function () {
+ var _verMade = 0x0A,
+ _version = 0x0A,
+ _flags = 0,
+ _method = 0,
+ _time = 0,
+ _crc = 0,
+ _compressedSize = 0,
+ _size = 0,
+ _fnameLen = 0,
+ _extraLen = 0,
+
+ _comLen = 0,
+ _diskStart = 0,
+ _inattr = 0,
+ _attr = 0,
+ _offset = 0;
+
+ var _dataHeader = {};
+
+ function setTime(val) {
+ var val = new Date(val);
+ _time = (val.getFullYear() - 1980 & 0x7f) << 25 // b09-16 years from 1980
+ | (val.getMonth() + 1) << 21 // b05-08 month
+ | val.getDay() << 16 // b00-04 hour
+
+ // 2 bytes time
+ | val.getHours() << 11 // b11-15 hour
+ | val.getMinutes() << 5 // b05-10 minute
+ | val.getSeconds() >> 1; // b00-04 seconds divided by 2
+ }
+
+ setTime(+new Date());
+
+ return {
+ get made () { return _verMade; },
+ set made (val) { _verMade = val; },
+
+ get version () { return _version; },
+ set version (val) { _version = val },
+
+ get flags () { return _flags },
+ set flags (val) { _flags = val; },
+
+ get method () { return _method; },
+ set method (val) { _method = val; },
+
+ get time () { return new Date(
+ ((_time >> 25) & 0x7f) + 1980,
+ ((_time >> 21) & 0x0f) - 1,
+ (_time >> 16) & 0x1f,
+ (_time >> 11) & 0x1f,
+ (_time >> 5) & 0x3f,
+ (_time & 0x1f) << 1
+ );
+ },
+ set time (val) {
+ setTime(val);
+ },
+
+ get crc () { return _crc; },
+ set crc (val) { _crc = val; },
+
+ get compressedSize () { return _compressedSize; },
+ set compressedSize (val) { _compressedSize = val; },
+
+ get size () { return _size; },
+ set size (val) { _size = val; },
+
+ get fileNameLength () { return _fnameLen; },
+ set fileNameLength (val) { _fnameLen = val; },
+
+ get extraLength () { return _extraLen },
+ set extraLength (val) { _extraLen = val; },
+
+ get commentLength () { return _comLen },
+ set commentLength (val) { _comLen = val },
+
+ get diskNumStart () { return _diskStart },
+ set diskNumStart (val) { _diskStart = val },
+
+ get inAttr () { return _inattr },
+ set inAttr (val) { _inattr = val },
+
+ get attr () { return _attr },
+ set attr (val) { _attr = val },
+
+ get offset () { return _offset },
+ set offset (val) { _offset = val },
+
+ get encripted () { return (_flags & 1) == 1 },
+
+ get entryHeaderSize () {
+ return Constants.CENHDR + _fnameLen + _extraLen + _comLen;
+ },
+
+ get realDataOffset () {
+ return _offset + Constants.LOCHDR + _dataHeader.fnameLen + _dataHeader.extraLen;
+ },
+
+ get dataHeader () {
+ return _dataHeader;
+ },
+
+ loadDataHeaderFromBinary : function(/*Buffer*/input) {
+ var data = input.slice(_offset, _offset + Constants.LOCHDR);
+ // 30 bytes and should start with "PK\003\004"
+ if (data.readUInt32LE(0) != Constants.LOCSIG) {
+ throw Utils.Errors.INVALID_LOC;
+ }
+ _dataHeader = {
+ // version needed to extract
+ version : data.readUInt16LE(Constants.LOCVER),
+ // general purpose bit flag
+ flags : data.readUInt16LE(Constants.LOCFLG),
+ // compression method
+ method : data.readUInt16LE(Constants.LOCHOW),
+ // modification time (2 bytes time, 2 bytes date)
+ time : data.readUInt32LE(Constants.LOCTIM),
+ // uncompressed file crc-32 value
+ crc : data.readUInt32LE(Constants.LOCCRC),
+ // compressed size
+ compressedSize : data.readUInt32LE(Constants.LOCSIZ),
+ // uncompressed size
+ size : data.readUInt32LE(Constants.LOCLEN),
+ // filename length
+ fnameLen : data.readUInt16LE(Constants.LOCNAM),
+ // extra field length
+ extraLen : data.readUInt16LE(Constants.LOCEXT)
+ }
+ },
+
+ loadFromBinary : function(/*Buffer*/data) {
+ // data should be 46 bytes and start with "PK 01 02"
+ if (data.length != Constants.CENHDR || data.readUInt32LE(0) != Constants.CENSIG) {
+ throw Utils.Errors.INVALID_CEN;
+ }
+ // version made by
+ _verMade = data.readUInt16LE(Constants.CENVEM);
+ // version needed to extract
+ _version = data.readUInt16LE(Constants.CENVER);
+ // encrypt, decrypt flags
+ _flags = data.readUInt16LE(Constants.CENFLG);
+ // compression method
+ _method = data.readUInt16LE(Constants.CENHOW);
+ // modification time (2 bytes time, 2 bytes date)
+ _time = data.readUInt32LE(Constants.CENTIM);
+ // uncompressed file crc-32 value
+ _crc = data.readUInt32LE(Constants.CENCRC);
+ // compressed size
+ _compressedSize = data.readUInt32LE(Constants.CENSIZ);
+ // uncompressed size
+ _size = data.readUInt32LE(Constants.CENLEN);
+ // filename length
+ _fnameLen = data.readUInt16LE(Constants.CENNAM);
+ // extra field length
+ _extraLen = data.readUInt16LE(Constants.CENEXT);
+ // file comment length
+ _comLen = data.readUInt16LE(Constants.CENCOM);
+ // volume number start
+ _diskStart = data.readUInt16LE(Constants.CENDSK);
+ // internal file attributes
+ _inattr = data.readUInt16LE(Constants.CENATT);
+ // external file attributes
+ _attr = data.readUInt32LE(Constants.CENATX);
+ // LOC header offset
+ _offset = data.readUInt32LE(Constants.CENOFF);
+ },
+
+ dataHeaderToBinary : function() {
+ // LOC header size (30 bytes)
+ var data = new Buffer(Constants.LOCHDR);
+ // "PK\003\004"
+ data.writeUInt32LE(Constants.LOCSIG, 0);
+ // version needed to extract
+ data.writeUInt16LE(_version, Constants.LOCVER);
+ // general purpose bit flag
+ data.writeUInt16LE(_flags, Constants.LOCFLG);
+ // compression method
+ data.writeUInt16LE(_method, Constants.LOCHOW);
+ // modification time (2 bytes time, 2 bytes date)
+ data.writeUInt32LE(_time, Constants.LOCTIM);
+ // uncompressed file crc-32 value
+ data.writeUInt32LE(_crc, Constants.LOCCRC);
+ // compressed size
+ data.writeUInt32LE(_compressedSize, Constants.LOCSIZ);
+ // uncompressed size
+ data.writeUInt32LE(_size, Constants.LOCLEN);
+ // filename length
+ data.writeUInt16LE(_fnameLen, Constants.LOCNAM);
+ // extra field length
+ data.writeUInt16LE(_extraLen, Constants.LOCEXT);
+ return data;
+ },
+
+ entryHeaderToBinary : function() {
+ // CEN header size (46 bytes)
+ var data = new Buffer(Constants.CENHDR + _fnameLen + _extraLen + _comLen);
+ // "PK\001\002"
+ data.writeUInt32LE(Constants.CENSIG, 0);
+ // version made by
+ data.writeUInt16LE(_verMade, Constants.CENVEM);
+ // version needed to extract
+ data.writeUInt16LE(_version, Constants.CENVER);
+ // encrypt, decrypt flags
+ data.writeUInt16LE(_flags, Constants.CENFLG);
+ // compression method
+ data.writeUInt16LE(_method, Constants.CENHOW);
+ // modification time (2 bytes time, 2 bytes date)
+ data.writeUInt32LE(_time, Constants.CENTIM);
+ // uncompressed file crc-32 value
+ data.writeInt32LE(_crc, Constants.CENCRC, true);
+ // compressed size
+ data.writeUInt32LE(_compressedSize, Constants.CENSIZ);
+ // uncompressed size
+ data.writeUInt32LE(_size, Constants.CENLEN);
+ // filename length
+ data.writeUInt16LE(_fnameLen, Constants.CENNAM);
+ // extra field length
+ data.writeUInt16LE(_extraLen, Constants.CENEXT);
+ // file comment length
+ data.writeUInt16LE(_comLen, Constants.CENCOM);
+ // volume number start
+ data.writeUInt16LE(_diskStart, Constants.CENDSK);
+ // internal file attributes
+ data.writeUInt16LE(_inattr, Constants.CENATT);
+ // external file attributes
+ data.writeUInt32LE(_attr, Constants.CENATX);
+ // LOC header offset
+ data.writeUInt32LE(_offset, Constants.CENOFF);
+ // fill all with
+ data.fill(0x00, Constants.CENHDR);
+ return data;
+ },
+
+ toString : function() {
+ return '{\n' +
+ '\t"made" : ' + _verMade + ",\n" +
+ '\t"version" : ' + _version + ",\n" +
+ '\t"flags" : ' + _flags + ",\n" +
+ '\t"method" : ' + Utils.methodToString(_method) + ",\n" +
+ '\t"time" : ' + _time + ",\n" +
+ '\t"crc" : 0x' + _crc.toString(16).toUpperCase() + ",\n" +
+ '\t"compressedSize" : ' + _compressedSize + " bytes,\n" +
+ '\t"size" : ' + _size + " bytes,\n" +
+ '\t"fileNameLength" : ' + _fnameLen + ",\n" +
+ '\t"extraLength" : ' + _extraLen + " bytes,\n" +
+ '\t"commentLength" : ' + _comLen + " bytes,\n" +
+ '\t"diskNumStart" : ' + _diskStart + ",\n" +
+ '\t"inAttr" : ' + _inattr + ",\n" +
+ '\t"attr" : ' + _attr + ",\n" +
+ '\t"offset" : ' + _offset + ",\n" +
+ '\t"entryHeaderSize" : ' + (Constants.CENHDR + _fnameLen + _extraLen + _comLen) + " bytes\n" +
+ '}';
+ }
+ }
+};
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/node_modules/adm-zip/headers/index.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/node_modules/adm-zip/headers/index.js b/bin/templates/project/cordova/node_modules/adm-zip/headers/index.js
new file mode 100644
index 0000000..b54a722
--- /dev/null
+++ b/bin/templates/project/cordova/node_modules/adm-zip/headers/index.js
@@ -0,0 +1,2 @@
+exports.EntryHeader = require("./entryHeader");
+exports.MainHeader = require("./mainHeader");
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/a11ffb20/bin/templates/project/cordova/node_modules/adm-zip/headers/mainHeader.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/node_modules/adm-zip/headers/mainHeader.js b/bin/templates/project/cordova/node_modules/adm-zip/headers/mainHeader.js
new file mode 100644
index 0000000..de8ae1a
--- /dev/null
+++ b/bin/templates/project/cordova/node_modules/adm-zip/headers/mainHeader.js
@@ -0,0 +1,80 @@
+var Utils = require("../util"),
+ Constants = Utils.Constants;
+
+/* The entries in the end of central directory */
+module.exports = function () {
+ var _volumeEntries = 0,
+ _totalEntries = 0,
+ _size = 0,
+ _offset = 0,
+ _commentLength = 0;
+
+ return {
+ get diskEntries () { return _volumeEntries },
+ set diskEntries (/*Number*/val) { _volumeEntries = _totalEntries = val; },
+
+ get totalEntries () { return _totalEntries },
+ set totalEntries (/*Number*/val) { _totalEntries = _volumeEntries = val; },
+
+ get size () { return _size },
+ set size (/*Number*/val) { _size = val; },
+
+ get offset () { return _offset },
+ set offset (/*Number*/val) { _offset = val; },
+
+ get commentLength () { return _commentLength },
+ set commentLength (/*Number*/val) { _commentLength = val; },
+
+ get mainHeaderSize () {
+ return Constants.ENDHDR + _commentLength;
+ },
+
+ loadFromBinary : function(/*Buffer*/data) {
+ // data should be 22 bytes and start with "PK 05 06"
+ if (data.length != Constants.ENDHDR || data.readUInt32LE(0) != Constants.ENDSIG)
+ throw Utils.Errors.INVALID_END;
+
+ // number of entries on this volume
+ _volumeEntries = data.readUInt16LE(Constants.ENDSUB);
+ // total number of entries
+ _totalEntries = data.readUInt16LE(Constants.ENDTOT);
+ // central directory size in bytes
+ _size = data.readUInt32LE(Constants.ENDSIZ);
+ // offset of first CEN header
+ _offset = data.readUInt32LE(Constants.ENDOFF);
+ // zip file comment length
+ _commentLength = data.readUInt16LE(Constants.ENDCOM);
+ },
+
+ toBinary : function() {
+ var b = new Buffer(Constants.ENDHDR + _commentLength);
+ // "PK 05 06" signature
+ b.writeUInt32LE(Constants.ENDSIG, 0);
+ b.writeUInt32LE(0, 4);
+ // number of entries on this volume
+ b.writeUInt16LE(_volumeEntries, Constants.ENDSUB);
+ // total number of entries
+ b.writeUInt16LE(_totalEntries, Constants.ENDTOT);
+ // central directory size in bytes
+ b.writeUInt32LE(_size, Constants.ENDSIZ);
+ // offset of first CEN header
+ b.writeUInt32LE(_offset, Constants.ENDOFF);
+ // zip file comment length
+ b.writeUInt16LE(_commentLength, Constants.ENDCOM);
+ // fill comment memory with spaces so no garbage is left there
+ b.fill(" ", Constants.ENDHDR);
+
+ return b;
+ },
+
+ toString : function() {
+ return '{\n' +
+ '\t"diskEntries" : ' + _volumeEntries + ",\n" +
+ '\t"totalEntries" : ' + _totalEntries + ",\n" +
+ '\t"size" : ' + _size + " bytes,\n" +
+ '\t"offset" : 0x' + _offset.toString(16).toUpperCase() + ",\n" +
+ '\t"commentLength" : 0x' + _commentLength + "\n" +
+ '}';
+ }
+ }
+};
\ No newline at end of file