我如何将我的Meteor应用程序版本号放置在UI中? [英] How can I place my Meteor apps version number in the UI?

查看:156
本文介绍了我如何将我的Meteor应用程序版本号放置在UI中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个流星应用程序,它针对不同的客户有不同的分支。这是因为客户需要特殊的东西。当然是吧?

我希望能够将git分支和标记/哈希放置在用户界面某处的已部署应用程序版本中。 / p>

问题是怎么回事?有没有一种方法可以让流星获取这些信息并简单地使用它?

谢谢!

解决方案

在我的生产应用程序中,我通过这种方式解决了这个问题: App / .git / hooks / post.commit



App / MeteorApp / hooks / post-commit-version



应用程序结构:



 应用程序
.git
钩子
提交后(文件)
MeteorApp
客户
服务器
都是
私有
version.json
hooks
post-commit-version(文件)

每当开发人员提交代码 .git / hooks / post-commit 时,执行存储在<$ c $中的 nodejs脚本 C>应用/流星应用/钩/提交后的版本。

脚本 post-commit-version 生成 version.json in App / MeteorApp / private dir格式:

  {
timestamp:29-08-2014 23:16,
branch:master,
commit:3332f6dcbde57105a8dc353e5e878651cab89856
}

存储在 private 中的所有内容都可以在服务器上进行生产。 / p>

如何在应用程序中显示 version.json



App / MeteorApp / both / collections / Version.js

  Version = new Meteor.Collection ('版'); 

App / MeteorApp / server / startup.js

  Meteor.startup(function(){
if(Version.find()。count()> 0){
Version.remove({});
}
Version.insert(JSON.parse(Assets.getText(version.json)));
})

在部署应用程序后,它将触发启动回调,版本将会插入集合版本

App / MeteorApp / server / publish / version.js

<$ p $ Meteor.publish('version',function(){
return Version.find();
});

App / MeteorApp / client / startup.js

  Meteor.startup(function(){
Meteor.subscribe(version);
})

然后在模板的某个地方简单地创建helper:

<$ p $ {$ b $ version:function(){
return Version.findOne();
}
})

在template_name中,您使用 {{version.commit}}显示版本 {{version.branch}} {{version.timestamp}}



附注1



脚本 post-commit-version 没有 js 扩展名,因为我不希望meteor在每次更改此文件时将其包含在捆绑包中或重新加载应用程序。
然而,如果该文件存储在 .dir post-commit-version.js >(例如 App / MeteorApp / .hooks )作为具有作为第一个字符不被流星处理的目录。 / p>

附注2



另一种可能性是加载 version.json 在服务器端 Meteor.startup ,解析json并附加到全局变量,如 App.version 。稍后在 Meteor.method 中使用它:
$ b

  Meteor.methods({ 
getVersion:function(){
return App.version;
}
})

客户端只需调用方法:

  Meteor.call(getVersion,function错误,版本){
if(error){
throw new Error(Can not get version);
return;
}

Session。 set(version,version)
})

一些模板的助手可以使用它:

  Template.template_name.helpers({
version:function(){
return Session.get version);
}
})


I have a meteor application that has different branches for different clients. This is because clients want special things. Of course right?

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.

The question is how? Is there a way in Meteor to get this information and simply use it?

Thanks!

解决方案

In my production apps I solved this issue in this way:

Files

App/.git/hooks/post.commit

App/MeteorApp/hooks/post-commit-version

App structure:

App
  .git
     hooks
       post-commit (file)
  MeteorApp
    client
    server
    both
    private
      version.json
    hooks
      post-commit-version (file)

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 generates version.json in App/MeteorApp/private dir in format:

{
  "timestamp": "29-08-2014 23:16",
  "branch": "master",
  "commit": "3332f6dcbde57105a8dc353e5e878651cab89856"
}

Everything stored in private is accessible to server on production.

How to display version.json in app ?

App/MeteorApp/both/collections/Version.js:

Version = new Meteor.Collection('version');

App/MeteorApp/server/startup.js

Meteor.startup(function(){
    if (Version.find().count() > 0){
        Version.remove({});
    }
    Version.insert(JSON.parse(Assets.getText("version.json")));
})

After application is deployed it will fire startup callbacks and version will be inserted to collection Version.

App/MeteorApp/server/publish/version.js:

Meteor.publish('version', function () {
  return Version.find();
});

App/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();
  }
})

In template_name you display version using {{version.commit}} {{version.branch}} {{version.timestamp}}.

Side note 1

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.

Side note 2

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");
  }
})

这篇关于我如何将我的Meteor应用程序版本号放置在UI中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