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
77 lines (60 loc) • 1.99 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 _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;
}
class NpmHelper {
constructor(scopes, fsHelper, commandHelper) {
(0, _defineProperty2().default)(this, "command", void 0);
(0, _defineProperty2().default)(this, "fs", void 0);
(0, _defineProperty2().default)(this, "scopes", void 0);
this.scopes = scopes;
this.fs = fsHelper;
this.command = commandHelper;
}
initNpm(initPath = path().join(this.scopes.localPath)) {
this.command.runCmd('npm init -y', initPath);
}
/**
* install package, if you don't really need the package code and can use mock
* just run addNpmPackage which will be faster
* @param {*} name
* @param {*} version
*/
installNpmPackage(name, version, cwd = this.scopes.localPath) {
const versionWithDelimiter = version ? `@${version}` : '';
const cmd = `npm i --save ${name}${versionWithDelimiter}`;
return this.command.runCmd(cmd, cwd);
}
/**
* Add a fake package, don't really install it. if you need the real package
* use installNpmPackage below
* @param {*} name
* @param {*} version
*/
addNpmPackage(name = 'lodash.get', version = '4.4.2') {
const packageJsonFixture = JSON.stringify({
name,
version
});
this.fs.createFile(`node_modules/${name}`, 'index.js');
this.fs.createFile(`node_modules/${name}`, 'package.json', packageJsonFixture);
}
}
exports.default = NpmHelper;
;