@fimbul/wotan
Version:
Pluggable TypeScript and JavaScript linter
50 lines • 1.86 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadConfig = exports.run = void 0;
const ymir_1 = require("@fimbul/ymir");
const fs = require("fs");
const path = require("path");
const debug = require("debug");
const log = debug('wotan:cli');
async function run(argv) {
if (argv.length === 1 && /^(')?-(?:v|-version)\1$/.test(argv[0]))
return console.log(require('../package.json').version);
try {
const config = await loadConfig('.');
const args = (await Promise.resolve().then(() => require('./argparse'))).parseArguments(argv, config);
if (!await (await Promise.resolve().then(() => require('./commands'))).runCommand(args, undefined, config))
process.exitCode = 2;
}
catch (e) {
console.error(e instanceof ymir_1.ConfigurationError ? e.message : e);
process.exitCode = 1;
}
}
exports.run = run;
function loadConfig(dir) {
const fileName = path.join(dir, '.fimbullinter.yaml');
return new Promise((resolve) => {
return fs.readFile(fileName, { encoding: 'utf8' }, (err, content) => {
if (err) {
log("Not using '%s': %s", fileName, err.code);
return resolve({});
}
Promise.resolve().then(() => require('js-yaml')).then((yaml) => {
try {
resolve(yaml.load(content) || {});
log("Using global options from '%s'", fileName);
}
catch (e) {
log("Not using '%s': %s", fileName, e && e.message);
resolve({});
}
});
});
});
}
exports.loadConfig = loadConfig;
if (require.main === module) {
log('CLI arguments: %O', process.argv);
run(process.argv.slice(2));
}
//# sourceMappingURL=cli.js.map
;