ember-cli-build-info
Advanced tools
Comparing version 0.0.4 to 0.1.0
64
index.js
/* jshint node: true */ | ||
'use strict'; | ||
var execSync = require('exec-sync'); | ||
var parseVersion = require('./lib/parse-version'); | ||
var mergeOptions = require('./lib/merge-options'); | ||
var buildMetaTag = require('./lib/build-meta-tag'); | ||
@@ -10,50 +12,14 @@ module.exports = { | ||
/** | ||
* Collect Build Info data | ||
* Store Application options, merged with defaults. | ||
*/ | ||
included: function(app, parentAddon) { | ||
var target = (parentAddon || app); | ||
var info; | ||
var commit; | ||
var defaultOptions = { | ||
metaTemplate: false, // 'VERSION: {VERSION} SHA: {COMMIT}', | ||
injectedKey: 'buildInfo' | ||
}; | ||
this.options = target.options.buildInfoOptions || {}; | ||
// merge options | ||
for (var option in defaultOptions) { | ||
if (!this.options.hasOwnProperty(option)) { | ||
this.options[option] = defaultOptions[option]; | ||
} | ||
} | ||
// build info object | ||
info = { | ||
version: this.project.pkg.version || '', | ||
desc: execSync('git describe --tags --long --always') || null | ||
}; | ||
if (typeof info.desc === 'string') { | ||
commit = info.desc.split('-').pop(); | ||
// remove the prepended `g` | ||
if (commit[0] === 'g') { | ||
commit = commit.substr(1); | ||
} | ||
info.commit = commit; | ||
} | ||
// store the info | ||
this.info = info; | ||
this.options = mergeOptions(target); | ||
}, | ||
/** | ||
* Expose the data on the APP object. | ||
* FIXME: I doubt this is the best way to do this.. | ||
* Expose the build info on the APP object. | ||
*/ | ||
config: function(env, config) { | ||
config.APP.BUILD_INFO = this.info; | ||
config.APP.buildInfo = parseVersion(config.APP.version || require('git-repo-version')()); | ||
}, | ||
@@ -64,19 +30,7 @@ | ||
*/ | ||
contentFor: function(type) { | ||
var info = this.info; | ||
var options = this.options; | ||
var output; | ||
contentFor: function(type, config) { | ||
if (type === 'head') { | ||
//abort meta tag injection if there's no template | ||
if (!options.metaTemplate) { return; } | ||
output = options.metaTemplate | ||
.replace(/\{VERSION\}/g, info.version) | ||
.replace(/\{DESC\}/g, info.desc) | ||
.replace(/\{COMMIT\}/g, info.commit); | ||
return '<meta name="build-info" content="' + output + '"/>'; | ||
return buildMetaTag(config.APP.buildInfo, this.options.metaTemplate); | ||
} | ||
} | ||
}; |
{ | ||
"name": "ember-cli-build-info", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"directories": { | ||
@@ -34,7 +34,5 @@ "doc": "doc", | ||
"express": "^4.8.5", | ||
"git-repo-version": "^0.2.0", | ||
"glob": "^4.0.5" | ||
}, | ||
"dependencies": { | ||
"exec-sync": "^0.1.6" | ||
}, | ||
"description": "Inject build information (version, current SHA) into your Ember app.", | ||
@@ -41,0 +39,0 @@ "keywords": [ |
@@ -12,3 +12,2 @@ # ember-cli-build-info | ||
version: '0.1.4', // pulled from package.json | ||
desc: 'v0.1.4-3-g53df212', // from shell command `git describe` | ||
commit: '53df212', // from `desc` above | ||
@@ -18,4 +17,2 @@ } | ||
In order to retrieve the git information, this addon runs a syncronous shell command using [exec-sync](https://www.npmjs.com/package/exec-sync). | ||
## Installation | ||
@@ -42,3 +39,3 @@ | ||
## Configuration Options | ||
There is currently only 1 configurable option. Customize using the `buildInfoOptions` hash in your Brocfile: | ||
There is currently a single configurable option. Customize using the `buildInfoOptions` hash in your Brocfile: | ||
@@ -56,7 +53,7 @@ ```js | ||
Available template keys include `{VERSION}`, `{DESC}`, and `{COMMIT}`. These keys will be replaced by the current build info values. | ||
Available template keys include `{VERSION}` and `{COMMIT}`. These keys will be replaced by the current build info values. | ||
The example above would yeild: | ||
```html | ||
<meta name="build-info" content="version:0.0.2"/> | ||
<meta name="build-info" content="version=0.0.2"/> | ||
``` | ||
@@ -63,0 +60,0 @@ |
Sorry, the diff of this file is not supported yet
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
18840
0
46
243
13
81
- Removedexec-sync@^0.1.6
- Removedexec-sync@0.1.6(transitive)