Merge pull request #7972 from LiberisLabs/angular-environment

Added tests and support for angular-environment
This commit is contained in:
Masahiro Wakame
2016-02-07 01:46:55 +09:00
2 changed files with 82 additions and 0 deletions
@@ -0,0 +1,30 @@
/// <reference path="angular-environment.d.ts" />
var envServiceProvider: angular.environment.ServiceProvider;
var envService: angular.environment.Service;
envServiceProvider.config({
domains: {
development: ['localhost', 'dev.local'],
production: ['acme.com', 'acme.net', 'acme.org']
},
vars: {
development: {
apiUrl: '//localhost/api',
staticUrl: '//localhost/static'
},
production: {
apiUrl: '//api.acme.com/v2',
staticUrl: '//static.acme.com'
}
}
});
envServiceProvider.check();
envService.get();
envService.set('production');
var isProd: boolean = envService.is('production');
var val: any = envService.read('apiUrl');
+52
View File
@@ -0,0 +1,52 @@
// Type definitions for angular-environment v1.0.4
// Project: https://github.com/juanpablob/angular-environment
// Definitions by: Matt Wheatley <https://github.com/terrawheat>
// Definitions: https://github.com/LiberisLabs
declare module angular.environment {
interface ServiceProvider {
/**
* Sets the configuration object
*/
config: (config: angular.environment.Config) => void;
/**
* Evaluates the current domain and
* loads the correct environment variables.
*/
check: () => void;
}
interface Service {
/**
* Retrieve the current environment
*/
get: () => string,
/**
* Force sets the current environment
*/
set: (environment: string) => void,
/**
* Evaluates current environment against
* environment parameter.
*/
is: (environment: string) => boolean,
/**
* Retrieves the correct version of a
* variable for the current environment.
*/
read: (key: string) => any;
}
interface Config {
/**
* Map of domains to their environments
*/
domains: { [environment: string]: Array<string> },
/**
* List of variables split by environment
*/
vars: { [environment: string]: { [variable: string]: any }},
}
}