UNPKG

git-revision-webpack-plugin

Version:

[![npm version](https://badge.fury.io/js/git-revision-webpack-plugin.svg)](https://badge.fury.io/js/git-revision-webpack-plugin) [![downloads](https://img.shields.io/npm/dm/git-revision-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/

28 lines (23 loc) 749 B
import { exec } from 'child_process' import { execSync } from 'child_process' import path from 'path' import removeEmptyLines from './remove-empty-lines' interface Cb { (err: Error | null, output: string): void } export default function(gitWorkTree: string | undefined, command: string, callback?: Cb) { const gitCommand = gitWorkTree ? ['git', '--git-dir=' + path.join(gitWorkTree, '.git'), '--work-tree=' + gitWorkTree, command].join(' ') : ['git', command].join(' ') if (callback) { exec(gitCommand, function(err, stdout) { if (err) { return callback(err, '') } callback(null, removeEmptyLines(stdout)) }) return null } else { return removeEmptyLines(`${execSync(gitCommand)}`) } }