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

196 lines (144 loc) 4.06 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 path() { const data = _interopRequireWildcard(require("path")); path = function () { return data; }; return data; } function _tar() { const data = _interopRequireDefault(require("tar")); _tar = function () { return data; }; return data; } function _fsExtra() { const data = _interopRequireDefault(require("fs-extra")); _fsExtra = function () { return data; }; return data; } function _chai() { const data = require("chai"); _chai = function () { return data; }; return data; } function _constants() { const data = require("../constants"); _constants = function () { return data; }; return data; } function _defaultErrorHandler() { const data = _interopRequireDefault(require("../cli/default-error-handler")); _defaultErrorHandler = function () { return data; }; return data; } function _utils() { const data = require("../utils"); _utils = function () { return data; }; return data; } function _e2eHelper() { const data = require("./e2e-helper"); _e2eHelper = function () { return data; }; return data; } class GeneralHelper { constructor(scopes, npmHelper, commandHelper) { (0, _defineProperty2().default)(this, "scopes", void 0); (0, _defineProperty2().default)(this, "npm", void 0); (0, _defineProperty2().default)(this, "command", void 0); this.scopes = scopes; this.npm = npmHelper; this.command = commandHelper; } indexJsonPath() { return path().join(this.scopes.localPath, '.bit/index.json'); } getIndexJson() { return _fsExtra().default.readJsonSync(this.indexJsonPath()); } writeIndexJson(indexJson) { return (0, _e2eHelper().ensureAndWriteJson)(this.indexJsonPath(), indexJson); } installAndGetTypeScriptCompilerDir() { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! this.npm.installNpmPackage('typescript'); return path().join(this.scopes.localPath, 'node_modules', '.bin'); } setProjectAsAngular() { this.npm.initNpm(); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! this.npm.installNpmPackage('@angular/core'); } nodeStart(mainFilePath, cwd) { return this.command.runCmd(`node ${mainFilePath}`, cwd); } untarFile(filePath, dir, sync) { return _tar().default.x({ file: filePath, C: dir, sync }); } runWithTryCatch(cmd, cwd = this.scopes.localPath, overrideFeatures) { let output; try { output = this.command.runCmd(cmd, cwd, undefined, overrideFeatures); } catch (err) { output = err.toString() + err.stdout.toString(); } return output; } static alignOutput(str) { if (!str) return str; // on Mac the directory '/var' is sometimes shown as '/private/var' // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! return (0, _utils().removeChalkCharacters)(str).replace(/\/private\/var/g, '/var'); } expectToThrow(cmdFunc, error) { let output; try { cmdFunc(); } catch (err) { output = err.toString(); } const { message: errorString } = (0, _defaultErrorHandler().default)(error); (0, _chai().expect)(GeneralHelper.alignOutput(output)).to.have.string(GeneralHelper.alignOutput(errorString)); } getRequireBitPath(box, name) { return `@bit/${this.scopes.remote}.${box}.${name}`; } getBitVersion() { return _constants().BIT_VERSION; } generateRandomTmpDirName() { return path().join(this.scopes.e2eDir, (0, _utils().generateRandomStr)()); } } exports.default = GeneralHelper;