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

193 lines (139 loc) 4.71 kB
"use strict"; 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 _glob() { const data = _interopRequireDefault(require("glob")); _glob = 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; } function fixtures() { const data = _interopRequireWildcard(require("../../src/fixtures/fixtures")); fixtures = function () { return data; }; return data; } function _e2eHelper() { const data = require("./e2e-helper"); _e2eHelper = function () { return data; }; return data; } function _utils() { const data = require("../utils"); _utils = function () { return data; }; return data; } class FsHelper { constructor(scopes) { (0, _defineProperty2().default)(this, "scopes", void 0); (0, _defineProperty2().default)(this, "externalDirsArray", []); this.scopes = scopes; } getConsumerFiles(ext = '*.{js,ts}', includeDot = true, includeNodeModules = true) { const params = { cwd: this.scopes.localPath, dot: includeDot }; if (!includeNodeModules) { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! params.ignore = 'node_modules/**/*'; } return _glob().default.sync(path().normalize(`**/${ext}`), params).map(x => path().normalize(x)); } getObjectFiles() { return _glob().default.sync(path().normalize('*/*'), { cwd: path().join(this.scopes.localPath, '.bit/objects') }); } /** * @deprecated use outputFile instead */ createFile(folder, name, impl = fixtures().fooFixture) { const filePath = path().join(this.scopes.localPath, folder, name); _fsExtra().default.outputFileSync(filePath, impl); } createJsonFile(filePathRelativeToLocalScope, jsonContent) { const filePath = path().join(this.scopes.localPath, filePathRelativeToLocalScope); (0, _e2eHelper().ensureAndWriteJson)(filePath, jsonContent); } // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! createFileOnRootLevel(name = 'foo.js', impl = fixtures().fooFixture) { const filePath = path().join(this.scopes.localPath, name); _fsExtra().default.outputFileSync(filePath, impl); } readFile(filePathRelativeToLocalScope) { return _fsExtra().default.readFileSync(path().join(this.scopes.localPath, filePathRelativeToLocalScope)).toString(); } readJsonFile(filePathRelativeToLocalScope) { return _fsExtra().default.readJsonSync(path().join(this.scopes.localPath, filePathRelativeToLocalScope)); } outputFile(filePathRelativeToLocalScope, data = '') { return _fsExtra().default.outputFileSync(path().join(this.scopes.localPath, filePathRelativeToLocalScope), data); } moveSync(srcPathRelativeToLocalScope, destPathRelativeToLocalScope) { const src = path().join(this.scopes.localPath, srcPathRelativeToLocalScope); const dest = path().join(this.scopes.localPath, destPathRelativeToLocalScope); return _fsExtra().default.moveSync(src, dest); } /** * adds "\n" at the beginning of the file to make it modified. */ modifyFile(filePath) { const content = _fsExtra().default.readFileSync(filePath); _fsExtra().default.outputFileSync(filePath, `\n${content}`); } deletePath(relativePathToLocalScope) { return _fsExtra().default.removeSync(path().join(this.scopes.localPath, relativePathToLocalScope)); } createNewDirectory() { const newDir = `${(0, _utils().generateRandomStr)()}-dir`; const newDirPath = path().join(this.scopes.e2eDir, newDir); _fsExtra().default.ensureDirSync(newDirPath); this.externalDirsArray.push(newDirPath); return newDirPath; } createNewDirectoryInLocalWorkspace(dirPath) { const newDirPath = path().join(this.scopes.localPath, dirPath); _fsExtra().default.ensureDirSync(newDirPath); return newDirPath; } cleanDir(dirPath) { _fsExtra().default.removeSync(dirPath); } cleanExternalDirs() { this.externalDirsArray.forEach(dirPath => { this.cleanDir(dirPath); }); } } exports.default = FsHelper;