bonsai-analyzer
Version:
Trim your dependency tree.
45 lines (36 loc) • 1.23 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = resolveArgs;
exports.DEFAULT_FLAGS = void 0;
var _path = _interopRequireDefault(require("path"));
var _loadPkg = _interopRequireDefault(require("load-pkg"));
const DEFAULT_FLAGS = {
command: 'chunk-size',
root: '.',
statsFile: './stats.json',
fileA: './stats.json',
fileB: './stats.json'
};
exports.DEFAULT_FLAGS = DEFAULT_FLAGS;
function resolveDefaultArgs(args, defaults) {
return {
command: args.command || defaults.command,
root: args.root || defaults.root,
statsFile: args['stats-file'] || defaults.statsFile,
fileA: args['file-a'] || defaults.fileA,
fileB: args['file-b'] || defaults.fileB
};
}
function resolveArgs(args) {
if (process.env.VERBOSE) {
console.log('Parsing Args', args); // eslint-disable-line no-console
}
const pkg = _loadPkg.default.sync(_path.default.resolve(args.root || DEFAULT_FLAGS.root));
const defaults = pkg && pkg.bonsai ? resolveDefaultArgs({ ...pkg.bonsai,
command: null
}, DEFAULT_FLAGS) : DEFAULT_FLAGS;
return resolveDefaultArgs(args, defaults);
}