@extrahorizon/exh-cli 1.12.0-dev-147-8845ed1 → 1.12.0-dev-148-901fb95
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/config-json-schemas/Template.json +261 -0
- package/build/services/templates/sync.js +1 -1
- package/build/services/templates/util/models.d.ts +12 -0
- package/build/services/templates/util/models.js +2 -0
- package/build/services/templates/util/readTemplateFiles.d.ts +3 -2
- package/build/services/templates/util/readTemplateFiles.js +15 -6
- package/build/services/templates/util/utils.d.ts +2 -1
- package/build/services/templates/util/utils.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"if": {
|
|
4
|
+
"description": "Try to determine if we have V1 schema",
|
|
5
|
+
"anyOf": [
|
|
6
|
+
{
|
|
7
|
+
"type": "object",
|
|
8
|
+
"required": ["version"],
|
|
9
|
+
"properties": { "version": { "const": 1 } }
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "object",
|
|
13
|
+
"required": ["schema"],
|
|
14
|
+
"properties": {
|
|
15
|
+
"version": { "const": 1 },
|
|
16
|
+
"schema": true
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"type": "object",
|
|
21
|
+
"required": ["fields"],
|
|
22
|
+
"properties": {
|
|
23
|
+
"version": { "const": 1 },
|
|
24
|
+
"fields": true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"then": { "$ref": "#/definitions/TemplateV1" },
|
|
30
|
+
"else": { "$ref": "#/definitions/TemplateV2" },
|
|
31
|
+
"definitions": {
|
|
32
|
+
"TemplateV2": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"additionalProperties": false,
|
|
35
|
+
"properties": {
|
|
36
|
+
"version": { "const": 2 },
|
|
37
|
+
"$schema": { "type": "string" },
|
|
38
|
+
"description": { "type": "string" },
|
|
39
|
+
"extendsTemplate": { "type": "string" },
|
|
40
|
+
"properties": {
|
|
41
|
+
"type": "object",
|
|
42
|
+
"additionalProperties": { "$ref": "#/definitions/TypeConfigurationV2" }
|
|
43
|
+
},
|
|
44
|
+
"outputs": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"additionalProperties": { "type": "string" }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"TypeConfigurationV2": {
|
|
51
|
+
"type": "object",
|
|
52
|
+
"required": ["type"],
|
|
53
|
+
"properties": {
|
|
54
|
+
"type": { "enum": ["object", "array", "string", "number", "boolean"] }
|
|
55
|
+
},
|
|
56
|
+
"allOf": [
|
|
57
|
+
{
|
|
58
|
+
"if": {
|
|
59
|
+
"type": "object",
|
|
60
|
+
"properties": {
|
|
61
|
+
"type": { "const": "object" }
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"then": { "$ref": "#/definitions/ObjectConfigurationV2" }
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"if": {
|
|
68
|
+
"type": "object",
|
|
69
|
+
"properties": {
|
|
70
|
+
"type": { "const": "array" }
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"then": { "$ref": "#/definitions/ArrayConfigurationV2" }
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"if": {
|
|
77
|
+
"type": "object",
|
|
78
|
+
"properties": {
|
|
79
|
+
"type": { "const": "string" }
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"then": { "$ref": "#/definitions/StringConfigurationV2" }
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"if": {
|
|
86
|
+
"type": "object",
|
|
87
|
+
"properties": {
|
|
88
|
+
"type": { "const": "number" }
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"then": { "$ref": "#/definitions/NumberConfigurationV2" }
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"if": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"properties": {
|
|
97
|
+
"type": { "const": "boolean" }
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"then": { "$ref": "#/definitions/BooleanConfigurationV2" }
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
"ObjectConfigurationV2": {
|
|
105
|
+
"type": "object",
|
|
106
|
+
"additionalProperties": false,
|
|
107
|
+
"required": ["type", "properties"],
|
|
108
|
+
"properties": {
|
|
109
|
+
"type": { "const": "object" },
|
|
110
|
+
"properties": {
|
|
111
|
+
"type": "object",
|
|
112
|
+
"additionalProperties": { "$ref": "#/definitions/TypeConfigurationV2" }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"ArrayConfigurationV2": {
|
|
117
|
+
"type": "object",
|
|
118
|
+
"additionalProperties": false,
|
|
119
|
+
"required": ["type", "items"],
|
|
120
|
+
"properties": {
|
|
121
|
+
"type": { "const": "array" },
|
|
122
|
+
"items": { "$ref": "#/definitions/TypeConfigurationV2" }
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"StringConfigurationV2": {
|
|
126
|
+
"type": "object",
|
|
127
|
+
"additionalProperties": false,
|
|
128
|
+
"required": ["type"],
|
|
129
|
+
"properties": {
|
|
130
|
+
"type": { "const": "string" }
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"NumberConfigurationV2": {
|
|
134
|
+
"type": "object",
|
|
135
|
+
"additionalProperties": false,
|
|
136
|
+
"required": ["type"],
|
|
137
|
+
"properties": {
|
|
138
|
+
"type": { "const": "number" }
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"BooleanConfigurationV2": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"additionalProperties": false,
|
|
144
|
+
"required": ["type"],
|
|
145
|
+
"properties": {
|
|
146
|
+
"type": { "const": "boolean" }
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"TemplateV1": {
|
|
150
|
+
"type": "object",
|
|
151
|
+
"required": ["description", "schema", "fields"],
|
|
152
|
+
"properties": {
|
|
153
|
+
"version": { "const": 1 },
|
|
154
|
+
"$schema": { "type": "string" },
|
|
155
|
+
"extends_template": { "type": "string" },
|
|
156
|
+
"description": { "type": "string" },
|
|
157
|
+
"schema": { "$ref": "#/definitions/ObjectConfiguration" },
|
|
158
|
+
"fields": {
|
|
159
|
+
"type": "object",
|
|
160
|
+
"additionalProperties": { "type": "string" }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"TypeConfiguration": {
|
|
165
|
+
"type": "object",
|
|
166
|
+
"required": ["type"],
|
|
167
|
+
"properties": {
|
|
168
|
+
"type": { "enum": ["object", "array", "string", "number", "boolean"] }
|
|
169
|
+
},
|
|
170
|
+
"allOf": [
|
|
171
|
+
{
|
|
172
|
+
"if": {
|
|
173
|
+
"type": "object",
|
|
174
|
+
"properties": {
|
|
175
|
+
"type": { "const": "object" }
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
"then": { "$ref": "#/definitions/ObjectConfiguration" }
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"if": {
|
|
182
|
+
"type": "object",
|
|
183
|
+
"properties": {
|
|
184
|
+
"type": { "const": "array" }
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
"then": { "$ref": "#/definitions/ArrayConfiguration" }
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"if": {
|
|
191
|
+
"type": "object",
|
|
192
|
+
"properties": {
|
|
193
|
+
"type": { "const": "string" }
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
"then": { "$ref": "#/definitions/StringConfiguration" }
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"if": {
|
|
200
|
+
"type": "object",
|
|
201
|
+
"properties": {
|
|
202
|
+
"type": { "const": "number" }
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
"then": { "$ref": "#/definitions/NumberConfiguration" }
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"if": {
|
|
209
|
+
"type": "object",
|
|
210
|
+
"properties": {
|
|
211
|
+
"type": { "const": "boolean" }
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
"then": { "$ref": "#/definitions/BooleanConfiguration" }
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
"ObjectConfiguration": {
|
|
219
|
+
"type": "object",
|
|
220
|
+
"required": ["type"],
|
|
221
|
+
"properties": {
|
|
222
|
+
"type": { "const": "object" },
|
|
223
|
+
"fields": {
|
|
224
|
+
"type": "object",
|
|
225
|
+
"additionalProperties": {
|
|
226
|
+
"$ref": "#/definitions/TypeConfiguration"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
"ArrayConfiguration": {
|
|
232
|
+
"type": "object",
|
|
233
|
+
"required": ["type", "type_configuration"],
|
|
234
|
+
"properties": {
|
|
235
|
+
"type": { "const": "array" },
|
|
236
|
+
"type_configuration": { "$ref": "#/definitions/TypeConfiguration" }
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
"StringConfiguration": {
|
|
240
|
+
"type": "object",
|
|
241
|
+
"required": ["type"],
|
|
242
|
+
"properties": {
|
|
243
|
+
"type": { "const": "string" }
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"NumberConfiguration": {
|
|
247
|
+
"type": "object",
|
|
248
|
+
"required": ["type"],
|
|
249
|
+
"properties": {
|
|
250
|
+
"type": { "const": "number" }
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
"BooleanConfiguration": {
|
|
254
|
+
"type": "object",
|
|
255
|
+
"required": ["type"],
|
|
256
|
+
"properties": {
|
|
257
|
+
"type": { "const": "boolean" }
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -14,7 +14,7 @@ async function sync(path, template) {
|
|
|
14
14
|
}
|
|
15
15
|
let templ = null;
|
|
16
16
|
if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
|
|
17
|
-
templ = await (0, readTemplateFiles_1.
|
|
17
|
+
templ = await (0, readTemplateFiles_1.readAndValidateTemplateJson)(template);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
20
|
templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TemplateCreation, TemplateV2Creation } from '@extrahorizon/javascript-sdk';
|
|
2
|
+
export declare type TemplateConfig = TemplateV1Config | TemplateV2Config;
|
|
3
|
+
export interface TemplateV1Config extends TemplateCreation {
|
|
4
|
+
version?: 1;
|
|
5
|
+
$schema?: string;
|
|
6
|
+
extends_template?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TemplateV2Config extends TemplateV2Creation {
|
|
9
|
+
version?: 2;
|
|
10
|
+
$schema?: string;
|
|
11
|
+
extendsTemplate?: string;
|
|
12
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TemplateConfig } from './models';
|
|
1
2
|
export declare function readTemplateFiles(targetFolder: string): Promise<{}>;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function readTemplateFolder(subFolder: string): Promise<
|
|
3
|
+
export declare function readAndValidateTemplateJson(fileName: string): Promise<TemplateConfig>;
|
|
4
|
+
export declare function readTemplateFolder(subFolder: string): Promise<TemplateConfig>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readTemplateFolder = exports.
|
|
3
|
+
exports.readTemplateFolder = exports.readAndValidateTemplateJson = exports.readTemplateFiles = void 0;
|
|
4
4
|
const fs = require("fs/promises");
|
|
5
5
|
const path = require("path");
|
|
6
|
+
const templateConfigSchema = require("../../../config-json-schemas/Template.json");
|
|
7
|
+
const util_1 = require("../../../helpers/util");
|
|
6
8
|
const utils_1 = require("./utils");
|
|
7
9
|
async function readTemplateFiles(targetFolder) {
|
|
8
10
|
const fileNames = await (0, utils_1.listFolderContent)(targetFolder);
|
|
@@ -14,18 +16,25 @@ async function readTemplateFiles(targetFolder) {
|
|
|
14
16
|
}
|
|
15
17
|
else if (fileName.endsWith('.json')) {
|
|
16
18
|
const templateName = (0, utils_1.removeFileNameExtension)(fileName);
|
|
17
|
-
templateFilesByName[templateName] = await
|
|
19
|
+
templateFilesByName[templateName] = await readAndValidateTemplateJson(filePath);
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
return templateFilesByName;
|
|
21
23
|
}
|
|
22
24
|
exports.readTemplateFiles = readTemplateFiles;
|
|
23
|
-
async function
|
|
24
|
-
|
|
25
|
+
async function readAndValidateTemplateJson(fileName) {
|
|
26
|
+
try {
|
|
27
|
+
const content = await (0, utils_1.readJsonFile)(fileName);
|
|
28
|
+
(0, util_1.ajvValidate)(templateConfigSchema, content);
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error(`Error while reading template file ${fileName}: ${error.message}`);
|
|
33
|
+
}
|
|
25
34
|
}
|
|
26
|
-
exports.
|
|
35
|
+
exports.readAndValidateTemplateJson = readAndValidateTemplateJson;
|
|
27
36
|
async function readTemplateFolder(subFolder) {
|
|
28
|
-
const templateFile = await
|
|
37
|
+
const templateFile = await readAndValidateTemplateJson(path.join(subFolder, 'template.json'));
|
|
29
38
|
const extraFiles = await readExtraTemplateFolderFiles(subFolder);
|
|
30
39
|
if ((0, utils_1.isV1Template)(templateFile)) {
|
|
31
40
|
templateFile.fields = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { TemplateV1Config } from './models';
|
|
1
2
|
export declare function listFolderContent(path: string): Promise<string[]>;
|
|
2
3
|
export declare function readJsonFile(path: string): Promise<any>;
|
|
3
4
|
export declare function readTextFile(path: string): Promise<string>;
|
|
4
5
|
export declare function removeFileNameExtension(fileName: string): string;
|
|
5
|
-
export declare function isV1Template(template: any):
|
|
6
|
+
export declare function isV1Template(template: any): template is TemplateV1Config;
|
|
@@ -21,6 +21,8 @@ function removeFileNameExtension(fileName) {
|
|
|
21
21
|
}
|
|
22
22
|
exports.removeFileNameExtension = removeFileNameExtension;
|
|
23
23
|
function isV1Template(template) {
|
|
24
|
-
return
|
|
24
|
+
return (template.version === 1 ||
|
|
25
|
+
!!template.schema ||
|
|
26
|
+
!!template.fields);
|
|
25
27
|
}
|
|
26
28
|
exports.isV1Template = isV1Template;
|