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
72 lines (53 loc) • 1.78 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;
}
class ScopeJsonHelper {
constructor(scopes) {
(0, _defineProperty2().default)(this, "scopes", void 0);
this.scopes = scopes;
}
read(scopeJsonDir = composeScopePathForWorkspace(this.scopes.localPath)) {
const scopeJsonPath = path().join(scopeJsonDir, 'scope.json');
return _fsExtra().default.existsSync(scopeJsonPath) ? _fsExtra().default.readJSONSync(scopeJsonPath) : {};
}
write(scopeJson, scopeJsonDir = composeScopePathForWorkspace(this.scopes.localPath)) {
const scopeJsonPath = path().join(scopeJsonDir, 'scope.json');
return _fsExtra().default.writeJSONSync(scopeJsonPath, scopeJson, {
spaces: 2
});
}
addKeyVal(key, val, scopeJsonDir = composeScopePathForWorkspace(this.scopes.localPath)) {
const scopeJson = this.read(scopeJsonDir);
scopeJson[key] = val;
this.write(scopeJson, scopeJsonDir);
}
}
exports.default = ScopeJsonHelper;
function composeScopePathForWorkspace(workspacePath) {
return path().join(workspacePath, '.bit');
}
;