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
149 lines (102 loc) • 2.96 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 _bluebird() {
const data = require("bluebird");
_bluebird = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = _interopRequireDefault(require("fs-extra"));
_fsExtra = function () {
return data;
};
return data;
}
function _uuid() {
const data = require("uuid");
_uuid = function () {
return data;
};
return data;
}
function path() {
const data = _interopRequireWildcard(require("path"));
path = function () {
return data;
};
return data;
}
function _repository() {
const data = _interopRequireDefault(require("../repository"));
_repository = function () {
return data;
};
return data;
}
function _constants() {
const data = require("../../constants");
_constants = function () {
return data;
};
return data;
}
function _logger() {
const data = _interopRequireDefault(require("../../logger/logger"));
_logger = function () {
return data;
};
return data;
}
class Tmp extends _repository().default {
getPath() {
return path().join(super.getPath(), _constants().BIT_TMP_DIRNAME);
}
composePath(p) {
return path().join(this.getPath(), p);
}
save(data, ext = '.js') {
var _this = this;
return (0, _bluebird().coroutine)(function* () {
const fileName = (0, _uuid().v4)();
const filePath = _this.composePath(`${fileName}${ext}`);
yield _fsExtra().default.outputFile(filePath, data);
return filePath;
})();
}
saveSync(data, ext = '.js') {
const fileName = (0, _uuid().v4)();
const filePath = this.composePath(`${fileName}${ext}`);
_fsExtra().default.outputFileSync(filePath, data);
return filePath;
}
remove(fileNameOrPath, ext = '.js') {
const fileName = path().parse(fileNameOrPath).name;
const filePath = this.composePath(`${fileName}${ext}`);
_logger().default.info(`tmp.remove, deleting ${filePath}`);
return _fsExtra().default.remove(filePath);
}
removeSync(fileNameOrPath, ext = '.js') {
const fileName = path().parse(fileNameOrPath).name;
const filePath = this.composePath(`${fileName}${ext}`);
_logger().default.info(`tmp.removeSync, deleting ${filePath}`);
return _fsExtra().default.removeSync(filePath);
}
clear() {
const dirToDelete = this.getPath();
_logger().default.info(`tmp.clear, deleting ${dirToDelete}`);
return _fsExtra().default.emptyDir(dirToDelete);
}
clearSync() {
const dirToDelete = this.getPath();
_logger().default.info(`tmp.clearSync, deleting ${dirToDelete}`);
return _fsExtra().default.emptyDirSync(dirToDelete);
}
}
exports.default = Tmp;
;