AngularJs:无论从混帐或凉亭显示版本号 [英] AngularJs: Show version number from either git or bower

查看:102
本文介绍了AngularJs:无论从混帐或凉亭显示版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个角应用程序,我想表明我在屏幕上的应用程序的当前版本号。目前,我已经实现它作为一个常量:

I have created an Angular application where I want to show the current version number of my application on screen. Currently I have implemented it as a constant:

application
    .constant('constants', {
        VERSION: '1.1.2'
    });

但这就需要我更新不断的在每一个新版本。
我用的亭子和git,我想知道是否有任何方式从这些包之一获得的版本号作为变量动态?

But this will require me to update the constant on every new version. I use bower and git and I was wondering if there was any way to get the version number as a variable from one of these packages dynamically?

推荐答案

解决方案是使用咕嘟咕嘟并的吞掉-NG-不断插件。它会自动进行发布的工作流程,在不断的角度写服务,您的应用程序的版本。

Solution is to use Gulp and gulp-ng-constant plugin. It will automate your release workflow, write version of your app in Angular constant service.


  • 安装咕嘟咕嘟

  • 安装一饮而尽-NG-恒

  • 写您的任务,一饮而尽像下面并运行它一饮而尽常量

  • Install Gulp
  • Install gulp-ng-constant
  • Write your gulp task like following and run it gulp constants:
var gulp = require('gulp');
var ngConstant = require('gulp-ng-constant');

gulp.task('constants', function() {
  // get version from bower file
  var bower = require('./bower.json');
  // set version to ng contants
  var constants = { version: bower.version };

  return ngConstant({
      constants: constants,
      stream: true,
      name: 'app.constants'
    })
    // save ngConstant.js to src/app/
    .pipe(gulp.dest('./src/app'));
});

它会为你生成angular.module如下:

It will generate angular.module for you as following:

angular.module("app.constants", [])
  .constant("version", "0.0.1")

和你所需要的最后一步是在你的主应用注入你产生恒定的服务:

And the last step you need is to inject your generated constant service in your main app:

var app = angular.module('app', ['app.constants']);

您可能也有兴趣在使用一饮而尽凸点任务自动增加你的之前它会被添加应用程序版本NG-不变的服务。

You may be also interested in use gulp-bump task to automatically increment your app version before it will be added to ng-constant service.

请参阅以下教程:版本控制你的角与咕嘟咕嘟应用

这篇关于AngularJs:无论从混帐或凉亭显示版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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