From f57a6d7b028e476ed7dd9adda68a692bc7f47fc5 Mon Sep 17 00:00:00 2001 From: Matt Wheatley Date: Thu, 4 Feb 2016 16:11:41 +0000 Subject: [PATCH 1/2] Added tests and support for angular-environment --- .../angular-environment-tests.ts | 30 +++++++++++ angular-environment/angular-environment.d.ts | 52 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 angular-environment/angular-environment-tests.ts create mode 100644 angular-environment/angular-environment.d.ts diff --git a/angular-environment/angular-environment-tests.ts b/angular-environment/angular-environment-tests.ts new file mode 100644 index 000000000..ea3da32a5 --- /dev/null +++ b/angular-environment/angular-environment-tests.ts @@ -0,0 +1,30 @@ +/// +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'); diff --git a/angular-environment/angular-environment.d.ts b/angular-environment/angular-environment.d.ts new file mode 100644 index 000000000..a978f6883 --- /dev/null +++ b/angular-environment/angular-environment.d.ts @@ -0,0 +1,52 @@ +// Type definitions for angular-environment v1.0.4 +// Project: https://github.com/juanpablob/angular-environment +// Definitions by: Matt Wheatley +// 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 }, + /** + * List of variables split by environment + */ + vars: { [environment: string]: { [variable: string]: any }}, + } +} From 55da76ab813a655da7171f9f7d455312472ad918 Mon Sep 17 00:00:00 2001 From: Matt Wheatley Date: Thu, 4 Feb 2016 16:25:00 +0000 Subject: [PATCH 2/2] Renamed ng to angular for consistency --- angular-environment/angular-environment-tests.ts | 4 ++-- angular-environment/angular-environment.d.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/angular-environment/angular-environment-tests.ts b/angular-environment/angular-environment-tests.ts index ea3da32a5..b3f83b14f 100644 --- a/angular-environment/angular-environment-tests.ts +++ b/angular-environment/angular-environment-tests.ts @@ -1,6 +1,6 @@ /// -var envServiceProvider: ng.environment.ServiceProvider; -var envService: ng.environment.Service; +var envServiceProvider: angular.environment.ServiceProvider; +var envService: angular.environment.Service; envServiceProvider.config({ domains: { diff --git a/angular-environment/angular-environment.d.ts b/angular-environment/angular-environment.d.ts index a978f6883..6651817b6 100644 --- a/angular-environment/angular-environment.d.ts +++ b/angular-environment/angular-environment.d.ts @@ -3,12 +3,12 @@ // Definitions by: Matt Wheatley // Definitions: https://github.com/LiberisLabs -declare module ng.environment { +declare module angular.environment { interface ServiceProvider { /** * Sets the configuration object */ - config: (config: ng.environment.Config) => void; + config: (config: angular.environment.Config) => void; /** * Evaluates the current domain and * loads the correct environment variables.