11'use strict' ;
22
3- var path = require ( 'path' ) ,
4- fs = require ( 'fs' ) ;
5-
6- var defaults = require ( 'lodash.defaults' ) ;
7-
8- var defaultOptions = require ( './lib/default-options' ) ,
9- parseOptions = require ( './lib/parse-options' ) ,
10- getConfiguratorFactory = require ( './lib/get-configurator-factory' ) ;
3+ var multiConfigurator = require ( 'webpack-multi-configurator' ) ;
4+
5+ var configuratorFactory = require ( './lib/configurator-factory' ) ;
6+
7+ const DEFAULT_OPTIONS = {
8+ appDir : './app' ,
9+ buildDir : './app-build' ,
10+ testDir : './app-test' ,
11+ releaseDir : './app-release' ,
12+ testGlob : '**/*.spec.js' ,
13+ port : 55555 ,
14+ unminified : false ,
15+ names : 'app*, release' ,
16+ publicPath : undefined ,
17+ globals : { } ,
18+ stats : {
19+ hash : true ,
20+ version : true ,
21+ timings : true ,
22+ assets : true ,
23+ chunks : true ,
24+ modules : true ,
25+ reasons : true ,
26+ children : true ,
27+ source : true ,
28+ errors : true ,
29+ errorDetails : true ,
30+ warnings : true ,
31+ publicPath : true
32+ }
33+ } ;
1134
12- var DEFAULT_OPERATORS = {
35+ const OPERATORS = {
1336 addBrowserSync : require ( './config/add/browser-sync' ) ,
1437 addClean : require ( './config/add/clean' ) ,
15- addCommon : require ( './config/add/common' ) ,
1638 addComposition : require ( './config/add/composition' ) ,
1739 addConditionals : require ( './config/add/conditionals' ) ,
1840 addExternalChunkManifest : require ( './config/add/external-chunk-manifest' ) ,
@@ -22,72 +44,19 @@ var DEFAULT_OPERATORS = {
2244
2345/**
2446 * Create a set of accessors that yield webpack configurator(s).
25- * @param {...object } [options] Any number of options hashes to be merged
26- * @returns {{app :function, test :function, release :function, resolve:function} } A new instance
47+ * @param {...object } [options] Any number of options hashes to be merged, or single configurator factory method
48+ * @returns {function():{define :function, include :function, exclude :function, resolve:function} }
2749 */
28- function create ( options ) {
29-
30- // legacy support
31- // where angularity.json is present it should define the port
32- var angularityJsonPath = path . resolve ( 'angularity.json' ) ,
33- angularityPort = fs . existsSync ( angularityJsonPath ) && require ( angularityJsonPath ) . port || undefined ;
34-
35- // options set
36- var args = Array . prototype . slice . call ( arguments ) ,
37- opt = parseOptions (
38- defaults . apply ( null , [ { } ] . concat ( args ) ) , // merged options in
39- defaults ( { port : angularityPort } , defaultOptions ( ) ) // merged defaults
40- ) ;
41-
42- // default is the default operator set
43- return extend ( DEFAULT_OPERATORS ) ;
44-
45- /**
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} }
50- */
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- }
85-
86- function resolveElement ( configurator ) {
87- return configurator . resolve ( ) ;
88- }
89- }
90- }
91- }
92-
93- module . exports = create ;
50+ module . exports = multiConfigurator ( DEFAULT_OPTIONS , configuratorFactory ( OPERATORS ) )
51+ . define ( 'common' )
52+ . append ( require ( './config/common' ) )
53+ . define ( 'app' )
54+ . generate ( require ( './config/app' ) )
55+ . append ( 'common' )
56+ . define ( 'release' )
57+ . generate ( require ( './config/release' ) )
58+ . append ( 'common' )
59+ . define ( 'test' )
60+ . append ( require ( './config/test' ) )
61+ . append ( 'common' )
62+ . create ;
0 commit comments