@extrahorizon/exh-cli 1.12.0-dev-137-56e1ad4 → 1.12.0-dev-138-3fed4c5

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.
@@ -1,5 +1,4 @@
1
1
  /// <reference types="yargs" />
2
- import { TemplateService } from './util/templateService';
3
2
  export declare const command = "sync";
4
3
  export declare const desc = "Sync all templates in a directory with the ExH cloud";
5
4
  export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "template" | "path"> & import("yargs").InferredOptionTypes<{
@@ -15,7 +14,7 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
15
14
  };
16
15
  }>>;
17
16
  export declare const handler: ({ path, template }: {
18
- path: any;
19
- template: any;
17
+ path?: string;
18
+ template?: string;
20
19
  }) => Promise<void>;
21
- export declare function syncTargetDir(service: TemplateService, targetDir: string): Promise<void>;
20
+ export declare function syncTargetDir(targetDir: string): Promise<void>;
@@ -6,7 +6,6 @@ const ospath = require("path");
6
6
  const util_1 = require("../../helpers/util");
7
7
  const buildTemplates_1 = require("./util/buildTemplates");
8
8
  const readTemplateFiles_1 = require("./util/readTemplateFiles");
9
- const templateService_1 = require("./util/templateService");
10
9
  const uploadTemplate_1 = require("./util/uploadTemplate");
11
10
  const utils_1 = require("./util/utils");
12
11
  exports.command = 'sync';
@@ -36,30 +35,29 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
36
35
  });
37
36
  exports.builder = builder;
38
37
  const handler = async ({ path, template }) => {
39
- const service = new templateService_1.TemplateService();
40
38
  if (path) {
41
- await syncTargetDir(service, ospath.resolve(path || '.'));
39
+ await syncTargetDir(ospath.resolve(path));
42
40
  return;
43
41
  }
44
42
  let templ = null;
45
- const templateName = (0, utils_1.removeFileNameExtension)(ospath.basename(template));
46
43
  if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
47
44
  templ = await (0, readTemplateFiles_1.readTemplateJson)(template);
48
45
  }
49
46
  else {
50
47
  templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
51
48
  }
52
- await buildAndUploadTemplates(service, { [templateName]: templ });
49
+ const templateName = (0, utils_1.removeFileNameExtension)(ospath.basename(template));
50
+ await buildAndUploadTemplates({ [templateName]: templ });
53
51
  };
54
52
  exports.handler = handler;
