@extrahorizon/exh-cli 1.12.0-dev-142-82cc6de → 1.12.0-dev-143-312ba3f

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,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const chalk = require("chalk");
5
4
  const util_1 = require("../../helpers/util");
6
- const templateRepository = require("../../repositories/templates");
5
+ const templateService = require("../../services/templates");
7
6
  exports.command = 'delete';
8
7
  exports.desc = 'Delete a template';
9
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
8
+ const builder = (yargs) => (0, util_1.epilogue)(yargs)
9
+ .options({
10
10
  name: {
11
11
  describe: 'Name of the template to delete',
12
12
  type: 'string',
@@ -15,7 +15,8 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
15
15
  describe: 'ID of the template to delete',
16
16
  type: 'string',
17
17
  },
18
- }).check(({ id, name }) => {
18
+ })
19
+ .check(({ id, name }) => {
19
20
  if ((!id && !name) || (id && name)) {
20
21
  throw new Error('Either id or name needs to be provided');
21
22
  }
@@ -23,27 +24,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
23
24
  });
24
25
  exports.builder = builder;
25
26
  const handler = async function list({ name, id }) {
26
- let template = null;
27
- if (name) {
28
- template = await templateRepository.findByName(name);
29
- }
30
- if (id) {
31
- template = await templateRepository.findById(id);
32
- }
33
- if (!template) {
34
- console.log(chalk.red('Template not found!'));
35
- return;
36
- }
37
- try {
38
- const { affectedRecords } = await templateRepository.remove(template.id);
39
- if (!affectedRecords) {
40
- console.log(chalk.red('Failed to remove template', name));
41
- return;
42
- }
43
- console.log('Template deleted');
44
- }
45
- catch (err) {
46
- console.log(chalk.red('Failed to remove template', name));
47
- }
27
+ await templateService.remove(name, id);
48
28
  };
49
29
  exports.handler = handler;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const chalk = require("chalk");
5
4
  const util_1 = require("../../helpers/util");
6
- const templateRepository = require("../../repositories/templates");
5
+ const templateService = require("../../services/templates");
7
6
  exports.command = 'get';
8
7
  exports.desc = 'Fetch a template';
9
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
8
+ const builder = (yargs) => (0, util_1.epilogue)(yargs)
9
+ .options({
10
10
  name: {
11
11
  describe: 'Name of the template',
12
12
  type: 'string',
@@ -15,7 +15,8 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
15
15
  describe: 'ID of the template',
16
16
  type: 'string',
17
17
  },
18
- }).check(({ name, id }) => {
18
+ })
19
+ .check(({ name, id }) => {
19
20
  if ((name && id) || (!name && !id)) {
20
21
  throw new Error('Either name or id should be specified (but not both at the same time)');
21
22
  }
@@ -23,17 +24,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
23
24
  });
24
25
  exports.builder = builder;
25
26
  const handler = async function list({ name, id }) {
26
- let template;
27
- if (name) {
28
- template = await templateRepository.findByName(name);
29
- }
30
- else if (id) {
31
- template = await templateRepository.findById(id);
32
- }
33
- if (!template) {
34
- console.log(chalk.red('Failed to get template!'));
35
- return;
36
- }
37
- console.log(JSON.stringify(template, null, 4));
27
+ await templateService.get(name, id);
38
28
  };
39
29
  exports.handler = handler;
@@ -1,29 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const chalk = require("chalk");
5
4
  const util_1 = require("../../helpers/util");
6
- const templateRepository = require("../../repositories/templates");
5
+ const templateService = require("../../services/templates");
7
6
  exports.command = 'list';
8
7
  exports.desc = 'List all templates';
9
8
  const builder = (yargs) => (0, util_1.epilogue)(yargs);
10
9
  exports.builder = builder;
11
10
  const handler = async function list({ isTTY }) {
12
- const templates = await templateRepository.findAll();
13
- if (templates.length < 1) {
14
- console.log(chalk.red('No templates found'));
15
- return;
16
- }
17
- if (isTTY) {
18
- console.table(templates.map(template => ({
19
- Id: template.id,
20
- Name: template.name,
21
- Description: template.description || '<none>',
22
- 'Last updated': template.updateTimestamp.toISOString(),
23
- })));
24
- }
25
- else {
26
- templates.forEach(template => console.log(template));
27
- }
11
+ await templateService.list(isTTY);
28
12
  };
29
13
  exports.handler = handler;
@@ -17,4 +17,3 @@ export declare const handler: ({ path, template }: {
17
17
  path?: string;
18
18
  template?: string;
19
19
  }) => Promise<void>;
20
- export declare function syncTargetDir(targetDir: string): Promise<void>;
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syncTargetDir = exports.handler = exports.builder = exports.desc = exports.command = void 0;
3
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
4
  const fs = require("fs");
5
5
  const ospath = require("path");
6
6
  const util_1 = require("../../helpers/util");
