@@ -97,6 +97,12 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
9797 }
9898 }
9999
100+ var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) {
101+ return typeof obj ;
102+ } : function ( obj ) {
103+ return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ;
104+ } ;
105+
100106
101107
102108 function preventActionlessFormSubmit ( ) {
@@ -258,36 +264,53 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
258264 return next ( ) ;
259265 }
260266
261- function loadPlugin ( config , loader , info ) {
267+ function loadPlugin ( fwConfig , loader , info ) {
262268 logger . debug ( 'Loading plugin ' + info . moduleId + '.' ) ;
263- config . resourcesRelativeTo = info . resourcesRelativeTo ;
269+ if ( typeof info . moduleId === 'string' ) {
270+ fwConfig . resourcesRelativeTo = info . resourcesRelativeTo ;
264271
265- var id = info . moduleId ;
272+ var id = info . moduleId ;
266273
267- if ( info . resourcesRelativeTo . length > 1 ) {
268- return loader . normalize ( info . moduleId , info . resourcesRelativeTo [ 1 ] ) . then ( function ( normalizedId ) {
269- return _loadPlugin ( normalizedId ) ;
270- } ) ;
271- }
274+ if ( info . resourcesRelativeTo . length > 1 ) {
275+ return loader . normalize ( info . moduleId , info . resourcesRelativeTo [ 1 ] ) . then ( function ( normalizedId ) {
276+ return _loadPlugin ( normalizedId ) ;
277+ } ) ;
278+ }
272279
273- return _loadPlugin ( id ) ;
280+ return _loadPlugin ( id ) ;
281+ } else if ( typeof info . configure === 'function' ) {
282+ if ( fwConfig . configuredPlugins . indexOf ( info . configure ) !== - 1 ) {
283+ return Promise . resolve ( ) ;
284+ }
285+ fwConfig . configuredPlugins . push ( info . configure ) ;
286+
287+ return Promise . resolve ( info . configure . call ( null , fwConfig , info . config || { } ) ) ;
288+ }
289+ throw new Error ( invalidConfigMsg ( info . moduleId || info . configure , 'plugin' ) ) ;
274290
275291 function _loadPlugin ( moduleId ) {
276292 return loader . loadModule ( moduleId ) . then ( function ( m ) {
277293 if ( 'configure' in m ) {
278- return Promise . resolve ( m . configure ( config , info . config || { } ) ) . then ( function ( ) {
279- config . resourcesRelativeTo = null ;
294+ if ( fwConfig . configuredPlugins . indexOf ( m . configure ) !== - 1 ) {
295+ return Promise . resolve ( ) ;
296+ }
297+ return Promise . resolve ( m . configure ( fwConfig , info . config || { } ) ) . then ( function ( ) {
298+ fwConfig . configuredPlugins . push ( m . configure ) ;
299+ fwConfig . resourcesRelativeTo = null ;
280300 logger . debug ( 'Configured plugin ' + info . moduleId + '.' ) ;
281301 } ) ;
282302 }
283303
284- config . resourcesRelativeTo = null ;
304+ fwConfig . resourcesRelativeTo = null ;
285305 logger . debug ( 'Loaded plugin ' + info . moduleId + '.' ) ;
286306 } ) ;
287307 }
288308 }
289309
290310 function loadResources ( aurelia , resourcesToLoad , appResources ) {
311+ if ( Object . keys ( resourcesToLoad ) . length === 0 ) {
312+ return Promise . resolve ( ) ;
313+ }
291314 var viewEngine = aurelia . container . get ( _aureliaTemplating . ViewEngine ) ;
292315
293316 return Promise . all ( Object . keys ( resourcesToLoad ) . map ( function ( n ) {
@@ -344,12 +367,24 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
344367 }
345368 }
346369
370+ function loadBehaviors ( config ) {
371+ return Promise . all ( config . behaviorsToLoad . map ( function ( m ) {
372+ return m . load ( config . container , m . target ) ;
373+ } ) ) . then ( function ( ) {
374+ config . behaviorsToLoad = null ;
375+ } ) ;
376+ }
377+
347378 function assertProcessed ( plugins ) {
348379 if ( plugins . processed ) {
349380 throw new Error ( 'This config instance has already been applied. To load more plugins or global resources, create a new FrameworkConfiguration instance.' ) ;
350381 }
351382 }
352383
384+ function invalidConfigMsg ( cfg , type ) {
385+ return 'Invalid ' + type + ' [' + cfg + '], ' + type + ' must be specified as functions or relative module IDs.' ;
386+ }
387+
353388 var FrameworkConfiguration = function ( ) {
354389 function FrameworkConfiguration ( aurelia ) {
355390 var _this4 = this ;
@@ -358,10 +393,15 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
358393
359394 this . aurelia = aurelia ;
360395 this . container = aurelia . container ;
396+
361397 this . info = [ ] ;
362398 this . processed = false ;
363399 this . preTasks = [ ] ;
364400 this . postTasks = [ ] ;
401+
402+ this . behaviorsToLoad = [ ] ;
403+
404+ this . configuredPlugins = [ ] ;
365405 this . resourcesToLoad = { } ;
366406 this . preTask ( function ( ) {
367407 return aurelia . loader . normalize ( 'aurelia-bootstrapper' ) . then ( function ( name ) {
@@ -403,13 +443,26 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
403443 FrameworkConfiguration . prototype . feature = function feature ( plugin ) {
404444 var config = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
405445
406- var hasIndex = / \/ i n d e x $ / i. test ( plugin ) ;
407- var moduleId = hasIndex || getExt ( plugin ) ? plugin : plugin + '/index' ;
408- var root = hasIndex ? plugin . substr ( 0 , plugin . length - 6 ) : plugin ;
409- return this . plugin ( { moduleId : moduleId , resourcesRelativeTo : [ root , '' ] , config : config } ) ;
446+ switch ( typeof plugin === 'undefined' ? 'undefined' : _typeof ( plugin ) ) {
447+ case 'string' :
448+ var hasIndex = / \/ i n d e x $ / i. test ( plugin ) ;
449+ var _moduleId = hasIndex || getExt ( plugin ) ? plugin : plugin + '/index' ;
450+ var root = hasIndex ? plugin . substr ( 0 , plugin . length - 6 ) : plugin ;
451+ this . info . push ( { moduleId : _moduleId , resourcesRelativeTo : [ root , '' ] , config : config } ) ;
452+ break ;
453+
454+ case 'function' :
455+ this . info . push ( { configure : plugin , config : config || { } } ) ;
456+ break ;
457+ default :
458+ throw new Error ( invalidConfigMsg ( plugin , 'feature' ) ) ;
459+ }
460+ return this ;
410461 } ;
411462
412463 FrameworkConfiguration . prototype . globalResources = function globalResources ( resources ) {
464+ var _this5 = this ;
465+
413466 assertProcessed ( this ) ;
414467
415468 var toAdd = Array . isArray ( resources ) ? resources : arguments ;
@@ -418,19 +471,31 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
418471
419472 for ( var i = 0 , ii = toAdd . length ; i < ii ; ++ i ) {
420473 resource = toAdd [ i ] ;
421- if ( typeof resource !== 'string' ) {
422- throw new Error ( 'Invalid resource path [' + resource + ']. Resources must be specified as relative module IDs.' ) ;
474+ switch ( typeof resource === 'undefined' ? 'undefined' : _typeof ( resource ) ) {
475+ case 'string' :
476+ var parent = resourcesRelativeTo [ 0 ] ;
477+ var grandParent = resourcesRelativeTo [ 1 ] ;
478+ var name = resource ;
479+
480+ if ( ( resource . startsWith ( './' ) || resource . startsWith ( '../' ) ) && parent !== '' ) {
481+ name = ( 0 , _aureliaPath . join ) ( parent , resource ) ;
482+ }
483+
484+ this . resourcesToLoad [ name ] = { moduleId : name , relativeTo : grandParent } ;
485+ break ;
486+ case 'function' :
487+ var meta = this . aurelia . resources . autoRegister ( this . container , resource ) ;
488+ if ( meta instanceof _aureliaTemplating . HtmlBehaviorResource && meta . elementName !== null ) {
489+ if ( this . behaviorsToLoad . push ( meta ) === 1 ) {
490+ this . postTask ( function ( ) {
491+ return loadBehaviors ( _this5 ) ;
492+ } ) ;
493+ }
494+ }
495+ break ;
496+ default :
497+ throw new Error ( invalidConfigMsg ( resource , 'resource' ) ) ;
423498 }
424-
425- var parent = resourcesRelativeTo [ 0 ] ;
426- var grandParent = resourcesRelativeTo [ 1 ] ;
427- var name = resource ;
428-
429- if ( ( resource . startsWith ( './' ) || resource . startsWith ( '../' ) ) && parent !== '' ) {
430- name = ( 0 , _aureliaPath . join ) ( parent , resource ) ;
431- }
432-
433- this . resourcesToLoad [ name ] = { moduleId : name , relativeTo : grandParent } ;
434499 }
435500
436501 return this ;
@@ -442,25 +507,32 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
442507 return this ;
443508 } ;
444509
445- FrameworkConfiguration . prototype . plugin = function plugin ( _plugin , config ) {
510+ FrameworkConfiguration . prototype . plugin = function plugin ( _plugin , pluginConfig ) {
446511 assertProcessed ( this ) ;
447512
448- if ( typeof _plugin === 'string' ) {
449- return this . plugin ( { moduleId : _plugin , resourcesRelativeTo : [ _plugin , '' ] , config : config || { } } ) ;
513+ var info = void 0 ;
514+ switch ( typeof _plugin === 'undefined' ? 'undefined' : _typeof ( _plugin ) ) {
515+ case 'string' :
516+ info = { moduleId : _plugin , resourcesRelativeTo : [ _plugin , '' ] , config : pluginConfig || { } } ;
517+ break ;
518+ case 'function' :
519+ info = { configure : _plugin , config : pluginConfig || { } } ;
520+ break ;
521+ default :
522+ throw new Error ( invalidConfigMsg ( _plugin , 'plugin' ) ) ;
450523 }
451-
452- this . info . push ( _plugin ) ;
524+ this . info . push ( info ) ;
453525 return this ;
454526 } ;
455527
456528 FrameworkConfiguration . prototype . _addNormalizedPlugin = function _addNormalizedPlugin ( name , config ) {
457- var _this5 = this ;
529+ var _this6 = this ;
458530
459531 var plugin = { moduleId : name , resourcesRelativeTo : [ name , '' ] , config : config || { } } ;
460532 this . plugin ( plugin ) ;
461533
462534 this . preTask ( function ( ) {
463- var relativeTo = [ name , _this5 . bootstrapperName ] ;
535+ var relativeTo = [ name , _this6 . bootstrapperName ] ;
464536 plugin . moduleId = name ;
465537 plugin . resourcesRelativeTo = relativeTo ;
466538 return Promise . resolve ( ) ;
@@ -498,7 +570,7 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
498570 } ;
499571
500572 FrameworkConfiguration . prototype . developmentLogging = function developmentLogging ( level ) {
501- var _this6 = this ;
573+ var _this7 = this ;
502574
503575 var logLevel = level ? TheLogManager . logLevel [ level ] : undefined ;
504576
@@ -507,8 +579,8 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
507579 }
508580
509581 this . preTask ( function ( ) {
510- return _this6 . aurelia . loader . normalize ( 'aurelia-logging-console' , _this6 . bootstrapperName ) . then ( function ( name ) {
511- return _this6 . aurelia . loader . loadModule ( name ) . then ( function ( m ) {
582+ return _this7 . aurelia . loader . normalize ( 'aurelia-logging-console' , _this7 . bootstrapperName ) . then ( function ( name ) {
583+ return _this7 . aurelia . loader . loadModule ( name ) . then ( function ( m ) {
512584 TheLogManager . addAppender ( new m . ConsoleAppender ( ) ) ;
513585 TheLogManager . setLevel ( logLevel ) ;
514586 } ) ;
@@ -519,29 +591,30 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-m
519591 } ;
520592
521593 FrameworkConfiguration . prototype . apply = function apply ( ) {
522- var _this7 = this ;
594+ var _this8 = this ;
523595
524596 if ( this . processed ) {
525597 return Promise . resolve ( ) ;
526598 }
527599
528600 return runTasks ( this , this . preTasks ) . then ( function ( ) {
529- var loader = _this7 . aurelia . loader ;
530- var info = _this7 . info ;
601+ var loader = _this8 . aurelia . loader ;
602+ var info = _this8 . info ;
531603 var current = void 0 ;
532604
533605 var next = function next ( ) {
534606 current = info . shift ( ) ;
535607 if ( current ) {
536- return loadPlugin ( _this7 , loader , current ) . then ( next ) ;
608+ return loadPlugin ( _this8 , loader , current ) . then ( next ) ;
537609 }
538610
539- _this7 . processed = true ;
611+ _this8 . processed = true ;
612+ _this8 . configuredPlugins = null ;
540613 return Promise . resolve ( ) ;
541614 } ;
542615
543616 return next ( ) . then ( function ( ) {
544- return runTasks ( _this7 , _this7 . postTasks ) ;
617+ return runTasks ( _this8 , _this8 . postTasks ) ;
545618 } ) ;
546619 } ) ;
547620 } ;
0 commit comments