Write version in builds

This commit is contained in:
tsauerwein
2014-07-25 15:12:05 +02:00
parent f468239e71
commit 9102647751
2 changed files with 36 additions and 2 deletions

View File

@@ -58,7 +58,7 @@
"es5Strict"
],
"compilation_level": "ADVANCED",
"output_wrapper": "// OpenLayers 3. See http://ol3.js.org/\n(function(){%output%})();",
"output_wrapper": "(function(){%output%})();",
"use_types_for_optimization": true,
"manage_closure_dependencies": true
}

View File

@@ -9,6 +9,7 @@ var fse = require('fs-extra');
var fs = require('graceful-fs');
var nomnom = require('nomnom');
var temp = require('temp').track();
var exec = require('child_process').exec;
var generateExports = require('./generate-exports');
@@ -203,6 +204,39 @@ function main(config, callback) {
}
/**
* Adds a file header with the most recent Git tag.
* @param {String} compiledSource The compiled library.
* @param {function(Error, sourcesWithHeader)} callback Called with the output
* ready to be written into a file, or any error.
*/
function addFileHeader(compiledSource, callback) {
exec('git describe --tags', function (error, stdout, stderr) {
var version = '\n';
if (stdout !== '') {
version = stdout;
}
var fileHeader =
'// OpenLayers 3. See http://ol3.js.org/\n' +
'// Version: ' + version;
callback(null, fileHeader + compiledSource);
});
};
/**
* Write the compiled library to a file.
* @param {String} compiledSource The compiled library.
* @param {function(Error)} callback Called with an error if any.
*/
function writeOutputfile(compiledSource, callback) {
async.waterfall([
addFileHeader.bind(null, compiledSource),
fse.outputFile.bind(fse, options.output)
], callback);
}
/**
* If running this module directly, read the config file and call the main
* function.
@@ -238,7 +272,7 @@ if (require.main === module) {
async.waterfall([
readConfig.bind(null, options.config),
main,
fse.outputFile.bind(fse, options.output)
writeOutputfile
], function(err) {
if (err) {
log.error(err.message);