Skip to content

Commit f91bcbc

Browse files
committed
First public release 🐱
0 parents  commit f91bcbc

7 files changed

Lines changed: 100 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Git Revision Webpack Plugin
2+
3+
Simple [webpack](http://webpack.github.io/) plugin that generates `VERSION` and `COMMITHASH` files during build based on a local [git](http://www.git-scm.com/) repository.
4+
5+
## Usage
6+
7+
```bash
8+
npm install --save-dev git-revision-webpack-plugin
9+
```
10+
11+
Sample webpack config:
12+
13+
```javascript
14+
var GitRevisionPlugin = require('git-revision-webpack-plugin')
15+
16+
module.exports = {
17+
plugins: [
18+
new GitRevisionPlugin()
19+
]
20+
}
21+
```

lib/helpers/remove-empty-lines.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function removeEmptyLines (string) {
2+
return string.replace(/[\s\r\n]+$/, '')
3+
}

lib/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var writeCommithashFile = require('./write-commithash-file')
2+
var writeVersionFile = require('./write-version-file')
3+
4+
function GitRevisionPlugin () {}
5+
6+
GitRevisionPlugin.prototype.apply = function (compiler) {
7+
writeCommithashFile(compiler)
8+
writeVersionFile(compiler)
9+
}
10+
11+
module.exports = GitRevisionPlugin

lib/write-commithash-file.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var exec = require('child_process').exec
2+
var removeEmptyLines = require('./helpers/remove-empty-lines.js')
3+
4+
module.exports = function writeCommithashFile (compiler) {
5+
compiler.plugin('emit', function (compilation, callback) {
6+
exec('git rev-parse HEAD', function (err, stdout) {
7+
if (err) { callback(err) }
8+
const version = removeEmptyLines(stdout)
9+
10+
compilation.assets['COMMITHASH'] = {
11+
source: function () {
12+
return version
13+
},
14+
size: function () {
15+
return version.length
16+
}
17+
}
18+
19+
callback()
20+
})
21+
})
22+
}

lib/write-version-file.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var exec = require('child_process').exec
2+
var removeEmptyLines = require('./helpers/remove-empty-lines.js')
3+
4+
module.exports = function writeVersionFile (compiler) {
5+
compiler.plugin('emit', function (compilation, callback) {
6+
exec('git describe', function (err, stdout) {
7+
if (err) { callback(err) }
8+
const version = removeEmptyLines(stdout)
9+
10+
compilation.assets['VERSION'] = {
11+
source: function () {
12+
return version
13+
},
14+
size: function () {
15+
return version.length
16+
}
17+
}
18+
19+
callback()
20+
})
21+
})
22+
}

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "git-revision-webpack-plugin",
3+
"version": "0.0.1",
4+
"description": "Simple webpack plugin that generates VERSION and COMMITHASH files during build",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"test": "standard"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/pirelenito/git-revision-webpack-plugin.git"
12+
},
13+
"keywords": ["webpack", "plugin"],
14+
"author": "Paulo Ragonha",
15+
"license": "MIT",
16+
"bugs": {
17+
"url": "https://github.com/pirelenito/git-revision-webpack-plugin/issues"
18+
},
19+
"homepage": "https://github.com/pirelenito/git-revision-webpack-plugin"
20+
}

0 commit comments

Comments
 (0)