diff --git a/src/index.js b/src/index.js index 37b9b7f..561021a 100644 --- a/src/index.js +++ b/src/index.js @@ -57,7 +57,7 @@ function ensureLoader(){ }); } - return Promise.resolve(); + return Promise.resolve(); } function preparePlatform(){ @@ -107,6 +107,8 @@ function preparePlatform(){ }); } +var installedDevelopmentLogging = false; + function configureAurelia(aurelia){ return System.normalize('aurelia-bootstrapper').then(function(bName){ var toLoad = []; @@ -144,67 +146,76 @@ function configureAurelia(aurelia){ }; })); + aurelia.use.standardConfiguration = function(){ + aurelia.use + .defaultBindingLanguage() + .defaultResources() + .router() + .eventAggregator(); + return this; + }; + + aurelia.use.developmentLogging = function(){ + if(!installedDevelopmentLogging){ + installedDevelopmentLogging = true; + LogManager.addAppender(new ConsoleAppender()); + LogManager.setLevel(LogManager.levels.debug); + } + return this; + } + return Promise.all(toLoad); }); } -function handleMain(mainHost){ - var mainModuleId = mainHost.getAttribute('aurelia-main') || 'main', - loader = new window.AureliaLoader(); - - return loader.loadModule(mainModuleId) - .then(m => { - var aurelia = new Aurelia(loader); - return configureAurelia(aurelia).then(() => { return m.configure(aurelia); }); - }).catch(e => { - setTimeout(function(){ throw e; }, 0); - }); +function runningLocally(){ + return window.location.protocol !== 'http' && window.location.protocol !== 'https'; } function handleApp(appHost){ - var appModuleId = appHost.getAttribute('aurelia-app') || './app', - aurelia = new Aurelia(); - - return configureAurelia(aurelia).then(() => { - aurelia.use - .defaultBindingLanguage() - .defaultResources() - .router() - .eventAggregator(); - - if(appHost.hasAttribute('es5')){ - aurelia.use.es5(); - } else if(appHost.hasAttribute('atscript')){ - aurelia.use.atscript(); - } + var configModuleId = appHost.getAttribute('aurelia-app'), + aurelia, loader; - return aurelia.start().then(a => { return a.setRoot(appModuleId, appHost); }); - }).catch(e => { - setTimeout(function(){ throw e; }, 0); - }); -} + if(configModuleId){ + loader = new window.AureliaLoader(); -function runningLocally(){ - return window.location.protocol !== 'http' && - window.location.protocol !== 'https'; + return loader.loadModule(configModuleId) + .then(m => { + aurelia = new Aurelia(loader); + return configureAurelia(aurelia).then(() => { return m.configure(aurelia); }); + }).catch(e => { + setTimeout(function(){ throw e; }, 0); + }); + }else{ + aurelia = new Aurelia(); + + return configureAurelia(aurelia).then(() => { + if(runningLocally()){ + aurelia.use.developmentLogging(); + } + + aurelia.use.standardConfiguration(); + + if(appHost.hasAttribute('es5')){ + aurelia.use.es5(); + } else if(appHost.hasAttribute('atscript')){ + aurelia.use.atscript(); + } + + return aurelia.start().then(a => { return a.setRoot(undefined, appHost); }); + }).catch(e => { + setTimeout(function(){ throw e; }, 0); + }); + } } function run() { - return ready(window).then(function (doc) { - var mainHost = doc.querySelectorAll("[aurelia-main]"), - appHost = doc.querySelectorAll("[aurelia-app]"), - i, ii; - - if (appHost.length && !mainHost.length && runningLocally()) { - LogManager.addAppender(new ConsoleAppender()); - LogManager.setLevel(LogManager.levels.debug); - } + return ready(window).then(doc => { + var appHost = doc.querySelectorAll("[aurelia-app]"); return ensureLoader().then(() => { return preparePlatform().then(function(){ - for (i = 0, ii = mainHost.length; i < ii; ++i) { - handleMain(mainHost[i]); - } + var i, ii; for (i = 0, ii = appHost.length; i < ii; ++i) { handleApp(appHost[i]);