@@ -6,16 +6,16 @@ var logger = TheLogManager.getLogger('aurelia');
6
6
7
7
function loadPlugin ( aurelia , loader , info ) {
8
8
logger . debug ( `Loading plugin ${ info . moduleId } .` ) ;
9
- aurelia . currentPluginId = ( info . moduleId . endsWith ( '.js' ) || info . moduleId . endsWith ( '.ts' ) ) ? info . moduleId . substring ( 0 , info . moduleId . length - 3 ) : info . moduleId ;
9
+ aurelia . resourcesRelativeTo = info . resourcesRelativeTo ;
10
10
11
11
return loader . loadModule ( info . moduleId ) . then ( m => {
12
12
if ( 'configure' in m ) {
13
13
return Promise . resolve ( m . configure ( aurelia , info . config || { } ) ) . then ( ( ) => {
14
- aurelia . currentPluginId = null ;
14
+ aurelia . resourcesRelativeTo = null ;
15
15
logger . debug ( `Configured plugin ${ info . moduleId } .` ) ;
16
16
} ) ;
17
17
} else {
18
- aurelia . currentPluginId = null ;
18
+ aurelia . resourcesRelativeTo = null ;
19
19
logger . debug ( `Loaded plugin ${ info . moduleId } .` ) ;
20
20
}
21
21
} ) ;
@@ -38,19 +38,35 @@ export class Plugins {
38
38
}
39
39
40
40
/**
41
- * Configures a plugin before Aurelia starts.
41
+ * Configures an internal feature plugin before Aurelia starts.
42
+ *
43
+ * @method feature
44
+ * @param {string } plugin The folder for the internal plugin to configure (expects an index.js in that folder).
45
+ * @param {config } config The configuration for the specified plugin.
46
+ * @return {Plugins } Returns the current Plugins instance.
47
+ */
48
+ feature ( plugin :string , config :any ) :Plugins {
49
+ plugin = plugin . endsWith ( '.js' ) || plugin . endsWith ( '.ts' ) ? plugin . substring ( 0 , plugin . length - 3 ) : plugin ;
50
+ return this . plugin ( { moduleId : plugin + '/index' , resourcesRelativeTo : plugin , config : config || { } } ) ;
51
+ }
52
+
53
+ /**
54
+ * Configures an external, 3rd party plugin before Aurelia starts.
42
55
*
43
56
* @method plugin
44
- * @param {moduleId } moduleId The ID of the module to configure.
45
- * @param {config } config The configuration for the specified module .
57
+ * @param {string } plugin The ID of the 3rd party plugin to configure.
58
+ * @param {config } config The configuration for the specified plugin .
46
59
* @return {Plugins } Returns the current Plugins instance.
47
60
*/
48
- plugin ( moduleId :string , config :any ) :Plugins {
49
- var plugin = { moduleId :moduleId , config :config || { } } ;
61
+ plugin ( plugin :string , config :any ) :Plugins {
62
+ if ( typeof ( plugin ) === 'string' ) {
63
+ plugin = plugin . endsWith ( '.js' ) || plugin . endsWith ( '.ts' ) ? plugin . substring ( 0 , plugin . length - 3 ) : plugin ;
64
+ return this . plugin ( { moduleId : plugin , resourcesRelativeTo : plugin , config : config || { } } ) ;
65
+ }
50
66
51
- if ( this . processed ) {
67
+ if ( this . processed ) {
52
68
loadPlugin ( this . aurelia , this . aurelia . loader , plugin ) ;
53
- } else {
69
+ } else {
54
70
this . info . push ( plugin ) ;
55
71
}
56
72
0 commit comments