Skip to content

Commit 745d420

Browse files
committed
Refactor to remove code duplication 🦄
1 parent f4a2e61 commit 745d420

3 files changed

Lines changed: 6 additions & 29 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var exec = require('child_process').exec
22
var removeEmptyLines = require('./helpers/remove-empty-lines.js')
33

4-
module.exports = function writeVersionFile (compiler) {
4+
module.exports = function buildFile (compiler, command, asset) {
55
compiler.plugin('emit', function (compilation, callback) {
6-
exec('git describe', function (err, stdout) {
6+
exec(command, function (err, stdout) {
77
if (err) { return callback(err) }
88
const version = removeEmptyLines(stdout)
99

10-
compilation.assets['VERSION'] = {
10+
compilation.assets[asset] = {
1111
source: function () {
1212
return version
1313
},

lib/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
var writeCommithashFile = require('./write-commithash-file')
2-
var writeVersionFile = require('./write-version-file')
1+
var buildFile = require('./build-file')
32

43
function GitRevisionPlugin () {}
54

65
GitRevisionPlugin.prototype.apply = function (compiler) {
7-
writeCommithashFile(compiler)
8-
writeVersionFile(compiler)
6+
buildFile(compiler, 'git rev-parse HEAD', 'COMMITHASH')
7+
buildFile(compiler, 'git describe', 'VERSION')
98
}
109

1110
module.exports = GitRevisionPlugin

lib/write-commithash-file.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)