├── .github
├── FUNDING.yml
├── boring-cyborg.yml
├── CODEOWNERS
├── PULL_REQUEST_TEMPLATE.md
└── workflows
│ ├── build.yml
│ ├── lint.yml
│ ├── release.yml
│ └── tests.yml
├── .husky
├── commit-msg
└── prepare-commit-msg
├── .env.development.ext-project.jsonc
├── jest.setup.ts
├── src
└── index.ts
├── .vscode
├── extensions.json
└── settings.json
├── commitlint.config.js
├── tsconfig.eslint.json
├── .schemas
└── ext-project.env.schema.json
├── tsconfig.json
├── .all-contributorsrc
├── jest.config.js
├── LICENSE
├── .gitignore
├── package.json
├── .eslintrc.js
├── README.md
└── CHANGELOG.md
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | custom:
2 | - https://paypal.me/thatkookooguy?locale.x=en_US
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | npx --no-install commitlint --edit "$1"
--------------------------------------------------------------------------------
/.husky/prepare-commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | . "$(dirname "$0")/_/husky.sh"
3 | exec < /dev/tty && node_modules/.bin/cz --hook || true
--------------------------------------------------------------------------------
/.github/boring-cyborg.yml:
--------------------------------------------------------------------------------
1 | labelPRBasedOnFilePath:
2 |
3 | Tools:
4 | - .github/**/*
5 | - .vscode/**/*
6 | - .husky/**/*
--------------------------------------------------------------------------------
/.env.development.ext-project.jsonc:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": ".schemas/ext-project.env.schema.json",
3 | "PORT": "8080",
4 | "SLACK_API_KEY": "pizza",
5 | // hello
6 | }
7 |
--------------------------------------------------------------------------------
/jest.setup.ts:
--------------------------------------------------------------------------------
1 | import findRoot from 'find-root';
2 |
3 |
4 | jest.mock('fs-extra');
5 | jest.mock('find-root');
6 |
7 | const findRootMock = findRoot as jest.Mock;
8 |
9 | findRootMock.mockReturnValue('/');
10 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | import {
2 | parse as jsoncParse,
3 | stringify as jsoncStrigify } from 'comment-json';
4 |
5 | export function stringify(obj: Record) {
6 | return jsoncStrigify(obj, null, 2);
7 | }
8 |
9 | export function parse(text: string) {
10 | return jsoncParse(text);
11 | }
12 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "actboy168.tasks",
4 | "codeandstuff.package-json-upgrade",
5 | "dbaeumer.vscode-eslint",
6 | "eamodio.gitlens",
7 | "jock.svg",
8 | "mhutchie.git-graph",
9 | "wayou.vscode-todo-highlight",
10 | "wix.vscode-import-cost",
11 | "laktak.hjson"
12 | ]
13 | }
--------------------------------------------------------------------------------
/commitlint.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: [ '@commitlint/config-angular' ],
3 | rules: {
4 | 'type-enum': [
5 | 2,
6 | 'always', [
7 | 'build',
8 | 'chore',
9 | 'ci',
10 | 'docs',
11 | 'feat',
12 | 'fix',
13 | 'perf',
14 | 'refactor',
15 | 'revert',
16 | 'style',
17 | 'test'
18 | ]
19 | ]
20 | }
21 | };
22 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Each line is a file pattern followed by one or more owners.
2 |
3 | # These owners will be the default owners for everything in
4 | # the repo. Unless a later match takes precedence,
5 | # @global-owner1 and @global-owner2 will be requested for
6 | # review when someone opens a pull request.
7 | * @thatkookooguy
8 |
9 | # Build\Github Actions Owners
10 | /tools/ @thatkookooguy
11 | /.github/ @thatkookooguy
12 | /.devcontainer/ @thatkookooguy
13 | /.vscode/ @thatkookooguy
--------------------------------------------------------------------------------
/tsconfig.eslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "declaration": true,
5 | "declarationMap": true,
6 | "removeComments": true,
7 | "emitDecoratorMetadata": true,
8 | "experimentalDecorators": true,
9 | "allowSyntheticDefaultImports": true,
10 | "target": "es2017",
11 | "sourceMap": true,
12 | "esModuleInterop": true,
13 | "baseUrl": "./",
14 | "paths": {
15 | },
16 | "incremental": true,
17 | "skipLibCheck": true
18 | },
19 | "exclude": [ "node_modules", "test", "dist", "lib" ]
20 | }
--------------------------------------------------------------------------------
/.schemas/ext-project.env.schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "properties": {
3 | "PORT": {
4 | "type": "string",
5 | "description": "Server port"
6 | },
7 | "SLACK_ORGANIZATION_NAME": {
8 | "type": "string",
9 | "description": "This is the slack organization to talk to"
10 | },
11 | "SLACK_API_KEY": {
12 | "type": "string",
13 | "description": "This is the slack API to talk and report to channel \"hello\""
14 | }
15 | },
16 | "type": "object",
17 | "required": [
18 | "PORT",
19 | "SLACK_ORGANIZATION_NAME",
20 | "SLACK_API_KEY"
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "declaration": true,
5 | "declarationMap": true,
6 | "removeComments": true,
7 | "emitDecoratorMetadata": true,
8 | "experimentalDecorators": true,
9 | "allowSyntheticDefaultImports": true,
10 | "target": "es2017",
11 | "sourceMap": true,
12 | "esModuleInterop": true,
13 | "outDir": "./lib",
14 | "baseUrl": "./",
15 | "paths": {
16 | },
17 | "incremental": true,
18 | "skipLibCheck": true
19 | },
20 | "exclude": [
21 | "node_modules",
22 | "test",
23 | "dist",
24 | "lib",
25 | "examples",
26 | "**/*spec.ts",
27 | "**/*mock.ts",
28 | "jest.config.js",
29 | "jest.setup.ts"
30 | ]
31 | }
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Description
2 | 🚨 Review the [guidelines for contributing](../CONTRIBUTING.md) to this repository. 🚨
3 |
4 | Please explain the changes you made here.
5 |
6 | You can explain individual changes as a list:
7 |
8 | - [ ] feature name: extra details
9 | - [ ] bug: extra details (resolves #`issue_number`)
10 |
11 | ### Checklist
12 | Please check if your PR fulfills the following requirements:
13 | - [ ] Code compiles correctly (`npm run build`)
14 | - [ ] Code is linted
15 | - [ ] Created tests which fail without the change (if possible)
16 | - All **relevant** tests are passing
17 | - [ ] Server Unit Tests
18 | - [ ] Client Unit Tests
19 | - [ ] Achievements Unit Tests
20 | - [ ] API Tests
21 | - [ ] E2E Tests
22 | - [ ] Extended the README / documentation, if necessary
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | pull_request:
5 | push:
6 | branches:
7 | - main
8 | - beta
9 |
10 | jobs:
11 | build:
12 | name: Build Production
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: Checkout commit
16 | uses: actions/checkout@v2
17 | - name: Setup Node.js
18 | uses: actions/setup-node@v1
19 | with:
20 | node-version: 14
21 | - name: Cache node modules
22 | uses: actions/cache@v2
23 | env:
24 | cache-name: cache-node-modules
25 | with:
26 | path: '**/node_modules'
27 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
28 | restore-keys: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.lock') }}
29 | - name: Install Dependencies
30 | run: npm install
31 | - name: Build
32 | run: npm run build
--------------------------------------------------------------------------------
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "projectName": "configit",
3 | "projectOwner": "Kibibit",
4 | "repoType": "github",
5 | "repoHost": "https://github.com",
6 | "files": [
7 | "README.md"
8 | ],
9 | "badgeTemplate": "
-orange.svg?style=flat-square\" alt=\"All Contributors\">",
10 | "imageSize": 100,
11 | "commit": false,
12 | "commitConvention": "angular",
13 | "contributors": [
14 | {
15 | "login": "Thatkookooguy",
16 | "name": "Neil Kalman",
17 | "avatar_url": "https://avatars3.githubusercontent.com/u/10427304?v=4",
18 | "profile": "http://thatkookooguy.kibibit.io/",
19 | "contributions": [
20 | "code",
21 | "doc",
22 | "design",
23 | "maintenance",
24 | "infra",
25 | "test"
26 | ]
27 | }
28 | ],
29 | "contributorsPerLine": 7,
30 | "skipCi": true
31 | }
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | testEnvironment: 'node',
3 | roots: [
4 | '/src'
5 | ],
6 | setupFilesAfterEnv: [
7 | './jest.setup.ts'
8 | ],
9 | testMatch: [
10 | '**/__tests__/**/*.+(ts|tsx|js)',
11 | '**/?(*.)+(spec|test).+(ts|tsx|js)'
12 | ],
13 | transform: {
14 | '^.+\\.(ts|tsx)$': 'ts-jest'
15 | },
16 | collectCoverageFrom: [
17 | '**/*.(t|j)s',
18 | '!**/*.decorator.ts',
19 | '!**/*.mock.ts',
20 | '!**/index.ts',
21 | '!**/dev-tools/**/*.ts'
22 | ],
23 | reporters: [
24 | 'default',
25 | [
26 | 'jest-stare',
27 | {
28 | 'resultDir': './test-results',
29 | 'reportTitle': 'jest-stare!',
30 | 'additionalResultsProcessors': [
31 | 'jest-junit'
32 | ],
33 | 'coverageLink': './coverage/lcov-report/index.html'
34 | }
35 | ]
36 | ],
37 | coverageReporters: [
38 | 'json',
39 | 'lcov',
40 | 'text',
41 | 'clover',
42 | 'html'
43 | ],
44 | coverageDirectory: './test-results/coverage'
45 | };
46 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 kibibit
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 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.tabSize": 2,
3 | "editor.insertSpaces": true,
4 | "editor.detectIndentation": false,
5 | "editor.rulers": [120],
6 | "editor.matchBrackets": "always",
7 | "editor.bracketPairColorization.enabled": true,
8 | "editor.guides.bracketPairs":"active",
9 | "debug.javascript.autoAttachFilter": "onlyWithFlag",
10 | "editor.codeActionsOnSave": {
11 | "source.fixAll.eslint": true,
12 | },
13 | "eslint.format.enable": true,
14 | "bracketPairColorizer.colorMode": "Consecutive",
15 | "bracketPairColorizer.forceUniqueOpeningColor": true,
16 | "bracketPairColorizer.showBracketsInGutter": true,
17 | "window.title": "${activeEditorShort}${separator}${rootName} [kibibit]",
18 | "debug.javascript.terminalOptions": {
19 | "skipFiles": [
20 | "/**"
21 | ]
22 | },
23 | "svg.preview.background": "black",
24 | "todotodohighlight.isEnable": true,
25 | "todohighlight.keywordsPattern": "TODO(@\\w+?)?:",
26 | "todohighlight.defaultStyle": {
27 | "color": "black",
28 | "backgroundColor": "rgba(255, 221, 87, .8)",
29 | "overviewRulerColor": "rgba(255, 221, 87, .8)",
30 | "fontWeight": "bold",
31 | "borderRadius": "2px",
32 | "isWholeLine": true,
33 | }
34 | }
--------------------------------------------------------------------------------
/.github/workflows/lint.yml:
--------------------------------------------------------------------------------
1 | name: Lint
2 |
3 | on:
4 | workflow_dispatch:
5 | pull_request:
6 | push:
7 | branches:
8 | - main
9 | - beta
10 |
11 | jobs:
12 | run-linters:
13 | name: Run linters Server
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - name: Checkout Commit
18 | uses: actions/checkout@v2
19 | with:
20 | fetch-depth: 0
21 | - name: Setup Node.js
22 | uses: actions/setup-node@v1
23 | with:
24 | node-version: 14
25 | - name: Cache node modules
26 | uses: actions/cache@v2
27 | env:
28 | cache-name: cache-node-modules
29 | with:
30 | path: '**/node_modules'
31 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
32 | restore-keys: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.lock') }}
33 | - name: Install Dependencies
34 | run: npm install
35 | - name: Run linters
36 | uses: wearerequired/lint-action@v1.9.0
37 | with:
38 | # github_token: ${{ secrets.BOT_TOKEN }}
39 | # Enable linters
40 | eslint: true
41 | # Eslint options
42 | # eslint_dir: server/
43 | eslint_extensions: js,ts
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 | on:
3 | push:
4 | branches:
5 | - main
6 | - beta
7 | jobs:
8 | release:
9 | name: Release
10 | runs-on: ubuntu-18.04
11 | steps:
12 | - name: Checkout Commit
13 | uses: actions/checkout@v2
14 | with:
15 | fetch-depth: 0
16 | token: ${{ secrets.BOT_TOKEN }}
17 | - name: Setup Node.js
18 | uses: actions/setup-node@v1
19 | with:
20 | node-version: 14
21 | - name: Cache node modules
22 | uses: actions/cache@v2
23 | env:
24 | cache-name: cache-node-modules
25 | with:
26 | path: '**/node_modules'
27 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
28 | restore-keys: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.lock') }}
29 | - name: Install Dependencies
30 | run: npm install
31 | - name: Build
32 | run: npm run build --if-present
33 | - name: Release
34 | env:
35 | GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
36 | GIT_AUTHOR_NAME: k1b1b0t
37 | GIT_AUTHOR_EMAIL: k1b1b0t@kibibit.io
38 | GIT_COMMITTER_NAME: k1b1b0t
39 | GIT_COMMITTER_EMAIL: k1b1b0t@kibibit.io
40 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
41 | run: npm run semantic-release
--------------------------------------------------------------------------------
/.github/workflows/tests.yml:
--------------------------------------------------------------------------------
1 | name: Tests
2 | on:
3 | workflow_dispatch:
4 | pull_request:
5 | push:
6 | branches:
7 | - main
8 | - beta
9 |
10 | jobs:
11 | serverunittest:
12 | name: Tests
13 | runs-on: ubuntu-18.04
14 | steps:
15 | - name: Checkout Commit
16 | uses: actions/checkout@v2
17 | with:
18 | fetch-depth: 0
19 | - name: Setup Node.js
20 | uses: actions/setup-node@v1
21 | with:
22 | node-version: 14
23 | - name: Cache node modules
24 | uses: actions/cache@v2
25 | env:
26 | cache-name: cache-node-modules
27 | with:
28 | path: '**/node_modules'
29 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
30 | restore-keys: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.lock') }}
31 | - name: Install Dependencies
32 | run: npm install
33 | - name: Run Tests
34 | env:
35 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
37 | run: npm run test:cov
38 | - name: Archive test results & coverage
39 | uses: actions/upload-artifact@v2
40 | with:
41 | name: tests
42 | path: test-results
43 | - name: Upload coverage to Codecov
44 | uses: codecov/codecov-action@v1
45 | with:
46 | token: ${{ secrets.CODECOV_TOKEN }}
47 | directory: ./test-results/coverage
48 | fail_ci_if_error: true
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | lib
2 | test-results
3 |
4 | # Logs
5 | logs
6 | *.log
7 | npm-debug.log*
8 | yarn-debug.log*
9 | yarn-error.log*
10 | lerna-debug.log*
11 |
12 | # Diagnostic reports (https://nodejs.org/api/report.html)
13 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
14 |
15 | # Runtime data
16 | pids
17 | *.pid
18 | *.seed
19 | *.pid.lock
20 |
21 | # Directory for instrumented libs generated by jscoverage/JSCover
22 | lib-cov
23 |
24 | # Coverage directory used by tools like istanbul
25 | coverage
26 | *.lcov
27 |
28 | # nyc test coverage
29 | .nyc_output
30 |
31 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32 | .grunt
33 |
34 | # Bower dependency directory (https://bower.io/)
35 | bower_components
36 |
37 | # node-waf configuration
38 | .lock-wscript
39 |
40 | # Compiled binary addons (https://nodejs.org/api/addons.html)
41 | build/Release
42 |
43 | # Dependency directories
44 | node_modules/
45 | jspm_packages/
46 |
47 | # TypeScript v1 declaration files
48 | typings/
49 |
50 | # TypeScript cache
51 | *.tsbuildinfo
52 |
53 | # Optional npm cache directory
54 | .npm
55 |
56 | # Optional eslint cache
57 | .eslintcache
58 |
59 | # Microbundle cache
60 | .rpt2_cache/
61 | .rts2_cache_cjs/
62 | .rts2_cache_es/
63 | .rts2_cache_umd/
64 |
65 | # Optional REPL history
66 | .node_repl_history
67 |
68 | # Output of 'npm pack'
69 | *.tgz
70 |
71 | # Yarn Integrity file
72 | .yarn-integrity
73 |
74 | # dotenv environment variables file
75 | .env
76 | .env.test
77 |
78 | # parcel-bundler cache (https://parceljs.org/)
79 | .cache
80 |
81 | # Next.js build output
82 | .next
83 |
84 | # Nuxt.js build / generate output
85 | .nuxt
86 | dist
87 |
88 | # Gatsby files
89 | .cache/
90 | # Comment in the public line in if your project uses Gatsby and *not* Next.js
91 | # https://nextjs.org/blog/next-9-1#public-directory-support
92 | # public
93 |
94 | # vuepress build output
95 | .vuepress/dist
96 |
97 | # Serverless directories
98 | .serverless/
99 |
100 | # FuseBox cache
101 | .fusebox/
102 |
103 | # DynamoDB Local files
104 | .dynamodb/
105 |
106 | # TernJS port file
107 | .tern-port
108 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@kibibit/nconf-jsonc",
3 | "version": "1.0.0",
4 | "description": "Add support for json with comments files in nconf",
5 | "main": "lib/index.js",
6 | "scripts": {
7 | "prebuild": "rimraf lib",
8 | "build": "tsc",
9 | "lint": "eslint -c ./.eslintrc.js \"{src,apps,libs,test,examples}/**/*.ts\"",
10 | "lint:fix": "eslint -c ./.eslintrc.js \"{src,apps,libs,test,examples}/**/*.ts\" --fix",
11 | "contributors:all": "cross-env HUSKY=0 node ./tools/get-all-contributors.js",
12 | "contributors:add": "cross-env HUSKY=0 all-contributors add",
13 | "contributors:generate": "cross-env HUSKY=1 all-contributors generate",
14 | "prepare": "husky install",
15 | "semantic-release": "cross-env HUSKY=0 semantic-release",
16 | "test": "jest",
17 | "test:watch": "jest --watch --verbose",
18 | "test:cov": "jest --coverage --verbose",
19 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand"
20 | },
21 | "repository": {
22 | "type": "git",
23 | "url": "https://github.com/Kibibit/nconf-jsonc.git"
24 | },
25 | "keywords": [
26 | "nconf",
27 | "jsonc"
28 | ],
29 | "author": "thatkookooguy ",
30 | "license": "MIT",
31 | "bugs": {
32 | "url": "https://github.com/Kibibit/nconf-jsonc/issues"
33 | },
34 | "homepage": "https://github.com/Kibibit/nconf-jsonc#readme",
35 | "dependencies": {
36 | "comment-json": "^4.1.1"
37 | },
38 | "devDependencies": {
39 | "@commitlint/cli": "^13.2.1",
40 | "@commitlint/config-angular": "^13.2.0",
41 | "@commitlint/config-conventional": "^13.2.0",
42 | "@semantic-release/changelog": "^6.0.0",
43 | "@semantic-release/commit-analyzer": "^9.0.1",
44 | "@semantic-release/git": "^10.0.0",
45 | "@semantic-release/github": "^8.0.1",
46 | "@semantic-release/npm": "^8.0.0",
47 | "@semantic-release/release-notes-generator": "^10.0.2",
48 | "@types/jest": "^27.0.2",
49 | "@types/nconf": "^0.10.1",
50 | "@types/node": "^16.10.3",
51 | "@typescript-eslint/eslint-plugin": "^4.33.0",
52 | "@typescript-eslint/parser": "^4.33.0",
53 | "all-contributors-cli": "^6.20.0",
54 | "commitizen": "^4.2.4",
55 | "cross-env": "^7.0.3",
56 | "cz-conventional-changelog": "^3.3.0",
57 | "cz-conventional-changelog-emoji": "^0.1.0",
58 | "eslint": "^7.32.0",
59 | "eslint-plugin-import": "^2.24.2",
60 | "eslint-plugin-simple-import-sort": "^7.0.0",
61 | "eslint-plugin-unused-imports": "^1.1.5",
62 | "husky": "^7.0.2",
63 | "jest": "^27.3.1",
64 | "jest-mock-process": "^1.4.1",
65 | "jest-stare": "^2.3.0",
66 | "rimraf": "^3.0.2",
67 | "semantic-release": "^18.0.1",
68 | "semantic-release-cli": "^5.4.4",
69 | "ts-jest": "^27.0.7",
70 | "ts-node": "^10.2.1",
71 | "typescript": "^4.4.4"
72 | },
73 | "publishConfig": {
74 | "access": "public"
75 | },
76 | "config": {
77 | "commitizen": {
78 | "path": "./node_modules/cz-conventional-changelog-emoji"
79 | }
80 | },
81 | "release": {
82 | "branches": [
83 | {
84 | "name": "main"
85 | },
86 | {
87 | "name": "beta",
88 | "channel": "beta",
89 | "prerelease": "beta"
90 | }
91 | ],
92 | "plugins": [
93 | [
94 | "@semantic-release/commit-analyzer",
95 | {
96 | "preset": "angular",
97 | "parserOpts": {
98 | "noteKeywords": [
99 | "BREAKING CHANGE",
100 | "BREAKING CHANGES",
101 | "BREAKING"
102 | ]
103 | }
104 | }
105 | ],
106 | [
107 | "@semantic-release/release-notes-generator",
108 | {
109 | "preset": "angular",
110 | "parserOpts": {
111 | "noteKeywords": [
112 | "BREAKING CHANGE",
113 | "BREAKING CHANGES",
114 | "BREAKING"
115 | ]
116 | },
117 | "writerOpts": {
118 | "commitsSort": [
119 | "subject",
120 | "scope"
121 | ]
122 | }
123 | }
124 | ],
125 | [
126 | "@semantic-release/changelog",
127 | {
128 | "changelogFile": "CHANGELOG.md",
129 | "changelogTitle": "achievibit changelog"
130 | }
131 | ],
132 | [
133 | "@semantic-release/git",
134 | {
135 | "assets": [
136 | "CHANGELOG.md"
137 | ]
138 | }
139 | ],
140 | "@semantic-release/npm",
141 | "@semantic-release/git",
142 | "@semantic-release/github"
143 | ]
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | parser: '@typescript-eslint/parser',
3 | parserOptions: {
4 | project: [
5 | './tsconfig.eslint.json'
6 | ],
7 | sourceType: 'module',
8 | },
9 | plugins: [
10 | '@typescript-eslint/eslint-plugin',
11 | 'unused-imports',
12 | 'simple-import-sort',
13 | 'import'
14 | ],
15 | extends: [
16 | 'plugin:@typescript-eslint/eslint-recommended',
17 | 'plugin:@typescript-eslint/recommended',
18 | ],
19 | ignorePatterns: [
20 | '.eslintrc.js',
21 | '**/*.event.ts',
22 | '**/lib/**/*.ts'
23 | ],
24 | root: true,
25 | env: {
26 | node: true,
27 | jest: true,
28 | },
29 | rules: {
30 | 'unused-imports/no-unused-imports': 'error',
31 | 'simple-import-sort/imports': ['error', {
32 | groups: [
33 | // 1. built-in node.js modules
34 | [`^(${require("module").builtinModules.join("|")})(/|$)`],
35 | // 2.1. package that start without @
36 | // 2.2. package that start with @
37 | ['^\\w', '^@\\w'],
38 | // 3. @nestjs packages
39 | ['^@nestjs\/'],
40 | // 4. @kibibit external packages
41 | ['^@kibibit\/'],
42 | // 5. Internal kibibit packages (inside this project)
43 | ['^@kb-'],
44 | // 6. Parent imports. Put `..` last.
45 | // Other relative imports. Put same-folder imports and `.` last.
46 | ["^\\.\\.(?!/?$)", "^\\.\\./?$", "^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
47 | // 7. Side effect imports.
48 | // https://riptutorial.com/javascript/example/1618/importing-with-side-effects
49 | ["^\\u0000"]
50 | ]
51 | }],
52 | 'import/first': 'error',
53 | 'import/newline-after-import': 'error',
54 | 'import/no-duplicates': 'error',
55 | 'eol-last': [ 2, 'windows' ],
56 | 'comma-dangle': [ 'error', 'never' ],
57 | 'max-len': [ 'error', { 'code': 80, "ignoreComments": true } ],
58 | 'quotes': ["error", "single"],
59 | '@typescript-eslint/no-empty-interface': 'error',
60 | '@typescript-eslint/member-delimiter-style': 'error',
61 | '@typescript-eslint/explicit-function-return-type': 'off',
62 | '@typescript-eslint/explicit-module-boundary-types': 'off',
63 | '@typescript-eslint/naming-convention': [
64 | "error",
65 | {
66 | "selector": "interface",
67 | "format": ["PascalCase"],
68 | "custom": {
69 | "regex": "^I[A-Z]",
70 | "match": true
71 | }
72 | }
73 | ],
74 | "semi": "off",
75 | "@typescript-eslint/semi": ["error"],
76 | 'space-infix-ops': 'error',
77 | 'array-bracket-newline': 'off',
78 | 'array-bracket-spacing': [ 'error', 'always' ],
79 | 'array-element-newline': 'off',
80 | 'block-spacing': [ 'error', 'always' ],
81 | 'brace-style': [ 'error', '1tbs', {
82 | 'allowSingleLine': true
83 | } ],
84 | 'camelcase': [ 'error', {
85 | 'properties': 'never'
86 | } ],
87 | 'comma-dangle': [ 'error', 'never' ],
88 | 'comma-spacing': [ 'error', {
89 | 'after': true,
90 | 'before': false
91 | } ],
92 | 'comma-style': 'error',
93 | 'computed-property-spacing': 'error',
94 | 'curly': [ 'error', 'multi-line' ],
95 | 'eol-last': 'error',
96 | 'func-call-spacing': 'error',
97 | 'indent': [ 'error', 2, {
98 | 'CallExpression': {
99 | 'arguments': 1
100 | },
101 | 'FunctionDeclaration': {
102 | 'body': 1,
103 | 'parameters': 1
104 | },
105 | 'FunctionExpression': {
106 | 'body': 1,
107 | 'parameters': 1
108 | },
109 | 'ignoredNodes': [ 'ConditionalExpression' ],
110 | 'MemberExpression': 1,
111 | 'ObjectExpression': 1,
112 | 'SwitchCase': 1
113 | } ],
114 | 'key-spacing': 'error',
115 | 'keyword-spacing': 'error',
116 | 'linebreak-style': 'error',
117 | 'max-len': [ 'error', {
118 | // starting small (forcing 120), but later we should force 80
119 | code: 120,
120 | ignoreComments: true,
121 | ignoreUrls: true,
122 | ignoreStrings: true,
123 | tabWidth: 2
124 | } ],
125 | 'no-array-constructor': 'error',
126 | 'no-caller': 'error',
127 | 'no-extend-native': 'error',
128 | 'no-extra-bind': 'error',
129 | 'no-invalid-this': 'error',
130 | 'no-irregular-whitespace': 'error',
131 | 'no-mixed-spaces-and-tabs': 'error',
132 | 'no-multi-spaces': 'error',
133 | 'no-multi-str': 'error',
134 |
135 | 'no-multiple-empty-lines': [ 'error', {
136 | max: 2
137 | } ],
138 | 'no-new-object': 'error',
139 | 'no-new-wrappers': 'error',
140 | 'no-tabs': 'error',
141 | 'no-throw-literal': 'error',
142 | 'no-trailing-spaces': 'error',
143 | 'no-unused-vars': [ 'error', {
144 | args: 'none'
145 | } ],
146 |
147 | 'no-with': 'error',
148 | 'object-curly-spacing': [ 'error', 'always' ],
149 | 'one-var': [ 'error', {
150 | const: 'never',
151 | let: 'never',
152 | var: 'never'
153 | } ],
154 | 'operator-linebreak': [ 'error', 'after' ],
155 | 'padded-blocks': [ 'error', 'never' ],
156 | 'prefer-promise-reject-errors': 'error',
157 | 'quotes': [ 'error', 'single', {
158 | allowTemplateLiterals: true
159 | } ],
160 | 'semi': [ 'error' ],
161 | 'semi-spacing': 'error',
162 | 'space-before-blocks': 'error',
163 | 'space-before-function-paren': [ 'error', {
164 | asyncArrow: 'always',
165 | anonymous: 'never',
166 | named: 'never'
167 | } ],
168 | 'spaced-comment': [ 'error', 'always' ],
169 | 'switch-colon-spacing': 'error',
170 | 'arrow-parens': [ 'error', 'always' ],
171 | 'constructor-super': 'error', // eslint:recommended
172 | 'generator-star-spacing': [ 'error', 'after' ],
173 | 'no-new-symbol': 'error', // eslint:recommended
174 | 'no-this-before-super': 'error', // eslint:recommended
175 | 'no-var': 'error',
176 | 'prefer-const': [ 'error', { destructuring: 'all' } ],
177 | 'prefer-rest-params': 'error',
178 | 'prefer-spread': 'error',
179 | 'rest-spread-spacing': 'error',
180 | 'yield-star-spacing': [ 'error', 'after' ],
181 | 'no-await-in-loop': 'warn',
182 | 'no-unreachable-loop': 'error',
183 | 'require-atomic-updates': 'error',
184 | 'dot-notation': 'error',
185 | 'require-await': 'warn',
186 | 'no-undefined': 'error',
187 | 'line-comment-position': [ 'error', { position: 'above' } ],
188 | 'template-curly-spacing': [ 'error', 'always' ]
189 | }
190 | };
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | @kibibit/nconf-jsonc
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | A general typescript configuration service
28 |
29 |
30 |
31 |
32 | Unless forced to create a new service, this service will return the first created service
33 |
34 | ## Usage
35 |
36 | Create a new class to define your configuration.
37 | The class should extend the `Config` class from this repo
38 | ```typescript
39 | import { IsNumber, IsString } from 'class-validator';
40 |
41 | import { BaseConfig, Configuration, ConfigVariable } from '@kibibit/nconf-jsonc';
42 |
43 | @Configuration()
44 | export class ProjectConfig extends BaseConfig {
45 | @ConfigVariable('Server port')
46 | @IsNumber()
47 | PORT: number;
48 |
49 | @ConfigVariable([
50 | 'This is the slack API to talk and report to channel "hello"'
51 | ])
52 | @IsString()
53 | SLACK_API_KEY: string;
54 | }
55 |
56 | }
57 | ```
58 | Then, in your code, initialize the config service when you bootstrap your application
59 | ```typescript
60 | import express from 'express';
61 | import { ConfigService } from '@kibibit/nconf-jsonc';
62 | import { ProjectConfig } from './project-config.model';
63 |
64 | export const configService = new ConfigService(ProjectConfig);
65 | const app = express();
66 |
67 | app.get( '/', ( req, res ) => {
68 | res.send( 'Hello world!' );
69 | } );
70 |
71 | app.listen(configService.config.PORT, () => {
72 | console.log(
73 | `server started at http://localhost:${ configService.config.PORT }`
74 | );
75 | });
76 |
77 | ```
78 |
79 | ### Extending the Configuration Service (Recommended)
80 | You can extend the configuration to add your own customization and functions!
81 | ```typescript
82 | import { chain } from 'lodash';
83 |
84 | import { ConfigService, IConfigServiceOptions } from '@kibibit/nconf-jsonc';
85 | import { WinstonLogger } from '@kibibit/nestjs-winston';
86 |
87 | import { ExtProjectConfig } from './ext-project-config.model';
88 | import { initializeWinston } from './winston.config';
89 |
90 | export class ExtConfigService extends ConfigService {
91 | public logger: WinstonLogger;
92 | constructor(passedConfig?: Partial, options: IConfigServiceOptions = {}) {
93 | super(ExtProjectConfig, passedConfig, options);
94 |
95 | initializeWinston(this.appRoot);
96 | this.logger = new WinstonLogger('');
97 | }
98 |
99 | getSlackApiObject() {
100 | const slackApiObject = chain(this.toPlainObject())
101 | .pickBy((value, key) => key.startsWith('SLACK_'))
102 | .mapKeys((value, key) => key.replace(/^SLACK_/i, ''))
103 | .mapKeys((value, key) => key.toLowerCase())
104 | .value();
105 |
106 | return slackApiObject;
107 | }
108 | }
109 |
110 | export const configService = new ExtConfigService() as ExtConfigService;
111 |
112 | ```
113 |
114 |
115 | ## Features
116 | - Supports JSON\YAML files\env variables\cli flags as configuration inputs. See `yaml-config` in the examples folder
117 | - Supports shared configuration files (same file shared for multiple projects)
118 | - initialize a configuration file with `--saveToFile` or `--init`
119 | - save configuration files anywhere above your project's package.json
120 | - forced singleton for a single installation (reuse same class)
121 | - testable
122 | - The ability to create json schemas automatically and add descriptions
123 | to configuration variables
124 | - Get meaningfull errors when configuration is wrong!
125 |
126 | ## Examples
127 | See the examples folder for a variety of usage examples
128 |
129 | ## Contributors ✨
130 |
131 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
132 |
133 |
134 |
135 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!
147 |
148 |
149 |
150 |
151 | ## Stay in touch
152 |
153 | - Author - [Neil Kalman](https://github.com/thatkookooguy)
154 | - Website - [https://github.com/kibibit](https://github.com/kibibit)
155 | - StackOverflow - [thatkookooguy](https://stackoverflow.com/users/1788884/thatkookooguy)
156 | - Twitter - [@thatkookooguy](https://twitter.com/thatkookooguy)
157 | - Twitter - [@kibibit_opensrc](https://twitter.com/kibibit_opensrc)
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | achievibit changelog
2 |
3 | # 1.0.0 (2021-12-21)
4 |
5 |
6 | ### Features
7 |
8 | * **app:** initial implementation ([f8dd394](https://github.com/Kibibit/nconf-jsonc/commit/f8dd3944b466ecbe93832faed1bfdd2cf326156a))
9 |
10 | # [1.0.0-beta.13](https://github.com/Kibibit/configit/compare/v1.0.0-beta.12...v1.0.0-beta.13) (2021-10-29)
11 |
12 |
13 | ### Features
14 |
15 | * **service:** allow overriding config folder when exporting ([62f9edc](https://github.com/Kibibit/configit/commit/62f9edc01ac77b062097456b99bc9e3a106827c1))
16 | * **release:** force a release ([456b2a8](https://github.com/Kibibit/configit/commit/456b2a83444b897f1b310a9e40de925902c619cb))
17 | * **readme:** force another release? ([b3ba1fc](https://github.com/Kibibit/configit/commit/b3ba1fc8401177045d23d15eeaa643c46e1b8388))
18 | * **tests:** improve coverage ([329f9cc](https://github.com/Kibibit/configit/commit/329f9cc09f34532954f7ccb6c4b6ba5146ebe6c2))
19 | * **release:** try and force release ([4599bc7](https://github.com/Kibibit/configit/commit/4599bc7c67126a45c38405d5312ae1f824997342)), closes [/github.com/semantic-release/semantic-release/discussions/2213#discussioncomment-1555536](https://github.com//github.com/semantic-release/semantic-release/discussions/2213/issues/discussioncomment-1555536)
20 |
21 | # [1.0.0-beta.10](https://github.com/Kibibit/configit/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2021-10-28)
22 |
23 |
24 | ### Bug Fixes
25 |
26 | * **build:** fix build to not include configuration ([812386c](https://github.com/Kibibit/configit/commit/812386c32f2e81b3b2df1d761d615f39c1fdfc1f))
27 |
28 |
29 | ### Features
30 |
31 | * **service:** allow overriding config folder when exporting ([62f9edc](https://github.com/Kibibit/configit/commit/62f9edc01ac77b062097456b99bc9e3a106827c1))
32 | * **release:** force a release ([456b2a8](https://github.com/Kibibit/configit/commit/456b2a83444b897f1b310a9e40de925902c619cb))
33 | * **readme:** force another release? ([b3ba1fc](https://github.com/Kibibit/configit/commit/b3ba1fc8401177045d23d15eeaa643c46e1b8388))
34 | * **tests:** improve coverage ([329f9cc](https://github.com/Kibibit/configit/commit/329f9cc09f34532954f7ccb6c4b6ba5146ebe6c2))
35 |
36 | # [1.0.0-beta.10](https://github.com/Kibibit/configit/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2021-10-28)
37 |
38 |
39 | ### Bug Fixes
40 |
41 | * **build:** fix build to not include configuration ([812386c](https://github.com/Kibibit/configit/commit/812386c32f2e81b3b2df1d761d615f39c1fdfc1f))
42 |
43 |
44 | ### Features
45 |
46 | * **service:** allow overriding config folder when exporting ([62f9edc](https://github.com/Kibibit/configit/commit/62f9edc01ac77b062097456b99bc9e3a106827c1))
47 | * **readme:** force another release? ([b3ba1fc](https://github.com/Kibibit/configit/commit/b3ba1fc8401177045d23d15eeaa643c46e1b8388))
48 | * **tests:** improve coverage ([329f9cc](https://github.com/Kibibit/configit/commit/329f9cc09f34532954f7ccb6c4b6ba5146ebe6c2))
49 |
50 | # [1.0.0-beta.10](https://github.com/Kibibit/configit/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2021-10-28)
51 |
52 |
53 | ### Bug Fixes
54 |
55 | * **build:** fix build to not include configuration ([812386c](https://github.com/Kibibit/configit/commit/812386c32f2e81b3b2df1d761d615f39c1fdfc1f))
56 |
57 |
58 | ### Features
59 |
60 | * **service:** allow overriding config folder when exporting ([62f9edc](https://github.com/Kibibit/configit/commit/62f9edc01ac77b062097456b99bc9e3a106827c1))
61 | * **tests:** improve coverage ([329f9cc](https://github.com/Kibibit/configit/commit/329f9cc09f34532954f7ccb6c4b6ba5146ebe6c2))
62 |
63 | # [1.0.0-beta.10](https://github.com/Kibibit/configit/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2021-10-28)
64 |
65 |
66 | ### Bug Fixes
67 |
68 | * **build:** fix build to not include configuration ([812386c](https://github.com/Kibibit/configit/commit/812386c32f2e81b3b2df1d761d615f39c1fdfc1f))
69 |
70 |
71 | ### Features
72 |
73 | * **service:** allow overriding config folder when exporting ([62f9edc](https://github.com/Kibibit/configit/commit/62f9edc01ac77b062097456b99bc9e3a106827c1))
74 |
75 | # [1.0.0-beta.10](https://github.com/Kibibit/configit/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2021-10-28)
76 |
77 |
78 | ### Bug Fixes
79 |
80 | * **build:** fix build to not include configuration ([812386c](https://github.com/Kibibit/configit/commit/812386c32f2e81b3b2df1d761d615f39c1fdfc1f))
81 |
82 | # [1.0.0-beta.9](https://github.com/Kibibit/configit/compare/v1.0.0-beta.8...v1.0.0-beta.9) (2021-10-28)
83 |
84 |
85 | ### Features
86 |
87 | * **yaml:** support convertion of config file on save ([4b8000c](https://github.com/Kibibit/configit/commit/4b8000c79520f936308febdc20117d3ab97aac54))
88 |
89 | # [1.0.0-beta.8](https://github.com/Kibibit/configit/compare/v1.0.0-beta.7...v1.0.0-beta.8) (2021-10-19)
90 |
91 |
92 | ### Bug Fixes
93 |
94 | * **service:** small fixes to names and schemas ([b0a836c](https://github.com/Kibibit/configit/commit/b0a836c3853014685fa75602d9e8d7da2b9a2089))
95 |
96 |
97 | ### Features
98 |
99 | * **examples:** add example for shared config ([c47956c](https://github.com/Kibibit/configit/commit/c47956cbb1e0bc9ed9f1ac9973181556dcaee9d4))
100 | * **service:** add options to service and support shared configs ([589cd69](https://github.com/Kibibit/configit/commit/589cd697638a23e7bc34c706b470f73725e54d04))
101 | * **config:** support yaml config files ([4e5d507](https://github.com/Kibibit/configit/commit/4e5d507c7a214855e3ef7a545cd1a155af97bf8f))
102 |
103 | # [1.0.0-beta.7](https://github.com/Kibibit/configit/compare/v1.0.0-beta.6...v1.0.0-beta.7) (2021-10-12)
104 |
105 |
106 | ### Features
107 |
108 | * **decorators:** add configuration decorator ([1bfd918](https://github.com/Kibibit/configit/commit/1bfd918c51e2d69ba68a537a4c912960cd8dd463))
109 |
110 |
111 | ### BREAKING CHANGES
112 |
113 | * **decorators:** Since names have changed, this is a breaking change
114 |
115 | # [1.0.0-beta.6](https://github.com/Kibibit/configit/compare/v1.0.0-beta.5...v1.0.0-beta.6) (2021-10-12)
116 |
117 |
118 | ### Features
119 |
120 | * **schema:** define a decorator that combines Expose and Validate ([7f4387b](https://github.com/Kibibit/configit/commit/7f4387bed1e7ad4cd97992dc3d6ee8704cfff19d))
121 |
122 | # [1.0.0-beta.5](https://github.com/Kibibit/configit/compare/v1.0.0-beta.4...v1.0.0-beta.5) (2021-10-11)
123 |
124 |
125 | ### Features
126 |
127 | * **config:** force new version ([d3f437b](https://github.com/Kibibit/configit/commit/d3f437bfdb2b750d0dae3dd25b1bddd8059fbe49))
128 |
129 | # [1.0.0-beta.4](https://github.com/Kibibit/configit/compare/v1.0.0-beta.3...v1.0.0-beta.4) (2021-10-11)
130 |
131 |
132 | ### Bug Fixes
133 |
134 | * **base:** fix classtoplain for base config class ([b6847ee](https://github.com/Kibibit/configit/commit/b6847eeb9ada58d32b4967a11bbc3c952517db0b))
135 |
136 | # [1.0.0-beta.3](https://github.com/Kibibit/configit/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2021-10-11)
137 |
138 |
139 | ### Features
140 |
141 | * **release:** force version bump ([f19ae19](https://github.com/Kibibit/configit/commit/f19ae19e28ab8fad14f7ad922f0893c4e80ebfe9))
142 |
143 | # [1.0.0-beta.2](https://github.com/Kibibit/configit/compare/v1.0.0-beta.1...v1.0.0-beta.2) (2021-10-11)
144 |
145 |
146 | ### Features
147 |
148 | * **release:** force version major bump ([2b7dcbd](https://github.com/Kibibit/configit/commit/2b7dcbd2c73133efababd4ca3437b8d60053ce80))
149 |
150 |
151 | ### BREAKING CHANGES
152 |
153 | * **release:** force version major bump
154 |
155 | # 1.0.0-beta.1 (2021-10-11)
156 |
157 |
158 | ### Bug Fixes
159 |
160 | * **examples:** fix port reference ([c3691b1](https://github.com/Kibibit/configit/commit/c3691b1a72ddd31d612897f1809e865cdc20ace3))
161 |
--------------------------------------------------------------------------------