@@ -5,15 +5,27 @@ var path = require('path'),
55
66var defaults = require ( 'lodash.defaults' ) ;
77
8- var defaultOptions = require ( './lib/default-options' ) ,
9- parseOptions = require ( './lib/parse-options' ) ;
8+ var defaultOptions = require ( './lib/default-options' ) ,
9+ parseOptions = require ( './lib/parse-options' ) ,
10+ getConfiguratorFactory = require ( './lib/get-configurator-factory' ) ;
11+
12+ var DEFAULT_OPERATORS = {
13+ addBrowserSync : require ( './config/add/browser-sync' ) ,
14+ addClean : require ( './config/add/clean' ) ,
15+ addCommon : require ( './config/add/common' ) ,
16+ addComposition : require ( './config/add/composition' ) ,
17+ addConditionals : require ( './config/add/conditionals' ) ,
18+ addExternalChunkManifest : require ( './config/add/external-chunk-manifest' ) ,
19+ addMinification : require ( './config/add/minification' ) ,
20+ addTestSuiteGeneration : require ( './config/add/test-suite-generation' )
21+ } ;
1022
1123/**
1224 * Create a set of accessors that yield webpack configurator(s).
1325 * @param {...object } [options] Any number of options hashes to be merged
1426 * @returns {{app:function, test:function, release:function, resolve:function} } A new instance
1527 */
16- function configFactory ( options ) {
28+ function create ( options ) {
1729
1830 // legacy support
1931 // where angularity.json is present it should define the port
@@ -27,40 +39,55 @@ function configFactory(options) {
2739 defaults ( { port : angularityPort } , defaultOptions ( ) ) // merged defaults
2840 ) ;
2941
30- // create and return the instance
31- var instance = {
32- get app ( ) {
33- return require ( './config/app' ) ( opt ) ;
34- } ,
35- get test ( ) {
36- return require ( './config/test' ) ( opt ) ;
37- } ,
38- get release ( ) {
39- return require ( './config/release' ) ( opt ) ;
40- } ,
41- resolve : resolve
42- } ;
43- return instance ;
42+ // default is the default operator set
43+ return extend ( DEFAULT_OPERATORS ) ;
4444
4545 /**
46- * Call the given function with the instance (as this) and resolve() any webpack configurators that it returns.
47- * @param {function(instance:object }:Array.<Config>|Config} fn A method to call with the instance as this
48- * @returns {Array.<object>|object } A webpack configuration or Array thereof
46+ * Extend the configurator with the given operators.
47+ * @param {object } oldOperators A hash of the existing operators from the parent instance
48+ * @param {object } newOperators A hash of operator overrides
49+ * @returns {{extend:function, resolve:function, app:Array.<Configurator>, test:Configurator, release:Configurator} }
4950 */
50- function resolve ( fn ) {
51- if ( typeof fn !== 'function' ) {
52- throw new Error ( 'The argument given to resolve() must be a function' ) ;
53- }
54- else {
55- return [ ] . concat ( fn . call ( instance ) )
56- . filter ( Boolean )
57- . map ( resolveElement ) ;
58- }
51+ function extend ( oldOperators , newOperators ) {
52+ var operators = defaults ( { } , newOperators , oldOperators ) ,
53+ configuratorFactory = getConfiguratorFactory ( operators ) ;
54+
55+ // create and return the instance
56+ var instance = {
57+ extend : extend . bind ( null , operators ) ,
58+ resolve : resolve ,
59+ get app ( ) {
60+ return require ( './config/app' ) ( configuratorFactory , opt ) ;
61+ } ,
62+ get test ( ) {
63+ return require ( './config/test' ) ( configuratorFactory , opt ) ;
64+ } ,
65+ get release ( ) {
66+ return require ( './config/release' ) ( configuratorFactory , opt ) ;
67+ }
68+ } ;
69+ return instance ;
70+
71+ /**
72+ * Call the given function with the instance (as this) and resolve() any webpack configurators that it returns.
73+ * @param {function(instance:object):Config|Array.<Config> } fn A method to call with the instance as this
74+ * @returns {Array.<object>|object } A webpack configuration or Array thereof
75+ */
76+ function resolve ( fn ) {
77+ if ( typeof fn !== 'function' ) {
78+ throw new Error ( 'The argument given to resolve() must be a function' ) ;
79+ }
80+ else {
81+ return [ ] . concat ( fn . call ( instance ) )
82+ . filter ( Boolean )
83+ . map ( resolveElement ) ;
84+ }
5985
60- function resolveElement ( configurator ) {
61- return configurator . resolve ( ) ;
86+ function resolveElement ( configurator ) {
87+ return configurator . resolve ( ) ;
88+ }
6289 }
6390 }
6491}
6592
66- module . exports = configFactory ;
93+ module . exports = create ;
0 commit comments