diff --git a/angular-environment/angular-environment-tests.ts b/angular-environment/angular-environment-tests.ts new file mode 100644 index 0000000000..ea3da32a51 --- /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 0000000000..a978f68835 --- /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 }}, + } +}