如何在 UI 中放置我的 Meteor 应用程序版本号? [英] How can I place my Meteor apps version number in the UI?
问题描述
我有一个流星应用程序,它为不同的客户提供不同的分支.这是因为客户想要特别的东西.当然对吗?
I have a meteor application that has different branches for different clients. This is because clients want special things. Of course right?
我希望能够在 UI 某处为该客户端的应用程序部署版本放置 git 分支和标签/哈希.
I would like to be able to place the git branch and tag/hash for the deployed version of the app for that client in the UI somewhere.
问题是如何?Meteor 有没有办法获取这些信息并简单地使用它?
The question is how? Is there a way in Meteor to get this information and simply use it?
谢谢!
推荐答案
在我的生产应用中,我是这样解决这个问题的:
In my production apps I solved this issue in this way:
App/MeteorApp/hooks/post-commit-version
App
.git
hooks
post-commit (file)
MeteorApp
client
server
both
private
version.json
hooks
post-commit-version (file)
每当开发人员提交代码 .git/hooks/post-commit
时,都会执行 nodejs 脚本
存储在 App/MeteorApp/hooks/post-commit-版本
.
Whenever developer commits code .git/hooks/post-commit
is executed which executes nodejs script
stored in App/MeteorApp/hooks/post-commit-version
.
Script post-commit-version
在 App/MeteorApp/private
目录中生成 version.json
格式:
Script post-commit-version
generates version.json
in App/MeteorApp/private
dir in format:
{
"timestamp": "29-08-2014 23:16",
"branch": "master",
"commit": "3332f6dcbde57105a8dc353e5e878651cab89856"
}
存储在 private
中的所有内容都可以在生产环境中访问.
Everything stored in private
is accessible to server on production.
App/MeteorApp/both/collections/Version.js:
Version = new Meteor.Collection('version');
应用程序/MeteorApp/server/startup.js
Meteor.startup(function(){
if (Version.find().count() > 0){
Version.remove({});
}
Version.insert(JSON.parse(Assets.getText("version.json")));
})
部署应用程序后,它将触发 startup
回调,并且版本将插入到集合 Version
中.
After application is deployed it will fire startup
callbacks and version will be inserted to collection Version
.
应用程序/MeteorApp/server/publish/version.js:
Meteor.publish('version', function () {
return Version.find();
});
应用程序/MeteorApp/client/startup.js:
Meteor.startup(function(){
Meteor.subscribe("version");
})
然后在模板中的某处简单地创建助手:
And then somewhere in template simply create helper:
Template.template_name.helpers({
version:function(){
return Version.findOne();
}
})
在 template_name 中,您使用 {{version.commit}}
{{version.branch}}
{{version.timestamp}}
显示版本>.
In template_name you display version using {{version.commit}}
{{version.branch}}
{{version.timestamp}}
.
Script post-commit-version
没有 js
扩展,因为我不想让meteor 每次都将它包含在包中或重新加载开发中的应用程序更改此文件.但是,当该文件存储在 .dir
(如 App/MeteorApp/.hooks
)中时,可以使用 post-commit-version.js
) 作为以 .
作为第一个字符的目录不被meteor 处理.
Script post-commit-version
don't have js
extension, because I don't want meteor to include it in bundle or reload app in development every time I change this file.
However it is possible to use post-commit-version.js
when that file is stored in .dir
(like App/MeteorApp/.hooks
) as directories having .
as first character are not processed by meteor.
另一种可能性是在服务器端加载 version.json
Meteor.startup
,解析 json 并附加到全局变量,如 App.version
.稍后与 Meteor.method
一起使用:
Another possibility would be load version.json
on server side Meteor.startup
, parse json and attach to global variable like App.version
. Later use it with Meteor.method
:
Meteor.methods({
getVersion:function(){
return App.version;
}
})
在客户端,您只需调用方法:
On client you simply call method:
Meteor.call("getVersion", function(error,version){
if(error) {
throw new Error("Cannot get version");
return;
}
Session.set("version",version)
})
一些模板的助手可以使用它:
Some template's helper could use it :
Template.template_name.helpers({
version:function(){
return Session.get("version");
}
})
这篇关于如何在 UI 中放置我的 Meteor 应用程序版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!