UNPKG

youzanyun-devtool-worker

Version:

50 lines (49 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const spring4js_nodejs_1 = require("spring4js-nodejs"); let GitService = class GitService { constructor() { } async start() { } async getGitInfo(gitRepoDir) { const gitInfo = {}; try { const remoteInfo = await this.executeService.promiseExec('git remote -v', { cwd: gitRepoDir, }); const appNameArr = remoteInfo.split('/').pop().split('.git'); gitInfo.appName = appNameArr[0]; const username = await this.executeService.promiseExec('git config user.name', { cwd: gitRepoDir, }); gitInfo.username = username || 'unknown'; const commitId = await this.executeService.promiseExec('git rev-parse HEAD', { cwd: gitRepoDir, }); gitInfo.commitId = commitId; return gitInfo; } catch (error) { console.log(error); return gitInfo; } } async checkGitRepoClean(gitRepoDir) { try { const statusInfo = await this.executeService.promiseExec('git status -s', { cwd: gitRepoDir, }); return !statusInfo; } catch (error) { return false; } } }; tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], GitService.prototype, "executeService", void 0); GitService = tslib_1.__decorate([ (0, spring4js_nodejs_1.Service)() ], GitService); exports.default = GitService;