Added tests and support for angular-environment

This commit is contained in:
Matt Wheatley 2016-02-04 16:11:41 +00:00
parent e69fe60f2d
commit f57a6d7b02
2 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/// <reference path="angular-environment.d.ts" />
var envServiceProvider: ng.environment.ServiceProvider;
var envService: ng.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');

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 ng.environment {
interface ServiceProvider {
/**
* Sets the configuration object
*/
config: (config: ng.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 }},
}
}