@extrahorizon/exh-cli 1.12.0-dev-148-901fb95 → 1.12.0-dev-150-a93c690
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 +1 -1
- 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/util/buildTemplates.js +4 -4
- package/package.json +2 -2
|
@@ -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
|
+
}
|
|
@@ -59,7 +59,7 @@ async function extendV1Template(name, templateFilesByName, callChain) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
async function extendV2Template(name, templateFilesByName, callChain) {
|
|
62
|
-
const { extendsTemplate, description,
|
|
62
|
+
const { extendsTemplate, description, inputs, outputs } = templateFilesByName[name];
|
|
63
63
|
if (!templateFilesByName[extendsTemplate]) {
|
|
64
64
|
templateFilesByName[extendsTemplate] = await templateV2Repository.findByName(extendsTemplate);
|
|
65
65
|
}
|
|
@@ -77,13 +77,13 @@ async function extendV2Template(name, templateFilesByName, callChain) {
|
|
|
77
77
|
const newOutputs = {};
|
|
78
78
|
for (const output of Object.keys(extendingTemplate.outputs)) {
|
|
79
79
|
const extendedValue = extendingTemplate.outputs[output]
|
|
80
|
-
.replace(/{{[ ]*@
|
|
80
|
+
.replace(/{{[ ]*@inputs\.([a-zA-Z0-9_-]+)[ ]*}}/g, resolveMatch);
|
|
81
81
|
newOutputs[output] = extendedValue;
|
|
82
82
|
}
|
|
83
83
|
return {
|
|
84
84
|
name,
|
|
85
85
|
description,
|
|
86
|
-
|
|
86
|
+
inputs,
|
|
87
87
|
outputs: newOutputs,
|
|
88
88
|
};
|
|
89
89
|
}
|
|
@@ -101,7 +101,7 @@ function v2ExtendingV1Error(extendsTemplate, callChain) {
|
|
|
101
101
|
`In ${renderCallChain(callChain)}`);
|
|
102
102
|
}
|
|
103
103
|
function v2VariableNotFoundError(variableName, extendsTemplate, callChain) {
|
|
104
|
-
return new Error(`Could not find a value to fill '{{@
|
|
104
|
+
return new Error(`Could not find a value to fill '{{@inputs.${variableName}}}' ` +
|
|
105
105
|
`while extending '${extendsTemplate}' ` +
|
|
106
106
|
`in ${renderCallChain(callChain)}`);
|
|
107
107
|
}
|
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-150-a93c690",
|
|
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-144-fe86b3e",
|
|
45
45
|
"ajv": "^8.11.0",
|
|
46
46
|
"archiver": "^7.0.1",
|
|
47
47
|
"chalk": "^4.0.0",
|