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
75 lines (52 loc) • 1.5 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.onPersist = onPersist;
exports.onRead = onRead;
function _path() {
const data = _interopRequireDefault(require("path"));
_path = function () {
return data;
};
return data;
}
function _isRelativePath() {
const data = _interopRequireDefault(require("is-relative-path"));
_isRelativePath = function () {
return data;
};
return data;
}
function loadHooks(scopePath, scopeJson) {
const hooksPath = scopeJson.hooksPath;
if (hooksPath) {
const hooksFinalPath = (0, _isRelativePath().default)(hooksPath) ? _path().default.join(scopePath, hooksPath) : hooksPath; // eslint-disable-next-line global-require, import/no-dynamic-require
const hooks = require(hooksFinalPath);
return hooks;
}
return undefined;
}
function onPersist(scopePath, scopeJson) {
const defaultFunc = content => content;
const hooks = loadHooks(scopePath, scopeJson);
if (hooks) {
const onReadFunction = hooks.onPersist;
if (onReadFunction) {
return onReadFunction;
}
}
return defaultFunc;
}
function onRead(scopePath, scopeJson) {
const defaultFunc = content => content;
const hooks = loadHooks(scopePath, scopeJson);
if (hooks) {
const onReadFunction = hooks.onRead;
if (onReadFunction) {
return onReadFunction;
}
}
return defaultFunc;
}
;