mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
wip: try to get logging back. try to hot code push
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
|
||||
{{#each css}} <link rel="stylesheet" type="text/css" class="__meteor-css__" href="{{../bundledJsCssPrefix}}{{url}}">{{/each}}
|
||||
|
||||
<script type='text/javascript'>
|
||||
__meteor_runtime_config__ = {{meteorRuntimeConfig}};
|
||||
|
||||
@@ -14,12 +16,21 @@
|
||||
__meteor_runtime_config__.ROOT_URL = (__meteor_runtime_config__.ROOT_URL || '').replace(/localhost/i, '10.0.2.2');
|
||||
__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL = (__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL || '').replace(/localhost/i, '10.0.2.2');
|
||||
}
|
||||
|
||||
__meteor_manifest__ = {{meteorManifest}};
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="meteor_cordova_loader.js"></script>
|
||||
{{#each js}} <script type="text/javascript" src="{{../bundledJsCssPrefix}}{{url}}"></script>
|
||||
{{/each}}
|
||||
{{#each additionalStaticJs}}
|
||||
{{#if ../inlineScriptsAllowed}}
|
||||
<script type='text/javascript'>
|
||||
{{contents}}
|
||||
</script>
|
||||
{{else}}
|
||||
<script type='text/javascript'
|
||||
src='{{rootUrlPathPrefix}}{{pathname}}'></script>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
{{{head}}}
|
||||
</head>
|
||||
|
||||
|
||||
@@ -10,3 +10,8 @@ if (! /Android/i.test(navigator.userAgent)) {
|
||||
};
|
||||
}
|
||||
|
||||
document.addEventListener('deviceready', function () {
|
||||
if (window.cordova.logger)
|
||||
window.cordova.logger.__onDeviceReady();
|
||||
});
|
||||
|
||||
|
||||
@@ -67,5 +67,7 @@ Package.on_use(function(api) {
|
||||
});
|
||||
|
||||
Cordova.depends({
|
||||
'org.apache.cordova.device': '0.2.11'
|
||||
'org.apache.cordova.device': '0.2.11',
|
||||
'com.rjfun.cordova.httpd': 'https://github.com/floatinghotpot/cordova-httpd/tarball/d0c35b5f0af356c662580791a770ee655b2e3f34'
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ var ready = function() {
|
||||
};
|
||||
|
||||
if (document.addEventListener) {
|
||||
var event = Meteor.isCordova ? 'meteor-cordova-loaded' : 'DOMContentLoaded';
|
||||
var event = Meteor.isCordova ? 'deviceready' : 'DOMContentLoaded';
|
||||
document.addEventListener(event, ready, false);
|
||||
window.addEventListener('load', ready, false);
|
||||
} else {
|
||||
|
||||
13
tools/client/cordova_index.html
Normal file
13
tools/client/cordova_index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<head>
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="meteor_cordova_loader.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p>This is default index.html for the Meteor/Cordova apps. This file should
|
||||
find the correct location of the code we load, start a webserver and
|
||||
redirect there. If it is a new app, it will point at
|
||||
Application.app/www/application, if it had a hot code push before, it will
|
||||
point at Documents/meteor/version-number/.</p>
|
||||
<p>If you see this page, something might have gone wrong.</p>
|
||||
</body>
|
||||
|
||||
@@ -7,37 +7,6 @@
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
var loadedEvent = (function () {
|
||||
var usingEventConstructor = false;
|
||||
|
||||
// some browsers don't support the Event constructor
|
||||
// eg Cordova on Android JellyBean
|
||||
if (window.Event) {
|
||||
usingEventConstructor = true;
|
||||
}
|
||||
|
||||
var eventName = 'meteor-cordova-loaded';
|
||||
var event;
|
||||
if (usingEventConstructor) {
|
||||
try {
|
||||
event = new Event(eventName);
|
||||
} catch (err) {
|
||||
usingEventConstructor = false;
|
||||
}
|
||||
}
|
||||
if (! usingEventConstructor) {
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent(eventName, true, true);
|
||||
}
|
||||
|
||||
return {
|
||||
dispatch: function () {
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
var readFile = function (url, cb) {
|
||||
window.resolveLocalFileSystemURL(url,
|
||||
function (fileEntry) {
|
||||
@@ -66,68 +35,30 @@
|
||||
};
|
||||
|
||||
|
||||
// To ensure that all our <script> tags are loaded in the correct order we add
|
||||
// them to DOM one by one.
|
||||
// The assumption here is that every element in the queue is a function that
|
||||
// calls loadScript only once. Because loadScript makes sure to call
|
||||
// launchNext after the async operation is done, it works as intended. We
|
||||
// allow the last function to be something different (like trigger the
|
||||
// document event).
|
||||
var queue = [];
|
||||
var launchNext = function () {
|
||||
if (! queue.length)
|
||||
return;
|
||||
var fun = queue.shift();
|
||||
fun();
|
||||
};
|
||||
|
||||
var loadScript = function (url) {
|
||||
var scriptTag = document.createElement('script');
|
||||
scriptTag.type = "text/javascript";
|
||||
scriptTag.src = url;
|
||||
scriptTag.onload = launchNext;
|
||||
|
||||
document.getElementsByTagName('head')[0].appendChild(scriptTag);
|
||||
};
|
||||
|
||||
var loadStyle = function (url) {
|
||||
var styleTag = document.createElement('link');
|
||||
styleTag.rel = "stylesheet";
|
||||
styleTag.type = "text/css";
|
||||
styleTag.href = url;
|
||||
document.getElementsByTagName('head')[0].appendChild(styleTag);
|
||||
};
|
||||
|
||||
var stripLeadingSlash = function (p) {
|
||||
if (p.charAt(0) !== '/')
|
||||
throw new Error("bad path: " + p);
|
||||
return p.slice(1);
|
||||
};
|
||||
|
||||
var loadAssetsFromManifest = function (manifest, urlPrefix) {
|
||||
// Set the base href so that relative paths point to the correct version
|
||||
// of the app.
|
||||
var newBase = document.createElement("base");
|
||||
newBase.setAttribute("href", urlPrefix);
|
||||
document.getElementsByTagName("head")[0].appendChild(newBase);
|
||||
|
||||
each(manifest, function (item) {
|
||||
// We want to use relative paths so that our base href is taken into
|
||||
// account.
|
||||
var url = item.url ? stripLeadingSlash(item.url) : '';
|
||||
if (item.type === 'js')
|
||||
queue.push(function () {
|
||||
loadScript(url);
|
||||
var loadFromLocation = function (location) {
|
||||
var httpd = cordova && cordova.plugins && cordova.plugins.CorHttpd;
|
||||
httpd.getURL(function(url){
|
||||
if(url.length > 0) {
|
||||
// XXX shut down the server
|
||||
} else {
|
||||
httpd.startServer({
|
||||
'www_root' : location,
|
||||
'port' : 8080
|
||||
}, function(url) {
|
||||
// go to the new proxy url
|
||||
window.location = url;
|
||||
}, function( error ){
|
||||
console.error('Failed to start a proxy');
|
||||
});
|
||||
else if (item.type === 'css')
|
||||
loadStyle(url);
|
||||
});
|
||||
}
|
||||
|
||||
queue.push(function () {
|
||||
loadedEvent.dispatch();
|
||||
});
|
||||
|
||||
launchNext();
|
||||
},function(){});
|
||||
};
|
||||
|
||||
// Fallback to the bundled assets from the disk. If an error is passed as an
|
||||
@@ -141,7 +72,7 @@
|
||||
console.log('No new versions saved to disk.');
|
||||
}
|
||||
|
||||
loadAssetsFromManifest(__meteor_manifest__, '');
|
||||
loadFromLocation('application/');
|
||||
};
|
||||
|
||||
var listDirectory = function (url, options, cb) {
|
||||
@@ -176,21 +107,7 @@
|
||||
var loadVersion = function (version, localPathPrefix) {
|
||||
var versionPrefix = localPathPrefix + version + '/';
|
||||
// We have a version string, now read the new version
|
||||
readFile(versionPrefix + 'manifest.json',
|
||||
function (err, res) {
|
||||
if (err) {
|
||||
fallback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var program = JSON.parse(res);
|
||||
// update the version we are loading
|
||||
__meteor_runtime_config__.autoupdateVersionCordova = version;
|
||||
// update the public settings
|
||||
__meteor_runtime_config__.PUBLIC_SETTINGS = program.PUBLIC_SETTINGS;
|
||||
|
||||
loadAssetsFromManifest(program.manifest, versionPrefix);
|
||||
});
|
||||
loadFromLocation(versionPrefix);
|
||||
};
|
||||
|
||||
var loadApp = function (localPathPrefix) {
|
||||
@@ -230,19 +147,12 @@
|
||||
};
|
||||
|
||||
document.addEventListener("deviceready", function () {
|
||||
if (window.cordova.logger)
|
||||
window.cordova.logger.__onDeviceReady();
|
||||
|
||||
var localPathPrefix = cordova.file.applicationStorageDirectory +
|
||||
'Documents/meteor/';
|
||||
if (__meteor_runtime_config__.cleanCache) {
|
||||
// If cleanCache is enabled, clean the cache and then load the app.
|
||||
removeDirectory(localPathPrefix, function (err) {
|
||||
if (err) console.log('Failed to clear cache: ' + err.message);
|
||||
else console.log('Successfully cleared the cache.');
|
||||
|
||||
loadApp(localPathPrefix);
|
||||
});
|
||||
} else {
|
||||
loadApp(localPathPrefix);
|
||||
}
|
||||
loadApp(localPathPrefix);
|
||||
}, false);
|
||||
})();
|
||||
|
||||
|
||||
@@ -516,7 +516,8 @@ var buildCordova = function (localPath, buildCommand, options) {
|
||||
var programPath = path.join(bundlePath, 'programs');
|
||||
|
||||
var cordovaPath = path.join(localPath, 'cordova-build');
|
||||
var wwwPath = path.join(cordovaPath, "www");
|
||||
var wwwPath = path.join(cordovaPath, 'www');
|
||||
var applicationPath = path.join(wwwPath, 'application');
|
||||
var cordovaProgramPath = path.join(programPath, webArchName);
|
||||
var cordovaProgramAppPath = path.join(cordovaProgramPath, 'app');
|
||||
|
||||
@@ -536,24 +537,33 @@ var buildCordova = function (localPath, buildCommand, options) {
|
||||
files.rm_recursive(cordovaProgramAppPath);
|
||||
}
|
||||
|
||||
verboseLog('Rewriting the www folder');
|
||||
verboseLog('Removing the www folder');
|
||||
// rewrite the www folder
|
||||
files.rm_recursive(wwwPath);
|
||||
files.cp_r(cordovaProgramPath, wwwPath);
|
||||
|
||||
files.mkdir_p(applicationPath);
|
||||
verboseLog('Writing www/application folder');
|
||||
files.cp_r(cordovaProgramPath, applicationPath);
|
||||
|
||||
// clean up the temporary bundle directory
|
||||
files.rm_recursive(bundlePath);
|
||||
|
||||
verboseLog('Writing index.html, cordova_loader.js');
|
||||
verboseLog('Writing index.html');
|
||||
|
||||
// generate index.html
|
||||
var indexHtml = generateCordovaBoilerplate(wwwPath, options);
|
||||
fs.writeFileSync(path.join(wwwPath, 'index.html'), indexHtml, 'utf8');
|
||||
var indexHtml = generateCordovaBoilerplate(applicationPath, options);
|
||||
fs.writeFileSync(path.join(applicationPath, 'index.html'), indexHtml, 'utf8');
|
||||
|
||||
verboseLog('Writing meteor_cordova_loader');
|
||||
var loaderPath = path.join(__dirname, 'client', 'meteor_cordova_loader.js');
|
||||
var loaderCode = fs.readFileSync(loaderPath);
|
||||
fs.writeFileSync(path.join(wwwPath, 'meteor_cordova_loader.js'), loaderCode);
|
||||
|
||||
verboseLog('Writing a default index.html for cordova app');
|
||||
var indexPath = path.join(__dirname, 'client', 'cordova_index.html');
|
||||
var indexContent = fs.readFileSync(indexPath);
|
||||
fs.writeFileSync(path.join(wwwPath, 'index.html'), indexContent);
|
||||
|
||||
var buildOverridePath = path.join(project.rootDir, 'cordova-build-override');
|
||||
|
||||
if (fs.existsSync(buildOverridePath) &&
|
||||
|
||||
Reference in New Issue
Block a user