1 |
|
2 | var fs = require("fs-extra"),
|
3 | path = require("path"),
|
4 | cleanAddress = require("../clean_address");
|
5 |
|
6 |
|
7 | module.exports = function(loader, buildLoader, options){
|
8 | return new Configuration(loader, buildLoader, options);
|
9 | };
|
10 |
|
11 | function Configuration(loader, buildLoader, options){
|
12 | this.loader = loader;
|
13 | this.buildLoader = buildLoader;
|
14 | this.options = options;
|
15 |
|
16 | this.defaultBundlesPathName = options.defaultBundlesPathName != null ?
|
17 | options.defaultBundlesPathName : "bundles";
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Configuration.prototype = {
|
24 | join: function(src){
|
25 | if( src.indexOf("/") === 0 || /^\w+\:[\/\\]/.test(src) ) {
|
26 | return src;
|
27 | } else if( src.indexOf("./") === 0 ){
|
28 | return path.join(process.cwd(), src.substr(2));
|
29 | } else {
|
30 | return path.join(cleanAddress(this.loader.baseURL), src);
|
31 | }
|
32 | },
|
33 | get dest() {
|
34 | var dest = this.options.dest != null ? this.options.dest : "dist";
|
35 |
|
36 | if(typeof dest === "function") {
|
37 | dest = "dist";
|
38 | }
|
39 | return this.join(dest);
|
40 | },
|
41 | get bundlesPath() {
|
42 | var dest = this.dest;
|
43 | var bundlesPathName = this.defaultBundlesPathName;
|
44 |
|
45 | return path.join(dest, bundlesPathName);
|
46 | },
|
47 | get bundlesPathURL () {
|
48 | return path.relative( this.loader.baseURL, this.bundlesPath ).replace(/\\/g, '/');
|
49 | },
|
50 | mkBundlesPathDir: function(){
|
51 | var bundlesPath = this.bundlesPath;
|
52 | return new Promise(function(resolve, reject){
|
53 | fs.mkdirs(bundlesPath, function(err){
|
54 | if(err) {
|
55 | reject(err);
|
56 | } else {
|
57 | resolve();
|
58 | }
|
59 | });
|
60 | });
|
61 | },
|
62 | get configMain(){
|
63 | return this.loader.configMain || "@config";
|
64 | }
|
65 | };
|