-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): allow minify options to be supplied
- Loading branch information
1 parent
fd07344
commit 177b0c7
Showing
7 changed files
with
398 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
const CLIOptions = require('./cli-options').CLIOptions; | ||
|
||
exports.Configuration = class { | ||
constructor(options, defaultOptions, environment) { | ||
this.options = Object.assign({}, defaultOptions, options); | ||
this.environment = environment || CLIOptions.getEnvironment(); | ||
} | ||
|
||
getAllOptions() { | ||
return this.options; | ||
} | ||
|
||
getValue(propPath) { | ||
let split = propPath.split('.'); | ||
let cur = this.options; | ||
|
||
for (let i = 0; i < split.length; i++) { | ||
if (!cur) { | ||
return undefined; | ||
} | ||
|
||
cur = cur[split[i]]; | ||
} | ||
|
||
if (typeof cur === 'object') { | ||
let keys = Object.keys(cur); | ||
let result = undefined; | ||
|
||
if (keys.indexOf('default') > -1 && typeof(cur.default) === 'object') { | ||
result = cur.default; | ||
} | ||
|
||
for (let i = 0; i < keys.length; i++) { | ||
if (this.matchesEnvironment(this.environment, keys[i])) { | ||
if (typeof(cur[keys[i]]) === 'object') { | ||
result = Object.assign(result || {}, cur[keys[i]]); | ||
} else { | ||
return cur[keys[i]]; | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
return cur; | ||
} | ||
|
||
isApplicable(propPath) { | ||
let value = this.getValue(propPath); | ||
|
||
if (!value) { | ||
return false; | ||
} | ||
|
||
if (typeof value === 'boolean') { | ||
return value; | ||
} | ||
|
||
if (typeof value === 'string') { | ||
return this.matchesEnvironment(this.environment, value); | ||
} | ||
|
||
if (typeof value === 'object') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
matchesEnvironment(environment, value) { | ||
let parts = value.split('&').map(x => x.trim().toLowerCase()); | ||
return parts.indexOf(environment) !== -1; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.