@extrahorizon/exh-cli 1.12.0-dev-147-8845ed1 → 1.12.0-dev-149-5031bb3
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/get.d.ts +4 -0
- package/build/services/templates/get.js +53 -0
- package/build/services/templates/index.d.ts +3 -3
- package/build/services/templates/index.js +7 -62
- package/build/services/templates/list.d.ts +1 -0
- package/build/services/templates/list.js +44 -0
- package/build/services/templates/remove.d.ts +1 -0
- package/build/services/templates/remove.js +53 -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 +2 -2
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Template, type TemplateV2 } from '@extrahorizon/javascript-sdk';
|
|
2
|
+
export declare function get(name?: string, id?: string): Promise<void>;
|
|
3
|
+
export declare function getFromV1(name?: string, id?: string): Promise<Template>;
|
|
4
|
+
export declare function getFromV2(name?: string, id?: string): Promise<TemplateV2>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFromV2 = exports.getFromV1 = exports.get = void 0;
|
|
4
|
+
const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const templateRepository = require("../../repositories/templates");
|
|
7
|
+
const templateV2Repository = require("../../repositories/templatesV2");
|
|
8
|
+
async function get(name, id) {
|
|
9
|
+
let template = await getFromV2(name, id);
|
|
10
|
+
if (!template) {
|
|
11
|
+
template = await getFromV1(name, id);
|
|
12
|
+
}
|
|
13
|
+
if (!template) {
|
|
14
|
+
console.log(chalk.red('Failed to get template!'));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
console.log(JSON.stringify(template, null, 4));
|
|
18
|
+
}
|
|
19
|
+
exports.get = get;
|
|
20
|
+
async function getFromV1(name, id) {
|
|
21
|
+
try {
|
|
22
|
+
if (name) {
|
|
23
|
+
return await templateRepository.findByName(name);
|
|
24
|
+
}
|
|
25
|
+
if (id) {
|
|
26
|
+
return await templateRepository.findById(id);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (!(error instanceof javascript_sdk_1.ServiceNotFoundError)) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
exports.getFromV1 = getFromV1;
|
|
37
|
+
async function getFromV2(name, id) {
|
|
38
|
+
try {
|
|
39
|
+
if (name) {
|
|
40
|
+
return await templateV2Repository.findByName(name);
|
|
41
|
+
}
|
|
42
|
+
if (id) {
|
|
43
|
+
return await templateV2Repository.findById(id);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (!(error instanceof javascript_sdk_1.ServiceNotFoundError)) {
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
exports.getFromV2 = getFromV2;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { sync } from './sync';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export { get } from './get';
|
|
3
|
+
export { list } from './list';
|
|
4
|
+
export { remove } from './remove';
|
|
@@ -1,66 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.remove = exports.
|
|
4
|
-
const chalk = require("chalk");
|
|
5
|
-
const templateRepository = require("../../repositories/templates");
|
|
3
|
+
exports.remove = exports.list = exports.get = exports.sync = void 0;
|
|
6
4
|
var sync_1 = require("./sync");
|
|
7
5
|
Object.defineProperty(exports, "sync", { enumerable: true, get: function () { return sync_1.sync; } });
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (isTTY) {
|
|
15
|
-
console.table(templates.map(template => ({
|
|
16
|
-
Id: template.id,
|
|
17
|
-
Name: template.name,
|
|
18
|
-
Description: template.description || '<none>',
|
|
19
|
-
'Last updated': template.updateTimestamp.toISOString(),
|
|
20
|
-
})));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
templates.forEach(template => console.log(template));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.list = list;
|
|
27
|
-
async function get(name, id) {
|
|
28
|
-
let template;
|
|
29
|
-
if (name) {
|
|
30
|
-
template = await templateRepository.findByName(name);
|
|
31
|
-
}
|
|
32
|
-
else if (id) {
|
|
33
|
-
template = await templateRepository.findById(id);
|
|
34
|
-
}
|
|
35
|
-
if (!template) {
|
|
36
|
-
console.log(chalk.red('Failed to get template!'));
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
console.log(JSON.stringify(template, null, 4));
|
|
40
|
-
}
|
|
41
|
-
exports.get = get;
|
|
42
|
-
async function remove(name, id) {
|
|
43
|
-
let template = null;
|
|
44
|
-
if (name) {
|
|
45
|
-
template = await templateRepository.findByName(name);
|
|
46
|
-
}
|
|
47
|
-
if (id) {
|
|
48
|
-
template = await templateRepository.findById(id);
|
|
49
|
-
}
|
|
50
|
-
if (!template) {
|
|
51
|
-
console.log(chalk.red('Template not found!'));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
const { affectedRecords } = await templateRepository.remove(template.id);
|
|
56
|
-
if (!affectedRecords) {
|
|
57
|
-
console.log(chalk.red('Failed to remove template', name));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
console.log('Template deleted');
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
console.log(chalk.red('Failed to remove template', name));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.remove = remove;
|
|
6
|
+
var get_1 = require("./get");
|
|
7
|
+
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return get_1.get; } });
|
|
8
|
+
var list_1 = require("./list");
|
|
9
|
+
Object.defineProperty(exports, "list", { enumerable: true, get: function () { return list_1.list; } });
|
|
10
|
+
var remove_1 = require("./remove");
|
|
11
|
+
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return remove_1.remove; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function list(isTTY: boolean): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.list = void 0;
|
|
4
|
+
const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const templateRepository = require("../../repositories/templates");
|
|
7
|
+
const templateV2Repository = require("../../repositories/templatesV2");
|
|
8
|
+
async function list(isTTY) {
|
|
9
|
+
const templates = [];
|
|
10
|
+
try {
|
|
11
|
+
const templatesV1 = await templateRepository.findAll();
|
|
12
|
+
templates.push(...templatesV1);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (!(error instanceof javascript_sdk_1.ServiceNotFoundError)) {
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const templatesV2 = await templateV2Repository.findAll();
|
|
21
|
+
templates.push(...templatesV2);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (!(error instanceof javascript_sdk_1.ServiceNotFoundError)) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (templates.length < 1) {
|
|
29
|
+
console.log(chalk.red('No templates found'));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (isTTY) {
|
|
33
|
+
console.table(templates.map(template => ({
|
|
34
|
+
Id: template.id,
|
|
35
|
+
Name: template.name,
|
|
36
|
+
Description: template.description || '<none>',
|
|
37
|
+
'Last updated': template.updateTimestamp.toISOString(),
|
|
38
|
+
})));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
templates.forEach(template => console.log(template));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.list = list;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function remove(name?: string, id?: string): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remove = void 0;
|
|
4
|
+
const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const templateRepository = require("../../repositories/templates");
|
|
7
|
+
const templateV2Repository = require("../../repositories/templatesV2");
|
|
8
|
+
const get_1 = require("./get");
|
|
9
|
+
async function remove(name, id) {
|
|
10
|
+
let isRemoved = await removeFromV2(name, id);
|
|
11
|
+
if (!isRemoved) {
|
|
12
|
+
isRemoved = await removeFromV1(name, id);
|
|
13
|
+
}
|
|
14
|
+
if (!isRemoved) {
|
|
15
|
+
console.log(chalk.red('Template not found!'));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.log('Template deleted');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.remove = remove;
|
|
22
|
+
async function removeFromV1(name, id) {
|
|
23
|
+
const template = await (0, get_1.getFromV1)(name, id);
|
|
24
|
+
if (!template) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
await templateRepository.remove(template.id);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (!(error instanceof javascript_sdk_1.ServiceNotFoundError)) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
async function removeFromV2(name, id) {
|
|
39
|
+
const template = await (0, get_1.getFromV2)(name, id);
|
|
40
|
+
if (!template) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await templateV2Repository.remove(template.id);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (!(error instanceof javascript_sdk_1.ServiceNotFoundError)) {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extrahorizon/exh-cli",
|
|
3
|
-
"version": "1.12.0-dev-
|
|
3
|
+
"version": "1.12.0-dev-149-5031bb3",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"exports": "./build/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"typescript": "4.5.5"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@extrahorizon/javascript-sdk": "8.9.0-dev-
|
|
44
|
+
"@extrahorizon/javascript-sdk": "8.9.0-dev-141-b21be6e",
|
|
45
45
|
"ajv": "^8.11.0",
|
|
46
46
|
"archiver": "^7.0.1",
|
|
47
47
|
"chalk": "^4.0.0",
|