7
- const buildTemplates_1 = require("./util/buildTemplates");
8
- const readTemplateFiles_1 = require("./util/readTemplateFiles");
9
- const uploadTemplate_1 = require("./util/uploadTemplate");
10
- const utils_1 = require("./util/utils");
7
+ const templateService = require("../../services/templates");
11
8
  exports.command = 'sync';
12
9
  exports.desc = 'Sync all templates in a directory with the ExH cloud';
13
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
10
+ const builder = (yargs) => (0, util_1.epilogue)(yargs)
11
+ .options({
14
12
  path: {
15
13
  demandOption: false,
16
14
  describe: 'Directory containing the templates which need to be synced',
@@ -21,7 +19,8 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
21
19
  describe: 'Template file to sync',
22
20
  type: 'string',
23
21
  },
24
- }).check(({ path, template }) => {
22
+ })
23
+ .check(({ path, template }) => {
25
24
  if (template && !fs.existsSync(ospath.join(process.cwd(), template))) {
26
25
  throw new Error('please provide a valid file path for your template');
27
26
  }
@@ -35,29 +34,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
35
34
  });
36
35
  exports.builder = builder;
37
36
  const handler = async ({ path, template }) => {
38
- if (path) {
39
- await syncTargetDir(ospath.resolve(path));
40
- return;
41
- }
42
- let templ = null;
43
- if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
44
- templ = await (0, readTemplateFiles_1.readTemplateJson)(template);
45
- }
46
- else {
47
- templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
48
- }
49
- const templateName = (0, utils_1.removeFileNameExtension)(ospath.basename(template));
50
- await buildAndUploadTemplates({ [templateName]: templ });
37
+ await templateService.sync(path, template);
51
38
  };
52
39
  exports.handler = handler;
53
- async function buildAndUploadTemplates(templateObject) {
54
- const templates = await (0, buildTemplates_1.buildTemplates)(templateObject);
55
- for (const template of templates) {
56
- await (0, uploadTemplate_1.uploadTemplate)(template);
57
- }
58
- }
59
- async function syncTargetDir(targetDir) {
60
- const templateFilesByName = await (0, readTemplateFiles_1.readTemplateFiles)(targetDir);
61
- await buildAndUploadTemplates(templateFilesByName);
62
- }
63
- exports.syncTargetDir = syncTargetDir;
@@ -0,0 +1,4 @@
1
+ export { sync } from './sync';
2
+ export declare function list(isTTY: boolean): Promise<void>;
3
+ export declare function get(name?: string, id?: string): Promise<void>;
4
+ export declare function remove(name?: string, id?: string): Promise<void>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remove = exports.get = exports.list = exports.sync = void 0;
4
+ const chalk = require("chalk");
5
+ const templateRepository = require("../../repositories/templates");
6
+ var sync_1 = require("./sync");
7
+ Object.defineProperty(exports, "sync", { enumerable: true, get: function () { return sync_1.sync; } });
8
+ async function list(isTTY) {
9
+ const templates = await templateRepository.findAll();
10
+ if (templates.length < 1) {
11
+ console.log(chalk.red('No templates found'));
12
+ return;
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;
@@ -0,0 +1,2 @@
1
+ export declare function sync(path?: string, template?: string): Promise<void>;
2
+ export declare function syncTargetDir(targetDir: string): Promise<void>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncTargetDir = exports.sync = void 0;
4
+ const fs = require("fs");
5
+ const ospath = require("path");
6
+ const buildTemplates_1 = require("./util/buildTemplates");
7
+ const readTemplateFiles_1 = require("./util/readTemplateFiles");
8
+ const uploadTemplate_1 = require("./util/uploadTemplate");
9
+ const utils_1 = require("./util/utils");
10
+ async function sync(path, template) {
11
+ if (path) {
12
+ await syncTargetDir(ospath.resolve(path));
13
+ return;
14
+ }
15
+ let templ = null;
16
+ if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
17
+ templ = await (0, readTemplateFiles_1.readTemplateJson)(template);
18
+ }
19
+ else {
20
+ templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
21
+ }
22
+ const templateName = (0, utils_1.removeFileNameExtension)(ospath.basename(template));
23
+ await buildAndUploadTemplates({ [templateName]: templ });
24
+ }
25
+ exports.sync = sync;
26
+ async function buildAndUploadTemplates(templateObject) {
27
+ const templates = await (0, buildTemplates_1.buildTemplates)(templateObject);
28
+ for (const template of templates) {
29
+ await (0, uploadTemplate_1.uploadTemplate)(template);
30
+ }
31
+ }
32
+ async function syncTargetDir(targetDir) {
33
+ const templateFilesByName = await (0, readTemplateFiles_1.readTemplateFiles)(targetDir);
34
+ await buildAndUploadTemplates(templateFilesByName);
35
+ }
36
+ exports.syncTargetDir = syncTargetDir;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extrahorizon/exh-cli",
3
- "version": "1.12.0-dev-142-82cc6de",
3
+ "version": "1.12.0-dev-143-312ba3f",
4
4
  "main": "build/index.js",
5
5
  "exports": "./build/index.js",
6
6
  "license": "MIT",