Mark version with webpack

This commit is contained in:
Ray Schamp 2016-04-28 15:40:50 -04:00
parent 26ee49e9d8
commit 669a8c9ae3
4 changed files with 31 additions and 5 deletions

View file

@ -24,6 +24,7 @@ env:
- S3_LOCAL_DIR=build
- S3_REGION=us-east-1
- SKIP_CLEANUP=true
- WWW_VERSION==${TRAVIS_COMMIT:0:5}
# FASTLY_API_KEY
- secure: XNWcCnqSAd4MpKg6FVe3WeFmdqfdH753+PBCOEkJrHS+AHmLMuWsjIQFJ3LUR9ylEQRVPR2OyXJW/R8NI9toStREgwE4fwIVo0l4fwYqLStxYpEKlcWfkJ3uNpRZhvcVmUBycelrnjJqXVdrtlxPCKX0tNkpcKH2b98We7A2/r7HxKv13upDxWTQ/qRUv0+SJCRTB4n/QInABi87Ef8Q2rNGrL0WQzQvVBeiEXOP0JSkyYK4+q65gswMKPehgiFagnYVgJN9J9Q1VrBDc06gidbznBcEpPaBAYvsTTY9dWTJxaaKNSrmOIe/OiuJUEHjb+8NL+j6Lp7wX8lzEjbr0FkVlFnxS9VbftS2KFkN7+c3RF57+tsq0xwJ6vgomIVS5FupHgl/oCJicnH/FLfynditOLZhmhF+Ed5GCAoIEamRRzcVHdjvglsEtYsDX1/z2t+HKYtPQuXYOywDRVTSPf88eEbu8ehfgNcYaIAuD6eedyDnKTOIv7owWs3Y7GsxQ2jBLGXq1YoUEkPtB0vfaHi72CeEhDQ53mEn2Ure47UMGMgUjKtiIhDBNTbECwP/ZDJv1accGRljKjDy93aCJeRi1T7Op7tDbHSl4ScieeOwOeKJMcD1U5JGdA/sRnjjgSKb24P2ys4NYr95dgqWNNGPGMxca+lGufzdEaTQT44=
# FASTLY_SERVICE_ID_STAGING

View file

@ -4,9 +4,6 @@ SASSLINT=./node_modules/.bin/sass-lint -v
TAP=./node_modules/.bin/tap
WATCH=./node_modules/.bin/watch
WEBPACK=./node_modules/.bin/webpack
GIT_VERSION=$(shell git rev-parse --verify --short=5 HEAD 2> /dev/null)
GIT_VERSION?=$(WWW_VERSION)
GIT_MESSAGE=$(shell git log -1 --pretty=%s 2> /dev/null)
# ------------------------------------
@ -14,7 +11,6 @@ build:
@make clean
@make translations
@make webpack
@make tag
clean:
rm -rf ./build
@ -92,4 +88,4 @@ localization:
# ------------------------------------
.PHONY: build clean deploy static tag translations webpack watch stop start test lint
.PHONY: build clean deploy translations webpack stop start test lint unit functional integration localization

View file

@ -42,6 +42,7 @@
"exenv": "1.2.0",
"fastly": "1.2.1",
"file-loader": "0.8.4",
"git-bundle-sha": "0.0.2",
"glob": "5.0.15",
"json-loader": "0.5.2",
"json2po-stream": "1.0.3",

View file

@ -1,11 +1,38 @@
var autoprefixer = require('autoprefixer');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var gitsha = require('git-bundle-sha');
var MustacheRendererPlugin = require('./mustache-renderer-webpack-plugin');
var path = require('path');
var webpack = require('webpack');
var routes = require('./src/routes.json');
var VersionPlugin = function (options) {
this.options = options || {};
return this;
};
VersionPlugin.prototype.apply = function (compiler) {
var addVersion = function (compilation, versionId, callback) {
compilation.assets['version.txt'] = {
source: function () {return versionId;},
size: function () {return versionId.length;}
};
callback();
};
var plugin = this;
compiler.plugin('emit', function (compilation, callback) {
var sha = process.env.WWW_VERSION;
if (!sha) {
gitsha(plugin.options, function (err, sha) {
if (err) return callback(err);
return addVersion(compilation, sha, callback);
});
} else {
return addVersion(compilation, sha, callback);
}
});
};
// Prepare all entry points
var entry = {
init: './src/init.js'
@ -59,6 +86,7 @@ module.exports = {
fs: 'empty'
},
plugins: [
new VersionPlugin({length: 5}),
new MustacheRendererPlugin({
templatePath: path.resolve(__dirname, './src/template.html'),
routes: routes,