Skip to content

Commit 67d8013

Browse files
committed
implement naive asconfig
1 parent 3163abb commit 67d8013

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Diff for: cli/asc.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ exports.main = function main(argv, options, callback) {
194194
if (!stderr) throw Error("'options.stderr' must be specified");
195195

196196
const opts = optionsUtil.parse(argv, exports.options);
197-
const args = opts.options;
197+
let args = opts.options;
198+
198199
argv = opts.arguments;
199200
if (args.noColors) {
200201
colorsUtil.stdout.supported =
@@ -270,6 +271,24 @@ exports.main = function main(argv, options, callback) {
270271

271272
// Set up base directory
272273
const baseDir = args.baseDir ? path.resolve(args.baseDir) : ".";
274+
const target = args.target;
275+
276+
// Once the basedir is calculated, we can resolve the config, and it's extensions
277+
let asconfig = getAsconfig(opts.config, baseDir, readFile);
278+
while (asconfig) {
279+
if (asconfig.targets && asconfig.targets[target]) {
280+
optionsUtil.merge(exports.options, args, asconfig.targets[target])
281+
}
282+
if (asconfig.options) {
283+
optionsUtil.merge(exports.options, args, asconfig.options);
284+
}
285+
if (asconfig.extends) {
286+
const dirname = path.dirname(path.join(baseDir, options.config));
287+
asconfig = getAsconfig(asconfig.extends, dirname, readFile);
288+
} else {
289+
asconfig = null; // finished resolving the configuration
290+
}
291+
}
273292

274293
// Set up options
275294
const compilerOptions = assemblyscript.newOptions();
@@ -924,6 +943,16 @@ exports.main = function main(argv, options, callback) {
924943
}
925944
};
926945

946+
function getAsconfig(file, baseDir, readFile) {
947+
const contents = readFile(file, baseDir);
948+
if (!contents) return null;
949+
const config = JSON.parse(contents);
950+
// TODO: validate configuration shape
951+
// TODO: wrap JSON.parse() in try catch to obtain a more descriptive error
952+
return config;
953+
}
954+
exports.getAsconfig = getAsconfig;
955+
927956
/** Checks diagnostics emitted so far for errors. */
928957
function checkDiagnostics(program, stderr) {
929958
var diagnostic;

Diff for: cli/asc.json

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
"type": "b",
1818
"default": false
1919
},
20+
"config": {
21+
"category": "General",
22+
"description": "Provides a configuration for assemblyscript to compile your project.",
23+
"type": "s",
24+
"default": "asconfig.js"
25+
},
26+
"target": {
27+
"category": "General",
28+
"description": "Provides a compile target for use with an assemblyscript configuration.",
29+
"type": "s",
30+
"default": "release"
31+
},
2032

2133
"optimize": {
2234
"category": "Optimization",

0 commit comments

Comments
 (0)