From dae66517aab83b55141004e1152ffe7ba30c7c5b Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 8 Apr 2019 20:28:07 -0700 Subject: [PATCH] Adding versioning to front page. - Fixes #51 --- ui/.gitignore | 1 + ui/fuse.js | 6 ++++-- ui/set_version.js | 9 +++++++++ ui/src/components/moment-time.tsx | 4 ++-- ui/src/components/navbar.tsx | 3 ++- 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 ui/set_version.js diff --git a/ui/.gitignore b/ui/.gitignore index cc0ab540c..1e420dc49 100644 --- a/ui/.gitignore +++ b/ui/.gitignore @@ -1,3 +1,4 @@ +src/version.ts dist .fusebox _site diff --git a/ui/fuse.js b/ui/fuse.js index a9283fad2..c70edfb84 100644 --- a/ui/fuse.js +++ b/ui/fuse.js @@ -11,6 +11,7 @@ const transformInferno = require('ts-transform-inferno').default; const transformClasscat = require('ts-transform-classcat').default; let fuse, app; let isProduction = false; +var setVersion = require('./set_version.js').setVersion; Sparky.task('config', _ => { fuse = new FuseBox({ @@ -41,15 +42,16 @@ Sparky.task('config', _ => { }); app = fuse.bundle('app').instructions('>index.tsx'); }); +Sparky.task('version', _ => setVersion()); Sparky.task('clean', _ => Sparky.src('dist/').clean('dist/')); Sparky.task('env', _ => (isProduction = true)); Sparky.task('copy-assets', () => Sparky.src('assets/*.svg').dest('dist/')); -Sparky.task('dev', ['clean', 'config', 'copy-assets'], _ => { +Sparky.task('dev', ['clean', 'config', 'copy-assets', 'version'], _ => { fuse.dev(); app.hmr().watch(); return fuse.run(); }); -Sparky.task('prod', ['clean', 'env', 'config', 'copy-assets'], _ => { +Sparky.task('prod', ['clean', 'env', 'config', 'copy-assets', 'version'], _ => { // fuse.dev({ reload: true }); // remove after demo return fuse.run(); }); diff --git a/ui/set_version.js b/ui/set_version.js new file mode 100644 index 000000000..bfd640c25 --- /dev/null +++ b/ui/set_version.js @@ -0,0 +1,9 @@ +const fs = require('fs'); + +exports.setVersion = function() { + let revision = require('child_process') + .execSync('git describe --tags --long') + .toString().trim(); + let line = `export let version: string = "${revision}";`; + fs.writeFileSync("./src/version.ts", line); +} diff --git a/ui/src/components/moment-time.tsx b/ui/src/components/moment-time.tsx index f07f04a3f..b7402e7ec 100644 --- a/ui/src/components/moment-time.tsx +++ b/ui/src/components/moment-time.tsx @@ -17,11 +17,11 @@ export class MomentTime extends Component { render() { if (this.props.data.updated) { return ( - modified {moment.utc(this.props.data.updated).fromNow()} + modified {moment.utc(this.props.data.updated).fromNow()} ) } else { return ( - {moment.utc(this.props.data.published).fromNow()} + {moment.utc(this.props.data.published).fromNow()} ) } } diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index c4b51e375..ca0c5a2a2 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -2,6 +2,7 @@ import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; import { repoUrl } from '../utils'; import { UserService } from '../services'; +import { version } from '../version'; interface NavbarState { isLoggedIn: boolean; @@ -40,7 +41,7 @@ export class Navbar extends Component { navbar() { return (