From: Dessalines Date: Tue, 9 Apr 2019 03:28:07 +0000 (-0700) Subject: Adding versioning to front page. X-Git-Url: http://these/git/%7B%24%7B%60data:application/%22%7Burl%7D/readmes/README.zh.hant.md?a=commitdiff_plain;h=7fa6631a13467e983e8e7d78d7897a86be322c50;p=lemmy.git Adding versioning to front page. - Fixes #51 --- diff --git a/ui/.gitignore b/ui/.gitignore index cc0ab540..1e420dc4 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 a9283fad..c70edfb8 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 00000000..bfd640c2 --- /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 f07f04a3..b7402e7e 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 c4b51e37..ca0c5a2a 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 (