├── .circleci
└── config.yml
├── .editorconfig
├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .lintstagedrc
├── .prettierignore
├── .prettierrc
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── commitlint.config.js
├── lerna.json
├── package.json
├── packages
└── @ngx-config
│ ├── core
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── ng-package.json
│ ├── package.json
│ ├── src
│ │ ├── config.loader.ts
│ │ ├── config.module.ts
│ │ ├── config.pipe.ts
│ │ ├── config.service.ts
│ │ └── index.ts
│ └── tests
│ │ ├── common.ts
│ │ ├── config.loader.spec.ts
│ │ ├── config.pipe.spec.ts
│ │ └── config.service.spec.ts
│ ├── http-loader
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── ng-package.json
│ ├── package.json
│ ├── src
│ │ ├── config.http-loader.ts
│ │ └── index.ts
│ └── tests
│ │ └── config.http-loader.spec.ts
│ └── merge-loader
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── ng-package.json
│ ├── package.json
│ ├── src
│ ├── config.merge-loader.ts
│ └── index.ts
│ └── tests
│ └── config.merge-loader.spec.ts
├── tools
├── build
│ ├── helpers.ts
│ ├── packager.ts
│ └── tsconfig.package.json
├── test
│ └── jest.setup.ts
└── tslint.json
├── tsconfig.json
├── tsconfig.lint.json
├── tslint.json
└── yarn.lock
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | build:
4 | docker:
5 | - image: circleci/node:10-browsers
6 | environment:
7 | JOBS: 1
8 | steps:
9 | - checkout
10 | - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
11 | - run: git config --global user.email ${GH_USER_EMAIL}
12 | - run: git config --global user.name ${GH_USER_NAME}
13 | - run: sudo yarn global add greenkeeper-lockfile@1
14 | - run: sudo yarn global add lerna@3
15 | - restore_cache:
16 | keys:
17 | - deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
18 | - deps-
19 | - run: yarn
20 | - save_cache:
21 | key: deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
22 | paths: 'node_modules'
23 | - run: yarn ci:before
24 | - run: yarn test:ci
25 | - run: if [ ${CIRCLE_BRANCH} == "master" ]; then lerna version --create-release github --yes; fi
26 | - run: yarn build
27 | - run: yarn ci:after
28 | - run: if [ ${CIRCLE_BRANCH} == "master" ]; then lerna publish from-package --yes; fi
29 | - run: bash <(curl -s https://codecov.io/bash)
30 | - store_artifacts:
31 | path: coverage
32 | prefix: coverage
33 | - store_artifacts:
34 | path: dist
35 | prefix: dist
36 | - store_test_results:
37 | path: test-report.xml
38 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | end_of_line = lf
7 | indent_style = space
8 | indent_size = 2
9 | insert_final_newline = true
10 | trim_trailing_whitespace = true
11 |
12 | [*.md]
13 | max_line_length = 140
14 | trim_trailing_whitespace = false
15 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # More about this https://help.github.com/articles/about-codeowners/
2 | * @fulls1z3
3 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
6 |
7 | **I'm submitting a ...** (check one with "x")
8 | ```
9 | [ ] Regression (a behavior that used to work and stopped working in a new release)
10 | [ ] Bug report
11 | [ ] Support request =>
12 | [ ] Feature request
13 | [ ] Documentation issue or request
14 | ```
15 |
16 | **Current behavior**
17 |
18 |
19 | **Expected/desired behavior**
20 |
21 |
22 | **Minimal reproduction of the problem with instructions**
23 |
27 |
28 | **What is the motivation / use case for changing the behavior?**
29 |
30 |
31 | **Environment**
32 | * **Angular version:** X.Y.Z
33 |
34 |
35 | * **Browser:**
36 | - [ ] Chrome (desktop) version XX
37 | - [ ] Chrome (Android) version XX
38 | - [ ] Chrome (iOS) version XX
39 | - [ ] Firefox version XX
40 | - [ ] Safari (desktop) version XX
41 | - [ ] Safari (iOS) version XX
42 | - [ ] IE version XX
43 | - [ ] Edge version XX
44 |
45 | * **For Tooling issues:**
46 | - Node version: XX
47 | - Platform:
48 |
49 | * Others:
50 |
51 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ** PR Checklist
2 | Please check if your PR fulfills the following requirements:
3 |
4 | - [ ] The commit message follows our guidelines: https://github.com/fulls1z3/ngx-config/blob/master/CONTRIBUTING.md#commit
5 | - [ ] Tests for the changes have been added (for bug fixes / features)
6 | - [ ] Docs have been added / updated (for bug fixes / features)
7 |
8 | ** PR Type
9 | What kind of change does this PR introduce?
10 |
11 |
12 | ```
13 | [ ] Bugfix
14 | [ ] Feature
15 | [ ] Code style update (formatting, local variables)
16 | [ ] Refactoring (no functional changes, no api changes)
17 | [ ] Build related changes
18 | [ ] CI related changes
19 | [ ] Documentation content changes
20 | [ ] Other... Please describe:
21 | ```
22 |
23 | ** What is the current behavior?
24 |
25 |
26 | Issue Number: N/A
27 |
28 | ** What is the new behavior?
29 |
30 | ** Does this PR introduce a breaking change?
31 | ```
32 | [ ] Yes
33 | [ ] No
34 | ```
35 |
36 |
37 |
38 | ** Other information
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | yarn-error.log
34 | testem.log
35 | test-report.xml
36 | /typings
37 |
38 | # System Files
39 | .DS_Store
40 | Thumbs.db
41 |
--------------------------------------------------------------------------------
/.lintstagedrc:
--------------------------------------------------------------------------------
1 | {
2 | "*.{json,css,scss,md,js}": ["prettier --write", "git add"],
3 | "*.(ts)": ["prettier-tslint fix", "git add"]
4 | }
5 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | # Add files here to ignore them from prettier formatting
2 |
3 | # compiled output
4 | /dist
5 | /docs
6 | /tmp
7 | /out-tsc
8 |
9 | # dependencies
10 | /node_modules
11 |
12 | # IDEs and editors
13 | /.idea
14 | .project
15 | .classpath
16 | .c9/
17 | *.launch
18 | .settings/
19 | *.sublime-workspace
20 |
21 | # IDE - VSCode
22 | .vscode/*
23 | !.vscode/settings.json
24 | !.vscode/tasks.json
25 | !.vscode/launch.json
26 | !.vscode/extensions.json
27 |
28 | # misc
29 | /.sass-cache
30 | /connect.lock
31 | /coverage
32 | /libpeerconnection.log
33 | npm-debug.log
34 | yarn-error.log
35 | testem.log
36 | test-report.xml
37 | /typings
38 |
39 | # System Files
40 | .DS_Store
41 | Thumbs.db
42 |
43 | # others
44 | /tools
45 | angular.json
46 | yarn.lock
47 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 140,
3 | "singleQuote": true
4 | }
5 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 |
6 | # [9.0.0](https://github.com/fulls1z3/ngx-config/compare/v8.2.0...v9.0.0) (2020-04-27)
7 |
8 |
9 | ### Features
10 |
11 | * **package:** migrate to ng9 ([9370d36](https://github.com/fulls1z3/ngx-config/commit/9370d36f63fcfb81b50e688d660edda83c077aed))
12 | * **package:** migrate to ng9 ([a8ad746](https://github.com/fulls1z3/ngx-config/commit/a8ad74608ec94fe935e4dcb5857ae3c282a3432f))
13 |
14 |
15 | ### BREAKING CHANGES
16 |
17 | * **package:** ng9
18 | * **package:** ng9
19 |
20 |
21 |
22 |
23 |
24 | # [8.2.0](https://github.com/fulls1z3/ngx-config/compare/v8.1.0...v8.2.0) (2020-04-27)
25 |
26 |
27 | ### Features
28 |
29 | * **package:** migrate to ng9 ([#161](https://github.com/fulls1z3/ngx-config/issues/161)) ([58fdac3](https://github.com/fulls1z3/ngx-config/commit/58fdac3d0e8c581440e8854c66b3db58dc2ef47c))
30 |
31 |
32 |
33 |
34 |
35 | # [8.1.0](https://github.com/fulls1z3/ngx-config/compare/v8.0.2...v8.1.0) (2020-03-10)
36 |
37 |
38 | ### Features
39 |
40 | * **core:** Make ConfigModule importable in every NgModule ([#157](https://github.com/fulls1z3/ngx-config/issues/157)) ([30d9e09](https://github.com/fulls1z3/ngx-config/commit/30d9e095945144246b57b8664ec59d9d1226c427))
41 |
42 |
43 |
44 |
45 |
46 | ## [8.0.2](https://github.com/fulls1z3/ngx-config/compare/v8.0.1...v8.0.2) (2019-12-02)
47 |
48 |
49 | ### Bug Fixes
50 |
51 | * **packaging:** fix deployment ([#158](https://github.com/fulls1z3/ngx-config/issues/158)) ([7538157](https://github.com/fulls1z3/ngx-config/commit/75381576cb58a76b6acffda81b6c73bf99944338))
52 | * **packaging:** fix deployment ([#159](https://github.com/fulls1z3/ngx-config/issues/159)) ([32061d0](https://github.com/fulls1z3/ngx-config/commit/32061d0bf44c42fa67222e36396839737d265b40))
53 |
54 |
55 |
56 |
57 |
58 | ## [8.0.1](https://github.com/fulls1z3/ngx-config/compare/v8.0.0...v8.0.1) (2019-11-21)
59 |
60 | **Note:** Version bump only for package ngx-config
61 |
62 |
63 |
64 |
65 |
66 | # [8.0.0](https://github.com/fulls1z3/ngx-config/compare/v6.0.0-rc.1...v8.0.0) (2019-11-21)
67 |
68 |
69 | ### Bug Fixes
70 |
71 | * **packaging:** fix publish ([46cb1e5](https://github.com/fulls1z3/ngx-config/commit/46cb1e579765ac3b48ce1333e561afa6ee28769d))
72 |
73 |
74 | ### Features
75 |
76 | * **getSettings:** added generic type for getSetting function ([#146](https://github.com/fulls1z3/ngx-config/issues/146)) ([e1cb64b](https://github.com/fulls1z3/ngx-config/commit/e1cb64b6c0999b0dddc9e2ec583a22cd380503e1))
77 | * **package:** upgrade to angular 8 ([0d5161f](https://github.com/fulls1z3/ngx-config/commit/0d5161f6aca4bc00edf057cc10dd510ae10aee5e))
78 |
79 |
80 | ### BREAKING CHANGES
81 |
82 | * **package:** ng8
83 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at mail@buraktasci.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to ngx-config
2 |
3 | We would love for you to contribute to **`ngx-config`** and help make it even better than it is today! As a contributor,
4 | here are the guidelines we would like you to follow:
5 |
6 | - [Code of Conduct](#coc)
7 | - [Issues and Bugs](#issue)
8 | - [Feature requests](#feature)
9 | - [Submission guidelines](#submit)
10 | - [Coding rules](#rules)
11 | - [Commit message guidelines](#commit)
12 |
13 | ## Code of Conduct
14 | Help us keep **`ngx-config`** open and inclusive. Please read and follow our [Code of Conduct][coc].
15 |
16 | ## Found a Bug?
17 | If you find a bug in the source code, you can help us by [submitting an issue](#submit-issue) to our [GitHub Repository][github].
18 |
19 | Even better, you can [submit a Pull Request](#submit-pr) with a fix.
20 |
21 | ## Missing a Feature?
22 | You can *request* a new feature by [submitting an issue](#submit-issue) to our GitHub Repository.
23 |
24 | If you would like to *implement* a new feature, please submit an issue with a proposal for your work first, to be sure that
25 | we can use it.
26 |
27 | Please consider what kind of change it is:
28 | * For a **Major Feature**, first open an issue and outline your proposal so that it can be discussed.
29 | This will also allow us to better coordinate our efforts, prevent duplication of work, and help you to craft the change
30 | so that it is successfully accepted into the project.
31 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
32 |
33 | ## Submission guidelines
34 | ### Submitting an Issue
35 | Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion
36 | might inform you of workarounds readily available.
37 |
38 | We want to fix all the issues as soon as possible, but before fixing a bug we need to reproduce and confirm it. In order
39 | to reproduce bugs we will systematically ask you to provide a minimal reproduction scenario using http://plnkr.co.
40 |
41 | Having a live, reproducible scenario gives us wealth of important information without going back & forth to you with additional
42 | questions like:
43 | - version used
44 | - 3rd-party libraries and their versions
45 | - and most importantly: a use-case that fails
46 |
47 | A minimal reproduce scenario using http://plnkr.co/ allows us to quickly confirm a bug (or point out coding problem) as
48 | well as confirm that we are fixing the right problem. If plunker is not a suitable way to demonstrate the problem (*ex:
49 | issues related to our npm packaging*), please create a standalone git repository demonstrating the problem.
50 |
51 | We will be insisting on a minimal reproduce scenario in order to save maintainers time and ultimately be able to fix more
52 | bugs.
53 |
54 | Interestingly, from our experience users often find coding problems themselves while preparing a minimal plunk. We understand
55 | that sometimes it might be hard to extract essentials bits of code from a larger code-base but we really need to isolate
56 | the problem before we can fix it.
57 |
58 | Unfortunately we are not able to investigate / fix bugs without a minimal reproduction, so if we don't hear back from you,
59 | we are going to close an issue that don't have enough info to be reproduced.
60 |
61 | You can file new issues by filling out our [new issue form](https://github.com/fulls1z3/ngx-config/issues/new).
62 |
63 | ### Submitting a Pull Request (PR)
64 | Before you submit your Pull Request (PR) consider the following guidelines:
65 |
66 | * Search [GitHub](https://github.com/fulls1z3/ngx-config/pulls) for an open or closed PR that relates to your submission.
67 | You don't want to duplicate effort.
68 | * Make your changes in a new git branch:
69 | ```shell
70 | git checkout -b my-fix-branch master
71 | ```
72 | * Create your patch, **including appropriate test cases**.
73 | * Follow our [Coding rules](#rules).
74 | * Run the full test suite and ensure that all tests pass.
75 | * Commit your changes using a descriptive commit message that follows our [commit message conventions](#commit).
76 | Adherence to these conventions is necessary because release notes are automatically generated from these messages.
77 | ```shell
78 | git commit -a
79 | ```
80 | Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
81 | * Push your branch to GitHub:
82 | ```shell
83 | git push origin my-fix-branch
84 | ```
85 | * In GitHub, send a pull request to `ngx-config:master`.
86 | * If we suggest changes then:
87 | * Make the required updates.
88 | * Re-run the test suites to ensure tests are still passing.
89 | * Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
90 | ```shell
91 | git rebase master -i
92 | git push -f
93 | ```
94 | That's it, thanks for your contribution!
95 |
96 | #### After your pull request is merged
97 | After your pull request is merged, you can safely delete your branch and pull the changes from the main (upstream) repository:
98 | * Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
99 | ```shell
100 | git push origin --delete my-fix-branch
101 | ```
102 | * Check out the master branch:
103 | ```shell
104 | git checkout master -f
105 | ```
106 | * Delete the local branch:
107 | ```shell
108 | git branch -D my-fix-branch
109 | ```
110 | * Update your master with the latest upstream version:
111 | ```shell
112 | git pull --ff upstream master
113 | ```
114 |
115 | ## Coding rules
116 | To ensure consistency throughout the source code, keep these rules in mind as you are working:
117 | * All features or bug fixes **must be tested** by one or more specs (unit-tests).
118 | * All public API methods **must be documented**. (Details TBC).
119 | * We follow [fulls1z3's Angular TSLint rules][angular-tslint-rules].
120 |
121 | ## Commit message guidelines
122 | We have very precise rules over how our git commit messages can be formatted. This leads to **more readable messages** that
123 | are easy to follow when looking through the **project history**. But also, we use the git commit messages to **generate
124 | the `ngx-config` change log**.
125 |
126 | ### Commit Message Format
127 | Each commit message consists of a **header**, a **body** and a **footer**. The header has a special format that includes
128 | a **type**, a **scope** (*when applicable*) and a **subject**:
129 | ```
130 | ():
131 |
132 |
133 |
134 |
135 | ```
136 |
137 | The **header** is mandatory and the **scope** of the header is optional.
138 |
139 | Any line of the commit message cannot be longer 100 characters. This allows the message to be easier to read on GitHub as
140 | well as in various git tools.
141 |
142 | Footer should contain a [closing reference to an issue](https://help.github.com/articles/closing-issues-via-commit-messages/)
143 | if any.
144 |
145 | Samples: (even more [samples](https://github.com/fulls1z3/ngx-config/commits/master))
146 | ```
147 | docs(changelog): update change log to alpha.4
148 | ```
149 | ```
150 | fix(release): need to depend on latest rxjs and zone.js
151 |
152 | The version in our package.json gets copied to the one we publish, and users need the latest of these.
153 | ```
154 |
155 | ### Revert
156 | If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit.
157 | In the body it should say: `This reverts commit .`, where the hash is the SHA of the commit being reverted.
158 |
159 | ### Type
160 | Must be one of the following:
161 | * **build**: Changes that affect the build system or external dependencies (example scopes: gulp, npm, webpack)
162 | * **ci**: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, etc)
163 | * **docs**: Documentation only changes
164 | * **feat**: A new feature
165 | * **fix**: A bug fix
166 | * **perf**: A code change that improves performance
167 | * **refactor**: A code change that neither fixes a bug nor adds a feature
168 | * **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
169 | * **test**: Adding missing tests or correcting existing tests
170 |
171 | ### Scope
172 | The scope should be the name of the project affected.
173 |
174 | The following is the list of supported scopes:
175 | * **core**
176 | * **http-loader**
177 | * **fs-loader**
178 | * **merge-loader**
179 | * **config-loader** (*which is actually packaged under `@ngx-universal` scope, but source code is located at the `ngx-config` repository*)
180 |
181 | There are currently a few exceptions to the "use project name" rule:
182 |
183 | * **packaging**: used for changes that change the package layout (*e.g. package.json, bundles, path changes, etc.*)
184 | * **changelog**: used for updating the release notes in CHANGELOG.md
185 |
186 | ### Subject
187 | The subject contains succinct description of the change:
188 | * use the imperative, present tense: "change" not "changed" nor "changes"
189 | * don't capitalize first letter
190 | * no dot (.) at the end
191 |
192 | ### Body
193 | Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes". The body should include
194 | the motivation for the change and contrast this with previous behavior.
195 |
196 | ### Footer
197 | The footer should contain any information about **Breaking Changes** and is also the place to reference GitHub issues that
198 | this commit **Closes**.
199 |
200 | **Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit
201 | message is then used for this.
202 |
203 | [coc]: https://github.com/fulls1z3/ngx-config/blob/master/CODE_OF_CONDUCT.md
204 | [github]: https://github.com/fulls1z3/ngx-config
205 | [angular-tslint-rules]: https://github.com/fulls1z3/angular-tslint-rules
206 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Burak Tasci
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ngx-config
2 |
3 | Configuration utility for **Angular**
4 |
5 | [](https://circleci.com/gh/fulls1z3/ngx-config)
6 | [](https://codecov.io/gh/fulls1z3/ngx-config)
7 | [](https://github.com/facebook/jest)
8 | [](https://conventionalcommits.org)
9 | [](https://greenkeeper.io/)
10 | [](https://angular.io/styleguide)
11 |
12 | > Please support this project by simply putting a Github star. Share this library with friends on Twitter and everywhere else you can.
13 |
14 | **`ngx-config`** uses `APP_INITIALIZER` which executes a function when **Angular** app is initialized, and delay the completion
15 | of initialization process until application settings have been provided.
16 |
17 | ## Packages:
18 |
19 | | Name | Description | NPM |
20 | | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
21 | | [@ngx-config/core](https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/core) | Configuration utility for **Angular** | [](https://www.npmjs.com/package/@ngx-config/core) |
22 | | [@ngx-config/http-loader](https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/http-loader) | Loader for [ngx-config] that provides application settings using **`http`** | [](https://www.npmjs.com/package/@ngx-config/http-loader) |
23 | | [@ngx-config/merge-loader](https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/merge-loader) | Loader for [ngx-config] that provides application settings by executing loaders in **parallel** and in **series** | [](https://www.npmjs.com/package/@ngx-config/merge-loader) |
24 |
25 | ## Examples
26 |
27 | - [ng-seed/universal] and [fulls1z3/example-app] are officially maintained projects, showcasing common patterns and best
28 | practices for **`ngx-config`**.
29 |
30 | ## Contributing
31 |
32 | If you want to file a bug, contribute some code, or improve documentation, please read up on the following contribution guidelines:
33 |
34 | - [Issue guidelines](CONTRIBUTING.md#submit)
35 | - [Contributing guidelines](CONTRIBUTING.md)
36 | - [Coding rules](CONTRIBUTING.md#rules)
37 | - [Change log](/releases)
38 |
39 | #### Thanks to
40 |
41 | - [JetBrains], for their support to this open source project with free [WebStorm] licenses.
42 |
43 | ## License
44 |
45 | The MIT License (MIT)
46 |
47 | Copyright (c) 2019 [Burak Tasci]
48 |
49 | [ngx-config]: https://github.com/fulls1z3/ngx-config
50 | [ng-seed/universal]: https://github.com/ng-seed/universal
51 | [fulls1z3/example-app]: https://github.com/fulls1z3/example-app
52 | [jetbrains]: https://www.jetbrains.com/community/opensource
53 | [webstorm]: https://www.jetbrains.com/webstorm
54 | [burak tasci]: https://github.com/fulls1z3
55 |
--------------------------------------------------------------------------------
/commitlint.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['@commitlint/config-conventional'],
3 | rules: {
4 | 'scope-enum': [2, 'always', ['core', 'http-loader', 'merge-loader', 'package', 'npm', 'circle', 'lint', 'packaging', 'changelog']]
5 | }
6 | };
7 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "packages": [
3 | "packages/@ngx-config/*"
4 | ],
5 | "version": "9.0.0",
6 | "npmClient": "yarn",
7 | "command": {
8 | "publish": {
9 | "allowBranch": "master",
10 | "conventionalCommits": true,
11 | "message": "chore(release): release %s"
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ngx-config",
3 | "version": "0.0.0",
4 | "description": "Configuration utility for Angular",
5 | "repository": {
6 | "type": "git",
7 | "url": "https://github.com/fulls1z3/ngx-config.git"
8 | },
9 | "keywords": [],
10 | "author": {
11 | "name": "Burak Tasci",
12 | "email": "mail@buraktasci.com"
13 | },
14 | "license": "MIT",
15 | "bugs": {
16 | "url": "https://github.com/fulls1z3/ngx-config/issues"
17 | },
18 | "homepage": "https://github.com/fulls1z3/ngx-config#readme",
19 | "scripts": {
20 | "clean": "rimraf dist",
21 | "build:core": "ts-node tools/build/packager.ts core",
22 | "build:http-loader": "ts-node tools/build/packager.ts http-loader",
23 | "build:merge-loader": "ts-node tools/build/packager.ts merge-loader",
24 | "build": "npm run build:core && npm run build:http-loader && npm run build:merge-loader",
25 | "lint": "tslint -p ./tsconfig.lint.json --force",
26 | "lint:check": "tslint-config-prettier-check ./tslint.lint.json",
27 | "rebuild": "npm run clean && npm run build",
28 | "ci:before": "greenkeeper-lockfile-update",
29 | "ci:after": "greenkeeper-lockfile-upload",
30 | "test": "jest --runInBand --colors",
31 | "test:ci": "jest --ci --updateSnapshot --colors",
32 | "release": "standard-version"
33 | },
34 | "devDependencies": {
35 | "@angular/common": "^9.1.0",
36 | "@angular/compiler": "^9.1.0",
37 | "@angular/compiler-cli": "^9.1.0",
38 | "@angular/core": "^9.1.0",
39 | "@angular/platform-browser": "^9.1.0",
40 | "@angular/platform-browser-dynamic": "^9.1.0",
41 | "@commitlint/cli": "^8.3.5",
42 | "@commitlint/config-conventional": "^8.3.4",
43 | "@types/jest": "^23.3.14",
44 | "@types/lodash": "^4.14.150",
45 | "@types/node": "^10.0.0",
46 | "angular-tslint-rules": "^1.20.4",
47 | "codelyzer": "^5.2.2",
48 | "cz-conventional-changelog": "^3.1.0",
49 | "husky": "^4.2.0",
50 | "jest": "^23.6.0",
51 | "jest-junit-reporter": "^1.1.0",
52 | "jest-preset-angular": "8.1.2",
53 | "lerna": "^3.20.2",
54 | "lint-staged": "^10.0.0",
55 | "lodash": "^4.17.15",
56 | "ng-packagr": "^9.0.0",
57 | "prettier": "1.19.1",
58 | "prettier-tslint": "^0.4.2",
59 | "reflect-metadata": "^0.1.13",
60 | "request": "^2.88.2",
61 | "rimraf": "^3.0.2",
62 | "rxjs": "~6.5.4",
63 | "ts-node": "^8.9.0",
64 | "tsickle": "^0.38.0",
65 | "tslint": "^5.20.1",
66 | "tslint-config-prettier": "^1.18.0",
67 | "typescript": "~3.8.3",
68 | "zone.js": "^0.10.2"
69 | },
70 | "husky": {
71 | "hooks": {
72 | "pre-commit": "lint-staged",
73 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
74 | }
75 | },
76 | "jest": {
77 | "preset": "jest-preset-angular",
78 | "setupTestFrameworkScriptFile": "./tools/test/jest.setup.ts",
79 | "testResultsProcessor": "./node_modules/jest-junit-reporter",
80 | "testMatch": [
81 | "**/+(*.)+(spec|test).+(ts|js)?(x)"
82 | ],
83 | "globals": {
84 | "ts-jest": {
85 | "tsConfigFile": "./tsconfig.json"
86 | },
87 | "__TRANSFORM_HTML__": true
88 | },
89 | "moduleDirectories": [
90 | "node_modules",
91 | "packages"
92 | ],
93 | "moduleNameMapper": {
94 | "^@ngx-config/core": "/packages/@ngx-config/core/src/index.ts",
95 | "^@ngx-config/http-loader": "/packages/@ngx-config/http-loader/src/index.ts",
96 | "^@ngx-config/merge-loader": "/packages/@ngx-config/merge-loader/src/index.ts"
97 | },
98 | "cache": false,
99 | "silent": true,
100 | "collectCoverage": true,
101 | "collectCoverageFrom": [
102 | "packages/@ngx-config/core/src/**.ts",
103 | "packages/@ngx-config/http-loader/src/**.ts",
104 | "packages/@ngx-config/merge-loader/src/**.ts"
105 | ]
106 | },
107 | "config": {
108 | "commitizen": {
109 | "path": "./node_modules/cz-conventional-changelog"
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 |
6 | # [9.0.0](https://github.com/fulls1z3/ngx-config/compare/v8.2.0...v9.0.0) (2020-04-27)
7 |
8 |
9 | ### Features
10 |
11 | * **package:** migrate to ng9 ([9370d36](https://github.com/fulls1z3/ngx-config/commit/9370d36f63fcfb81b50e688d660edda83c077aed))
12 |
13 |
14 | ### BREAKING CHANGES
15 |
16 | * **package:** ng9
17 |
18 |
19 |
20 |
21 |
22 | # [8.2.0](https://github.com/fulls1z3/ngx-config/compare/v8.1.0...v8.2.0) (2020-04-27)
23 |
24 |
25 | ### Features
26 |
27 | * **package:** migrate to ng9 ([#161](https://github.com/fulls1z3/ngx-config/issues/161)) ([58fdac3](https://github.com/fulls1z3/ngx-config/commit/58fdac3d0e8c581440e8854c66b3db58dc2ef47c))
28 |
29 |
30 |
31 |
32 |
33 | # [8.1.0](https://github.com/fulls1z3/ngx-config/compare/v8.0.2...v8.1.0) (2020-03-10)
34 |
35 |
36 | ### Features
37 |
38 | * **core:** Make ConfigModule importable in every NgModule ([#157](https://github.com/fulls1z3/ngx-config/issues/157)) ([30d9e09](https://github.com/fulls1z3/ngx-config/commit/30d9e095945144246b57b8664ec59d9d1226c427))
39 |
40 |
41 |
42 |
43 |
44 | ## [8.0.1](https://github.com/fulls1z3/ngx-config/compare/v8.0.0...v8.0.1) (2019-11-21)
45 |
46 | **Note:** Version bump only for package @ngx-config/core
47 |
48 |
49 |
50 |
51 |
52 | # [8.0.0](https://github.com/fulls1z3/ngx-config/compare/v6.0.0-rc.1...v8.0.0) (2019-11-21)
53 |
54 |
55 | ### Features
56 |
57 | * **getSettings:** added generic type for getSetting function ([#146](https://github.com/fulls1z3/ngx-config/issues/146)) ([e1cb64b](https://github.com/fulls1z3/ngx-config/commit/e1cb64b6c0999b0dddc9e2ec583a22cd380503e1))
58 | * **package:** upgrade to angular 8 ([0d5161f](https://github.com/fulls1z3/ngx-config/commit/0d5161f6aca4bc00edf057cc10dd510ae10aee5e))
59 |
60 |
61 | ### BREAKING CHANGES
62 |
63 | * **package:** ng8
64 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/README.md:
--------------------------------------------------------------------------------
1 | # @ngx-config/core [](https://www.npmjs.com/package/@ngx-config/core) [](https://www.npmjs.com/package/@ngx-config/core)
2 |
3 | Configuration utility for **Angular**
4 |
5 | [](https://circleci.com/gh/fulls1z3/ngx-config)
6 | [](https://codecov.io/gh/fulls1z3/ngx-config)
7 | [](https://github.com/facebook/jest)
8 | [](https://conventionalcommits.org)
9 | [](https://angular.io/styleguide)
10 |
11 | > Please support this project by simply putting a Github star. Share this library with friends on Twitter and everywhere else you can.
12 |
13 | **`@ngx-config/core`** uses `APP_INITIALIZER` which executes a function when **Angular** app is initialized, and delay the
14 | completion of initialization process until application settings have been provided.
15 |
16 | ## Table of contents:
17 |
18 | - [Getting started](#getting-started)
19 | - [Installation](#installation) - [Examples](#examples) - [Related packages](#related-packages) - [Recommended packages](#recommended-packages) - [Adding `@ngx-config/core` to your project (SystemJS)](#adding-systemjs)
20 | - [app.module configuration](#appmodule-config)
21 | - [Settings](#settings) - [Setting up `ConfigModule` to use `ConfigStaticLoader`](#setting-up-staticloader) - [Setting up `ConfigModule` to use `ConfigHttpLoader`](#setting-up-httploader) - [Setting up `ConfigModule` to use `ConfigMergeLoader`](#setting-up-mergeloader)
22 | - [Usage](#usage)
23 | - [Pipe](#pipe)
24 | - [License](#license)
25 |
26 | ## Getting started
27 |
28 | ### Installation
29 |
30 | You can install **`@ngx-config/core`** using `npm`
31 |
32 | ```
33 | npm install @ngx-config/core --save
34 | ```
35 |
36 | ### Examples
37 |
38 | - [ng-seed/universal] and [fulls1z3/example-app] are officially maintained projects, showcasing common patterns and best
39 | practices for **`@ngx-config/core`**.
40 |
41 | ### Related packages
42 |
43 | The following packages may be used in conjunction with **`@ngx-config/core`**:
44 |
45 | - [@ngx-config/http-loader]
46 | - [@ngx-config/merge-loader]
47 | - [@ngx-i18n-router/config-loader]
48 |
49 | ### Recommended packages
50 |
51 | The following package(s) have no dependency for **`@ngx-config/core`**, however may provide supplementary/shorthand functionality:
52 |
53 | - [@ngx-cache/core]: provides caching features to retrieve the application settings using `non-static loaders` (_[@ngx-config/http-loader],
54 | [@ngx-i18n-router/config-loader]_).
55 |
56 | ### Adding `@ngx-config/core` to your project (SystemJS)
57 |
58 | Add `map` for **`@ngx-config/core`** in your `systemjs.config`
59 |
60 | ```javascript
61 | '@ngx-config/core': 'node_modules/@ngx-config/core/bundles/core.umd.min.js'
62 | ```
63 |
64 | ### app.module configuration
65 |
66 | Import `ConfigModule` using the mapping `'@ngx-config/core'` and append `ConfigModule.forRoot({...})` within the imports
67 | property of **app.module** (_considering the app.module is the core module in Angular application_).
68 |
69 | ## Settings
70 |
71 | You can call the [forRoot] static method using `ConfigStaticLoader`. By default, it is configured to have no settings.
72 |
73 | > You can customize this behavior (_and ofc other settings_) by supplying **application settings** to `ConfigStaticLoader`.
74 |
75 | The following examples show the use of an exported function (_instead of an inline function_) for [AoT compilation].
76 |
77 | ### Setting up `ConfigModule` to use `ConfigStaticLoader`
78 |
79 | ```TypeScript
80 | ...
81 | import { ConfigModule, ConfigLoader, ConfigStaticLoader } from '@ngx-config/core';
82 | ...
83 |
84 | export function configFactory(): ConfigLoader {
85 | return new ConfigStaticLoader({
86 | "system": {
87 | "applicationName": "Mighty Mouse",
88 | "applicationUrl": "http://localhost:8000"
89 | },
90 | "seo": {
91 | "pageTitle": "Tweeting bird"
92 | },
93 | "i18n":{
94 | "locale": "en"
95 | }
96 | });
97 | }
98 |
99 | @NgModule({
100 | declarations: [
101 | AppComponent,
102 | ...
103 | ],
104 | ...
105 | imports: [
106 | ConfigModule.forRoot({
107 | provide: ConfigLoader,
108 | useFactory: (configFactory)
109 | }),
110 | ...
111 | ],
112 | ...
113 | bootstrap: [AppComponent]
114 | })
115 | ```
116 |
117 | `ConfigStaticLoader` has one parameter:
118 |
119 | - **providedSettings**: `any` : application settings
120 |
121 | > :+1: Cool! **`@ngx-config/core`** will retrieve application settings before **Angular** initializes the app.
122 |
123 | ### Setting up `ConfigModule` to use `ConfigHttpLoader`
124 |
125 | If you provide application settings using a `JSON` file or an `API`, you can call the [forRoot] static method using the
126 | `ConfigHttpLoader`. By default, it is configured to retrieve **application settings** from the endpoint `/config.json`
127 | (_if not specified_).
128 |
129 | > You can customize this behavior (_and ofc other settings_) by supplying a **api endpoint** to `ConfigHttpLoader`.
130 |
131 | You can find detailed information about the usage guidelines for the `ConfigHttpLoader` [here](https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/http-loader).
132 |
133 | ### Setting up `ConfigModule` to use `ConfigMergeLoader`
134 |
135 | `ConfigMergeLoader` provides application settings by executing loaders in **parallel** and in **series**.
136 |
137 | You can find detailed information about the usage guidelines for the `ConfigMergeLoader` [here](https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/merge-loader).
138 |
139 | ## Usage
140 |
141 | `ConfigService` has the `getSettings` method, which you can fetch settings loaded during application initialization.
142 |
143 | When the `getSettings` method is invoked without parameters, it returns entire application configuration. However, the `getSettings`
144 | method can be invoked using two optional parameters: **`key`** and **`defaultValue`**.
145 |
146 | To specify returning value type you can add generic type in `getSettings`.
147 |
148 | The following example shows how to read configuration settings using all available overloads of `getSettings` method.
149 |
150 | #### anyclass.ts
151 |
152 | ```TypeScript
153 | ...
154 | import { ConfigService } from '@ngx-config/core';
155 |
156 | @Injectable()
157 | export class AnyClass {
158 | constructor(private readonly config: ConfigService) {
159 | // note that ConfigService is injected into a private property of AnyClass
160 | }
161 |
162 | myMethodToGetUrl1a() {
163 | // will retrieve 'http://localhost:8000'
164 | const url = this.config.getSettings('system.applicationUrl');
165 | }
166 |
167 | myMethodToGetUrl1b() {
168 | // will retrieve 'http://localhost:8000'
169 | const url = this.config.getSettings(['system', 'applicationUrl']);
170 | }
171 |
172 | myMethodToGetUrl2a() {
173 | // will retrieve 'http://localhost:8000'
174 | const url = this.config.getSettings('system').applicationUrl;
175 | }
176 |
177 | myMethodToGetUrl2b() {
178 | // will retrieve 'http://localhost:8000'
179 | const url = this.config.getSettings().system.applicationUrl;
180 | }
181 |
182 | myMethodToGetUrl3a() {
183 | // will throw an exception (system.non_existing is not in the application settings)
184 | const url = this.config.getSettings('system.non_existing');
185 | }
186 |
187 | myMethodToGetUrl3b() {
188 | // will retrieve 'no data' (system.non_existing is not in the application settings)
189 | const url = this.config.getSettings('system.non_existing', 'no data');
190 | }
191 |
192 | myMethodToGetSeo1() {
193 | // will retrieve {"pageTitle":"Tweeting bird"}
194 | const seoSettings = this.config.getSettings('seo');
195 | }
196 |
197 | myMethodToGetSeo1() {
198 | // will retrieve {"pageTitle":"Tweeting bird"}
199 | const seoSettings = this.config.getSettings().seo;
200 | }
201 | }
202 | ```
203 |
204 | ## Pipe
205 |
206 | `ConfigPipe` is used to get the application settings on the view level. Pipe can be appended to a **string** or to an
207 | **Array**.
208 |
209 | ```Html
210 | {{'some.setting' | config}}
211 | {{['some', 'setting'] | config}}
212 | ```
213 |
214 | In order to use this pipe in lazy-loaded modules, you must import `ConfigModule.forChild()`.
215 |
216 | ## License
217 |
218 | The MIT License (MIT)
219 |
220 | Copyright (c) 2019 [Burak Tasci]
221 |
222 | [ng-seed/universal]: https://github.com/ng-seed/universal
223 | [fulls1z3/example-app]: https://github.com/fulls1z3/example-app
224 | [@ngx-config/http-loader]: https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/http-loader
225 | [@ngx-config/merge-loader]: https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/merge-loader
226 | [@ngx-i18n-router/config-loader]: https://github.com/fulls1z3/ngx-i18n-router/tree/master/packages/@ngx-i18n-router/config-loader
227 | [@ngx-cache/core]: https://github.com/fulls1z3/ngx-cache/tree/master/packages/@ngx-cache/core
228 | [forroot]: https://angular.io/docs/ts/latest/guide/ngmodule.html#!#core-for-root
229 | [aot compilation]: https://angular.io/docs/ts/latest/cookbook/aot-compiler.html
230 | [burak tasci]: https://github.com/fulls1z3
231 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/ng-package.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
3 | "dest": "../../../dist/@ngx-config/core",
4 | "lib": {
5 | "entryFile": "src/index.ts"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ngx-config/core",
3 | "version": "9.0.0",
4 | "description": "Configuration utility for Angular",
5 | "repository": {
6 | "type": "git",
7 | "url": "https://github.com/fulls1z3/ngx-config.git"
8 | },
9 | "keywords": [
10 | "app initializer",
11 | "app config",
12 | "configmodule",
13 | "configuration",
14 | "settings",
15 | "APP_INITIALIZER",
16 | "config",
17 | "angular"
18 | ],
19 | "author": {
20 | "name": "Burak Tasci",
21 | "email": "mail@buraktasci.com"
22 | },
23 | "license": "MIT",
24 | "bugs": {
25 | "url": "https://github.com/fulls1z3/ngx-config/issues"
26 | },
27 | "homepage": "https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/core#readme",
28 | "peerDependencies": {
29 | "@angular/common": ">=9.0.0 <10.0.0",
30 | "@angular/core": ">=9.0.0 <10.0.0",
31 | "@angular/platform-browser-dynamic": ">=9.0.0 <10.0.0"
32 | },
33 | "publishConfig": {
34 | "access": "public",
35 | "directory": "../../../dist/@ngx-config/core"
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/src/config.loader.ts:
--------------------------------------------------------------------------------
1 | export abstract class ConfigLoader {
2 | abstract loadSettings(): any;
3 | }
4 |
5 | export class ConfigStaticLoader implements ConfigLoader {
6 | constructor(private readonly providedSettings?: any) {
7 | }
8 |
9 | loadSettings(): any {
10 | return Promise.resolve(this.providedSettings);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/src/config.module.ts:
--------------------------------------------------------------------------------
1 | import { APP_INITIALIZER, Inject, InjectionToken, ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
2 |
3 | import { ConfigLoader, ConfigStaticLoader } from './config.loader';
4 | import { ConfigPipe } from './config.pipe';
5 | import { ConfigService } from './config.service';
6 |
7 | export const configFactory = () => new ConfigStaticLoader();
8 |
9 | export const initializerFactory = (config: ConfigService) => {
10 | // workaround for AoT compilation
11 | const res = () => config.init();
12 |
13 | return res;
14 | };
15 |
16 | export const CONFIG_FORROOT_GUARD = new InjectionToken('CONFIG_FORROOT_GUARD');
17 |
18 | // tslint:disable-next-line:only-arrow-functions
19 | export function provideForRootGuard(config?: ConfigService): any {
20 | if (config) {
21 | throw new Error(`ConfigModule.forRoot() called twice. Lazy loaded modules should use ConfigModule.forChild() instead.`);
22 | }
23 |
24 | return 'guarded';
25 | }
26 |
27 | @NgModule({
28 | declarations: [ConfigPipe],
29 | exports: [ConfigPipe]
30 | })
31 | export class ConfigModule {
32 | static forRoot(
33 | configuredProvider: any = {
34 | provide: ConfigLoader,
35 | useFactory: configFactory
36 | }
37 | ): ModuleWithProviders {
38 | return {
39 | ngModule: ConfigModule,
40 | providers: [
41 | configuredProvider,
42 | ConfigService,
43 | {
44 | provide: APP_INITIALIZER,
45 | useFactory: initializerFactory,
46 | deps: [ConfigService],
47 | multi: true
48 | },
49 | {
50 | provide: CONFIG_FORROOT_GUARD,
51 | useFactory: provideForRootGuard,
52 | deps: [[ConfigService, new Optional(), new SkipSelf()]]
53 | }
54 | ]
55 | };
56 | }
57 |
58 | static forChild(): ModuleWithProviders {
59 | return {
60 | ngModule: ConfigModule
61 | };
62 | }
63 |
64 | // tslint:disable-next-line:no-empty
65 | constructor(@Optional() @Inject(CONFIG_FORROOT_GUARD) guard: any) {}
66 | }
67 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/src/config.pipe.ts:
--------------------------------------------------------------------------------
1 | import { Injectable, Pipe, PipeTransform } from '@angular/core';
2 |
3 | import { ConfigService } from './config.service';
4 |
5 | @Injectable()
6 | @Pipe({
7 | name: 'config'
8 | })
9 | export class ConfigPipe implements PipeTransform {
10 | constructor(private readonly config: ConfigService) {}
11 |
12 | transform(value: string | Array): any {
13 | return this.config.getSettings(value);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/src/config.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 |
3 | import { ConfigLoader } from './config.loader';
4 |
5 | @Injectable()
6 | export class ConfigService {
7 | protected settings: any;
8 |
9 | constructor(readonly loader: ConfigLoader) {}
10 |
11 | init(): any {
12 | return this.loader.loadSettings().then((res: any) => (this.settings = res));
13 | }
14 |
15 | getSettings(key?: string | Array, defaultValue?: any): T {
16 | if (!key || (Array.isArray(key) && !key[0])) {
17 | return this.settings;
18 | }
19 |
20 | const paths = !Array.isArray(key) ? key.split('.') : key;
21 |
22 | let result = paths.reduce((acc: any, current: string) => acc && acc[current], this.settings);
23 |
24 | if (result === undefined) {
25 | result = defaultValue;
26 |
27 | if (result === undefined) {
28 | throw new Error(`No setting found with the specified key [${paths.join('/')}]!`);
29 | }
30 | }
31 |
32 | return result;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './config.loader';
2 | export * from './config.module';
3 | export * from './config.pipe';
4 | export * from './config.service';
5 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/tests/common.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
3 |
4 | import { ConfigModule } from '../src';
5 |
6 | export const testSettings = {
7 | system: {
8 | applicationName: 'Mighty Mouse',
9 | applicationUrl: 'http://localhost:8000'
10 | },
11 | i18n: {
12 | locale: 'en'
13 | },
14 | falsy: {
15 | zero: 0,
16 | null: null as any,
17 | emptyString: ''
18 | }
19 | };
20 |
21 | export const testModuleConfig = (moduleOptions?: any) => {
22 | TestBed.resetTestEnvironment();
23 |
24 | TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()).configureTestingModule({
25 | imports: [ConfigModule.forRoot(moduleOptions)]
26 | });
27 | };
28 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/tests/config.loader.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 |
3 | import { ConfigLoader, ConfigService, ConfigStaticLoader } from '../src';
4 |
5 | import { testModuleConfig } from './common';
6 |
7 | describe('@ngx-config/core:', () => {
8 | beforeEach(() => {
9 | const configFactory = () => new ConfigStaticLoader();
10 |
11 | testModuleConfig({
12 | provide: ConfigLoader,
13 | useFactory: configFactory
14 | });
15 | });
16 |
17 | describe('ConfigLoader', () => {
18 | it('should not return any settings unless provided', () => {
19 | const loader = new ConfigStaticLoader();
20 |
21 | loader.loadSettings().then((res: any) => {
22 | expect(res).toBeUndefined();
23 | });
24 | });
25 |
26 | it('should be able to provide `ConfigStaticLoader`', () => {
27 | const config = TestBed.get(ConfigService);
28 |
29 | expect(ConfigStaticLoader).toBeDefined();
30 | expect(config.loader).toBeDefined();
31 | expect(config.loader instanceof ConfigStaticLoader).toBeTruthy();
32 | });
33 |
34 | it('should be able to provide any `ConfigLoader`', () => {
35 | class CustomLoader implements ConfigLoader {
36 | loadSettings(): any {
37 | return Promise.resolve({});
38 | }
39 | }
40 |
41 | testModuleConfig({
42 | provide: ConfigLoader,
43 | useClass: CustomLoader
44 | });
45 |
46 | const config = TestBed.get(ConfigService);
47 |
48 | expect(CustomLoader).toBeDefined();
49 | expect(config.loader).toBeDefined();
50 | expect(config.loader instanceof CustomLoader).toBeTruthy();
51 | });
52 | });
53 | });
54 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/tests/config.pipe.spec.ts:
--------------------------------------------------------------------------------
1 | import { inject } from '@angular/core/testing';
2 |
3 | import { ConfigLoader, ConfigPipe, ConfigService, ConfigStaticLoader } from '../src';
4 |
5 | import { testModuleConfig, testSettings } from './common';
6 |
7 | describe('@ngx-config/core:', () => {
8 | beforeEach(() => {
9 | const configFactory = () => new ConfigStaticLoader(testSettings);
10 |
11 | testModuleConfig({
12 | provide: ConfigLoader,
13 | useFactory: configFactory
14 | });
15 | });
16 |
17 | describe('ConfigPipe', () => {
18 | it('is defined', inject([ConfigService], (config: ConfigService) => {
19 | const pipe = new ConfigPipe(config);
20 |
21 | expect(ConfigPipe).toBeDefined();
22 | expect(pipe).toBeDefined();
23 | expect(pipe instanceof ConfigPipe).toBeTruthy();
24 | }));
25 |
26 | it('should be able to get setting(s) using `key`', inject([ConfigService], (config: ConfigService) => {
27 | config.loader.loadSettings().then(() => {
28 | const pipe = new ConfigPipe(config);
29 |
30 | let setting = pipe.transform(['system', 'applicationName']);
31 | expect(setting).toEqual('Mighty Mouse');
32 |
33 | setting = pipe.transform('system.applicationUrl');
34 | expect(setting).toEqual('http://localhost:8000');
35 | });
36 | }));
37 |
38 | it('should throw if you provide an invalid `key` w/o `default value`', inject([ConfigService], (config: ConfigService) => {
39 | config.loader.loadSettings().then(() => {
40 | const pipe = new ConfigPipe(config);
41 |
42 | expect(() => pipe.transform('layout')).toThrowError('No setting found with the specified key [layout]!');
43 | });
44 | }));
45 | });
46 | });
47 |
--------------------------------------------------------------------------------
/packages/@ngx-config/core/tests/config.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, inject } from '@angular/core/testing';
2 |
3 | import { ConfigLoader, ConfigService, ConfigStaticLoader } from '../src';
4 |
5 | import { testModuleConfig, testSettings } from './common';
6 |
7 | describe('@ngx-config/core:', () => {
8 | beforeEach(() => {
9 | const configFactory = () => new ConfigStaticLoader(testSettings);
10 |
11 | testModuleConfig({
12 | provide: ConfigLoader,
13 | useFactory: configFactory
14 | });
15 | });
16 |
17 | describe('ConfigService', () => {
18 | it('is defined', inject([ConfigService], (config: ConfigService) => {
19 | expect(ConfigService).toBeDefined();
20 | expect(config).toBeDefined();
21 | expect(config instanceof ConfigService).toBeTruthy();
22 | }));
23 |
24 | it('should be able to get all settings', inject([ConfigService], (config: ConfigService) => {
25 | config.loader.loadSettings().then(() => {
26 | expect(config.getSettings()).toEqual(testSettings);
27 | expect(config.getSettings('')).toEqual(testSettings);
28 | expect(config.getSettings([])).toEqual(testSettings);
29 | });
30 | }));
31 |
32 | it('should be able to get setting(s) using `key`', async(
33 | inject([ConfigService], (config: ConfigService) => {
34 | config.loader.loadSettings().then(() => {
35 | expect(config.getSettings('system')).toEqual({
36 | applicationName: 'Mighty Mouse',
37 | applicationUrl: 'http://localhost:8000'
38 | });
39 |
40 | expect(config.getSettings(['system', 'applicationName'])).toEqual('Mighty Mouse');
41 | expect(config.getSettings('system.applicationName')).toEqual('Mighty Mouse');
42 |
43 | expect(config.getSettings(['system', 'applicationUrl'])).toEqual('http://localhost:8000');
44 | expect(config.getSettings('system.applicationUrl')).toEqual('http://localhost:8000');
45 |
46 | expect(config.getSettings('i18n')).toEqual({
47 | locale: 'en'
48 | });
49 |
50 | expect(config.getSettings(['i18n', 'locale'])).toEqual('en');
51 | expect(config.getSettings('i18n.locale')).toEqual('en');
52 | });
53 | })
54 | ));
55 |
56 | it('should be able to get setting(s) using `key` (zero value)', async(
57 | inject([ConfigService], (config: ConfigService) => {
58 | config.loader.loadSettings().then(() => {
59 | expect(config.getSettings('falsy.zero')).toEqual(0);
60 | });
61 | })
62 | ));
63 |
64 | it('should be able to get setting(s) using `key` (null value)', async(
65 | inject([ConfigService], (config: ConfigService) => {
66 | config.loader.loadSettings().then(() => {
67 | expect(config.getSettings('falsy.null')).toBeNull();
68 | });
69 | })
70 | ));
71 |
72 | it('should be able to get setting(s) using `key` (empty string)', async(
73 | inject([ConfigService], (config: ConfigService) => {
74 | config.loader.loadSettings().then(() => {
75 | expect(config.getSettings('falsy.emptyString')).toEqual('');
76 | });
77 | })
78 | ));
79 |
80 | it('should be able to get `default value` w/invalid `key`', async(
81 | inject([ConfigService], (config: ConfigService) => {
82 | config.loader.loadSettings().then(() => {
83 | expect(config.getSettings('layout', 'default')).toEqual('default');
84 | });
85 | })
86 | ));
87 |
88 | it('should throw if you provide an invalid `key` w/o `default value`', async(
89 | inject([ConfigService], (config: ConfigService) => {
90 | config.loader.loadSettings().then(() => {
91 | expect(() => config.getSettings('layout')).toThrowError('No setting found with the specified key [layout]!');
92 | });
93 | })
94 | ));
95 | });
96 | });
97 |
--------------------------------------------------------------------------------
/packages/@ngx-config/http-loader/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 |
6 | # [9.0.0](https://github.com/fulls1z3/ngx-config/compare/v8.2.0...v9.0.0) (2020-04-27)
7 |
8 |
9 | ### Features
10 |
11 | * **package:** migrate to ng9 ([9370d36](https://github.com/fulls1z3/ngx-config/commit/9370d36f63fcfb81b50e688d660edda83c077aed))
12 |
13 |
14 | ### BREAKING CHANGES
15 |
16 | * **package:** ng9
17 |
18 |
19 |
20 |
21 |
22 | # [8.2.0](https://github.com/fulls1z3/ngx-config/compare/v8.1.0...v8.2.0) (2020-04-27)
23 |
24 |
25 | ### Features
26 |
27 | * **package:** migrate to ng9 ([#161](https://github.com/fulls1z3/ngx-config/issues/161)) ([58fdac3](https://github.com/fulls1z3/ngx-config/commit/58fdac3d0e8c581440e8854c66b3db58dc2ef47c))
28 |
29 |
30 |
31 |
32 |
33 | ## [8.0.2](https://github.com/fulls1z3/ngx-config/compare/v8.0.1...v8.0.2) (2019-12-02)
34 |
35 |
36 | ### Bug Fixes
37 |
38 | * **packaging:** fix deployment ([#158](https://github.com/fulls1z3/ngx-config/issues/158)) ([7538157](https://github.com/fulls1z3/ngx-config/commit/75381576cb58a76b6acffda81b6c73bf99944338))
39 | * **packaging:** fix deployment ([#159](https://github.com/fulls1z3/ngx-config/issues/159)) ([32061d0](https://github.com/fulls1z3/ngx-config/commit/32061d0bf44c42fa67222e36396839737d265b40))
40 |
41 |
42 |
43 |
44 |
45 | ## [8.0.1](https://github.com/fulls1z3/ngx-config/compare/v8.0.0...v8.0.1) (2019-11-21)
46 |
47 | **Note:** Version bump only for package @ngx-config/http-loader
48 |
49 |
50 |
51 |
52 |
53 | # [8.0.0](https://github.com/fulls1z3/ngx-config/compare/v6.0.0-rc.1...v8.0.0) (2019-11-21)
54 |
55 |
56 | ### Features
57 |
58 | * **package:** upgrade to angular 8 ([0d5161f](https://github.com/fulls1z3/ngx-config/commit/0d5161f6aca4bc00edf057cc10dd510ae10aee5e))
59 |
60 |
61 | ### BREAKING CHANGES
62 |
63 | * **package:** ng8
64 |
--------------------------------------------------------------------------------
/packages/@ngx-config/http-loader/README.md:
--------------------------------------------------------------------------------
1 | # @ngx-config/http-loader [](https://www.npmjs.com/package/@ngx-config/http-loader) [](https://www.npmjs.com/package/@ngx-config/http-loader)
2 |
3 | Loader for [ngx-config] that provides application settings using **`http`**
4 |
5 | [](https://circleci.com/gh/fulls1z3/ngx-config)
6 | [](https://codecov.io/gh/fulls1z3/ngx-config)
7 | [](https://github.com/facebook/jest)
8 | [](https://conventionalcommits.org)
9 | [](https://angular.io/styleguide)
10 |
11 | > Please support this project by simply putting a Github star. Share this library with friends on Twitter and everywhere else you can.
12 |
13 | ## Table of contents:
14 |
15 | - [Getting started](#getting-started)
16 | - [Installation](#installation) - [Examples](#examples) - [Related packages](#related-packages) - [Adding `@ngx-config/http-loader` to your project (SystemJS)](#adding-systemjs)
17 | - [Settings](#settings) - [Setting up `ConfigModule` to use `ConfigHttpLoader`](#setting-up-httploader)
18 | - [License](#license)
19 |
20 | ## Getting started
21 |
22 | ### Installation
23 |
24 | You can install **`@ngx-config/http-loader`** using `npm`
25 |
26 | ```
27 | npm install @ngx-config/http-loader --save
28 | ```
29 |
30 | **Note**: You should have already installed [@ngx-config/core].
31 |
32 | ### Examples
33 |
34 | - [ng-seed/universal] and [fulls1z3/example-app] are officially maintained projects, showcasing common patterns and best
35 | practices for **`@ngx-config/http-loader`**.
36 |
37 | ### Related packages
38 |
39 | The following packages may be used in conjunction with **`@ngx-config/http-loader`**:
40 |
41 | - [@ngx-config/core]
42 | - [@ngx-config/merge-loader]
43 |
44 | ### Adding `@ngx-config/http-loader` to your project (SystemJS)
45 |
46 | Add `map` for **`@ngx-config/http-loader`** in your `systemjs.config`
47 |
48 | ```javascript
49 | '@ngx-config/http-loader': 'node_modules/@ngx-config/http-loader/bundles/http-loader.umd.min.js'
50 | ```
51 |
52 | ## Settings
53 |
54 | ### Setting up `ConfigModule` to use `ConfigHttpLoader`
55 |
56 | If you provide application settings using a `JSON` file or an `API`, you can call the [forRoot] static method using the
57 | `ConfigHttpLoader`. By default, it is configured to retrieve **application settings** from the endpoint `/config.json`
58 | (_if not specified_).
59 |
60 | > You can customize this behavior (_and ofc other settings_) by supplying a **api endpoint** to `ConfigHttpLoader`.
61 |
62 | - Import `ConfigModule` using the mapping `'@ngx-config/core'` and append `ConfigModule.forRoot({...})` within the imports
63 | property of **app.module**.
64 | - Import `ConfigHttpLoader` using the mapping `'@ngx-config/http-loader'`.
65 |
66 | **Note**: _Considering the app.module is the core module in Angular application_.
67 |
68 | #### config.json
69 |
70 | ```json
71 | {
72 | "system": {
73 | "applicationName": "Mighty Mouse",
74 | "applicationUrl": "http://localhost:8000"
75 | },
76 | "seo": {
77 | "pageTitle": "Tweeting bird"
78 | },
79 | "i18n": {
80 | "locale": "en"
81 | }
82 | }
83 | ```
84 |
85 | #### app.module.ts
86 |
87 | ```TypeScript
88 | ...
89 | import { HttpClient } from '@angular/common/http';
90 | import { ConfigModule, ConfigLoader, } from '@ngx-config/core';
91 | import { ConfigHttpLoader } from '@ngx-config/http-loader';
92 | ...
93 |
94 | export function configFactory(http: HttpClient): ConfigLoader {
95 | return new ConfigHttpLoader(http, './config.json'); // API ENDPOINT
96 | }
97 |
98 | @NgModule({
99 | declarations: [
100 | AppComponent,
101 | ...
102 | ],
103 | ...
104 | imports: [
105 | ConfigModule.forRoot({
106 | provide: ConfigLoader,
107 | useFactory: (configFactory),
108 | deps: [HttpClient]
109 | }),
110 | ...
111 | ],
112 | ...
113 | bootstrap: [AppComponent]
114 | })
115 | ```
116 |
117 | `ConfigHttpLoader` has two parameters:
118 |
119 | - **http**: `HttpClient` : Http instance
120 | - **endpoint**: `string` : the `API endpoint`, to retrieve application settings from (_by default, `config.json`_)
121 |
122 | > :+1: Well! **`@ngx-config/http-loader`** will now provide **application settings** to [@ngx-config/core] using `http`.
123 |
124 | ## License
125 |
126 | The MIT License (MIT)
127 |
128 | Copyright (c) 2019 [Burak Tasci]
129 |
130 | [ngx-config]: https://github.com/fulls1z3/ngx-config
131 | [ng-seed/universal]: https://github.com/ng-seed/universal
132 | [fulls1z3/example-app]: https://github.com/fulls1z3/example-app
133 | [@ngx-config/core]: https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/core
134 | [@ngx-config/merge-loader]: https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/merge-loader
135 | [forroot]: https://angular.io/docs/ts/latest/guide/ngmodule.html#!#core-for-root
136 | [burak tasci]: https://github.com/fulls1z3
137 |
--------------------------------------------------------------------------------
/packages/@ngx-config/http-loader/ng-package.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
3 | "dest": "../../../dist/@ngx-config/http-loader",
4 | "lib": {
5 | "entryFile": "src/index.ts"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/packages/@ngx-config/http-loader/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ngx-config/http-loader",
3 | "version": "9.0.0",
4 | "description": "Loader for ngx-config that provides application settings using http",
5 | "repository": {
6 | "type": "git",
7 | "url": "https://github.com/fulls1z3/ngx-config.git"
8 | },
9 | "keywords": [
10 | "plugin",
11 | "loader",
12 | "http",
13 | "configmodule",
14 | "config",
15 | "angular"
16 | ],
17 | "author": {
18 | "name": "Burak Tasci",
19 | "email": "mail@buraktasci.com"
20 | },
21 | "license": "MIT",
22 | "bugs": {
23 | "url": "https://github.com/fulls1z3/ngx-config/issues"
24 | },
25 | "homepage": "https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/http-loader#readme",
26 | "peerDependencies": {
27 | "@angular/common": ">=9.0.0 <10.0.0",
28 | "@angular/core": ">=9.0.0 <10.0.0",
29 | "@angular/platform-browser-dynamic": ">=9.0.0 <10.0.0",
30 | "@ngx-config/core": ">=9.0.0 <10.0.0",
31 | "rxjs": ">=6.0.0"
32 | },
33 | "publishConfig": {
34 | "access": "public",
35 | "directory": "../../../dist/@ngx-config/http-loader"
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/packages/@ngx-config/http-loader/src/config.http-loader.ts:
--------------------------------------------------------------------------------
1 | import { HttpClient } from '@angular/common/http';
2 | import { forwardRef, Inject, resolveForwardRef } from '@angular/core';
3 | import { ConfigLoader } from '@ngx-config/core';
4 |
5 | export class ConfigHttpLoader implements ConfigLoader {
6 | constructor(
7 | @Inject(forwardRef(() => HttpClient)) private readonly http: HttpClient,
8 | private readonly endpoint: string = '/config.json'
9 | ) {}
10 |
11 | loadSettings(): any {
12 | return new Promise((resolve: any, reject: Function) => {
13 | const http = resolveForwardRef(this.http);
14 |
15 | http.get(this.endpoint).subscribe(resolve, () => reject('Endpoint unreachable!'));
16 | });
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/packages/@ngx-config/http-loader/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './config.http-loader';
2 |
--------------------------------------------------------------------------------
/packages/@ngx-config/http-loader/tests/config.http-loader.spec.ts:
--------------------------------------------------------------------------------
1 | import { HttpClient } from '@angular/common/http';
2 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
3 | import { async, TestBed } from '@angular/core/testing';
4 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
5 | import { ConfigLoader, ConfigModule, ConfigService } from '@ngx-config/core';
6 |
7 | import { ConfigHttpLoader } from '../src';
8 |
9 | const testSettings = {
10 | system: {
11 | applicationName: 'Mighty Mouse',
12 | applicationUrl: 'http://localhost:8000'
13 | },
14 | i18n: {
15 | locale: 'en'
16 | }
17 | };
18 |
19 | const testModuleConfig = (moduleOptions?: any) => {
20 | TestBed.resetTestEnvironment();
21 |
22 | TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()).configureTestingModule({
23 | imports: [HttpClientTestingModule, ConfigModule.forRoot(moduleOptions)]
24 | });
25 | };
26 |
27 | describe('@ngx-config/http-loader:', () => {
28 | describe('ConfigHttpLoader', () => {
29 | it('should be able to provide `ConfigHttpLoader`', () => {
30 | const configFactory = (http: HttpClient) => new ConfigHttpLoader(http);
31 |
32 | testModuleConfig({
33 | provide: ConfigLoader,
34 | useFactory: configFactory,
35 | deps: [HttpClient]
36 | });
37 |
38 | const config = TestBed.get(ConfigService);
39 |
40 | expect(ConfigHttpLoader).toBeDefined();
41 | expect(config.loader).toBeDefined();
42 | expect(config.loader instanceof ConfigHttpLoader).toBeTruthy();
43 |
44 | const httpMock = TestBed.get(HttpTestingController);
45 | httpMock.expectOne({ method: 'GET', url: '/config.json' }).flush(testSettings);
46 | httpMock.verify();
47 | });
48 | });
49 |
50 | it('should be able to retrieve settings from the specified `endpoint`', async(() => {
51 | const configFactory = (http: HttpClient) => new ConfigHttpLoader(http, '/api/settings');
52 |
53 | testModuleConfig({
54 | provide: ConfigLoader,
55 | useFactory: configFactory,
56 | deps: [HttpClient]
57 | });
58 |
59 | const config = TestBed.get(ConfigService);
60 |
61 | config.loader.loadSettings().then((res: any) => {
62 | expect(res).toEqual(testSettings);
63 | });
64 |
65 | const httpMock = TestBed.get(HttpTestingController);
66 | const reqs = httpMock.match('/api/settings');
67 |
68 | for (const req of reqs) {
69 | req.flush(testSettings);
70 | }
71 |
72 | httpMock.verify();
73 | }));
74 |
75 | it('should throw w/o a valid `endpoint`', (done: jest.DoneCallback) => {
76 | const configFactory = (http: HttpClient) => new ConfigHttpLoader(http, '/api/wrong-settings');
77 |
78 | testModuleConfig({
79 | provide: ConfigLoader,
80 | useFactory: configFactory,
81 | deps: [HttpClient]
82 | });
83 |
84 | const config = TestBed.get(ConfigService);
85 |
86 | config.loader.loadSettings().catch((err: any) => {
87 | expect(err).toEqual('Endpoint unreachable!');
88 | done();
89 | });
90 |
91 | const httpMock = TestBed.get(HttpTestingController);
92 | const reqs = httpMock.match('/api/wrong-settings');
93 |
94 | for (const req of reqs) {
95 | req.flush({}, { status: 500, statusText: '' });
96 | }
97 |
98 | httpMock.verify();
99 | });
100 | });
101 |
--------------------------------------------------------------------------------
/packages/@ngx-config/merge-loader/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 |
6 | # [9.0.0](https://github.com/fulls1z3/ngx-config/compare/v8.2.0...v9.0.0) (2020-04-27)
7 |
8 |
9 | ### Features
10 |
11 | * **package:** migrate to ng9 ([9370d36](https://github.com/fulls1z3/ngx-config/commit/9370d36f63fcfb81b50e688d660edda83c077aed))
12 |
13 |
14 | ### BREAKING CHANGES
15 |
16 | * **package:** ng9
17 |
18 |
19 |
20 |
21 |
22 | # [8.2.0](https://github.com/fulls1z3/ngx-config/compare/v8.1.0...v8.2.0) (2020-04-27)
23 |
24 |
25 | ### Features
26 |
27 | * **package:** migrate to ng9 ([#161](https://github.com/fulls1z3/ngx-config/issues/161)) ([58fdac3](https://github.com/fulls1z3/ngx-config/commit/58fdac3d0e8c581440e8854c66b3db58dc2ef47c))
28 |
29 |
30 |
31 |
32 |
33 | ## [8.0.1](https://github.com/fulls1z3/ngx-config/compare/v8.0.0...v8.0.1) (2019-11-21)
34 |
35 | **Note:** Version bump only for package @ngx-config/merge-loader
36 |
37 |
38 |
39 |
40 |
41 | # [8.0.0](https://github.com/fulls1z3/ngx-config/compare/v6.0.0-rc.1...v8.0.0) (2019-11-21)
42 |
43 |
44 | ### Features
45 |
46 | * **package:** upgrade to angular 8 ([0d5161f](https://github.com/fulls1z3/ngx-config/commit/0d5161f6aca4bc00edf057cc10dd510ae10aee5e))
47 |
48 |
49 | ### BREAKING CHANGES
50 |
51 | * **package:** ng8
52 |
--------------------------------------------------------------------------------
/packages/@ngx-config/merge-loader/README.md:
--------------------------------------------------------------------------------
1 | # @ngx-config/merge-loader [](https://www.npmjs.com/package/@ngx-config/merge-loader) [](https://www.npmjs.com/package/@ngx-config/merge-loader)
2 |
3 | Loader for [ngx-config] that provides application settings by executing loaders in **parallel** and in **series**
4 |
5 | [](https://circleci.com/gh/fulls1z3/ngx-config)
6 | [](https://codecov.io/gh/fulls1z3/ngx-config)
7 | [](https://github.com/facebook/jest)
8 | [](https://conventionalcommits.org)
9 | [](https://angular.io/styleguide)
10 |
11 | > Please support this project by simply putting a Github star. Share this library with friends on Twitter and everywhere else you can.
12 |
13 | ## Table of contents:
14 |
15 | - [Getting started](#getting-started)
16 | - [Installation](#installation) - [Examples](#examples) - [Related packages](#related-packages) - [Adding `@ngx-config/merge-loader` to your project (SystemJS)](#adding-systemjs)
17 | - [Settings](#settings) - [Setting up `ConfigModule` to use `ConfigMergeLoader`](#setting-up-mergeloader)
18 | - [License](#license)
19 |
20 | ## Getting started
21 |
22 | ### Installation
23 |
24 | You can install **`@ngx-config/merge-loader`** using `npm`
25 |
26 | ```
27 | npm install @ngx-config/merge-loader --save
28 | ```
29 |
30 | **Note**: You should have already installed [@ngx-config/core].
31 |
32 | ### Examples
33 |
34 | - [ng-seed/universal] and [fulls1z3/example-app] are officially maintained projects, showcasing common patterns and best
35 | practices for **`@ngx-config/merge-loader`**.
36 |
37 | ### Related packages
38 |
39 | The following packages may be used in conjunction with **`@ngx-config/merge-loader`**:
40 |
41 | - [@ngx-config/core]
42 | - [@ngx-config/http-loader]
43 |
44 | ### Adding `@ngx-config/merge-loader` to your project (SystemJS)
45 |
46 | Add `map` for **`@ngx-config/merge-loader`** in your `systemjs.config`
47 |
48 | ```javascript
49 | '@ngx-config/merge-loader': 'node_modules/@ngx-config/merge-loader/bundles/merge-loader.umd.min.js'
50 | ```
51 |
52 | ## Settings
53 |
54 | ### Setting up `ConfigModule` to use `ConfigMergeLoader`
55 |
56 | `ConfigMergeLoader` requires one or more loaders of type `ConfigLoader` to load application settings by executing specified
57 | loaders in **parallel** and in **series**.
58 |
59 | - Import `ConfigModule` using the mapping `'@ngx-config/core'` and append `ConfigModule.forRoot({...})` within the imports
60 | property of **app.module**.
61 | - Import `ConfigMergeLoader` using the mapping `'@ngx-config/merge-loader'`.
62 |
63 | **Note**: _Considering the app.module is the core module in Angular application_.
64 |
65 | #### app.module.ts
66 |
67 | ```TypeScript
68 | ...
69 | import { HttpClient } from '@angular/common/http';
70 | import { ConfigModule, ConfigLoader } from '@ngx-config/core';
71 | import { ConfigHttpLoader } from '@ngx-config/http-loader';
72 | import { ConfigMergeLoader } from '@ngx-config/merge-loader';
73 | ...
74 |
75 | export function configFactory(http: HttpClient): ConfigLoader {
76 | const remoteConfigLoader = new ConfigHttpLoader(http, 'http://mysite.com/api/settings'); // API ENDPOINT (remote)
77 | const localConfigLoader = new ConfigHttpLoader(http, './config.local.json'); // API ENDPOINT (local)
78 |
79 | return new ConfigMergeLoader([remoteConfigLoader, localConfigLoader]); // PARALLEL EXECUTION
80 | }
81 |
82 | export function configFactorySeries(http: HttpClient): ConfigLoader {
83 | const localConfigLoader = new ConfigHttpLoader(http, './config.local.json'); // API ENDPOINT (local)
84 |
85 | return new ConfigMergeLoader([localConfigLoader])
86 | .next((res: any) => new ConfigHttpLoader(http, res['apiEndpoint'] + 'api/settings')); // SERIES EXECUTION
87 | }
88 |
89 | @NgModule({
90 | declarations: [
91 | AppComponent,
92 | ...
93 | ],
94 | ...
95 | imports: [
96 | ConfigModule.forRoot({
97 | provide: ConfigLoader,
98 | useFactory: (configFactory),
99 | deps: [Http]
100 | }),
101 | ...
102 | ],
103 | ...
104 | bootstrap: [AppComponent]
105 | })
106 | ```
107 |
108 | `ConfigMergeLoader` has one parameter:
109 |
110 | - **loaders**: `Array` : the `loaders` to be executed (_by default, `[new ConfigStaticLoader()]`_)
111 |
112 | `ConfigMergeLoader` has also the `next` public method, which you can pass the loader to be executed in series.
113 |
114 | > :+1: Well! **`@ngx-config/merge-loader`** will now provide **application settings** to [@ngx-config/core] by executing
115 | > loaders in **parallel** and in **series**.
116 |
117 | ## License
118 |
119 | The MIT License (MIT)
120 |
121 | Copyright (c) 2019 [Burak Tasci]
122 |
123 | [ngx-config]: https://github.com/fulls1z3/ngx-config
124 | [ng-seed/universal]: https://github.com/ng-seed/universal
125 | [fulls1z3/example-app]: https://github.com/fulls1z3/example-app
126 | [@ngx-config/core]: https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/core
127 | [@ngx-config/http-loader]: https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/http-loader
128 | [burak tasci]: https://github.com/fulls1z3
129 |
--------------------------------------------------------------------------------
/packages/@ngx-config/merge-loader/ng-package.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
3 | "dest": "../../../dist/@ngx-config/merge-loader",
4 | "lib": {
5 | "entryFile": "src/index.ts",
6 | "umdModuleIds": {
7 | "rxjs": "rxjs",
8 | "lodash": "_",
9 | "@ngx-config/core": "_ngxConfig_core"
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/packages/@ngx-config/merge-loader/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ngx-config/merge-loader",
3 | "version": "9.0.0",
4 | "description": "Loader for ngx-config that provides application settings by executing loaders in parallel and in series",
5 | "repository": {
6 | "type": "git",
7 | "url": "https://github.com/fulls1z3/ngx-config.git"
8 | },
9 | "keywords": [
10 | "plugin",
11 | "loader",
12 | "series",
13 | "parallel",
14 | "merge",
15 | "configmodule",
16 | "config",
17 | "angular"
18 | ],
19 | "author": {
20 | "name": "Burak Tasci",
21 | "email": "mail@buraktasci.com"
22 | },
23 | "license": "MIT",
24 | "bugs": {
25 | "url": "https://github.com/fulls1z3/ngx-config/issues"
26 | },
27 | "homepage": "https://github.com/fulls1z3/ngx-config/tree/master/packages/@ngx-config/merge-loader#readme",
28 | "peerDependencies": {
29 | "@angular/core": ">=9.0.0 <10.0.0",
30 | "@angular/platform-browser-dynamic": ">=9.0.0 <10.0.0",
31 | "@ngx-config/core": ">=9.0.0 <10.0.0",
32 | "lodash": ">=4.17.10",
33 | "rxjs": ">=6.0.0"
34 | },
35 | "publishConfig": {
36 | "access": "public",
37 | "directory": "../../../dist/@ngx-config/merge-loader"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/packages/@ngx-config/merge-loader/src/config.merge-loader.ts:
--------------------------------------------------------------------------------
1 | import { ConfigLoader, ConfigStaticLoader } from '@ngx-config/core';
2 | import { mergeWith as _mergeWith } from 'lodash/fp';
3 | import { EMPTY, from as fromObservable, merge, Observable, onErrorResumeNext, throwError } from 'rxjs';
4 | import { filter, isEmpty, mergeMap, reduce, share } from 'rxjs/operators';
5 |
6 | const errorIfEmpty = (source: Observable) =>
7 | source.pipe(
8 | isEmpty(),
9 | mergeMap((empty: boolean) => (empty ? throwError(new Error('No setting found at the specified loader!')) : EMPTY))
10 | );
11 |
12 | const mergeWith = (object: any) => (source: Array) =>
13 | _mergeWith((objValue: any, srcValue: any) => {
14 | if (Array.isArray(objValue)) {
15 | return srcValue;
16 | }
17 | })(object)(source);
18 |
19 | const mergeSeries = async (merged: any, current: Promise) => current.then(mergeWith(merged));
20 |
21 | export class ConfigMergeLoader implements ConfigLoader {
22 | private nextLoader: Function;
23 |
24 | constructor(private readonly loaders: Array = []) {}
25 |
26 | loadSettings(): any {
27 | if (typeof this.nextLoader === 'function') {
28 | return this.mergeParallel().then(async (res: any) => mergeSeries(res, this.nextLoader(res).loadSettings()));
29 | }
30 |
31 | return this.mergeParallel();
32 | }
33 |
34 | next(loader: Function): any {
35 | this.nextLoader = loader;
36 |
37 | return this;
38 | }
39 |
40 | private async mergeParallel(): Promise {
41 | const loaders: Array = [new ConfigStaticLoader(), ...this.loaders];
42 |
43 | const mergedSettings = onErrorResumeNext(loaders.map((loader: ConfigLoader) => fromObservable(loader.loadSettings()))).pipe(
44 | filter((res: any) => res),
45 | share()
46 | );
47 |
48 | return new Promise((resolve: () => void, reject: Function) => {
49 | merge(mergedSettings, errorIfEmpty(mergedSettings), mergedSettings)
50 | .pipe(reduce((merged: any, current: any) => mergeWith(merged)(current), {}))
51 | .subscribe(resolve, () => reject('Loaders unreachable!'));
52 | });
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/packages/@ngx-config/merge-loader/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './config.merge-loader';
2 |
--------------------------------------------------------------------------------
/packages/@ngx-config/merge-loader/tests/config.merge-loader.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, inject, TestBed } from '@angular/core/testing';
2 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
3 | import { ConfigLoader, ConfigModule, ConfigService, ConfigStaticLoader } from '@ngx-config/core';
4 |
5 | import { ConfigMergeLoader } from '../src';
6 |
7 | const testSettingsMain = {
8 | setting1: 'value1',
9 | setting2: 'from config.json',
10 | arr: [1, 2, 3],
11 | nested: {
12 | k1: 'v1',
13 | k2: 'v2 from config.json'
14 | }
15 | };
16 |
17 | const testSettingsLocal = {
18 | setting2: 'from config.local.json',
19 | setting3: 'value3',
20 | arr: [4, 5]
21 | };
22 |
23 | const testSettingsEnv = {
24 | setting4: 'value4',
25 | nested: {
26 | k2: 'v2 from env/test.json',
27 | k3: 'v3'
28 | }
29 | };
30 |
31 | const testSettingsMerged = {
32 | setting1: 'value1',
33 | setting2: 'from config.local.json',
34 | setting3: 'value3',
35 | setting4: 'value4',
36 | arr: [4, 5],
37 | nested: {
38 | k1: 'v1',
39 | k2: 'v2 from env/test.json',
40 | k3: 'v3'
41 | }
42 | };
43 |
44 | const testModuleConfig = (moduleOptions?: any) => {
45 | TestBed.resetTestEnvironment();
46 |
47 | TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()).configureTestingModule({
48 | imports: [ConfigModule.forRoot(moduleOptions)]
49 | });
50 | };
51 |
52 | describe('@ngx-config/merge-loader:', () => {
53 | beforeEach(() => {
54 | const mainLoader = new ConfigStaticLoader(testSettingsMain);
55 | const localLoader = new ConfigStaticLoader(testSettingsLocal);
56 | const envLoader = new ConfigStaticLoader(testSettingsEnv);
57 |
58 | const configFactory = () => new ConfigMergeLoader([mainLoader, localLoader, envLoader]);
59 |
60 | testModuleConfig({
61 | provide: ConfigLoader,
62 | useFactory: configFactory
63 | });
64 | });
65 |
66 | describe('ConfigMergeLoader', () => {
67 | it('should be able to provide `ConfigMergeLoader`', () => {
68 | const configFactory = () => new ConfigMergeLoader();
69 |
70 | testModuleConfig({
71 | provide: ConfigLoader,
72 | useFactory: configFactory
73 | });
74 |
75 | const config = TestBed.get(ConfigService);
76 |
77 | expect(ConfigMergeLoader).toBeDefined();
78 | expect(config.loader).toBeDefined();
79 | expect(config.loader instanceof ConfigMergeLoader).toBeTruthy();
80 | });
81 |
82 | it('should be able to retrieve and merge settings `in parallel`', async(
83 | inject([ConfigService], (config: ConfigService) => {
84 | config.loader.loadSettings().then((res: any) => {
85 | expect(res).toEqual(testSettingsMerged);
86 | });
87 | })
88 | ));
89 |
90 | it('should be able to retrieve and merge settings `in parallel` w/some of the `loaders` are unavailable', () => {
91 | class UnavailableLoader implements ConfigLoader {
92 | loadSettings(): any {
93 | return Promise.reject('Endpoint unreachable!');
94 | }
95 | }
96 |
97 | const mainLoader = new ConfigStaticLoader(testSettingsMain);
98 | const localLoader = new UnavailableLoader();
99 | const envLoader = new ConfigStaticLoader(testSettingsEnv);
100 |
101 | const configFactory = () => new ConfigMergeLoader([mainLoader, localLoader, envLoader]);
102 |
103 | testModuleConfig({
104 | provide: ConfigLoader,
105 | useFactory: configFactory
106 | });
107 |
108 | const config = TestBed.get(ConfigService);
109 |
110 | const expectedSettings = {
111 | setting1: 'value1',
112 | setting2: 'from config.json',
113 | setting4: 'value4',
114 | arr: [1, 2, 3],
115 | nested: {
116 | k1: 'v1',
117 | k2: 'v2 from env/test.json',
118 | k3: 'v3'
119 | }
120 | };
121 |
122 | config.loader.loadSettings().then((res: any) => {
123 | expect(res).toEqual(expectedSettings);
124 | });
125 | });
126 |
127 | it('should throw w/o any reachable `loaders`', (done: jest.DoneCallback) => {
128 | const configFactory = () => new ConfigMergeLoader();
129 |
130 | testModuleConfig({
131 | provide: ConfigLoader,
132 | useFactory: configFactory
133 | });
134 |
135 | const config = TestBed.get(ConfigService);
136 |
137 | config.loader.loadSettings().catch((err: any) => {
138 | expect(err).toEqual('Loaders unreachable!');
139 | done();
140 | });
141 | });
142 |
143 | it('should be able to retrieve and merge settings `in series`', () => {
144 | const mainLoader = new ConfigStaticLoader(testSettingsMain);
145 | const localLoader = new ConfigStaticLoader(testSettingsLocal);
146 | const envLoader = new ConfigStaticLoader(testSettingsEnv);
147 |
148 | const configFactory = () => new ConfigMergeLoader([mainLoader, localLoader]).next(() => envLoader);
149 |
150 | testModuleConfig({
151 | provide: ConfigLoader,
152 | useFactory: configFactory
153 | });
154 |
155 | const config = TestBed.get(ConfigService);
156 |
157 | config.loader.loadSettings().then((res: any) => {
158 | expect(res).toEqual(testSettingsMerged);
159 | });
160 | });
161 |
162 | it('should be able to retrieve and merge settings `in series` w/data from parent `loaders`', () => {
163 | const envLoader = new ConfigStaticLoader(testSettingsEnv);
164 |
165 | const configFactory = () => new ConfigMergeLoader([envLoader]).next((res: any) => new ConfigStaticLoader({ env: res }));
166 |
167 | testModuleConfig({
168 | provide: ConfigLoader,
169 | useFactory: configFactory
170 | });
171 |
172 | const config = TestBed.get(ConfigService);
173 |
174 | const expectedSettings = {
175 | setting4: 'value4',
176 | nested: {
177 | k2: 'v2 from env/test.json',
178 | k3: 'v3'
179 | },
180 | env: {
181 | setting4: 'value4',
182 | nested: {
183 | k2: 'v2 from env/test.json',
184 | k3: 'v3'
185 | }
186 | }
187 | };
188 |
189 | config.loader.loadSettings().then((res: any) => {
190 | expect(res).toEqual(expectedSettings);
191 | });
192 | });
193 | });
194 | });
195 |
--------------------------------------------------------------------------------
/tools/build/helpers.ts:
--------------------------------------------------------------------------------
1 | // tslint:disable
2 | import * as path from 'path';
3 |
4 | export function root(args: any = ''): string {
5 | const ROOT = path.resolve(__dirname, '../..');
6 | args = [].slice.call(arguments, 0);
7 |
8 | return path.join.apply(path, [ROOT].concat(args));
9 | }
10 |
--------------------------------------------------------------------------------
/tools/build/packager.ts:
--------------------------------------------------------------------------------
1 | import { ngPackagr } from 'ng-packagr';
2 |
3 | import { root } from './helpers';
4 |
5 | ngPackagr()
6 | .forProject(root(`./packages/@ngx-config/${process.argv[2]}/ng-package.json`))
7 | .withTsConfig(root('./tools/build/tsconfig.package.json'))
8 | .build()
9 | .catch(() => (process.exitCode = 1));
10 |
--------------------------------------------------------------------------------
/tools/build/tsconfig.package.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.json",
3 | "compilerOptions": {
4 | "target": "es2015",
5 | "module": "es2015",
6 | "noImplicitAny": true,
7 | "suppressImplicitAnyIndexErrors": true,
8 | "importHelpers": true,
9 | "sourceMap": true,
10 | "inlineSources": true,
11 | "declaration": true,
12 | "removeComments": true,
13 | "stripInternal": true,
14 | "rootDir": "./",
15 | "baseUrl": "",
16 | "paths": {
17 | "@ngx-config/*": ["../../dist/@ngx-config/*"]
18 | },
19 | "typeRoots": ["../../node_modules/@types"],
20 | "lib": [
21 | "es2015",
22 | "dom"
23 | ]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tools/test/jest.setup.ts:
--------------------------------------------------------------------------------
1 | // tslint:disable
2 | import 'jest-preset-angular';
3 |
4 | const mock = () => {
5 | let storage = {};
6 |
7 | return {
8 | getItem: (key: string) => (key in storage ? (storage as any)[key] : undefined),
9 | setItem: (key: string, value: any) => ((storage as any)[key] = value || ''),
10 | removeItem: (key: string) => delete (storage as any)[key],
11 | clear: () => (storage = {})
12 | };
13 | };
14 |
15 | Object.defineProperty(window, 'CSS', { value: mock() });
16 | Object.defineProperty(window, 'localStorage', { value: mock() });
17 | Object.defineProperty(window, 'sessionStorage', { value: mock() });
18 |
19 | Object.defineProperty(document, 'doctype', {
20 | value: ''
21 | });
22 |
23 | Object.defineProperty(window, 'getComputedStyle', {
24 | value: () => {
25 | return {
26 | display: 'none',
27 | appearance: ['-webkit-appearance']
28 | };
29 | }
30 | });
31 |
--------------------------------------------------------------------------------
/tools/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "../tslint.json"
4 | ],
5 | "rules": {
6 | "no-implicit-dependencies": [
7 | true,
8 | "dev"
9 | ],
10 | "no-dynamic-delete": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "rootDir": ".",
4 | "sourceMap": true,
5 | "declaration": false,
6 | "moduleResolution": "node",
7 | "emitDecoratorMetadata": true,
8 | "experimentalDecorators": true,
9 | "importHelpers": true,
10 | "target": "es2015",
11 | "module": "commonjs",
12 | "typeRoots": ["node_modules/@types"],
13 | "lib": ["es2017", "dom"],
14 | "skipLibCheck": true,
15 | "skipDefaultLibCheck": true,
16 | "baseUrl": ".",
17 | "paths": {
18 | "@ngx-config/core": ["packages/@ngx-config/core/src/index.ts"],
19 | "@ngx-config/http-loader": ["packages/@ngx-config/http-loader/src/index.ts"],
20 | "@ngx-config/merge-loader": ["packages/@ngx-config/merge-loader/src/index.ts"]
21 | },
22 | "noImplicitAny": true,
23 | "suppressImplicitAnyIndexErrors": true
24 | },
25 | "include": ["tools/**/*.ts", "packages/**/*.ts"]
26 | }
27 |
--------------------------------------------------------------------------------
/tsconfig.lint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "target": "es2015",
5 | "strictNullChecks": true
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": ["node_modules/codelyzer"],
3 | "extends": ["angular-tslint-rules", "tslint-config-prettier"],
4 | "rules": {
5 | "ordered-imports": [
6 | true,
7 | {
8 | "import-sources-order": "case-insensitive",
9 | "named-imports-order": "case-insensitive",
10 | "grouped-imports": true
11 | }
12 | ],
13 | "no-null-keyword": false,
14 | "no-forward-ref": false
15 | }
16 | }
17 |
--------------------------------------------------------------------------------