vils
Version:
Recursively outputs file paths and contents in various formats
51 lines (50 loc) • 2.09 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadConfig = loadConfig;
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
function loadConfig(cli) {
var _a, _b, _c, _d, _e, _f, _g;
const cwd = process.cwd();
let configPath;
if (cli.config) {
configPath = path_1.default.isAbsolute(cli.config) ? cli.config : path_1.default.join(cwd, cli.config);
}
else {
const candidates = ['vils.config.ts', 'vils.config.js', 'vils.config.mjs', 'vils.config.cjs'];
for (const name of candidates) {
const full = path_1.default.join(cwd, name);
if (fs_extra_1.default.existsSync(full)) {
configPath = full;
break;
}
}
}
let cfg = {};
if (configPath) {
const ext = path_1.default.extname(configPath);
if (ext === '.ts') {
const tsNode = require('ts-node');
tsNode.register({ transpileOnly: true });
cfg = require(configPath).default;
}
else {
cfg = require(configPath).default || require(configPath);
}
}
const source = cli._[0] && typeof cli._[0] === 'string' ? cli._[0] : cfg.source || '.';
const merged = {
source,
log: (_b = (_a = cli.log) !== null && _a !== void 0 ? _a : cfg.log) !== null && _b !== void 0 ? _b : false,
file: (_c = cli.file) !== null && _c !== void 0 ? _c : cfg.file,
ignore: cli.ignore.length
? cli.ignore
: ((_d = cfg.ignore) !== null && _d !== void 0 ? _d : ['node_modules', 'dist', '.git', 'package-lock.json', /^vils\..+$/]),
format: (_f = (_e = cli.format) !== null && _e !== void 0 ? _e : cfg.format) !== null && _f !== void 0 ? _f : 'md',
confirm: (_g = cfg.confirm) !== null && _g !== void 0 ? _g : false
};
return merged;
}