bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
102 lines (75 loc) • 2.14 kB
JavaScript
;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _defineProperty2() {
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
_defineProperty2 = function () {
return data;
};
return data;
}
function path() {
const data = _interopRequireWildcard(require("path"));
path = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = _interopRequireDefault(require("fs-extra"));
_fsExtra = function () {
return data;
};
return data;
}
function _constants() {
const data = require("../constants");
_constants = function () {
return data;
};
return data;
}
function _utils() {
const data = require("../utils");
_utils = function () {
return data;
};
return data;
}
class GlobalRemotes {
constructor(remotes) {
(0, _defineProperty2().default)(this, "remotes", void 0);
this.remotes = remotes;
}
addRemote(remote) {
this.remotes[remote.name] = remote.host;
return this;
}
rmRemote(name) {
if (!this.remotes[name]) return false;
delete this.remotes[name];
return true;
}
toJson(readable = true) {
if (!readable) return JSON.stringify(this.toPlainObject());
return JSON.stringify(this.toPlainObject(), null, 4);
}
toPlainObject() {
return this.remotes;
}
write() {
return (0, _utils().writeFile)(path().join(_constants().GLOBAL_CONFIG, _constants().GLOBAL_REMOTES), this.toJson());
}
static load() {
return _fsExtra().default.readFile(path().join(_constants().GLOBAL_CONFIG, _constants().GLOBAL_REMOTES)).then(contents => new GlobalRemotes(JSON.parse(contents.toString('utf8')))).catch(err => {
if (err.code !== 'ENOENT') return err;
const globalRemotes = new GlobalRemotes({});
return globalRemotes.write().then(() => globalRemotes);
});
}
}
exports.default = GlobalRemotes;