|
|
@ -1,7 +1,7 @@
|
|
|
|
/*!
|
|
|
|
/*!
|
|
|
|
* parse-git-config <https://github.com/jonschlinkert/parse-git-config>
|
|
|
|
* parse-git-config <https://github.com/jonschlinkert/parse-git-config>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015-2018, Jon Schlinkert.
|
|
|
|
* Copyright (c) 2015-present, Jon Schlinkert.
|
|
|
|
* Released under the MIT License.
|
|
|
|
* Released under the MIT License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
@ -9,13 +9,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const util = require('util');
|
|
|
|
const ini = require('ini');
|
|
|
|
const ini = require('ini');
|
|
|
|
const configPath = require('git-config-path');
|
|
|
|
const configPath = require('git-config-path');
|
|
|
|
const expand = require('expand-tilde');
|
|
|
|
const expand = require('expand-tilde');
|
|
|
|
|
|
|
|
|
|
|
|
const read = promisify(fs.readFile);
|
|
|
|
|
|
|
|
const stat = promisify(fs.stat);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Asynchronously parse a `.git/config` file. If only the callback is passed,
|
|
|
|
* Asynchronously parse a `.git/config` file. If only the callback is passed,
|
|
|
|
* the `.git/config` file relative to `process.cwd()` is used.
|
|
|
|
* the `.git/config` file relative to `process.cwd()` is used.
|
|
|
@ -61,23 +59,22 @@ function parse(options, callback) {
|
|
|
|
* @api public
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
parse.promise = function(options) {
|
|
|
|
parse.promise = options => {
|
|
|
|
const opts = Object.assign({}, options);
|
|
|
|
const filepath = parse.resolveConfigPath(options);
|
|
|
|
const filepath = parse.resolveConfigPath(opts);
|
|
|
|
const read = util.promisify(fs.readFile);
|
|
|
|
|
|
|
|
const stat = util.promisify(fs.stat);
|
|
|
|
|
|
|
|
|
|
|
|
if (!filepath) {
|
|
|
|
if (!filepath) {
|
|
|
|
return Promise.resolve(null);
|
|
|
|
return Promise.resolve(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return stat(filepath)
|
|
|
|
return stat(filepath)
|
|
|
|
.then(() => {
|
|
|
|
.then(() => read(filepath, 'utf8'))
|
|
|
|
return read(filepath, 'utf8');
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.then(str => {
|
|
|
|
.then(str => {
|
|
|
|
if (opts.include === true) {
|
|
|
|
if (options && options.include === true) {
|
|
|
|
str = injectInclude(str, path.resolve(path.dirname(filepath)));
|
|
|
|
str = injectInclude(str, path.resolve(path.dirname(filepath)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parseIni(str, opts);
|
|
|
|
return parseIni(str, options);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -95,7 +92,7 @@ parse.promise = function(options) {
|
|
|
|
* @api public
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
parse.sync = function(options) {
|
|
|
|
parse.sync = options => {
|
|
|
|
const opts = Object.assign({}, options);
|
|
|
|
const opts = Object.assign({}, options);
|
|
|
|
const filepath = parse.resolveConfigPath(opts);
|
|
|
|
const filepath = parse.resolveConfigPath(opts);
|
|
|
|
if (filepath && fs.existsSync(filepath)) {
|
|
|
|
if (filepath && fs.existsSync(filepath)) {
|
|
|
@ -116,7 +113,7 @@ parse.sync = function(options) {
|
|
|
|
* Resolve the git config path
|
|
|
|
* Resolve the git config path
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
parse.resolveConfigPath = function(options) {
|
|
|
|
parse.resolveConfigPath = options => {
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
options = { type: options };
|
|
|
|
options = { type: options };
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -129,9 +126,7 @@ parse.resolveConfigPath = function(options) {
|
|
|
|
* Deprecated: use `.resolveConfigPath` instead
|
|
|
|
* Deprecated: use `.resolveConfigPath` instead
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
parse.resolve = function(options) {
|
|
|
|
parse.resolve = options => parse.resolveConfigPath(options);
|
|
|
|
return parse.resolveConfigPath(options);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Returns an object with only the properties that had ini-style keys
|
|
|
|
* Returns an object with only the properties that had ini-style keys
|
|
|
@ -146,7 +141,7 @@ parse.resolve = function(options) {
|
|
|
|
* @api public
|
|
|
|
* @api public
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
parse.expandKeys = function(config) {
|
|
|
|
parse.expandKeys = config => {
|
|
|
|
for (const key of Object.keys(config)) {
|
|
|
|
for (const key of Object.keys(config)) {
|
|
|
|
const m = /(\S+) "(.*)"/.exec(key);
|
|
|
|
const m = /(\S+) "(.*)"/.exec(key);
|
|
|
|
if (!m) continue;
|
|
|
|
if (!m) continue;
|
|
|
@ -173,10 +168,7 @@ function parseIni(str, options) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function injectInclude(input, cwd) {
|
|
|
|
function injectInclude(input, cwd) {
|
|
|
|
const lines = input.split('\n').filter(function(line) {
|
|
|
|
const lines = input.split('\n').filter(line => line.trim() !== '');
|
|
|
|
return line.trim() !== '';
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const len = lines.length;
|
|
|
|
const len = lines.length;
|
|
|
|
const res = [];
|
|
|
|
const res = [];
|
|
|
|
|
|
|
|
|
|
|
@ -194,22 +186,6 @@ function injectInclude(input, cwd) {
|
|
|
|
return res.join('\n');
|
|
|
|
return res.join('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Wraps an arbitrary function in a Promise.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param {Function} `fn` The function to be wrapped.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function promisify(fn) {
|
|
|
|
|
|
|
|
return (...args) => {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
fn(...args, (err, res) => {
|
|
|
|
|
|
|
|
err ? reject(err) : resolve(res);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Expose `parse`
|
|
|
|
* Expose `parse`
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|