Skip to content

Commit

Permalink
fix(config): instantiate config schema before loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Aug 9, 2020
1 parent 9dbd35b commit 0d47f4b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
40 changes: 20 additions & 20 deletions docs/test-valid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ data:
- isolex
- isolex-test
controllers:
- !include ../docs/controller/account-controller.yml
- !include ../docs/controller/bot-controller.yml
- !include ../docs/controller/completion-controller.yml
- !include ../docs/controller/dice-controller.yml
- !include ../docs/controller/learn-controller.yml
- !include ../docs/controller/math-controller.yml
- !include ../docs/controller/random-controller.yml
- !include ../docs/controller/reaction-controller.yml
- !include ../docs/controller/sed-controller.yml
- !include ../docs/controller/time-controller.yml
- !include ../docs/controller/token-controller.yml
- !include ../docs/controller/user-controller.yml
- !include ./docs/controller/account-controller.yml
- !include ./docs/controller/bot-controller.yml
- !include ./docs/controller/completion-controller.yml
- !include ./docs/controller/dice-controller.yml
- !include ./docs/controller/learn-controller.yml
- !include ./docs/controller/math-controller.yml
- !include ./docs/controller/random-controller.yml
- !include ./docs/controller/reaction-controller.yml
- !include ./docs/controller/sed-controller.yml
- !include ./docs/controller/time-controller.yml
- !include ./docs/controller/token-controller.yml
- !include ./docs/controller/user-controller.yml
endpoints:
- !include ../docs/endpoint/echo-endpoint.yml
- !include ../docs/endpoint/graph-endpoint.yml
- !include ../docs/endpoint/health-endpoint.yml
- !include ../docs/endpoint/metrics-endpoint.yml
- !include ./docs/endpoint/echo-endpoint.yml
- !include ./docs/endpoint/graph-endpoint.yml
- !include ./docs/endpoint/health-endpoint.yml
- !include ./docs/endpoint/metrics-endpoint.yml
generators:
- !include ../docs/generator/metrics-generator.yml
- !include ./docs/generator/metrics-generator.yml
listeners:
- !include ../docs/listener/express-listener.yml
- !include ./docs/listener/express-listener.yml
locale:
metadata:
kind: locale
Expand All @@ -49,8 +49,8 @@ data:
- require: isolex-oot-example
export: example-module
parsers:
- !include ../docs/parser/args-parser.yml
- !include ../docs/parser/yaml-parser.yml
- !include ./docs/parser/args-parser.yml
- !include ./docs/parser/yaml-parser.yml
process:
pid:
file: ./out/test-valid.pid
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"typeorm": "0.2.25"
},
"devDependencies": {
"@apextoaster/js-config": "^0.1.2-2",
"@apextoaster/js-config": "^0.1.2-3",
"@apextoaster/js-utils": "0.2.1",
"@apextoaster/js-yaml-schema": "0.4.0-2",
"@apextoaster/js-yaml-schema": "0.4.0-3",
"@istanbuljs/nyc-config-typescript": "1.0.1",
"@microsoft/api-documenter": "7.8.22",
"@microsoft/api-extractor": "7.9.3",
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface CreateOptions {

export async function main(argv: Array<string>): Promise<ExitStatus> {
const args = yargs(argv, MAIN_ARGS);
const config = initConfig(args[CONFIG_ARGS_NAME], args[CONFIG_ARGS_PATH]);
const config = initConfig(args[CONFIG_ARGS_PATH], args[CONFIG_ARGS_NAME]);

const logger = BunyanLogger.create(config.data.logger);
logger.info(VERSION_INFO, 'version info');
Expand Down
9 changes: 7 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Config } from '@apextoaster/js-config';
import { createSchema } from '@apextoaster/js-yaml-schema';
import Ajv from 'ajv';
import { existsSync, readFileSync, realpathSync } from 'fs';
import { DEFAULT_SAFE_SCHEMA } from 'js-yaml';
Expand All @@ -25,7 +26,7 @@ export const MAIN_ARGS: yargs.Options = {
envPrefix: 'isolex',
};

export function initConfig(root: string, filename: string) {
export function initConfig(paths: Array<string>, filename: string) {
const include = {
exists: existsSync,
join,
Expand All @@ -34,6 +35,10 @@ export function initConfig(root: string, filename: string) {
schema: DEFAULT_SAFE_SCHEMA,
};

createSchema({
include,
});

const schema = new Ajv({
allErrors: true,
coerceTypes: 'array',
Expand All @@ -57,7 +62,7 @@ export function initConfig(root: string, filename: string) {
include,
key: '',
name: filename,
paths: [root],
paths,
type: 'file',
}],
});
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# yarn lockfile v1


"@apextoaster/js-config@^0.1.2-2":
version "0.1.2-2"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@apextoaster/js-config/-/js-config-0.1.2-2.tgz#71ddf32f290a31d167f7719099fcab771e5c4da0"
integrity sha512-0Gb1kkTrqxe+A8fvze9Xr/s3R/Jw5vddPoO6B7Fh8aEc4ncxWKndGuEBCH2IgKChJ+NFHMjJ46xIg2QUoXMR5g==
"@apextoaster/js-config@^0.1.2-3":
version "0.1.2-3"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@apextoaster/js-config/-/js-config-0.1.2-3.tgz#63fc1302d856b940bc2359b11f3eee02c3c7143a"
integrity sha512-7cQoxVwYKrVnbMwAFPUvi7omUP7WMo2unFWdsygCui7Od2WqrTWHeIc8/FrGWqxUA+hChp+J+nUZYT77xSWLXA==

"@apextoaster/js-utils@0.2.1":
version "0.2.1"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@apextoaster/js-utils/-/js-utils-0.2.1.tgz#8488b454e528a50b942afa65630099bd072e5e3e"
integrity sha512-VrrIU1AiEv7Uq958QREm7gthLF/8FU9Y1PTPXunzmdZqPVMkCKYjMyklKtNmYeXeMBnsNHFETuZmTNUynZfxjQ==

"@apextoaster/js-yaml-schema@0.4.0-2":
version "0.4.0-2"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@apextoaster/js-yaml-schema/-/js-yaml-schema-0.4.0-2.tgz#f02f756247ccec74aadda69aab5b1a98f7779296"
integrity sha512-5LjPQMrCPcw8cOCKq5d1Hi1QC48F8iWTOEh4Y6nV/ODT/9yduVVQnOr55FFjsFkLDLkk6fiClBDD/faAAdoEhQ==
"@apextoaster/js-yaml-schema@0.4.0-3":
version "0.4.0-3"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@apextoaster/js-yaml-schema/-/js-yaml-schema-0.4.0-3.tgz#f6a6222b588ab04270dd2806f7e72b145ebc8245"
integrity sha512-QpM5LUrVpGJk3cUxLxQjs8mXNcwipts1ul75+YMTgiIo6rmYO5/0HZg0RF5C7nLcxzVEkcCytct9TNbXnftuwQ==

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.5.5":
version "7.5.5"
Expand Down

0 comments on commit 0d47f4b

Please sign in to comment.