Skip to content

Commit ba59213

Browse files
committed
switch to target flag, comments, small fix
1 parent 200057d commit ba59213

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

cli/asc.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,12 @@ exports.main = function main(argv, options, callback) {
272272
}
273273

274274
// Set up base directory
275-
const configOption = args.config || "asconfig.json:release";
276-
const configSplitIndex = configOption.indexOf(":");
277-
const configLocation = configSplitIndex === -1
278-
? configOption
279-
: configOption.slice(0, configSplitIndex);
280-
const configTarget = configSplitIndex === -1
281-
? "release"
282-
: configOption.slice(configSplitIndex + 1) || "release";
275+
const configOption = args.config;
276+
const configTarget = args.target;
283277

284278
// override all the configuration options with the asconfig values, unless specified by the cli
285279
exports.getASConfig(
286-
configLocation,
280+
configOption,
287281
configTarget,
288282
readFile,
289283
exports.options,

cli/asc.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
"category": "General",
2222
"description": "Provide the location and the target configuration for this build.",
2323
"type": "s",
24-
"default": "asconfig.json:release"
24+
"default": "asconfig.json"
25+
},
26+
"target": {
27+
"category": "General",
28+
"description": "Provide a configuration target for this build as described in the asconfig.",
29+
"type": "s",
30+
"default": "release"
2531
},
26-
2732
"optimize": {
2833
"category": "Optimization",
2934
"description": [

cli/asconfig.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ function getASConfig(asconfigPath, targetName, readFile, configuration, cliOptio
7676
// }
7777

7878
// if no options are provided in the configuration, return early
79-
if (!config.options) return;
79+
if (!config.options && !config.targets) return;
8080

8181
// first reconcile the top level options
8282
if (config.options) {
8383
reconcile(cliOptions, config.options, configuration, overrides);
8484
}
8585

86-
// then reconvile the target
86+
// then reconcile the target
8787
if (config.targets && config.targets[targetName]) {
8888
reconcile(cliOptions, config.targets[targetName], configuration, overrides);
8989
}
@@ -101,7 +101,7 @@ exports.getASConfig = getASConfig;
101101
// V | array of values (provided in "values" property)
102102

103103
function validateOptionsObject(options, configDefinition) {
104-
for (const key of Object.keys(configDefinition)) {
104+
for (const key of Object.getOwnPropertyNames(configDefinition)) {
105105
const type = configDefinition[key].type;
106106
if (!(key in options)) continue;
107107
switch (type) {
@@ -145,6 +145,11 @@ function validateOptionsObject(options, configDefinition) {
145145
default: throw new Error("Invalid asconfig option type '" + type + "'.");
146146
}
147147
}
148+
149+
for (const key of Object.getOwnPropertyNames(options)) {
150+
// console.log(options);
151+
if (!configDefinition[key]) throw new Error("Invalid asconfig option '" + key + "'.");
152+
}
148153
}
149154

150155
function validate(contents, configDefinition) {
@@ -157,10 +162,11 @@ function validate(contents, configDefinition) {
157162
// if (path.extname(config.extends) !== ".json") throw new Error( "Configuration must extend a json file.");
158163
// }
159164
if (config.targets) {
160-
if (!Array.isArray(config.targets)) throw new Error("Configuration targets value must be an Array.");
161-
config.targets.forEach(target => {
162-
if (typeof target.name !== "string") throw new Error("All configuration targets must have a name.");
163-
});
165+
if (typeof config.targets !== "object") throw new Error("Configuration property 'targets' must be an Object.");
166+
167+
for (const key of Object.getOwnPropertyNames(config.targets)) {
168+
if (typeof config.targets[key] !== "object") throw new Error("Configuration target '" + key + "' must be an Object.");
169+
}
164170
}
165171

166172
// validate the options object

0 commit comments

Comments
 (0)