Skip to content

Commit 3f6546a

Browse files
author
benholloway
committed
Squashed commit of the following:
commit 3f7a6de Author: benholloway <[email protected]> Date: Tue Mar 15 14:49:48 2016 +1100 reorder release and test commit 1553209 Author: benholloway <[email protected]> Date: Tue Mar 15 11:07:39 2016 +1100 tweak docs commit e8462d6 Author: benholloway <[email protected]> Date: Tue Mar 15 09:03:59 2016 +1100 tweak docs commit 75d37eb Author: benholloway <[email protected]> Date: Tue Mar 15 08:54:02 2016 +1100 tweak docs commit 2e6aef2 Author: benholloway <[email protected]> Date: Mon Mar 14 18:35:28 2016 +1100 added filtering of compositions by name option, fix name not appearing in stats commit d7964ba Author: benholloway <[email protected]> Date: Mon Mar 14 15:16:43 2016 +1100 tweak readme commit 7c19737 Author: benholloway <[email protected]> Date: Mon Mar 14 15:08:52 2016 +1100 move readme to wiki commit d32b8ef Author: benholloway <[email protected]> Date: Mon Mar 14 15:01:48 2016 +1100 move readme to wiki commit 34f9cee Author: benholloway <[email protected]> Date: Mon Mar 14 14:13:49 2016 +1100 move readme to wiki commit d80ef00 Author: benholloway <[email protected]> Date: Mon Mar 14 14:11:59 2016 +1100 move readme to wiki commit ab7ca48 Author: benholloway <[email protected]> Date: Fri Mar 11 15:25:59 2016 +1100 tweak documentation commit 40aaa74 Author: benholloway <[email protected]> Date: Fri Mar 11 15:23:30 2016 +1100 tweak documentation commit a74ebbb Author: benholloway <[email protected]> Date: Fri Mar 11 15:22:40 2016 +1100 tweak documentation commit 0f8746f Author: benholloway <[email protected]> Date: Fri Mar 11 15:21:45 2016 +1100 tweak documentation commit 652d9f0 Author: benholloway <[email protected]> Date: Fri Mar 11 15:09:56 2016 +1100 tweak documentation commit 6dcacf1 Author: benholloway <[email protected]> Date: Fri Mar 11 15:08:34 2016 +1100 tweak documentation commit 549b48a Author: benholloway <[email protected]> Date: Fri Mar 11 14:45:48 2016 +1100 tweak documentation commit 9f8941f Author: benholloway <[email protected]> Date: Fri Mar 11 14:44:18 2016 +1100 tweak documentation commit 4436acc Author: benholloway <[email protected]> Date: Fri Mar 11 14:41:00 2016 +1100 documentation complete commit 4bedfa4 Author: benholloway <[email protected]> Date: Fri Mar 11 11:47:18 2016 +1100 api complete, documentation in progress commit 4e986b6 Author: benholloway <[email protected]> Date: Fri Mar 4 23:08:56 2016 +1100 lazy import packages commit f8957a8 Author: benholloway <[email protected]> Date: Fri Mar 4 23:03:26 2016 +1100 attempt new api using webpack-multi-configurator
1 parent f43bcbc commit 3f6546a

File tree

14 files changed

+250
-576
lines changed

14 files changed

+250
-576
lines changed

.jshintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"maxlen": 120,
2424
"scripturl": true,
2525
"node": true,
26-
"jasmine": true
26+
"jasmine": true,
27+
"esnext": true
2728
}

config/app.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
'use strict';
22

