git-revision-webpack-plugin
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -9,2 +9,3 @@ var buildFile = require('./build-file') | ||
this.gitWorkTree = options && options.gitWorkTree | ||
this.lightweightTags = options && options.lightweightTags || false | ||
} | ||
@@ -14,3 +15,3 @@ | ||
buildFile(compiler, this.gitWorkTree, commithashCommand, /\[git-revision-hash\]/gi, 'COMMITHASH') | ||
buildFile(compiler, this.gitWorkTree, versionCommand, /\[git-revision-version\]/gi, 'VERSION') | ||
buildFile(compiler, this.gitWorkTree, versionCommand + (this.lightweightTags ? ' --tags' : ''), /\[git-revision-version\]/gi, 'VERSION') | ||
} | ||
@@ -23,5 +24,5 @@ | ||
GitRevisionPlugin.prototype.version = function (callback) { | ||
return runGitCommand(this.gitWorkTree, versionCommand) | ||
return runGitCommand(this.gitWorkTree, versionCommand + (this.lightweightTags ? ' --tags' : '')) | ||
} | ||
module.exports = GitRevisionPlugin |
@@ -45,3 +45,3 @@ /* global describe, beforeEach, it */ | ||
expect(VERSION.toString()).to.eql('v1.0.0') | ||
expect(VERSION.toString()).to.eql('v1.0.0-1-g9a15b3b') | ||
}) | ||
@@ -53,3 +53,3 @@ | ||
expect(COMMITHASH.toString()).to.eql('10e1ff4c17ad1f12241b5c4d9a708a76e98289d8') | ||
expect(COMMITHASH.toString()).to.eql('9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2') | ||
}) | ||
@@ -59,3 +59,3 @@ | ||
it('should support templates in the output.filename', function () { | ||
var versionPath = path.join(targetBuild, 'main-v1.0.0.js') | ||
var versionPath = path.join(targetBuild, 'main-v1.0.0-1-g9a15b3b.js') | ||
fs.readFileSync(versionPath) | ||
@@ -65,6 +65,6 @@ }) | ||
it('should support setting the public path', function () { | ||
var versionPath = path.join(targetBuild, 'main-v1.0.0.js') | ||
var versionPath = path.join(targetBuild, 'main-v1.0.0-1-g9a15b3b.js') | ||
var mainJs = fs.readFileSync(versionPath) | ||
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/v1.0.0/10e1ff4c17ad1f12241b5c4d9a708a76e98289d8";' | ||
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/v1.0.0-1-g9a15b3b/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";' | ||
@@ -78,3 +78,3 @@ expect(mainJs.indexOf(expectedPublicPath) !== -1).to.eql(true) | ||
var plugin = new GitRevisionPlugin({ gitWorkTree: targetProject }) | ||
expect(plugin.commithash()).to.eql('10e1ff4c17ad1f12241b5c4d9a708a76e98289d8') | ||
expect(plugin.commithash()).to.eql('9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2') | ||
}) | ||
@@ -84,5 +84,72 @@ | ||
var plugin = new GitRevisionPlugin({ gitWorkTree: targetProject }) | ||
expect(plugin.version()).to.eql('v1.0.0') | ||
expect(plugin.version()).to.eql('v1.0.0-1-g9a15b3b') | ||
}) | ||
}) | ||
}) | ||
describe('git-revision-webpack-plugin with lightweightTags option', function () { | ||
beforeEach(function (done) { | ||
fs.emptyDirSync(targetProject) | ||
fs.copySync(sourceProject, targetProject) | ||
fs.emptyDirSync(targetGitRepository) | ||
fs.copySync(sourceGitRepository, targetGitRepository) | ||
fs.remove(targetBuild) | ||
var config = require(targetProjectConfig) | ||
config.context = targetProject | ||
config.output.path = targetBuild | ||
config.plugins = [ | ||
new GitRevisionPlugin({ gitWorkTree: targetProject, lightweightTags: true }) | ||
] | ||
webpack(config, function () { | ||
done() | ||
}) | ||
}) | ||
it('should create the VERSION file', function () { | ||
var versionPath = path.join(targetBuild, 'VERSION') | ||
var VERSION = fs.readFileSync(versionPath) | ||
expect(VERSION.toString()).to.eql('v2.0.0-beta') | ||
}) | ||
it('should create the COMMITHASH file', function () { | ||
var versionPath = path.join(targetBuild, 'COMMITHASH') | ||
var COMMITHASH = fs.readFileSync(versionPath) | ||
expect(COMMITHASH.toString()).to.eql('9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2') | ||
}) | ||
describe('[git-revision-version] and [git-revision-hash] templates', function () { | ||
it('should support templates in the output.filename', function () { | ||
var versionPath = path.join(targetBuild, 'main-v2.0.0-beta.js') | ||
fs.readFileSync(versionPath) | ||
}) | ||
it('should support setting the public path', function () { | ||
var versionPath = path.join(targetBuild, 'main-v2.0.0-beta.js') | ||
var mainJs = fs.readFileSync(versionPath) | ||
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/v2.0.0-beta/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";' | ||
expect(mainJs.indexOf(expectedPublicPath) !== -1).to.eql(true) | ||
}) | ||
}) | ||
describe('public API', () => { | ||
it('should expose the commithash', () => { | ||
var plugin = new GitRevisionPlugin({ gitWorkTree: targetProject, lightweightTags: true }) | ||
expect(plugin.commithash()).to.eql('9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2') | ||
}) | ||
it('should expose the version', () => { | ||
var plugin = new GitRevisionPlugin({ gitWorkTree: targetProject, lightweightTags: true }) | ||
expect(plugin.version()).to.eql('v2.0.0-beta') | ||
}) | ||
}) | ||
}) | ||
{ | ||
"name": "git-revision-webpack-plugin", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Simple webpack plugin that generates VERSION and COMMITHASH files during build", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -42,2 +42,14 @@ # Git Revision Webpack Plugin | ||
If you need [lightweight tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging#Lightweight-Tags) support, you may turn on `lighweithTags` option in this way: | ||
```javascript | ||
var GitRevisionPlugin = require('git-revision-webpack-plugin') | ||
module.exports = { | ||
plugins: [ | ||
new GitRevisionPlugin({ lightweightTags: true }) | ||
] | ||
} | ||
``` | ||
### Path Substitutions | ||
@@ -44,0 +56,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11187
186
90
118186
3