@goldstack/utils-config 0.3.37 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/utilsConfig.d.ts +10 -10
- package/dist/src/utilsConfig.js +51 -51
- package/package.json +4 -4
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
interface ValidateOptions {
|
|
2
|
-
errorMessage?: string;
|
|
3
|
-
additionalSchemas?: object[];
|
|
4
|
-
}
|
|
5
|
-
export declare const validateConfig: (config: object, schema: object, options?: ValidateOptions) => object;
|
|
6
|
-
export declare const parseConfig: (data: string, schema: object, options: ValidateOptions) => object;
|
|
7
|
-
export declare const getPackageConfigPaths: (workspacePath: string) => string[];
|
|
8
|
-
export declare const getAwsConfigPath: (workspacePath: string) => string;
|
|
9
|
-
export declare const getAwsTerraformConfigPath: (workspacePath: string) => string;
|
|
10
|
-
export {};
|
|
1
|
+
interface ValidateOptions {
|
|
2
|
+
errorMessage?: string;
|
|
3
|
+
additionalSchemas?: object[];
|
|
4
|
+
}
|
|
5
|
+
export declare const validateConfig: (config: object, schema: object, options?: ValidateOptions) => object;
|
|
6
|
+
export declare const parseConfig: (data: string, schema: object, options: ValidateOptions) => object;
|
|
7
|
+
export declare const getPackageConfigPaths: (workspacePath: string) => string[];
|
|
8
|
+
export declare const getAwsConfigPath: (workspacePath: string) => string;
|
|
9
|
+
export declare const getAwsTerraformConfigPath: (workspacePath: string) => string;
|
|
10
|
+
export {};
|
|
11
11
|
//# sourceMappingURL=utilsConfig.d.ts.map
|
package/dist/src/utilsConfig.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAwsTerraformConfigPath = exports.getAwsConfigPath = exports.getPackageConfigPaths = exports.parseConfig = exports.validateConfig = void 0;
|
|
7
|
-
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
-
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
9
|
-
const validateConfig = (config, schema, options) => {
|
|
10
|
-
const ajv = new ajv_1.default();
|
|
11
|
-
if (options === null || options === void 0 ? void 0 : options.additionalSchemas) {
|
|
12
|
-
options.additionalSchemas.forEach((schema) => ajv.addSchema(schema));
|
|
13
|
-
}
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
const buildError = (e) => {
|
|
16
|
-
return new Error(`${(options === null || options === void 0 ? void 0 : options.errorMessage) || 'Cannot read configuration'}\n` +
|
|
17
|
-
ajv.errorsText() ||
|
|
18
|
-
'' + e ||
|
|
19
|
-
'');
|
|
20
|
-
};
|
|
21
|
-
let valid;
|
|
22
|
-
try {
|
|
23
|
-
valid = ajv.validate(schema, config);
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
throw buildError(e);
|
|
27
|
-
}
|
|
28
|
-
if (!valid) {
|
|
29
|
-
throw buildError(null);
|
|
30
|
-
}
|
|
31
|
-
return config;
|
|
32
|
-
};
|
|
33
|
-
exports.validateConfig = validateConfig;
|
|
34
|
-
const parseConfig = (data, schema, options) => {
|
|
35
|
-
const config = JSON.parse(data);
|
|
36
|
-
return (0, exports.validateConfig)(config, schema, options);
|
|
37
|
-
};
|
|
38
|
-
exports.parseConfig = parseConfig;
|
|
39
|
-
const getPackageConfigPaths = (workspacePath) => {
|
|
40
|
-
const res = (0, utils_sh_1.globSync)(workspacePath + 'packages/*/goldstack.json');
|
|
41
|
-
return res;
|
|
42
|
-
};
|
|
43
|
-
exports.getPackageConfigPaths = getPackageConfigPaths;
|
|
44
|
-
const getAwsConfigPath = (workspacePath) => {
|
|
45
|
-
return workspacePath + 'config/infra/aws/config.json';
|
|
46
|
-
};
|
|
47
|
-
exports.getAwsConfigPath = getAwsConfigPath;
|
|
48
|
-
const getAwsTerraformConfigPath = (workspacePath) => {
|
|
49
|
-
return workspacePath + 'config/infra/aws/terraform.json';
|
|
50
|
-
};
|
|
51
|
-
exports.getAwsTerraformConfigPath = getAwsTerraformConfigPath;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAwsTerraformConfigPath = exports.getAwsConfigPath = exports.getPackageConfigPaths = exports.parseConfig = exports.validateConfig = void 0;
|
|
7
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
+
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
9
|
+
const validateConfig = (config, schema, options) => {
|
|
10
|
+
const ajv = new ajv_1.default();
|
|
11
|
+
if (options === null || options === void 0 ? void 0 : options.additionalSchemas) {
|
|
12
|
+
options.additionalSchemas.forEach((schema) => ajv.addSchema(schema));
|
|
13
|
+
}
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
const buildError = (e) => {
|
|
16
|
+
return new Error(`${(options === null || options === void 0 ? void 0 : options.errorMessage) || 'Cannot read configuration'}\n` +
|
|
17
|
+
ajv.errorsText() ||
|
|
18
|
+
'' + e ||
|
|
19
|
+
'');
|
|
20
|
+
};
|
|
21
|
+
let valid;
|
|
22
|
+
try {
|
|
23
|
+
valid = ajv.validate(schema, config);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
throw buildError(e);
|
|
27
|
+
}
|
|
28
|
+
if (!valid) {
|
|
29
|
+
throw buildError(null);
|
|
30
|
+
}
|
|
31
|
+
return config;
|
|
32
|
+
};
|
|
33
|
+
exports.validateConfig = validateConfig;
|
|
34
|
+
const parseConfig = (data, schema, options) => {
|
|
35
|
+
const config = JSON.parse(data);
|
|
36
|
+
return (0, exports.validateConfig)(config, schema, options);
|
|
37
|
+
};
|
|
38
|
+
exports.parseConfig = parseConfig;
|
|
39
|
+
const getPackageConfigPaths = (workspacePath) => {
|
|
40
|
+
const res = (0, utils_sh_1.globSync)(workspacePath + 'packages/*/goldstack.json');
|
|
41
|
+
return res;
|
|
42
|
+
};
|
|
43
|
+
exports.getPackageConfigPaths = getPackageConfigPaths;
|
|
44
|
+
const getAwsConfigPath = (workspacePath) => {
|
|
45
|
+
return workspacePath + 'config/infra/aws/config.json';
|
|
46
|
+
};
|
|
47
|
+
exports.getAwsConfigPath = getAwsConfigPath;
|
|
48
|
+
const getAwsTerraformConfigPath = (workspacePath) => {
|
|
49
|
+
return workspacePath + 'config/infra/aws/terraform.json';
|
|
50
|
+
};
|
|
51
|
+
exports.getAwsTerraformConfigPath = getAwsTerraformConfigPath;
|
|
52
52
|
//# sourceMappingURL=utilsConfig.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goldstack/utils-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Utilities to work with JSON configuration files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"goldstack",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"version:apply:force": "yarn version $@ && yarn version apply"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@goldstack/utils-log": "0.
|
|
40
|
-
"@goldstack/utils-sh": "0.
|
|
39
|
+
"@goldstack/utils-log": "0.3.0",
|
|
40
|
+
"@goldstack/utils-sh": "0.5.0",
|
|
41
41
|
"ajv": "^6.12.2",
|
|
42
42
|
"handlebars": "4.7.7"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@goldstack/utils-git": "0.
|
|
45
|
+
"@goldstack/utils-git": "0.2.0",
|
|
46
46
|
"@types/jest": "^28.1.8",
|
|
47
47
|
"@types/node": "^18.7.13",
|
|
48
48
|
"jest": "^28.1.0",
|