UNPKG

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

127 lines (91 loc) 2.83 kB
"use strict"; 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 _fsExtra() { const data = _interopRequireDefault(require("fs-extra")); _fsExtra = function () { return data; }; return data; } function _abstractVinyl() { const data = _interopRequireDefault(require("./abstract-vinyl")); _abstractVinyl = function () { return data; }; return data; } function _validationError() { const data = _interopRequireDefault(require("../../../error/validation-error")); _validationError = function () { return data; }; return data; } function _logger() { const data = _interopRequireDefault(require("../../../logger/logger")); _logger = function () { return data; }; return data; } class JSONFile extends _abstractVinyl().default { constructor(...args) { super(...args); (0, _defineProperty2().default)(this, "override", false); } write() { var _this = this; return (0, _bluebird().coroutine)(function* () { const stat = yield _this._getStatIfFileExists(); if (stat) { if (stat.isSymbolicLink()) { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! throw new (_validationError().default)(`fatal: trying to write a json file into a symlink file at "${_this.path}"`); } if (!_this.override) { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! _logger().default.debug(`json-file.write, ignore existing file ${_this.path}`); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! return _this.path; } } // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! _logger().default.debug(`json-file.write, path ${_this.path}`); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! yield _fsExtra().default.outputFile(_this.path, _this.contents); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! return _this.path; })(); } static load({ base, path, content, override = false }) { const jsonStr = JSON.stringify(content, null, 4); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const jsonFile = new JSONFile({ base, path, contents: Buffer.from(jsonStr) }); jsonFile.override = override; return jsonFile; } } exports.default = JSONFile;