UNPKG

reg-keygen-git-hash-plugin

Version:

Detect the snapshot key to be compare with using Git hash.

53 lines 1.69 kB
"use strict"; const reg_suit_util_1 = require("reg-suit-util"); const commit_explorer_1 = require("./commit-explorer"); class GitHashKeyGenPlugin { constructor() { this._explorer = new commit_explorer_1.CommitExplorer(); } init(config) { this._conf = config; } getExpectedKey() { var _a; if (!this._checkAndMessage()) { return Promise.reject(null); } try { const result = this._explorer.getBaseCommitHash(); if (result) { return Promise.resolve(result); } else { return Promise.reject(null); } } catch (e) { this._conf.logger.error(this._conf.logger.colors.red((_a = e.message) !== null && _a !== void 0 ? _a : "unknown error")); return Promise.reject(null); } } getActualKey() { if (!this._checkAndMessage()) { return Promise.reject(new Error()); } return Promise.resolve(this._explorer.getCurrentCommitHash()); } _isInGitRepository() { return !!reg_suit_util_1.fsUtil.lookup(".git", this._conf.workingDirs.base); } _checkAndMessage() { const result = this._isInGitRepository(); if (!result) { this._conf.logger.error(this._conf.logger.colors.red("reg-keygen-git-hash-plugin does not work outside of a Git repository. Please retry after running `git init`.")); } return result; } } const pluginFactory = () => { return { keyGenerator: new GitHashKeyGenPlugin(), }; }; module.exports = pluginFactory; //# sourceMappingURL=index.js.map