config file available through --save (autoloads if existing in cwd)

This commit is contained in:
Thomas Rory Gummerson committed 2019-06-20 15:45:41 +02:00
1 parent 51c0768141
commit 58b5578ecb
1 file changed
+15
+15
View File
@@ -2,6 +2,8 @@
'use strict';
const { existsSync, readFileSync, writeFileSync } = require('fs');
const parseArgs = require('minimist');
const read = require('./testreader');
@@ -15,6 +17,15 @@ const args = parseArgs(process.argv.slice(2), {
}
});
if (existsSync('codin.config.json')) {
const config = JSON.parse(readFileSync('codin.config.json'));
for (const [ key, value ] of Object.entries(config)) {
if (!args[key] || Array.isArray(args[key]) && args[key].length === 0) {
args[key] = value;
}
}
}
const readTests = () => {
if (args.test) {
const testfiles = Array.isArray(args.test)
@@ -52,6 +63,10 @@ const main = tests => {
}
};
if (args.save) {
writeFileSync('codin.config.json', JSON.stringify(args, null, '\t'));
}
if (args.size) {
const files = Array.isArray(args.size)
? args.size