@extrahorizon/exh-cli 1.10.0-dev-105-4051888 → 1.10.0-dev-107-31b7fb4
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/build/commands/data/schemas/init.js +1 -1
- package/build/commands/tasks/createrepo.js +1 -0
- package/build/commands/tasks/taskConfig.js +2 -14
- package/build/helpers/util.d.ts +2 -0
- package/build/helpers/util.js +25 -1
- package/build/services/localizations/assertValidFileContent.js +13 -7
- package/package.json +1 -2
|
@@ -29,7 +29,7 @@ const handler = async function init({ name, path }) {
|
|
|
29
29
|
exports.handler = handler;
|
|
30
30
|
function createSchema(name) {
|
|
31
31
|
return {
|
|
32
|
-
$schema:
|
|
32
|
+
$schema: `https://swagger.extrahorizon.com/cli/${(0, util_1.getCliVersion)()}/config-json-schemas/Schema.json`,
|
|
33
33
|
name,
|
|
34
34
|
description: `The ${name} schema`,
|
|
35
35
|
createMode: 'allUsers',
|
|
@@ -34,6 +34,7 @@ async function changePackageFile(name) {
|
|
|
34
34
|
}
|
|
35
35
|
try {
|
|
36
36
|
const taskConfig = JSON.parse((await (0, promises_1.readFile)(`${name}/task-config.json`)).toString());
|
|
37
|
+
taskConfig.$schema = `https://swagger.extrahorizon.com/cli/${(0, util_1.getCliVersion)()}/config-json-schemas/TaskConfig.json`;
|
|
37
38
|
taskConfig.name = name;
|
|
38
39
|
taskConfig.description = `${name} task`;
|
|
39
40
|
await (0, promises_1.writeFile)(`${name}/task-config.json`, JSON.stringify(taskConfig, null, 4));
|
|
@@ -6,6 +6,7 @@ const fs = require("fs/promises");
|
|
|
6
6
|
const ospath = require("path");
|
|
7
7
|
const ajv_1 = require("ajv");
|
|
8
8
|
const taskConfigSchema = require("../../config-json-schemas/TaskConfig.json");
|
|
9
|
+
const util_1 = require("../../helpers/util");
|
|
9
10
|
var permissionModes;
|
|
10
11
|
(function (permissionModes) {
|
|
11
12
|
permissionModes["permissionRequired"] = "permissionRequired";
|
|
@@ -54,7 +55,7 @@ async function validateConfig(config) {
|
|
|
54
55
|
const validate = new ajv_1.default().compile(taskConfigSchema);
|
|
55
56
|
const valid = validate(config);
|
|
56
57
|
if (!valid) {
|
|
57
|
-
const errors = getAjvErrorStrings(validate.errors);
|
|
58
|
+
const errors = (0, util_1.getAjvErrorStrings)(validate.errors);
|
|
58
59
|
throw new Error(errors[0] || 'Unknown config validation error');
|
|
59
60
|
}
|
|
60
61
|
try {
|
|
@@ -154,16 +155,3 @@ async function* getValidatedConfigIterator({ path, name, code, entryPoint, runti
|
|
|
154
155
|
yield taskConfig;
|
|
155
156
|
}
|
|
156
157
|
exports.getValidatedConfigIterator = getValidatedConfigIterator;
|
|
157
|
-
function getAjvErrorStrings(errors) {
|
|
158
|
-
return errors.map(error => {
|
|
159
|
-
let message = '';
|
|
160
|
-
if (error.instancePath) {
|
|
161
|
-
const normalizedPath = error.instancePath
|
|
162
|
-
.replace(/^\//, '')
|
|
163
|
-
.replace(/\//g, '.');
|
|
164
|
-
message += `"${normalizedPath}" `;
|
|
165
|
-
}
|
|
166
|
-
message += error.message || 'has an unknown error';
|
|
167
|
-
return message;
|
|
168
|
-
});
|
|
169
|
-
}
|
package/build/helpers/util.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ import * as yargs from 'yargs';
|
|
|
2
2
|
export declare function epilogue(y: yargs.Argv): yargs.Argv;
|
|
3
3
|
export declare function asyncExec(cmd: string): Promise<string>;
|
|
4
4
|
export declare function loadAndAssertCredentials(): void;
|
|
5
|
+
export declare function getCliVersion(): any;
|
|
6
|
+
export declare function getAjvErrorStrings(errors: any[]): string[];
|
package/build/helpers/util.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadAndAssertCredentials = exports.asyncExec = exports.epilogue = void 0;
|
|
3
|
+
exports.getAjvErrorStrings = exports.getCliVersion = exports.loadAndAssertCredentials = exports.asyncExec = exports.epilogue = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
6
7
|
const chalk = require("chalk");
|
|
7
8
|
const constants_1 = require("../constants");
|
|
8
9
|
const error_1 = require("./error");
|
|
@@ -65,3 +66,26 @@ function loadAndAssertCredentials() {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
exports.loadAndAssertCredentials = loadAndAssertCredentials;
|
|
69
|
+
function getCliVersion() {
|
|
70
|
+
const packageJsonPath = path.join(__dirname, '../../package.json');
|
|
71
|
+
const packageJsonString = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
72
|
+
return JSON.parse(packageJsonString).version;
|
|
73
|
+
}
|
|
74
|
+
exports.getCliVersion = getCliVersion;
|
|
75
|
+
function getAjvErrorStrings(errors) {
|
|
76
|
+
return errors.map(error => {
|
|
77
|
+
let message = '';
|
|
78
|
+
if (error.instancePath) {
|
|
79
|
+
const normalizedPath = error.instancePath
|
|
80
|
+
.replace(/^\//, '')
|
|
81
|
+
.replace(/\//g, '.');
|
|
82
|
+
message += `"${normalizedPath}" `;
|
|
83
|
+
}
|
|
84
|
+
message += error.message || 'has an unknown error';
|
|
85
|
+
if (!['type', 'required'].includes(error.keyword) && error.params) {
|
|
86
|
+
message += ` ${JSON.stringify(error.params)}`;
|
|
87
|
+
}
|
|
88
|
+
return message;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exports.getAjvErrorStrings = getAjvErrorStrings;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assertValidFileContent = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
4
|
+
const ajv_1 = require("ajv");
|
|
5
|
+
const util_1 = require("../../helpers/util");
|
|
6
|
+
const validate = new ajv_1.default().compile({
|
|
7
|
+
type: 'object',
|
|
8
|
+
patternProperties: {
|
|
9
|
+
'^[a-z0-9_.-]{1,200}$': { type: 'string' },
|
|
10
|
+
},
|
|
11
|
+
additionalProperties: false,
|
|
12
|
+
});
|
|
8
13
|
function assertValidFileContent(fileName, content) {
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
|
|
14
|
+
const valid = validate(content);
|
|
15
|
+
if (!valid) {
|
|
16
|
+
const errors = (0, util_1.getAjvErrorStrings)(validate.errors);
|
|
17
|
+
throw new Error(`The content of localization file '${fileName}' is not valid: ${errors[0]}`);
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
20
|
exports.assertValidFileContent = assertValidFileContent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extrahorizon/exh-cli",
|
|
3
|
-
"version": "1.10.0-dev-
|
|
3
|
+
"version": "1.10.0-dev-107-31b7fb4",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"exports": "./build/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"ajv": "^8.11.0",
|
|
46
46
|
"archiver": "^7.0.1",
|
|
47
47
|
"chalk": "^4.0.0",
|
|
48
|
-
"joi": "^17.6.0",
|
|
49
48
|
"lodash": "^4.17.21",
|
|
50
49
|
"yargs": "^17.5.1"
|
|
51
50
|
}
|