@@ -44,7 +44,7 @@ const overrides = {
44
44
cliOptions . options . optimizeLevel = asconfigOptions . optimizeLevel ;
45
45
}
46
46
} ,
47
- }
47
+ } ;
48
48
49
49
function getASConfig ( asconfigPath , targetName , readFile , configuration , cliOptions , required ) {
50
50
// calculate the directory and collect the asconfig
@@ -54,26 +54,26 @@ function getASConfig(asconfigPath, targetName, readFile, configuration, cliOptio
54
54
55
55
// if no asconfig exists
56
56
if ( ! contents ) {
57
- assert ( ! required , "No config was found at " + asconfigPath ) ;
58
- return ;
57
+ if ( required ) throw new Error ( "No config was found at " + asconfigPath ) ;
58
+ else return ;
59
59
}
60
60
61
61
// validate here
62
62
const config = validate ( contents , configuration ) ;
63
63
64
64
// resolve each parent configuration first
65
- if ( config . extends ) {
66
- getASConfig (
67
- path . isAbsolute ( config . extends )
68
- ? config . extends
69
- : path . resolve ( path . dirname ( asconfigPath ) , config . extends ) ,
70
- targetName ,
71
- readFile ,
72
- configuration ,
73
- cliOptions ,
74
- true
75
- ) ;
76
- }
65
+ // if (config.extends) {
66
+ // getASConfig(
67
+ // path.isAbsolute(config.extends)
68
+ // ? config.extends
69
+ // : path.resolve(path.dirname(asconfigPath), config.extends),
70
+ // targetName,
71
+ // readFile,
72
+ // configuration,
73
+ // cliOptions,
74
+ // true
75
+ // );
76
+ // }
77
77
78
78
// if no options are provided in the configuration, return early
79
79
if ( ! config . options ) return ;
@@ -103,42 +103,42 @@ exports.getASConfig = getASConfig;
103
103
function validateOptionsObject ( options , configDefinition ) {
104
104
for ( const key of Object . keys ( configDefinition ) ) {
105
105
const type = configDefinition [ key ] . type ;
106
- if ( ! options . hasOwnProperty ( key ) ) continue ;
106
+ if ( ! ( key in options ) ) continue ;
107
107
switch ( type ) {
108
108
case "b" : {
109
- assert ( typeof options [ key ] === "boolean" , "Invalid configuration option " + key + ", must be a boolean." ) ;
109
+ if ( typeof options [ key ] !== "boolean" ) throw new Error ( "Invalid configuration option " + key + ", must be a boolean." ) ;
110
110
break ;
111
111
}
112
112
case "f" : {
113
- assert ( typeof options [ key ] === "number" , "Invalid configuration option " + key + ", must be a number." ) ;
113
+ if ( typeof options [ key ] !== "number" ) throw new Error ( "Invalid configuration option " + key + ", must be a number." ) ;
114
114
break ;
115
115
}
116
116
case "F" : {
117
- assert ( Array . isArray ( options [ key ] ) , "Invalid configuration option " + key + ", must be an array." ) ;
117
+ if ( ! Array . isArray ( options [ key ] ) ) throw new Error ( "Invalid configuration option " + key + ", must be an array." ) ;
118
118
for ( const value of options [ key ] ) {
119
- assert ( typeof value === "number" , "Invalid configuration value in option " + key + ", " + value + " must be a number." ) ;
119
+ if ( typeof value !== "number" ) throw new Error ( "Invalid configuration value in option " + key + ", " + value + " must be a number." ) ;
120
120
}
121
121
break ;
122
122
}
123
123
case "i" : {
124
- assert ( Number . isInteger ( options [ key ] ) , "Invalid configuration option " + key + ", must be an integer." ) ;
124
+ if ( ! Number . isInteger ( options [ key ] ) ) throw new Error ( "Invalid configuration option " + key + ", must be an integer." ) ;
125
125
break ;
126
126
}
127
127
case "I" : {
128
- assert ( Array . isArray ( options [ key ] ) , "Invalid configuration option " + key + ", must be an array." ) ;
128
+ if ( ! Array . isArray ( options [ key ] ) ) throw new Error ( "Invalid configuration option " + key + ", must be an array." ) ;
129
129
for ( const value of options [ key ] ) {
130
- assert ( Number . isInteger ( value ) , "Invalid configuration value in option " + key + ", " + value + " must be an integer." ) ;
130
+ if ( ! Number . isInteger ( value ) ) throw new Error ( "Invalid configuration value in option " + key + ", " + value + " must be an integer." ) ;
131
131
}
132
132
break ;
133
133
}
134
134
case "s" : {
135
- assert ( typeof options [ key ] === "string" , "Invalid configuration option " + key + ", must be a string." ) ;
135
+ if ( typeof options [ key ] !== "string" ) throw new Error ( "Invalid configuration option " + key + ", must be a string." ) ;
136
136
break ;
137
137
}
138
138
case "S" : {
139
- assert ( Array . isArray ( options [ key ] ) , "Invalid configuration option " + key + ", must be an array." ) ;
139
+ if ( ! Array . isArray ( options [ key ] ) ) throw new Error ( "Invalid configuration option " + key + ", must be an array." ) ;
140
140
for ( const value of options [ key ] ) {
141
- assert ( typeof value === "string" , "Invalid configuration value in option " + key + ", " + value + " must be a string.") ;
141
+ if ( typeof value !== "string" ) throw new Error ( "Invalid configuration option " + key + ", must be a string." ) ;
142
142
}
143
143
break ;
144
144
}
@@ -150,22 +150,23 @@ function validateOptionsObject(options, configDefinition) {
150
150
function validate ( contents , configDefinition ) {
151
151
let config ;
152
152
try {
153
- config = assert ( JSON . parse ( contents ) , "Configuration must be an object." ) ;
154
- if ( config . extends ) {
155
- assert ( typeof config . extends === "string" , "Configuration extends value must be a string." ) ;
156
- assert ( path . extname ( config . extends ) === ".json" , "Configuration must extend a json file." ) ;
157
- }
153
+ config = JSON . parse ( contents ) ;
154
+ if ( ! config ) throw new Error ( "Configuration must be an object." ) ;
155
+ // if (config.extends) {
156
+ // if (typeof config.extends !== "string") throw new Error("Configuration extends value must be a string.");
157
+ // if (path.extname(config.extends) !== ".json") throw new Error( "Configuration must extend a json file.");
158
+ // }
158
159
if ( config . targets ) {
159
- assert ( Array . isArray ( config . targets ) , "Configuration targets value must be an Array." ) ;
160
+ if ( ! Array . isArray ( config . targets ) ) throw new Error ( "Configuration targets value must be an Array." ) ;
160
161
config . targets . forEach ( target => {
161
- assert ( typeof target . name === "string" , "All configuration targets must have a name." ) ;
162
+ if ( typeof target . name !== "string" ) throw new Error ( "All configuration targets must have a name." ) ;
162
163
} ) ;
163
164
}
164
165
165
166
// validate the options object
166
167
if ( config . options ) {
167
168
const options = config . options ;
168
- assert ( typeof options === "object" , "Configuration options must be an object." ) ;
169
+ if ( typeof options !== "object" ) throw new Error ( "Configuration options must be an object." ) ;
169
170
validateOptionsObject ( options , configDefinition ) ;
170
171
}
171
172
@@ -174,17 +175,17 @@ function validate(contents, configDefinition) {
174
175
175
176
// targets must be an array
176
177
const targets = config . targets ;
177
- assert ( typeof targets === "object" , "Configuration property 'targets' must be an object." ) ;
178
+ if ( typeof targets !== "object" ) throw new Error ( "Configuration property 'targets' must be an object." ) ;
178
179
for ( const targetName of Object . keys ( targets ) ) {
179
180
const target = targets [ targetName ] ;
180
181
181
182
// each target must be an object with a name and an options
182
- assert ( typeof target === "object" , "Configuration target '" + targetName + "' must be an object." ) ;
183
- validateOptionsObject ( options , configDefinition ) ;
183
+ if ( typeof target !== "object" ) throw new Error ( "Configuration target '" + targetName + "' must be an object." ) ;
184
+ validateOptionsObject ( target , configDefinition ) ;
184
185
}
185
186
}
186
187
} catch ( ex ) {
187
- throw new Error ( "Invalid asconfig at location " + asconfigPath + " : " + ex . message ) ;
188
+ throw new Error ( "Invalid asconfig: " + ex . message ) ;
188
189
}
189
190
return config ;
190
191
}
@@ -222,4 +223,5 @@ function reconcile(cliOptions, asconfigOptions, asconfig, overrides) {
222
223
}
223
224
}
224
225
}
226
+
225
227
exports . reconcile = reconcile ;
0 commit comments