55
- async function buildAndUploadTemplates(service, templateObject) {
56
- const templates = await (0, buildTemplates_1.buildTemplates)(service, templateObject);
53
+ async function buildAndUploadTemplates(templateObject) {
54
+ const templates = await (0, buildTemplates_1.buildTemplates)(templateObject);
57
55
  for (const template of templates) {
58
- await (0, uploadTemplate_1.uploadTemplate)(service, template);
56
+ await (0, uploadTemplate_1.uploadTemplate)(template);
59
57
  }
60
58
  }
61
- async function syncTargetDir(service, targetDir) {
59
+ async function syncTargetDir(targetDir) {
62
60
  const templateFilesByName = await (0, readTemplateFiles_1.readTemplateFiles)(targetDir);
63
- await buildAndUploadTemplates(service, templateFilesByName);
61
+ await buildAndUploadTemplates(templateFilesByName);
64
62
  }
65
63
  exports.syncTargetDir = syncTargetDir;
@@ -1,2 +1 @@
1
- import { TemplateService } from './templateService';
2
- export declare function buildTemplates(service: TemplateService, templateFilesByName: any): Promise<any[]>;
1
+ export declare function buildTemplates(templateFilesByName: any): Promise<any[]>;
@@ -1,21 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildTemplates = void 0;
4
- async function buildTemplates(service, templateFilesByName) {
4
+ const templateRepository = require("../../../repositories/templates");
5
+ async function buildTemplates(templateFilesByName) {
5
6
  const templates = [];
6
7
  for (const name of Object.keys(templateFilesByName)) {
7
- templates.push(await buildTemplate(service, name, templateFilesByName));
8
+ templates.push(await buildTemplate(name, templateFilesByName));
8
9
  }
9
10
  return templates;
10
11
  }
11
12
  exports.buildTemplates = buildTemplates;
12
- async function buildTemplate(service, name, templateFilesByName, callChain = []) {
13
+ async function buildTemplate(name, templateFilesByName, callChain = []) {
13
14
  if (callChain.includes(name)) {
14
15
  throw new Error(`Circular extension detected. ${[...callChain, name].reverse().map((n) => `'${n}'`).join(' > ')}`);
15
16
  }
16
17
  let templateFile = templateFilesByName[name];
17
18
  if (templateFile === undefined) {
18
- templateFile = await service.byName(name);
19
+ templateFile = await templateRepository.findByName(name);
19
20
  if (!templateFile) {
20
21
  throw new Error(`Template file dependency ${name} not found!`);
21
22
  }
@@ -23,7 +24,7 @@ async function buildTemplate(service, name, templateFilesByName, callChain = [])
23
24
  const { description, extends_template, schema } = templateFile;
24
25
  let { fields } = templateFile;
25
26
  if (extends_template) {
26
- const extendingTemplate = await buildTemplate(service, extends_template, templateFilesByName, [...callChain, name]);
27
+ const extendingTemplate = await buildTemplate(extends_template, templateFilesByName, [...callChain, name]);
27
28
  const match = (_fullMatch, variableName) => {
28
29
  const value = fields[variableName];
29
30
  if (typeof value === 'undefined') {
@@ -1,2 +1 @@
1
- import { TemplateService } from './templateService';
2
- export declare function uploadTemplate(service: TemplateService, template: any): Promise<void>;
1
+ export declare function uploadTemplate(template: any): Promise<void>;
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.uploadTemplate = void 0;
4
- async function uploadTemplate(service, template) {
5
- const existingTemplate = await service.byName(template.name);
4
+ const templateRepository = require("../../../repositories/templates");
5
+ async function uploadTemplate(template) {
6
+ const existingTemplate = await templateRepository.findByName(template.name);
6
7
  try {
7
8
  if (!existingTemplate) {
8
9
  console.log(`Creating new template '${template.name}'`);
9
- await service.create(template);
10
+ await templateRepository.create(template);
10
11
  }
11
12
  else {
12
13
  console.log(`Updating existing template '${template.name}'`);
13
- await service.update(existingTemplate.id, template);
14
+ await templateRepository.update(existingTemplate.id, template);
14
15
  }
15
16
  }
16
17
  catch (err) {
@@ -1,4 +1,7 @@
1
+ import type { TemplateIn } from '@extrahorizon/javascript-sdk';
1
2
  export declare function findByName(name: string): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
2
3
  export declare function findById(id: string): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
3
4
  export declare function findAll(): Promise<import("@extrahorizon/javascript-sdk").TemplateOut[]>;
5
+ export declare function create(data: TemplateIn): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
6
+ export declare function update(id: string, data: TemplateIn): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
4
7
  export declare function remove(id: string): Promise<import("@extrahorizon/javascript-sdk").AffectedRecords>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.remove = exports.findAll = exports.findById = exports.findByName = void 0;
3
+ exports.remove = exports.update = exports.create = exports.findAll = exports.findById = exports.findByName = void 0;
4
4
  const exh_1 = require("../exh");
5
5
  async function findByName(name) {
6
6
  return await (0, exh_1.getSdk)().templates.findByName(name);
@@ -14,6 +14,14 @@ async function findAll() {
14
14
  return await (0, exh_1.getSdk)().templates.findAll();
15
15
  }
16
16
  exports.findAll = findAll;
17
+ async function create(data) {
18
+ return await (0, exh_1.getSdk)().templates.create(data);
19
+ }
20
+ exports.create = create;
21
+ async function update(id, data) {
22
+ return await (0, exh_1.getSdk)().templates.update(id, data);
23
+ }
24
+ exports.update = update;
17
25
  async function remove(id) {
18
26
  return await (0, exh_1.getSdk)().templates.remove(id);
19
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extrahorizon/exh-cli",
3
- "version": "1.12.0-dev-137-56e1ad4",
3
+ "version": "1.12.0-dev-138-3fed4c5",
4
4
  "main": "build/index.js",
5
5
  "exports": "./build/index.js",
6
6
  "license": "MIT",
@@ -1,7 +0,0 @@
1
- export declare class TemplateService {
2
- private sdk;
3
- constructor();
4
- byName(name: string): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
5
- update(name: string, data: any): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
6
- create(data: any): Promise<import("@extrahorizon/javascript-sdk").TemplateOut>;
7
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TemplateService = void 0;
4
- const exh_1 = require("../../../exh");
5
- class TemplateService {
6
- constructor() {
7
- this.sdk = (0, exh_1.getSdk)();
8
- }
9
- async byName(name) {
10
- return this.sdk.templates.findByName(name);
11
- }
12
- async update(name, data) {
13
- return this.sdk.templates.update(name, data);
14
- }
15
- async create(data) {
16
- return this.sdk.templates.create(data);
17
- }
18
- }
19
- exports.TemplateService = TemplateService;