3-
var path = require('path');
4-
5-
var listCompositions = require('../lib/list-compositions');
6-
73
/**
84
* Create a list of webpack configurators, one for each application detected.
9-
* @param {function} configuratorFactory A factory for the webpack-configurator
10-
* @param {{appDir:string, buildDir:string, globals:object, unminified:boolean, port:number}} options An options hash
11-
* @returns {Array.<Config>} A list of configurators, one for each application detected
5+
* @param {function():Config} factory A factory for the webpack-configurator
6+
* @param {{appDir:string, buildDir:string, names:Array, globals:object, unminified:boolean, port:number}} options
7+
* @returns {Array.<Config>} A list of Webpack-configurator instances, one for each application detected
128
*/
13-
function app(configuratorFactory, options) {
9+
function app(factory, options) {
10+
11+
// lazy import packages
12+
var path = require('path'),
13+
listCompositions = require('../lib/list-compositions'),
14+
appFilter = require('../lib/app-filter');
1415

1516
// there may be any number of compositions in subdirectories
16-
return listCompositions(options.appDir)
17-
.map(eachComposition);
17+
var list = listCompositions(options.appDir, 'app')
18+
.filter(appFilter(options.names));
19+
20+
// ensure at least one composition or webpack will crash with a cryptic error
21+
if (list.length) {
22+
return list.map(eachComposition);
23+
}
24+
else {
25+
throw new Error('There are no compositions included in this build.');
26+
}
1827

1928
function eachComposition(composition, i) {
2029
var buildDir = path.join(options.buildDir, composition.directory),
21-
config = configuratorFactory()
30+
config = factory()
2231
.addClean(buildDir)
23-
.addCommon(path.resolve(__dirname, '..', 'node_modules'), options)
2432
.addComposition(composition)
2533
.addConditionals({
2634
TEST : false,
@@ -29,6 +37,7 @@ function app(configuratorFactory, options) {
2937
})
3038
.addMinification(!options.unminified)
3139
.merge({
40+
name : composition.namespace.join('.'),
3241
output: {
3342
path: path.resolve(buildDir)
3443
}
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
'use strict';
22

3-
var path = require('path');
4-
5-
var webpack = require('webpack'),
6-
adjustSourcemapLoader = require('adjust-sourcemap-loader'),
7-
ExtractTextPlugin = require('extract-text-webpack-plugin'),
8-
BowerWebpackPlugin = require('bower-webpack-plugin'),
9-
EntryGeneratorPlugin = require('entry-generator-webpack-plugin'),
10-
OmitTildePlugin = require('omit-tilde-webpack-plugin'),
11-
Md5HashPlugin = require('webpack-md5-hash');
12-
133
/**
144
* Add configuration common to all modes.
15-
* @this {Config} A webpack-configurator instance
16-
* @param {string} loaderRoot The base path in which to locate loaders
5+
* @param {Config} configurator A webpack-configurator instance
176
* @param {{appDir:string, globals:object, stats:string}} options A hash of options
187
* @returns {Config} The given webpack-configurator instance
198
*/
20-
function common(loaderRoot, options) {
21-
var vendorEntry = path.resolve(options.appDir, 'vendor.js'),
22-
templateFn = adjustSourcemapLoader.moduleFilenameTemplate({
23-
format: 'projectRelative'
24-
});
9+
function common(configurator, options) {
10+
11+
// lazy import packages
12+
var path = require('path');
13+
var webpack = require('webpack'),
14+
adjustSourcemapLoader = require('adjust-sourcemap-loader'),
15+
ExtractTextPlugin = require('extract-text-webpack-plugin'),
16+
BowerWebpackPlugin = require('bower-webpack-plugin'),
17+
EntryGeneratorPlugin = require('entry-generator-webpack-plugin'),
18+
OmitTildePlugin = require('omit-tilde-webpack-plugin'),
19+
Md5HashPlugin = require('webpack-md5-hash');
2520

2621
// Note that DedupePlugin causes problems when npm linked so we will ommit it from the common configuration
2722
// you need to add it yourself if you wish to use it
2823
// https://github.com/webpack/karma-webpack/issues/41#issuecomment-139516692
2924

30-
/* jshint validthis:true */
31-
return this
25+
var vendorEntry = path.resolve(options.appDir, 'vendor.js'),
26+
loaderRoot = path.resolve(__dirname, '..', 'node_modules'),
27+
templateFn = adjustSourcemapLoader.moduleFilenameTemplate({
28+
format: 'projectRelative'
29+
});
30+
31+
return configurator
3232
.merge({
3333
context : process.cwd(),
3434
cache : true,

config/release.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
'use strict';
22

3-
var path = require('path');
4-
5-
var listCompositions = require('../lib/list-compositions');
6-
73
/**
8-
* Create a single webpack configurator for release.
9-
* @param {function} configuratorFactory A factory for the webpack-configurator
10-
* @param {{appDir:string, releaseDir:string, globals:object, unminified:boolean, port:number}} options An options hash
11-
* @returns {Config} A webpack configurator
4+
* Create a list of webpack configurators, one for each application detected.
5+
* @param {function():Config} factory A factory for the webpack-configurator
6+
* @param {{appDir:string, releaseDir:string, names:Array, globals:object, unminified:boolean, port:number}} options
7+
* @returns {Array.<Config>} A list of Webpack-configurator instances, one for each application detected
128
*/
13-
function release(configuratorFactory, options) {
9+
function release(factory, options) {
10+
11+
// lazy import packages
12+
var path = require('path'),
13+
listCompositions = require('../lib/list-compositions'),
14+
appFilter = require('../lib/app-filter');
15+
16+
// there may be any number of compositions in subdirectories
17+
var list = listCompositions(options.appDir, 'release')
18+
.filter(appFilter(options.names));
19+
20+
// ensure at least one composition or webpack will crash with a cryptic error
21+
if (list.length) {
22+
return list.map(eachComposition);
23+
}
24+
else {
25+
throw new Error('There are no compositions included in this build.');
26+
}
1427

15-
// only the primary application will be released
16-
var composition = listCompositions(options.appDir)[0];
17-
if (composition) {
18-
return configuratorFactory()
19-
.addBrowserSync(options.releaseDir, options.port)
20-
.addClean(options.releaseDir)
28+
function eachComposition(composition) {
29+
var releaseDir = path.join(options.releaseDir, composition.directory);
30+
return factory()
31+
.addClean(releaseDir)
2132
.addComposition(composition, options.publicPath)
22-
.addCommon(path.resolve(__dirname, '..', 'node_modules'), options)
2333
.addConditionals({
2434
TEST : false,
2535
DEBUG : false,
@@ -28,16 +38,13 @@ function release(configuratorFactory, options) {
2838
.addExternalChunkManifest()
2939
.addMinification(!options.unminified)
3040
.merge({
31-
name : 'release',
41+
name : composition.namespace.join('.'),
3242
output: {
33-
path : path.resolve(options.releaseDir),
43+
path : path.resolve(releaseDir),
3444
publicPath: options.publicPath
3545
}
3646
});
3747
}
38-
else {
39-
throw new Error('there are no compositions in the app directory');
40-
}
4148
}
4249

4350
module.exports = release;

config/test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
'use strict';
22

3-
var path = require('path');
4-
53
/**
64
* Create a single webpack configurator for test.
7-
* @param {function} configuratorFactory A factory for the webpack-configurator
5+
* @param {Config} configurator A webpack-configurator instance
86
* @param {{appDir:string, testDir:string, globals:object, testGlob:string}} options An options hash
9-
* @returns {Config} A webpack configurator
7+
* @returns {Config} The given webpack-configurator instance
108
*/
11-
function test(configuratorFactory, options) {
9+
function test(configurator, options) {
10+
11+
// lazy import packages
12+
var path = require('path');
13+
14+
// generate an entry file for all tests
1215
var testEntry = path.resolve(options.appDir, 'test.js');
1316

14-
return configuratorFactory()
17+
return configurator
1518
.addClean(options.testDir)
16-
.addCommon(path.resolve(__dirname, '..', 'node_modules'), options)
1719
.addConditionals({
1820
TEST : true,
1921
DEBUG : true,

index.js

Lines changed: 47 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
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;

lib/app-filter.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
/**
4+
* Create a filter for apps given a comma separated list.
5+
* @param {string} names A comma separated list of names to include
6+
* @returns {function} A composition filter function
7+
*/
8+
function appFilter(names) {
9+
var list = Array.isArray(names) ? names.map(trim) : String(names).split(',').map(trim);
10+
11+
return function filter(composition) {
12+
var actual = composition.namespace.join('.'),
13+
result = list.some(testName);
14+
console.log(result, list, composition);
15+
return result;
16+
17+
function testName(name) {
18+
if (name.slice(-1) === '*') {
19+
var short = name.slice(0, -1);
20+
return (actual.slice(0, short.length) === short);
21+
}
22+
else {
23+
return (actual === name);
24+
}
25+
}
26+
};
27+
28+
function trim(value) {
29+
return String(value).trim();
30+
}
31+
}
32+
33+
module.exports = appFilter;

0 commit comments

Comments
 (0)