Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cordova-app-loader

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-app-loader - npm Package Compare versions

Comparing version 0.2.1 to 0.3.1

www/.htaccess

12

bin/update-manifest.js

@@ -23,3 +23,4 @@ var path = require('path');

rootDir = path.resolve(rootDir);
console.log('root='+rootDir+", manifest="+manifestFile);
console.log('root='+rootDir);
console.log('manifest='+manifestFile);

@@ -37,5 +38,8 @@ var manifest;

var versionChecksum = "";
for(var filename in manifest.files) {
try {
manifest.files[filename].version = checksum(path.resolve(rootDir,filename));
var version = checksum(path.resolve(rootDir,filename));
versionChecksum += version;
manifest.files[filename].version = version;
} catch(e){

@@ -46,6 +50,8 @@ console.error('Could not hash file.',e);

manifest.version = crypto.createHash('sha1').update(versionChecksum).digest('hex');
try {
fs.writeFileSync(
path.resolve(rootDir, manifestFile),
JSON.stringify(manifest,null,4)
JSON.stringify(manifest,null,2)
);

@@ -52,0 +58,0 @@ } catch(e) {

{
"name": "cordova-app-loadaer",
"main": "www/lib/CordovaAppLoader.js",
"version": "0.2.1",
"version": "0.3.1",
"homepage": "https://github.com/markmarijnissen/cordova-file-cache",

@@ -6,0 +6,0 @@ "authors": [

{
"name": "cordova-app-loader",
"version": "0.2.1",
"version": "0.3.1",
"description": "Cordova App Loader - remote update your cordova app",

@@ -9,3 +9,3 @@ "main": "index.js",

"cordova-app-loader":"webpack index.js www/lib/CordovaAppLoader.js --output-library CordovaAppLoader --output-library-target var",
"bootstrap":"cp bootstrap.js www/bootstrap.js",
"bootstrap":"uglifyjs -m --screw-ie8 bootstrap.js > www/bootstrap.js",
"prepublish": "npm run-script bootstrap && npm run-script cordova-promise-fs && npm run-script cordova-app-loader",

@@ -24,4 +24,4 @@ "test": "echo \"Error: no test specified\" && exit 1"

"dependencies": {
"cordova-file-cache": "^0.3.0"
"cordova-file-cache": "^0.4.0"
}
}

@@ -27,2 +27,4 @@ cordova-app-loader

Check out [Cordova App Loader](http://data.madebymark.nl/cordova-app-loader/index.html) in Chrome for a demo! (**Chrome only!**)
```bash

@@ -114,2 +116,6 @@ git clone git@github.com:markmarijnissen/cordova-app-loader.git

### 0.3.0 (13/11/2014)
* Chrome support!
### 0.2.0 (09/11/2014)

@@ -116,0 +122,0 @@

var fs = new CordovaPromiseFS({});
var fs = new CordovaPromiseFS({ persistent: false });
var SERVER = 'http://data.madebymark.nl/cordova-app-loader/';

@@ -14,2 +14,3 @@ //var SERVER = 'http://localhost:8000/ios/www/';

var tapEvent = typeof cordova !== 'undefined'?'touchstart':'click';

@@ -21,2 +22,6 @@

setStatus('ready');
fs.fs.then(undefined,function(){
setStatus('ERROR: Only Chrome and Cordova-iOS/Android are supported!');
});
});

@@ -23,0 +28,0 @@

@@ -1,127 +0,1 @@

(function(){
// Retrieved and slightly modified from: https://github.com/typicode/pegasus
// --------------------------------------------------------------------------
//
// a url (naming it a, beacause it will be reused to store callbacks)
// xhr placeholder to avoid using var, not to be used
window.pegasus = function pegasus(a, xhr) {
xhr = new XMLHttpRequest();
// Open url
xhr.open('GET', a);
// Reuse a to store callbacks
a = [];
// onSuccess handler
// onError handler
// cb placeholder to avoid using var, should not be used
xhr.onreadystatechange = xhr.then = function(onSuccess, onError, cb) {
// Test if onSuccess is a function or a load event
if (onSuccess.call) a = [onSuccess, onError];
// Test if request is complete
if (xhr.readyState == 4) {
// index will be:
// 0 if status is between 0 and 399
// 1 if status is over
cb = a[0|xhr.status / 400];
// Safari doesn't support xhr.responseType = 'json'
// so the response is parsed
if (cb) cb(xhr.status === 200 || xhr.status === 0?JSON.parse(xhr.responseText):xhr);
}
};
// Send
xhr.send();
// Return request
return xhr;
};
//------------------------------------------------------------------
// Step 2: After fetching manifest (localStorage or XHR), load it
function loadManifest(manifest,fromLocalStorage,timeout){
if(!manifest.load) {
console.error('Manifest has nothing to load (manifest.load is empty).',manifest);
return;
}
var el,
head = document.getElementsByTagName('head')[0],
scripts = manifest.load.concat();
// Load Next Script
function loadScript(){
var src = scripts.shift();
if(!src) return;
// Ensure the 'src' has no '/' (it's in the root already)
if(src[0] === '/') src = src.substr(1);
src = manifest.root + src;
// Load javascript
if(src.substr(-3) === ".js"){
el= document.createElement('script');
el.type= 'text/javascript';
el.src= src;
el.onload = loadScript;
// Load CSS
} else {
el= document.createElement('link');
el.rel = "stylesheet";
el.href = src;
el.type = "text/css";
setTimeout(loadScript,0);
}
head.appendChild(el);
}
//---------------------------------------------------
// Step 3: Ensure the 'root' end with a '/'
manifest.root = manifest.root || './';
if(manifest.root.length > 0 && manifest.root[manifest.root.length-1] !== '/')
manifest.root += '/';
// Step 4: Save manifest for next time
if(!fromLocalStorage)
localStorage.setItem('manifest',JSON.stringify(manifest));
// Step 5: Load Scripts
// If we're loading Cordova files, make sure Cordova is ready first!
if(manifest.root.substr(0,7) === 'cdvfile'){
document.addEventListener("deviceready", loadScript, false);
} else {
loadScript();
}
// Save to global scope
window.Manifest = manifest;
// Safety timeout. If BOOTSTRAP_OK is not defined,
// it will delete the 'localStorage' version and revert to factory settings.
if(fromLocalStorage){
setTimeout(function(){
if(!window.BOOTSTRAP_OK){
localStorage.removeItem('manifest');
location.reload();
}
},timeout);
}
}
//---------------------------------------------------------------------
// Step 1: Load manifest from localStorage
var manifest = JSON.parse(localStorage.getItem('manifest'));
// grab manifest.json location from <script manifest="..."></script>
var s = document.querySelector('script[manifest]');
// Not in localStorage? Fetch it!
if(!manifest){
var url = (s? s.getAttribute('manifest'): null) || 'manifest.json';
// get manifest.json, then loadManifest.
pegasus(url).then(loadManifest,function(xhr){
console.error('Could not download '+url+': '+xhr.status);
});
// Manifest was in localStorage. Load it immediatly.
} else {
loadManifest(manifest,true,s.getAttribute('timeout') || 10000);
}
})();
(function(){window.pegasus=function t(e,o){o=new XMLHttpRequest;o.open("GET",e);e=[];o.onreadystatechange=o.then=function(t,n,s){if(t.call)e=[t,n];if(o.readyState==4){s=e[0|o.status/400];if(s)s(o.status===200||o.status===0?JSON.parse(o.responseText):o)}};o.send();return o};function t(t,e,o){if(!t.load){console.error("Manifest has nothing to load (manifest.load is empty).",t);return}var n,s=document.getElementsByTagName("head")[0],a=t.load.concat();function r(){var e=a.shift();if(!e)return;if(e[0]==="/")e=e.substr(1);e=t.root+e;if(e.substr(-3)===".js"){n=document.createElement("script");n.type="text/javascript";n.src=e;n.onload=r}else{n=document.createElement("link");n.rel="stylesheet";n.href=e;n.type="text/css";setTimeout(r,0)}s.appendChild(n)}t.root=t.root||"./";if(t.root.length>0&&t.root[t.root.length-1]!=="/")t.root+="/";if(!e)localStorage.setItem("manifest",JSON.stringify(t));if(t.root.substr(0,7)==="cdvfile"){document.addEventListener("deviceready",r,false)}else{r()}window.Manifest=t;if(e){setTimeout(function(){if(!window.BOOTSTRAP_OK){localStorage.removeItem("manifest");location.reload()}},o)}}var e=JSON.parse(localStorage.getItem("manifest"));var o=document.querySelector("script[manifest]");if(!e){var n=(o?o.getAttribute("manifest"):null)||"manifest.json";pegasus(n).then(t,function(t){console.error("Could not download "+n+": "+t.status)})}else{t(e,true,o.getAttribute("timeout")||1e4)}})();

@@ -192,3 +192,9 @@ var CordovaAppLoader =

var Promise = null;
var isCordova = typeof cordova !== 'undefined';
var SERVER_DETECT = isCordova? '://':'filesystem:';
if(!isCordova) {
window.ProgressEvent = function ProgressEvent(){}
}
/* Cordova File Cache x */

@@ -239,3 +245,3 @@ function FileCache(options){

self._cached[entry.fullPath] = {
toInternalURL: entry.toInternalURL(),
toInternalURL: isCordova? entry.toInternalURL(): entry.toURL(),
toURL: entry.toURL(),

@@ -314,3 +320,5 @@ };

var queue = self.getDownloadQueue();
var started = [];
var index = self._downloading.length;
var done = self._downloading.length;
var total = self._downloading.length + queue.length;

@@ -333,2 +341,6 @@

}
if(started.indexOf(url) < 0) {
started.push(url);
index++;
}
onprogress(ev);

@@ -340,5 +352,5 @@ };

var onDone = function(){
index++;
done++;
// when we're done
if(index === total) {
if(done === total) {
// reset downloads

@@ -393,3 +405,3 @@ self._downloading = [];

if(this._cached[path]) return this._cached[path].toInternalURL;
return 'cdvfile://localhost/'+(this._fs.options.persistent?'persistent':'temporary')+path;
return this._fs.toInternalURLSync(path);
};

@@ -409,3 +421,4 @@

FileCache.prototype.toServerURL = function toServerURL(path){
return path.indexOf('://') < 0? this._serverRoot + path: path;
if(path[0] === '/') path = path.substr(1);
return path.indexOf(SERVER_DETECT) < 0? this._serverRoot + path: path;
};

@@ -412,0 +425,0 @@

@@ -98,6 +98,35 @@ var CordovaPromiseFS =

/* Cordova deviceready promise */
var deviceready = new Promise(function(resolve,reject){
document.addEventListener("deviceready", resolve, false);
setTimeout(function(){ reject(new Error('deviceready has not fired after 5 seconds.')); },5100);
});
var deviceready, isCordova = typeof cordova !== 'undefined';
if(isCordova){
deviceready = new Promise(function(resolve,reject){
document.addEventListener("deviceready", resolve, false);
setTimeout(function(){ reject(new Error('deviceready has not fired after 5 seconds.')); },5100);
});
} else {
/* FileTransfer implementation for Chrome */
deviceready = Promise.resolve();
if(typeof webkitRequestFileSystem !== 'undefined'){
window.requestFileSystem = webkitRequestFileSystem;
window.FileTransfer = function FileTransfer(){};
FileTransfer.prototype.download = function download(url,file,win,fail) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onreadystatechange = function(onSuccess, onError, cb) {
if (xhr.readyState == 4) {
if(xhr.status === 200){
write(file,xhr.responseText).then(win,fail);
} else {
fail(xhr.status);
}
}
};
xhr.send();
return xhr;
};
} else {
window.requestFileSystem = function(x,y,z,fail){
fail(new Error('requestFileSystem not supported!'));
};
}
}

@@ -168,14 +197,28 @@

/* convert path to URL to be used in JS/CSS/HTML */
function toInternalURL(path) {
return file(path).then(function(fileEntry) {
return fileEntry.toInternalURL();
});
}
if(isCordova) {
/* synchronous helper to get internal URL. */
function toInternalURLSync(path){
if(path[0] !== '/') path = '/' + path;
return 'cdvfile://localhost/'+(options.persistent? 'persistent':'temporary') + path;
}
/* synchronous helper to get internal URL. */
function toInternalURLSync(path){
if(path[0] !== '/') path = '/' + path;
return 'cdvfile://localhost/'+(options.persistent? 'persistent':'temporary') + path;
}
function toInternalURL(path) {
return file(path).then(function(fileEntry) {
return fileEntry.toInternalURL();
});
}
} else {
/* synchronous helper to get internal URL. */
function toInternalURLSync(path){
if(path[0] !== '/') path = '/' + path;
return 'filesystem:'+location.origin+(options.persistent? '/persistent':'/temporary') + path;
}
function toInternalURL(path) {
return file(path).then(function(fileEntry) {
return fileEntry.toURL();
});
}
}
/* convert path to base64 date URI */

@@ -345,2 +388,8 @@ function toDataURL(path) {

var isDownload = args.shift();
var serverUrl = args.shift();
var localPath = args.shift();
var win = args.shift();
var fail = args.shift();
var trustAllHosts = args.shift();
var transferOptions = args.shift();

@@ -350,10 +399,6 @@ if(ft._aborted) {

} else if(isDownload){
ft.download.apply(ft,args);
ft.download.call(ft,serverUrl,localPath,win,fail,transferOptions,trustAllHosts);
if(ft.onprogress) ft.onprogress(new ProgressEvent());
} else {
// Stupid API. 'upload' switched around the 'trustAllHosts' and 'options' arguments.
var opts = args[4]; args[4] = args[5]; args[5] = opts;
// Switch around serverUrl/localPath because we transfer in reverse direction
var localPath = args[1]; args[1] = args[0]; args[0] = localPath;
ft.upload.apply(ft,args);
ft.upload.call(ft,localPath,serverUrl,win,fail,trustAllHosts,transferOptions);
}

@@ -378,3 +423,3 @@ }

serverUrl = encodeURI(serverUrl);
localPath = toInternalURLSync(localPath);
if(isCordova) localPath = toInternalURLSync(localPath);

@@ -448,2 +493,4 @@ transferOptions = transferOptions || {};

toURL:toURL,
isCordova:isCordova,
toInternalURLSync: toInternalURLSync,
toInternalURL:toInternalURL,

@@ -450,0 +497,0 @@ toDataURL:toDataURL,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc