@extrahorizon/exh-cli 1.5.0 → 1.5.1-dev-27-7bdff2e
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/CHANGELOG.md +56 -53
- package/README.md +0 -12
- package/build/commands/completion.d.ts +5 -5
- package/build/commands/completion.js +38 -38
- package/build/commands/data/schemas/delete.d.ts +10 -10
- package/build/commands/data/schemas/delete.js +29 -29
- package/build/commands/data/schemas/list.d.ts +8 -8
- package/build/commands/data/schemas/list.js +20 -20
- package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -3
- package/build/commands/data/schemas/sync/statusHelpers.js +49 -49
- package/build/commands/data/schemas/sync.d.ts +35 -35
- package/build/commands/data/schemas/sync.js +72 -72
- package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -1
- package/build/commands/data/schemas/util/listFilesInDir.js +25 -25
- package/build/commands/data/schemas/util/metaschema.json +455 -455
- package/build/commands/data/schemas/util/readJson.d.ts +1 -1
- package/build/commands/data/schemas/util/readJson.js +11 -11
- package/build/commands/data/schemas/util/schemaverify.d.ts +28 -28
- package/build/commands/data/schemas/util/schemaverify.js +202 -202
- package/build/commands/data/schemas/util/syncSchema.d.ts +20 -20
- package/build/commands/data/schemas/util/syncSchema.js +276 -276
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -1
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -40
- package/build/commands/data/schemas/verify.d.ts +18 -18
- package/build/commands/data/schemas/verify.js +82 -82
- package/build/commands/data/schemas.d.ts +5 -5
- package/build/commands/data/schemas.js +10 -10
- package/build/commands/data.d.ts +5 -5
- package/build/commands/data.js +10 -10
- package/build/commands/dispatchers/sync.d.ts +21 -21
- package/build/commands/dispatchers/sync.js +24 -24
- package/build/commands/dispatchers.d.ts +5 -5
- package/build/commands/dispatchers.js +10 -10
- package/build/commands/login.d.ts +37 -37
- package/build/commands/login.js +59 -59
- package/build/commands/sync.d.ts +55 -55
- package/build/commands/sync.js +107 -107
- package/build/commands/tasks/createrepo.d.ts +22 -22
- package/build/commands/tasks/createrepo.js +70 -70
- package/build/commands/tasks/delete.d.ts +10 -10
- package/build/commands/tasks/delete.js +29 -29
- package/build/commands/tasks/list.d.ts +8 -8
- package/build/commands/tasks/list.js +27 -27
- package/build/commands/tasks/sync.d.ts +56 -56
- package/build/commands/tasks/sync.js +122 -122
- package/build/commands/tasks/taskConfig.d.ts +24 -24
- package/build/commands/tasks/taskConfig.js +169 -169
- package/build/commands/tasks/util.d.ts +1 -1
- package/build/commands/tasks/util.js +27 -27
- package/build/commands/tasks.d.ts +5 -5
- package/build/commands/tasks.js +10 -10
- package/build/commands/templates/delete.d.ts +19 -19
- package/build/commands/templates/delete.js +48 -48
- package/build/commands/templates/get.d.ts +19 -19
- package/build/commands/templates/get.js +37 -37
- package/build/commands/templates/list.d.ts +9 -9
- package/build/commands/templates/list.js +25 -25
- package/build/commands/templates/sync.d.ts +22 -22
- package/build/commands/templates/sync.js +65 -65
- package/build/commands/templates/util/buildTemplates.d.ts +2 -2
- package/build/commands/templates/util/buildTemplates.js +50 -50
- package/build/commands/templates/util/readTemplateFiles.d.ts +3 -3
- package/build/commands/templates/util/readTemplateFiles.js +52 -52
- package/build/commands/templates/util/templateService.d.ts +8 -8
- package/build/commands/templates/util/templateService.js +18 -18
- package/build/commands/templates/util/uploadTemplate.d.ts +2 -2
- package/build/commands/templates/util/uploadTemplate.js +20 -20
- package/build/commands/templates/util/utils.d.ts +4 -4
- package/build/commands/templates/util/utils.js +22 -22
- package/build/commands/templates.d.ts +5 -5
- package/build/commands/templates.js +10 -10
- package/build/constants.d.ts +13 -13
- package/build/constants.js +37 -37
- package/build/exh.d.ts +3 -3
- package/build/exh.js +65 -65
- package/build/helpers/error.d.ts +2 -2
- package/build/helpers/error.js +6 -6
- package/build/helpers/repoConfig.d.ts +2 -2
- package/build/helpers/repoConfig.js +60 -60
- package/build/helpers/util.d.ts +3 -3
- package/build/helpers/util.js +36 -36
- package/build/index.d.ts +2 -2
- package/build/index.js +33 -33
- package/build/repositories/dispatchers.d.ts +8 -8
- package/build/repositories/dispatchers.js +31 -31
- package/build/repositories/functions.d.ts +24 -24
- package/build/repositories/functions.js +28 -28
- package/build/repositories/schemas.d.ts +44 -44
- package/build/repositories/schemas.js +86 -86
- package/build/services/dispatchers.d.ts +3 -3
- package/build/services/dispatchers.js +132 -132
- package/package.json +53 -53
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
|
-
const util_1 = require("../../helpers/util");
|
|
6
|
-
exports.command = 'get';
|
|
7
|
-
exports.desc = 'Fetch a template';
|
|
8
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
9
|
-
name: {
|
|
10
|
-
describe: 'Name of the template',
|
|
11
|
-
type: 'string',
|
|
12
|
-
},
|
|
13
|
-
id: {
|
|
14
|
-
describe: 'ID of the template',
|
|
15
|
-
type: 'string',
|
|
16
|
-
},
|
|
17
|
-
}).check(({ name, id }) => {
|
|
18
|
-
if ((name && id) || (!name && !id)) {
|
|
19
|
-
throw new Error('Either name or id should be specified (but not both at the same time)');
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
});
|
|
23
|
-
exports.builder = builder;
|
|
24
|
-
const handler = async function list({ sdk, name, id }) {
|
|
25
|
-
try {
|
|
26
|
-
const template = name ? await sdk.templates.findByName(name) : await sdk.templates.findById(id);
|
|
27
|
-
if (!template) {
|
|
28
|
-
console.log(chalk.red('Failed to get template!'));
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
console.log(JSON.stringify(template, null, 4));
|
|
32
|
-
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
console.log(chalk.red('Failed to get template', name));
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
exports.handler = handler;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const util_1 = require("../../helpers/util");
|
|
6
|
+
exports.command = 'get';
|
|
7
|
+
exports.desc = 'Fetch a template';
|
|
8
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
9
|
+
name: {
|
|
10
|
+
describe: 'Name of the template',
|
|
11
|
+
type: 'string',
|
|
12
|
+
},
|
|
13
|
+
id: {
|
|
14
|
+
describe: 'ID of the template',
|
|
15
|
+
type: 'string',
|
|
16
|
+
},
|
|
17
|
+
}).check(({ name, id }) => {
|
|
18
|
+
if ((name && id) || (!name && !id)) {
|
|
19
|
+
throw new Error('Either name or id should be specified (but not both at the same time)');
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
exports.builder = builder;
|
|
24
|
+
const handler = async function list({ sdk, name, id }) {
|
|
25
|
+
try {
|
|
26
|
+
const template = name ? await sdk.templates.findByName(name) : await sdk.templates.findById(id);
|
|
27
|
+
if (!template) {
|
|
28
|
+
console.log(chalk.red('Failed to get template!'));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
console.log(JSON.stringify(template, null, 4));
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
console.log(chalk.red('Failed to get template', name));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.handler = handler;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/// <reference types="yargs" />
|
|
2
|
-
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
3
|
-
export declare const command = "list";
|
|
4
|
-
export declare const desc = "List all templates";
|
|
5
|
-
export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
|
|
6
|
-
export declare const handler: ({ sdk, isTTY }: {
|
|
7
|
-
sdk: OAuth1Client;
|
|
8
|
-
isTTY: boolean;
|
|
9
|
-
}) => Promise<void>;
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
3
|
+
export declare const command = "list";
|
|
4
|
+
export declare const desc = "List all templates";
|
|
5
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
|
|
6
|
+
export declare const handler: ({ sdk, isTTY }: {
|
|
7
|
+
sdk: OAuth1Client;
|
|
8
|
+
isTTY: boolean;
|
|
9
|
+
}) => Promise<void>;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
|
-
const util_1 = require("../../helpers/util");
|
|
6
|
-
exports.command = 'list';
|
|
7
|
-
exports.desc = 'List all templates';
|
|
8
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
9
|
-
exports.builder = builder;
|
|
10
|
-
const handler = async function list({ sdk, isTTY }) {
|
|
11
|
-
const templates = await sdk.templates.findAll();
|
|
12
|
-
if (templates) {
|
|
13
|
-
if (!templates.length) {
|
|
14
|
-
console.log(chalk.red('No templates found'));
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (isTTY) {
|
|
18
|
-
console.table(templates.map((c) => ({ Id: c.id, Name: c.name, Description: c.description || '<none>', 'Last updated': c.updateTimestamp.toISOString() })));
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
templates.forEach((f) => (console.log(f)));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
exports.handler = handler;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const util_1 = require("../../helpers/util");
|
|
6
|
+
exports.command = 'list';
|
|
7
|
+
exports.desc = 'List all templates';
|
|
8
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
9
|
+
exports.builder = builder;
|
|
10
|
+
const handler = async function list({ sdk, isTTY }) {
|
|
11
|
+
const templates = await sdk.templates.findAll();
|
|
12
|
+
if (templates) {
|
|
13
|
+
if (!templates.length) {
|
|
14
|
+
console.log(chalk.red('No templates found'));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (isTTY) {
|
|
18
|
+
console.table(templates.map((c) => ({ Id: c.id, Name: c.name, Description: c.description || '<none>', 'Last updated': c.updateTimestamp.toISOString() })));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
templates.forEach((f) => (console.log(f)));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.handler = handler;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/// <reference types="yargs" />
|
|
2
|
-
import { TemplateService } from './util/templateService';
|
|
3
|
-
export declare const command = "sync";
|
|
4
|
-
export declare const desc = "Sync all templates in a directory with the ExH cloud";
|
|
5
|
-
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "template" | "path"> & import("yargs").InferredOptionTypes<{
|
|
6
|
-
path: {
|
|
7
|
-
demandOption: false;
|
|
8
|
-
describe: string;
|
|
9
|
-
type: "string";
|
|
10
|
-
};
|
|
11
|
-
template: {
|
|
12
|
-
demandOption: false;
|
|
13
|
-
describe: string;
|
|
14
|
-
type: "string";
|
|
15
|
-
};
|
|
16
|
-
}>>;
|
|
17
|
-
export declare const handler: ({ sdk, path, template }: {
|
|
18
|
-
sdk: any;
|
|
19
|
-
path: any;
|
|
20
|
-
template: any;
|
|
21
|
-
}) => Promise<void>;
|
|
22
|
-
export declare function syncTargetDir(service: TemplateService, targetDir: string): Promise<void>;
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
import { TemplateService } from './util/templateService';
|
|
3
|
+
export declare const command = "sync";
|
|
4
|
+
export declare const desc = "Sync all templates in a directory with the ExH cloud";
|
|
5
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "template" | "path"> & import("yargs").InferredOptionTypes<{
|
|
6
|
+
path: {
|
|
7
|
+
demandOption: false;
|
|
8
|
+
describe: string;
|
|
9
|
+
type: "string";
|
|
10
|
+
};
|
|
11
|
+
template: {
|
|
12
|
+
demandOption: false;
|
|
13
|
+
describe: string;
|
|
14
|
+
type: "string";
|
|
15
|
+
};
|
|
16
|
+
}>>;
|
|
17
|
+
export declare const handler: ({ sdk, path, template }: {
|
|
18
|
+
sdk: any;
|
|
19
|
+
path: any;
|
|
20
|
+
template: any;
|
|
21
|
+
}) => Promise<void>;
|
|
22
|
+
export declare function syncTargetDir(service: TemplateService, targetDir: string): Promise<void>;
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.syncTargetDir = exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const ospath = require("path");
|
|
6
|
-
const util_1 = require("../../helpers/util");
|
|
7
|
-
const buildTemplates_1 = require("./util/buildTemplates");
|
|
8
|
-
const readTemplateFiles_1 = require("./util/readTemplateFiles");
|
|
9
|
-
const templateService_1 = require("./util/templateService");
|
|
10
|
-
const uploadTemplate_1 = require("./util/uploadTemplate");
|
|
11
|
-
const utils_1 = require("./util/utils");
|
|
12
|
-
exports.command = 'sync';
|
|
13
|
-
exports.desc = 'Sync all templates in a directory with the ExH cloud';
|
|
14
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
15
|
-
path: {
|
|
16
|
-
demandOption: false,
|
|
17
|
-
describe: 'Directory containing the templates which need to be synced',
|
|
18
|
-
type: 'string',
|
|
19
|
-
},
|
|
20
|
-
template: {
|
|
21
|
-
demandOption: false,
|
|
22
|
-
describe: 'Template file to sync',
|
|
23
|
-
type: 'string',
|
|
24
|
-
},
|
|
25
|
-
}).check(({ path, template }) => {
|
|
26
|
-
if (template && !fs.existsSync(ospath.join(process.cwd(), template))) {
|
|
27
|
-
throw new Error('please provide a valid file path for your template');
|
|
28
|
-
}
|
|
29
|
-
if (path && (!fs.existsSync(ospath.join(process.cwd(), path)) || fs.statSync(ospath.join(process.cwd(), path)).isFile())) {
|
|
30
|
-
throw new Error('please provide a valid directory path for your code');
|
|
31
|
-
}
|
|
32
|
-
if ((template && path) || (!template && !path)) {
|
|
33
|
-
throw new Error('Either path or template must be specified (but not both at the same time)');
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
});
|
|
37
|
-
exports.builder = builder;
|
|
38
|
-
const handler = async ({ sdk, path, template }) => {
|
|
39
|
-
const service = new templateService_1.TemplateService(sdk);
|
|
40
|
-
if (path) {
|
|
41
|
-
await syncTargetDir(service, ospath.resolve(path || '.'));
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
let templ = null;
|
|
45
|
-
const templateName = (0, utils_1.removeFileNameExtension)(ospath.basename(template));
|
|
46
|
-
if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
|
|
47
|
-
templ = await (0, readTemplateFiles_1.readTemplateJson)(template);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
|
|
51
|
-
}
|
|
52
|
-
await buildAndUploadTemplates(service, { [templateName]: templ });
|
|
53
|
-
};
|
|
54
|
-
exports.handler = handler;
|
|
55
|
-
async function buildAndUploadTemplates(service, templateObject) {
|
|
56
|
-
const templates = await (0, buildTemplates_1.buildTemplates)(service, templateObject);
|
|
57
|
-
for (const template of templates) {
|
|
58
|
-
await (0, uploadTemplate_1.uploadTemplate)(service, template);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async function syncTargetDir(service, targetDir) {
|
|
62
|
-
const templateFilesByName = await (0, readTemplateFiles_1.readTemplateFiles)(targetDir);
|
|
63
|
-
await buildAndUploadTemplates(service, templateFilesByName);
|
|
64
|
-
}
|
|
65
|
-
exports.syncTargetDir = syncTargetDir;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncTargetDir = exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const ospath = require("path");
|
|
6
|
+
const util_1 = require("../../helpers/util");
|
|
7
|
+
const buildTemplates_1 = require("./util/buildTemplates");
|
|
8
|
+
const readTemplateFiles_1 = require("./util/readTemplateFiles");
|
|
9
|
+
const templateService_1 = require("./util/templateService");
|
|
10
|
+
const uploadTemplate_1 = require("./util/uploadTemplate");
|
|
11
|
+
const utils_1 = require("./util/utils");
|
|
12
|
+
exports.command = 'sync';
|
|
13
|
+
exports.desc = 'Sync all templates in a directory with the ExH cloud';
|
|
14
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
15
|
+
path: {
|
|
16
|
+
demandOption: false,
|
|
17
|
+
describe: 'Directory containing the templates which need to be synced',
|
|
18
|
+
type: 'string',
|
|
19
|
+
},
|
|
20
|
+
template: {
|
|
21
|
+
demandOption: false,
|
|
22
|
+
describe: 'Template file to sync',
|
|
23
|
+
type: 'string',
|
|
24
|
+
},
|
|
25
|
+
}).check(({ path, template }) => {
|
|
26
|
+
if (template && !fs.existsSync(ospath.join(process.cwd(), template))) {
|
|
27
|
+
throw new Error('please provide a valid file path for your template');
|
|
28
|
+
}
|
|
29
|
+
if (path && (!fs.existsSync(ospath.join(process.cwd(), path)) || fs.statSync(ospath.join(process.cwd(), path)).isFile())) {
|
|
30
|
+
throw new Error('please provide a valid directory path for your code');
|
|
31
|
+
}
|
|
32
|
+
if ((template && path) || (!template && !path)) {
|
|
33
|
+
throw new Error('Either path or template must be specified (but not both at the same time)');
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
});
|
|
37
|
+
exports.builder = builder;
|
|
38
|
+
const handler = async ({ sdk, path, template }) => {
|
|
39
|
+
const service = new templateService_1.TemplateService(sdk);
|
|
40
|
+
if (path) {
|
|
41
|
+
await syncTargetDir(service, ospath.resolve(path || '.'));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let templ = null;
|
|
45
|
+
const templateName = (0, utils_1.removeFileNameExtension)(ospath.basename(template));
|
|
46
|
+
if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
|
|
47
|
+
templ = await (0, readTemplateFiles_1.readTemplateJson)(template);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
|
|
51
|
+
}
|
|
52
|
+
await buildAndUploadTemplates(service, { [templateName]: templ });
|
|
53
|
+
};
|
|
54
|
+
exports.handler = handler;
|
|
55
|
+
async function buildAndUploadTemplates(service, templateObject) {
|
|
56
|
+
const templates = await (0, buildTemplates_1.buildTemplates)(service, templateObject);
|
|
57
|
+
for (const template of templates) {
|
|
58
|
+
await (0, uploadTemplate_1.uploadTemplate)(service, template);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function syncTargetDir(service, targetDir) {
|
|
62
|
+
const templateFilesByName = await (0, readTemplateFiles_1.readTemplateFiles)(targetDir);
|
|
63
|
+
await buildAndUploadTemplates(service, templateFilesByName);
|
|
64
|
+
}
|
|
65
|
+
exports.syncTargetDir = syncTargetDir;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TemplateService } from './templateService';
|
|
2
|
-
export declare function buildTemplates(service: TemplateService, templateFilesByName: any): Promise<any[]>;
|
|
1
|
+
import { TemplateService } from './templateService';
|
|
2
|
+
export declare function buildTemplates(service: TemplateService, templateFilesByName: any): Promise<any[]>;
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildTemplates = void 0;
|
|
4
|
-
async function buildTemplates(service, templateFilesByName) {
|
|
5
|
-
const templates = [];
|
|
6
|
-
for (const name of Object.keys(templateFilesByName)) {
|
|
7
|
-
templates.push(await buildTemplate(service, name, templateFilesByName));
|
|
8
|
-
}
|
|
9
|
-
return templates;
|
|
10
|
-
}
|
|
11
|
-
exports.buildTemplates = buildTemplates;
|
|
12
|
-
async function buildTemplate(service, name, templateFilesByName, callChain = []) {
|
|
13
|
-
if (callChain.includes(name)) {
|
|
14
|
-
throw new Error(`Circular extension detected. ${[...callChain, name].reverse().map((n) => `'${n}'`).join(' > ')}`);
|
|
15
|
-
}
|
|
16
|
-
let templateFile = templateFilesByName[name];
|
|
17
|
-
if (templateFile === undefined) {
|
|
18
|
-
templateFile = await service.byName(name);
|
|
19
|
-
if (!templateFile) {
|
|
20
|
-
throw new Error(`Template file dependency ${name} not found!`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const { description, extends_template, schema } = templateFile;
|
|
24
|
-
let { fields } = templateFile;
|
|
25
|
-
if (extends_template) {
|
|
26
|
-
const extendingTemplate = await buildTemplate(service, extends_template, templateFilesByName, [...callChain, name]);
|
|
27
|
-
const match = (_fullMatch, variableName) => {
|
|
28
|
-
const value = fields[variableName];
|
|
29
|
-
if (typeof value === 'undefined') {
|
|
30
|
-
throw new Error(`Could not find a value to fill '$content.${variableName}' ` +
|
|
31
|
-
`while extending '${extends_template}' ` +
|
|
32
|
-
`in ${[...callChain, name].reverse().map(n => `'${n}'`).join(' > ')}`);
|
|
33
|
-
}
|
|
34
|
-
return value;
|
|
35
|
-
};
|
|
36
|
-
const extendedFields = {};
|
|
37
|
-
for (const extendingField of Object.keys(extendingTemplate.fields)) {
|
|
38
|
-
const extendedValue = extendingTemplate.fields[extendingField]
|
|
39
|
-
.replace(/\$content\.([a-z0-9_-]+)/ig, match);
|
|
40
|
-
extendedFields[extendingField] = extendedValue;
|
|
41
|
-
}
|
|
42
|
-
fields = extendedFields;
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
name,
|
|
46
|
-
description,
|
|
47
|
-
schema,
|
|
48
|
-
fields,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildTemplates = void 0;
|
|
4
|
+
async function buildTemplates(service, templateFilesByName) {
|
|
5
|
+
const templates = [];
|
|
6
|
+
for (const name of Object.keys(templateFilesByName)) {
|
|
7
|
+
templates.push(await buildTemplate(service, name, templateFilesByName));
|
|
8
|
+
}
|
|
9
|
+
return templates;
|
|
10
|
+
}
|
|
11
|
+
exports.buildTemplates = buildTemplates;
|
|
12
|
+
async function buildTemplate(service, name, templateFilesByName, callChain = []) {
|
|
13
|
+
if (callChain.includes(name)) {
|
|
14
|
+
throw new Error(`Circular extension detected. ${[...callChain, name].reverse().map((n) => `'${n}'`).join(' > ')}`);
|
|
15
|
+
}
|
|
16
|
+
let templateFile = templateFilesByName[name];
|
|
17
|
+
if (templateFile === undefined) {
|
|
18
|
+
templateFile = await service.byName(name);
|
|
19
|
+
if (!templateFile) {
|
|
20
|
+
throw new Error(`Template file dependency ${name} not found!`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const { description, extends_template, schema } = templateFile;
|
|
24
|
+
let { fields } = templateFile;
|
|
25
|
+
if (extends_template) {
|
|
26
|
+
const extendingTemplate = await buildTemplate(service, extends_template, templateFilesByName, [...callChain, name]);
|
|
27
|
+
const match = (_fullMatch, variableName) => {
|
|
28
|
+
const value = fields[variableName];
|
|
29
|
+
if (typeof value === 'undefined') {
|
|
30
|
+
throw new Error(`Could not find a value to fill '$content.${variableName}' ` +
|
|
31
|
+
`while extending '${extends_template}' ` +
|
|
32
|
+
`in ${[...callChain, name].reverse().map(n => `'${n}'`).join(' > ')}`);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
const extendedFields = {};
|
|
37
|
+
for (const extendingField of Object.keys(extendingTemplate.fields)) {
|
|
38
|
+
const extendedValue = extendingTemplate.fields[extendingField]
|
|
39
|
+
.replace(/\$content\.([a-z0-9_-]+)/ig, match);
|
|
40
|
+
extendedFields[extendingField] = extendedValue;
|
|
41
|
+
}
|
|
42
|
+
fields = extendedFields;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
description,
|
|
47
|
+
schema,
|
|
48
|
+
fields,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function readTemplateFiles(targetFolder: string): Promise<{}>;
|
|
2
|
-
export declare function readTemplateJson(fileName: string): Promise<any>;
|
|
3
|
-
export declare function readTemplateFolder(subFolder: string): Promise<any>;
|
|
1
|
+
export declare function readTemplateFiles(targetFolder: string): Promise<{}>;
|
|
2
|
+
export declare function readTemplateJson(fileName: string): Promise<any>;
|
|
3
|
+
export declare function readTemplateFolder(subFolder: string): Promise<any>;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readTemplateFolder = exports.readTemplateJson = exports.readTemplateFiles = void 0;
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
async function readTemplateFiles(targetFolder) {
|
|
8
|
-
const fileNames = await (0, utils_1.listFolderContent)(targetFolder);
|
|
9
|
-
const templateFilesByName = {};
|
|
10
|
-
for (const fileName of fileNames) {
|
|
11
|
-
const filePath = path.join(targetFolder, fileName);
|
|
12
|
-
if ((await fs.stat(filePath)).isDirectory()) {
|
|
13
|
-
templateFilesByName[fileName] = await readTemplateFolder(filePath);
|
|
14
|
-
}
|
|
15
|
-
else if (fileName.endsWith('.json')) {
|
|
16
|
-
const templateName = (0, utils_1.removeFileNameExtension)(fileName);
|
|
17
|
-
templateFilesByName[templateName] = await readTemplateJson(filePath);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return templateFilesByName;
|
|
21
|
-
}
|
|
22
|
-
exports.readTemplateFiles = readTemplateFiles;
|
|
23
|
-
async function readTemplateJson(fileName) {
|
|
24
|
-
return (0, utils_1.readJsonFile)(fileName);
|
|
25
|
-
}
|
|
26
|
-
exports.readTemplateJson = readTemplateJson;
|
|
27
|
-
async function readTemplateFolder(subFolder) {
|
|
28
|
-
const templateFile = await readTemplateJson(path.join(subFolder, 'template.json'));
|
|
29
|
-
const templateFields = await readTemplateFolderFieldFiles(subFolder);
|
|
30
|
-
if (!templateFile.fields) {
|
|
31
|
-
templateFile.fields = templateFields;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
templateFile.fields = {
|
|
35
|
-
...templateFile.fields,
|
|
36
|
-
...templateFields,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return templateFile;
|
|
40
|
-
}
|
|
41
|
-
exports.readTemplateFolder = readTemplateFolder;
|
|
42
|
-
async function readTemplateFolderFieldFiles(subFolder) {
|
|
43
|
-
const templateFields = {};
|
|
44
|
-
const folderFileNames = await (0, utils_1.listFolderContent)(subFolder);
|
|
45
|
-
const fieldFileNames = folderFileNames.filter((fileName) => fileName !== 'template.json');
|
|
46
|
-
for (const fieldFileName of fieldFileNames) {
|
|
47
|
-
const fieldName = (0, utils_1.removeFileNameExtension)(fieldFileName);
|
|
48
|
-
const fieldContent = await (0, utils_1.readTextFile)(path.join(subFolder, fieldFileName));
|
|
49
|
-
templateFields[fieldName] = fieldContent;
|
|
50
|
-
}
|
|
51
|
-
return templateFields;
|
|
52
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readTemplateFolder = exports.readTemplateJson = exports.readTemplateFiles = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
async function readTemplateFiles(targetFolder) {
|
|
8
|
+
const fileNames = await (0, utils_1.listFolderContent)(targetFolder);
|
|
9
|
+
const templateFilesByName = {};
|
|
10
|
+
for (const fileName of fileNames) {
|
|
11
|
+
const filePath = path.join(targetFolder, fileName);
|
|
12
|
+
if ((await fs.stat(filePath)).isDirectory()) {
|
|
13
|
+
templateFilesByName[fileName] = await readTemplateFolder(filePath);
|
|
14
|
+
}
|
|
15
|
+
else if (fileName.endsWith('.json')) {
|
|
16
|
+
const templateName = (0, utils_1.removeFileNameExtension)(fileName);
|
|
17
|
+
templateFilesByName[templateName] = await readTemplateJson(filePath);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return templateFilesByName;
|
|
21
|
+
}
|
|
22
|
+
exports.readTemplateFiles = readTemplateFiles;
|
|
23
|
+
async function readTemplateJson(fileName) {
|
|
24
|
+
return (0, utils_1.readJsonFile)(fileName);
|
|
25
|
+
}
|
|
26
|
+
exports.readTemplateJson = readTemplateJson;
|
|
27
|
+
async function readTemplateFolder(subFolder) {
|
|
28
|
+
const templateFile = await readTemplateJson(path.join(subFolder, 'template.json'));
|
|
29
|
+
const templateFields = await readTemplateFolderFieldFiles(subFolder);
|
|
30
|
+
if (!templateFile.fields) {
|
|
31
|
+
templateFile.fields = templateFields;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
templateFile.fields = {
|
|
35
|
+
...templateFile.fields,
|
|
36
|
+
...templateFields,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return templateFile;
|
|
40
|
+
}
|
|
41
|
+
exports.readTemplateFolder = readTemplateFolder;
|
|
42
|
+
async function readTemplateFolderFieldFiles(subFolder) {
|
|
43
|
+
const templateFields = {};
|
|
44
|
+
const folderFileNames = await (0, utils_1.listFolderContent)(subFolder);
|
|
45
|
+
const fieldFileNames = folderFileNames.filter((fileName) => fileName !== 'template.json');
|
|
46
|
+
for (const fieldFileName of fieldFileNames) {
|
|
47
|
+
const fieldName = (0, utils_1.removeFileNameExtension)(fieldFileName);
|
|
48
|
+
const fieldContent = await (0, utils_1.readTextFile)(path.join(subFolder, fieldFileName));
|
|
49
|
+
templateFields[fieldName] = fieldContent;
|
|
50
|
+
}
|
|
51
|
+
return templateFields;
|
|
52
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
2
|
-
export declare class TemplateService {
|
|
3
|
-
private sdk;
|
|
4
|
-
constructor(sdk: OAuth1Client);
|
|
5
|
-
byName(name: string): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
|
|
6
|
-
update(name: string, data: any): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
|
|
7
|
-
create(data: any): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
|
|
8
|
-
}
|
|
1
|
+
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
2
|
+
export declare class TemplateService {
|
|
3
|
+
private sdk;
|
|
4
|
+
constructor(sdk: OAuth1Client);
|
|
5
|
+
byName(name: string): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
|
|
6
|
+
update(name: string, data: any): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
|
|
7
|
+
create(data: any): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
|
|
8
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TemplateService = void 0;
|
|
4
|
-
class TemplateService {
|
|
5
|
-
constructor(sdk) {
|
|
6
|
-
this.sdk = sdk;
|
|
7
|
-
}
|
|
8
|
-
async byName(name) {
|
|
9
|
-
return this.sdk.templates.findByName(name);
|
|
10
|
-
}
|
|
11
|
-
async update(name, data) {
|
|
12
|
-
return this.sdk.templates.update(name, data);
|
|
13
|
-
}
|
|
14
|
-
async create(data) {
|
|
15
|
-
return this.sdk.templates.create(data);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.TemplateService = TemplateService;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemplateService = void 0;
|
|
4
|
+
class TemplateService {
|
|
5
|
+
constructor(sdk) {
|
|
6
|
+
this.sdk = sdk;
|
|
7
|
+
}
|
|
8
|
+
async byName(name) {
|
|
9
|
+
return this.sdk.templates.findByName(name);
|
|
10
|
+
}
|
|
11
|
+
async update(name, data) {
|
|
12
|
+
return this.sdk.templates.update(name, data);
|
|
13
|
+
}
|
|
14
|
+
async create(data) {
|
|
15
|
+
return this.sdk.templates.create(data);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.TemplateService = TemplateService;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TemplateService } from './templateService';
|
|
2
|
-
export declare function uploadTemplate(service: TemplateService, template: any): Promise<void>;
|
|
1
|
+
import { TemplateService } from './templateService';
|
|
2
|
+
export declare function uploadTemplate(service: TemplateService, template: any): Promise<void>;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadTemplate = void 0;
|
|
4
|
-
async function uploadTemplate(service, template) {
|
|
5
|
-
const existingTemplate = await service.byName(template.name);
|
|
6
|
-
try {
|
|
7
|
-
if (!existingTemplate) {
|
|
8
|
-
console.log(`Creating new template '${template.name}'`);
|
|
9
|
-
await service.create(template);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
console.log(`Updating existing template '${template.name}'`);
|
|
13
|
-
await service.update(existingTemplate.id, template);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
catch (err) {
|
|
17
|
-
throw new Error(`Error creating or updating template: ${JSON.stringify(err.response)}`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.uploadTemplate = uploadTemplate;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadTemplate = void 0;
|
|
4
|
+
async function uploadTemplate(service, template) {
|
|
5
|
+
const existingTemplate = await service.byName(template.name);
|
|
6
|
+
try {
|
|
7
|
+
if (!existingTemplate) {
|
|
8
|
+
console.log(`Creating new template '${template.name}'`);
|
|
9
|
+
await service.create(template);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
console.log(`Updating existing template '${template.name}'`);
|
|
13
|
+
await service.update(existingTemplate.id, template);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
throw new Error(`Error creating or updating template: ${JSON.stringify(err.response)}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.uploadTemplate = uploadTemplate;
|