Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6e013f9

Browse files
authoredOct 24, 2017
Merge pull request #4 from geeklearningio/release/1.1.0
Release/1.1.0
2 parents d3cbc1d + aea76cf commit 6e013f9

File tree

10 files changed

+15094
-1900
lines changed

10 files changed

+15094
-1900
lines changed
 

‎.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
package/node_modules
2-
test-app/node_modules
1+
node_modules
32
npm-debug.log
43
test-app/www

‎GitVersion.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
branches:
2+
dev(elop)?(ment)?$:
3+
tag: alpha
4+
features?[/-]:
5+
tag: alpha.{BranchName}
6+
releases?[/-]:
7+
mode: ContinuousDeployment
8+
hotfix(es)?[/-]:
9+
mode: ContinuousDeployment

‎package.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎package/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Introduction
2+
This is a configuration package for Angular.
3+
It allows you to dynamically load a json file at the root of your project.
4+
It also provides a provider that allows you to add configuration values in the config function of your Angular app.
5+
6+
# Requirements
7+
- npm
8+
- angular
9+
10+
# How to configure
11+
1) In your project folder, install this plugin using npm
12+
`npm install git+https://git@github.com/geeklearningio/gl-angular-configuration.git --save`
13+
14+
2) You can use the Typescript (`package/src/ConfigurationProvider.ts`) or the Javascript ((`package/dist/ConfigurationProvider.js`)) version of the Provider.
15+
16+
3) In your application's main module, inject the dependency `gl-angular-configuration` in order to use the Provider.
17+
```
18+
angular.module('mainModuleName', ['ionic', 'gl-angular-configuration']){
19+
20+
}
21+
```
22+
23+
# How to use
24+
25+
## Dynamically load the configuration.json file (optional)
26+
Add a `configuration.json` file at the root of your project.
27+
28+
Note: If you look at the webpack config (`webpack.base.config.js`) of the test-app provided with the package, you'll see that I use the `CopyWebpackPlugin` to copy the right configuration named after a `env` argument passed to the webpack cli. The command line I use is a npm script. You can find it in the `package.json` file of the test-app.
29+
30+
Remove the automatic bootstrap of your angular app. You can do it by Removing the `ng-app` tag of your `index.html` file.
31+
It will allow you to boostrap it manually after the json has been loaded.
32+
```
33+
<html ng-app="testApp">
34+
```
35+
36+
In your application's main module, call the `loadConfigurationJSON` and pass a callback as a param. In the callback, get the html dom element and bootstrap manually your app.
37+
```
38+
loadConfigurationJSON(() => {
39+
var domElement = document.querySelector('html');
40+
angular.bootstrap(domElement, ["testApp"]);
41+
});
42+
```
43+
44+
## Add a configuration at config state
45+
In the config function of your Angular application, inject the `ConfigurationProvider` and call the `addConfiguration` function.
46+
You can also add a default configuration by calling `addDefaultConfiguration`. This function only changes the priority of the configuration loaded. It means that if the current configuration has a "env" param and the default configuration has also an "env" param, then it will keep the param of the current configuration, not the default one.
47+
You can specify the type of your configuration object in the Typescript version.
48+
49+
```
50+
import {ConfigurationProvider} from "gl-angular-configuration/package/src/ConfigurationProvider";
51+
52+
interface ITestAppConfiguration {
53+
env: string
54+
}
55+
56+
export class Config {
57+
constructor(configurationProvider: ConfigurationProvider<ITestAppConfiguration>) {
58+
configurationProvider.addObject({otherParam: 'test'});
59+
}
60+
}
61+
```

‎package/dist/ConfigurationProvider.js

Lines changed: 1349 additions & 1866 deletions
Large diffs are not rendered by default.

‎package/dist/src/ConfigurationProvider.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ export declare class ConfigurationProvider<T> {
1515
*/
1616
getConfiguration(): T;
1717
}
18-
export declare function loadConfigurationJSON(callback: any): void;
18+
export declare function loadConfigurationJSON(callback: any, configurationFileUrl?: string): void;

‎package/package-lock.json

Lines changed: 2671 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package/package.json

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
{
2-
"name": "gl-angular-configuration",
3-
"version": "0.0.1",
4-
"description": "Configuration module for Angular",
5-
"scripts": {
6-
"build": "webpack"
7-
},
8-
"author": "Geek Learning",
9-
"license": "MIT",
10-
"devDependencies": {
11-
"awesome-typescript-loader": "^1.1.1",
12-
"ng-annotate-webpack-plugin": "^0.1.3",
13-
"typescript": "^1.8.10",
14-
"typings": "^1.3.0",
15-
"webpack": "^1.13.1"
16-
},
17-
"dependencies": {
18-
"lodash": "^4.15.0"
19-
}
20-
}
2+
"name": "gl-angular-configuration",
3+
"version": "0.0.1",
4+
"scripts": {
5+
"build": "webpack"
6+
},
7+
"devDependencies": {
8+
"awesome-typescript-loader": "^1.1.1",
9+
"ng-annotate-webpack-plugin": "^0.1.3",
10+
"typescript": "^1.8.10",
11+
"typings": "^1.3.0",
12+
"webpack": "^1.13.1"
13+
},
14+
"dependencies": {
15+
"lodash": "^4.15.0"
16+
},
17+
"description": "A configuration package for Angular. It allows you to dynamically load a JSON file at the root of your project. It also provides a provider that allows you to add configuration values in the config function of your Angular app.",
18+
"keywords": [
19+
"angular",
20+
"configuration",
21+
"json",
22+
"typescript"
23+
],
24+
"homepage": "https://github.com/geeklearningio/gl-angular-configuration",
25+
"bugs": "https://github.com/geeklearningio/gl-angular-configuration/issues",
26+
"license": "MIT",
27+
"author": {
28+
"name": "Geek Learning",
29+
"url": "http://geeklearning.io/"
30+
},
31+
"contributors": [{
32+
"name": "Michel Vidailhet",
33+
"url": "http://geeklearning.io/author/michel/"
34+
},
35+
{
36+
"name": "Adrien Siffermann",
37+
"url": "http://geeklearning.io/author/adrien/"
38+
}
39+
],
40+
"repository": "geeklearningio/gl-angular-configuration"
41+
}

‎package/src/ConfigurationProvider.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare var require: Function;
2-
var merge = require('lodash/merge');
2+
var merge = require("lodash/merge");
33

44
export class ConfigurationProvider<T> {
55
private mergedConfiguration: T;
@@ -47,10 +47,10 @@ export class ConfigurationProvider<T> {
4747
}
4848
}
4949

50-
export function loadConfigurationJSON(callback) {
50+
export function loadConfigurationJSON(callback, configurationFileUrl: string = "configuration.json") {
5151
var xobj = new XMLHttpRequest();
5252
xobj.overrideMimeType("application/json");
53-
xobj.open('GET', 'configuration.json', true); // Replace 'my_data' with the path to your file
53+
xobj.open("GET", configurationFileUrl, true);
5454
xobj.onreadystatechange = function () {
5555
if (xobj.readyState === 4) {
5656
if ((xobj.status === 200 || xobj.status === 0) && xobj.responseText) {
@@ -66,5 +66,3 @@ declare var exports: any;
6666

6767
exports = angular.module("gl-angular-configuration", [])
6868
.provider("configuration", ConfigurationProvider);
69-
70-

‎test-app/package-lock.json

Lines changed: 10959 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.