polymer-project-config
Advanced tools
Comparing version 3.4.0 to 3.5.0
@@ -8,5 +8,8 @@ # Change Log | ||
## Unreleased | ||
<!-- ## Unreleased --> | ||
<!-- Add new, unreleased changes here. --> | ||
## [3.5.0] - 2017-11-21 | ||
* Added static methods for constructing a ProjectConfig directly from an unvalidated JSON object, in addition to the methods for reading it from disk. | ||
## [3.4.0] - 2017-06-21 | ||
@@ -13,0 +16,0 @@ * Modified the `bundle` property in project build options to support the subset of `polymer-bundler` options which can be serialized in a JSON file. |
@@ -83,2 +83,13 @@ import { ProjectBuildOptions } from './builds'; | ||
/** | ||
* Returns the given configJsonObject if it is a valid ProjectOptions object, | ||
* otherwise throws an informative error message. | ||
*/ | ||
static validateOptions(configJsonObject: {}): ProjectOptions; | ||
/** | ||
* Returns a new ProjectConfig from the given JSON object if it's valid. | ||
* | ||
* Throws if the given JSON object is an invalid ProjectOptions. | ||
*/ | ||
static validateAndCreate(configJsonObject: {}): ProjectConfig; | ||
/** | ||
* constructor - given a ProjectOptions object, create the correct project | ||
@@ -85,0 +96,0 @@ * configuration for those options. This involves setting the correct |
@@ -177,11 +177,3 @@ "use strict"; | ||
const contents = JSON.parse(configContent); | ||
const validator = new jsonschema.Validator(); | ||
const result = validator.validate(contents, getSchema()); | ||
if (result.throwError) { | ||
throw result.throwError; | ||
} | ||
if (result.errors.length > 0) { | ||
throw result.errors[0]; | ||
} | ||
return contents; | ||
return this.validateOptions(contents); | ||
} | ||
@@ -203,3 +195,3 @@ catch (error) { | ||
static loadConfigFromFile(filepath) { | ||
let configParsed = ProjectConfig.loadOptionsFromFile(filepath); | ||
const configParsed = ProjectConfig.loadOptionsFromFile(filepath); | ||
if (!configParsed) { | ||
@@ -210,2 +202,27 @@ return null; | ||
} | ||
/** | ||
* Returns the given configJsonObject if it is a valid ProjectOptions object, | ||
* otherwise throws an informative error message. | ||
*/ | ||
static validateOptions(configJsonObject) { | ||
const validator = new jsonschema.Validator(); | ||
const result = validator.validate(configJsonObject, getSchema()); | ||
if (result.errors.length > 0) { | ||
throw result.errors[0]; | ||
} | ||
if (result.throwError) { | ||
throw new Error(`An error was encountered while validating the ` + | ||
`Polymer Project Config.`); | ||
} | ||
return configJsonObject; | ||
} | ||
/** | ||
* Returns a new ProjectConfig from the given JSON object if it's valid. | ||
* | ||
* Throws if the given JSON object is an invalid ProjectOptions. | ||
*/ | ||
static validateAndCreate(configJsonObject) { | ||
const options = this.validateOptions(configJsonObject); | ||
return new this(options); | ||
} | ||
isFragment(filepath) { | ||
@@ -212,0 +229,0 @@ return this.allFragments.indexOf(filepath) !== -1; |
{ | ||
"name": "polymer-project-config", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"description": "reads, validates, and shapes your polymer.json project configuration", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -170,11 +170,3 @@ /** | ||
const contents = JSON.parse(configContent); | ||
const validator = new jsonschema.Validator(); | ||
const result = validator.validate(contents, getSchema()); | ||
if (result.throwError) { | ||
throw result.throwError; | ||
} | ||
if (result.errors.length > 0) { | ||
throw result.errors[0]; | ||
} | ||
return contents; | ||
return this.validateOptions(contents); | ||
} catch (error) { | ||
@@ -196,3 +188,3 @@ // swallow "not found" errors because they are so common / expected | ||
static loadConfigFromFile(filepath: string): ProjectConfig|null { | ||
let configParsed = ProjectConfig.loadOptionsFromFile(filepath); | ||
const configParsed = ProjectConfig.loadOptionsFromFile(filepath); | ||
if (!configParsed) { | ||
@@ -205,2 +197,30 @@ return null; | ||
/** | ||
* Returns the given configJsonObject if it is a valid ProjectOptions object, | ||
* otherwise throws an informative error message. | ||
*/ | ||
static validateOptions(configJsonObject: {}): ProjectOptions { | ||
const validator = new jsonschema.Validator(); | ||
const result = validator.validate(configJsonObject, getSchema()); | ||
if (result.errors.length > 0) { | ||
throw result.errors[0]; | ||
} | ||
if (result.throwError) { | ||
throw new Error( | ||
`An error was encountered while validating the ` + | ||
`Polymer Project Config.`); | ||
} | ||
return configJsonObject; | ||
} | ||
/** | ||
* Returns a new ProjectConfig from the given JSON object if it's valid. | ||
* | ||
* Throws if the given JSON object is an invalid ProjectOptions. | ||
*/ | ||
static validateAndCreate(configJsonObject: {}) { | ||
const options = this.validateOptions(configJsonObject); | ||
return new this(options); | ||
} | ||
/** | ||
* constructor - given a ProjectOptions object, create the correct project | ||
@@ -207,0 +227,0 @@ * configuration for those options. This involves setting the correct |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88547
2211
22