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
147 lines (108 loc) • 3.17 kB
JavaScript
;
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 _defineProperty2() {
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
_defineProperty2 = function () {
return data;
};
return data;
}
function _ramda() {
const data = _interopRequireDefault(require("ramda"));
_ramda = function () {
return data;
};
return data;
}
function _vinylFile() {
const data = _interopRequireDefault(require("vinyl-file"));
_vinylFile = function () {
return data;
};
return data;
}
function _abstractVinyl() {
const data = _interopRequireDefault(require("./abstract-vinyl"));
_abstractVinyl = function () {
return data;
};
return data;
}
function _fileSourceNotFound() {
const data = _interopRequireDefault(require("../exceptions/file-source-not-found"));
_fileSourceNotFound = function () {
return data;
};
return data;
}
function _logger() {
const data = _interopRequireDefault(require("../../../logger/logger"));
_logger = function () {
return data;
};
return data;
}
class SourceFile extends _abstractVinyl().default {
constructor(...args) {
super(...args);
(0, _defineProperty2().default)(this, "distFilePath", void 0);
}
static load(filePath, base, consumerPath, extendedProps) {
try {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
const file = new SourceFile(_vinylFile().default.readSync(filePath, {
base,
cwd: consumerPath
}));
const addToFile = (value, key) => file[key] = value;
/* eslint-disable-line no-return-assign */
_ramda().default.forEachObjIndexed(addToFile, extendedProps);
return file;
} catch (err) {
_logger().default.errorAndAddBreadCrumb('source-file.load', 'failed loading file {filePath}. Error: {message}', {
filePath,
message: err.message
}, err);
if (err.code === 'ENOENT' && err.path) {
throw new (_fileSourceNotFound().default)(err.path);
}
throw err;
}
}
static loadFromParsedString(parsedString) {
if (!parsedString) return null;
const opts = super.loadFromParsedStringBase(parsedString);
return new SourceFile(opts);
}
static loadFromParsedStringArray(arr) {
if (!arr) return null; // @ts-ignore
return arr.map(this.loadFromParsedString);
}
static loadFromSourceFileModel(file, repository) {
return (0, _bluebird().coroutine)(function* () {
const content = yield file.file.load(repository); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
return new SourceFile({
base: '.',
path: file.relativePath,
contents: content.contents,
test: file.test
});
})();
}
clone() {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
return new SourceFile(this);
}
}
exports.default = SourceFile;