Skip to content

Commit 1da5c9e

Browse files
committed
Add support for displaying component versions in the headers.
It defaults to false and it can be enabled via config option.
1 parent fdacf43 commit 1da5c9e

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ angular.module('main')
2222
// history details widget. Keep in mind that anything above 200-500 KB will take a long time to
2323
// render and likely freeze the browser window for deeply nested JSON object results.
2424
// Value is in bytes.
25-
// max_execution_result_size_for_render: 200 * 1024;
25+
// max_execution_result_size_for_render: 200 * 1024,
26+
//
27+
// Set to true to display StackStorm and st2web version in the header
28+
//show_version_in_header: false;
2629

2730
// hosts: [
2831
// {

index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919
throw new Error('The st2web angular-config-polyfill only supports the "main" module.');
2020
}
2121

22-
if (constant !== 'st2Config') {
23-
throw new Error('The st2web angular-config-polyfill only supports the "st2Config" constant.');
22+
if (constant !== 'st2Config' && constant !== 'st2PackageMeta') {
23+
throw new Error('The st2web angular-config-polyfill only supports the "st2Config" and "st2PackageMeta" constant.');
2424
}
2525

2626
window.st2constants = window.st2constants || {};
27-
window.st2constants.st2Config = value;
27+
28+
if (constant === 'st2Config') {
29+
window.st2constants.st2Config = value;
30+
}
31+
else if (constant === 'st2PackageMeta') {
32+
window.st2constants.st2PackageMeta = value;
33+
}
2834
},
2935
run: (fn) => {
3036
if (module !== 'main') {
@@ -33,6 +39,7 @@
3339

3440
window.st2constants = window.st2constants || {};
3541
window.st2constants.st2Config = window.st2constants.st2Config || {};
42+
window.st2constants.st2PackageMeta = window.st2constants.st2PackageMeta || {};
3643

3744
fn(window.st2constants.st2Config);
3845
},
@@ -44,6 +51,7 @@
4451
<body>
4552
<div class="wrapper" id="container"></div>
4653
<script src="config.js"></script>
54+
<script src="package.meta.js"></script>
4755
<script src="js/main.js"></script>
4856
</body>
4957

modules/st2-menu/menu.component.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default class Menu extends React.Component {
7373

7474
render() {
7575
const { className, location, routes: allRoutes, style, ...props } = this.props;
76-
76+
7777
const routes = _(allRoutes)
7878
.filter((e) => !!e.icon)
7979
.sortBy((e) => e.position)
@@ -82,10 +82,13 @@ export default class Menu extends React.Component {
8282

8383
const user = api.token && api.token.user;
8484
const server = api.server;
85+
const showVersion = window.st2constants.st2Config.show_version_in_header || false;
86+
const hasPackageMeta = (window.st2constants.st2PackageMeta !== undefined);
87+
const st2webCommitsUrl = (showVersion && hasPackageMeta) ? "https://github.com/StackStorm/st2web/commit/" + window.st2constants.st2PackageMeta.git_sha : ""
8588

8689
return (
8790
<header {...props} className={cx(style.component, className)}>
88-
<a href="#" className={style.logo} />
91+
<a href="#" className={style.logo} /> { (showVersion && hasPackageMeta) ? <span style={{ fontSize: 15, marginTop: 30 }}>st2: v{window.st2constants.st2PackageMeta.version}, st2web: <a href={st2webCommitsUrl} target="_blank">{window.st2constants.st2PackageMeta.git_sha}</a></span> : '' }
8992

9093
<div className={style.spacer} />
9194

tasks/production/package-metadata.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ gulp.task('production-package-metadata', (done) => {
2525

2626
const result = child_process.spawnSync('git', [ 'rev-parse', '--short', 'HEAD' ]);
2727
const git_sha = result.stdout.toString().trim();
28-
2928
const pkg_version = require(path.resolve('./package.json')).st2_version;
3029

31-
const data = `[st2web]\nversion = ${pkg_version}\ngit_sha = ${git_sha}\ncircle_build_url = ${circle_build_url}\n`;
30+
// Write it to ini style file
31+
const data_1 = `[st2web]\nversion = ${pkg_version}\ngit_sha = ${git_sha}\ncircle_build_url = ${circle_build_url}\n`;
32+
const file_path_1 = path.join(path.resolve('./build'), 'package.meta');
33+
fs.writeFileSync(file_path_1, data_1);
3234

33-
const file_path = path.join(path.resolve('./build'), 'package.meta');
35+
// Write it to .js file
36+
const data_2 = `angular.module('main').constant('st2PackageMeta', { version: "${pkg_version}", git_sha: "${git_sha}"});\n`
37+
const file_path_2 = path.join(path.resolve('./build'), 'package.meta.js');
38+
fs.writeFileSync(file_path_2, data_2);
3439

35-
fs.writeFileSync(file_path, data);
3640
done();
3741
});

0 commit comments

Comments
 (0)