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
104 lines (77 loc) • 2.65 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 _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;
}
class GitHelper {
constructor(scopes, commandHelper, scopeHelper) {
(0, _defineProperty2().default)(this, "scopes", void 0);
(0, _defineProperty2().default)(this, "command", void 0);
(0, _defineProperty2().default)(this, "scopeHelper", void 0);
this.scopes = scopes;
this.command = commandHelper;
this.scopeHelper = scopeHelper;
}
writeGitIgnore(list) {
const gitIgnorePath = path().join(this.scopes.localPath, '.gitignore');
return _fsExtra().default.writeFileSync(gitIgnorePath, list.join('\n'));
}
writeToGitHook(hookName, content) {
const hookPath = path().join(this.scopes.localPath, '.git', 'hooks', hookName);
return _fsExtra().default.outputFileSync(hookPath, content);
}
initNewGitRepo() {
return this.command.runCmd('git init');
}
addGitConfig(key, val, location = 'local') {
return this.command.runCmd(`git config --${location} ${key} ${val}`);
}
unsetGitConfig(key, location = 'local') {
return this.command.runCmd(`git config --unset --${location} ${key}`);
}
mimicGitCloneLocalProject(cloneWithComponentsFiles = true) {
_fsExtra().default.removeSync(path().join(this.scopes.localPath, '.bit'));
if (!cloneWithComponentsFiles) _fsExtra().default.removeSync(path().join(this.scopes.localPath, 'components')); // delete all node-modules from all directories
const directories = _glob().default.sync(path().normalize('**/'), {
cwd: this.scopes.localPath,
dot: true
});
directories.forEach(dir => {
if (dir.includes('node_modules')) {
_fsExtra().default.removeSync(path().join(this.scopes.localPath, dir));
}
});
this.scopeHelper.initWorkspace();
}
}
exports.default = GitHelper;