Skip to content

Instantly share code, notes, and snippets.

@chmac
Last active December 14, 2015 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmac/fcd6d3af33e8f19e116c to your computer and use it in GitHub Desktop.
Save chmac/fcd6d3af33e8f19e116c to your computer and use it in GitHub Desktop.
Meteor version in UI

Goals

Show the user a version string which identifies the version of the client code they are running. We don't need to know what version the database or server is running, so any kind of collection or method approach would fail because it will automatically update all clients. We want something hard coded into the client code, yet generated dynamically at build (deploy) time.

Solution

We create a template called version which we include in a remote corner of the UI. As part of our deployment process we put the last git commit hash into that file.

Notes

We use npm to start our meteor apps like npm start. That means we can ensure that all devs have a local copy of the version.html template.

The deploy.sh script below lives in the same folder as our mup config.

The version.html file is ignored by git so we never get it into our repo. We have a .gitignore file in app/client/templates/shared/ with a line version.html to exclude that file from git.

#!/bin/bash
# Get the short commit hash of the last commit
VERSION=$(git rev-parse --short HEAD)
echo 'Updating UI version'
echo "<template name=\"version\">$VERSION</template>" > app/client/templates/shared/version.html
echo 'Starting mup deploy'
mup deploy
{
"scripts": {
"start": "cd app/ && echo \"<template name=\\\"version\\\">devlocal</template>\" > client/templates/shared/version.html && meteor run --settings settings.json"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment