@extrahorizon/exh-cli 1.5.0 → 1.5.1-dev-31-9c0409d

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +56 -53
  2. package/README.md +0 -12
  3. package/build/commands/completion.d.ts +5 -5
  4. package/build/commands/completion.js +38 -38
  5. package/build/commands/data/schemas/delete.d.ts +10 -10
  6. package/build/commands/data/schemas/delete.js +29 -29
  7. package/build/commands/data/schemas/list.d.ts +8 -8
  8. package/build/commands/data/schemas/list.js +20 -20
  9. package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -3
  10. package/build/commands/data/schemas/sync/statusHelpers.js +49 -49
  11. package/build/commands/data/schemas/sync.d.ts +35 -35
  12. package/build/commands/data/schemas/sync.js +72 -72
  13. package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -1
  14. package/build/commands/data/schemas/util/listFilesInDir.js +25 -25
  15. package/build/commands/data/schemas/util/metaschema.json +455 -455
  16. package/build/commands/data/schemas/util/readJson.d.ts +1 -1
  17. package/build/commands/data/schemas/util/readJson.js +11 -11
  18. package/build/commands/data/schemas/util/schemaverify.d.ts +28 -28
  19. package/build/commands/data/schemas/util/schemaverify.js +202 -202
  20. package/build/commands/data/schemas/util/syncSchema.d.ts +20 -20
  21. package/build/commands/data/schemas/util/syncSchema.js +276 -276
  22. package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -1
  23. package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -40
  24. package/build/commands/data/schemas/verify.d.ts +18 -18
  25. package/build/commands/data/schemas/verify.js +82 -82
  26. package/build/commands/data/schemas.d.ts +5 -5
  27. package/build/commands/data/schemas.js +10 -10
  28. package/build/commands/data.d.ts +5 -5
  29. package/build/commands/data.js +10 -10
  30. package/build/commands/dispatchers/sync.d.ts +21 -21
  31. package/build/commands/dispatchers/sync.js +24 -24
  32. package/build/commands/dispatchers.d.ts +5 -5
  33. package/build/commands/dispatchers.js +10 -10
  34. package/build/commands/localizations/sync.d.ts +29 -0
  35. package/build/commands/localizations/sync.js +59 -0
  36. package/build/commands/localizations/utils/assertValidKey.d.ts +1 -0
  37. package/build/commands/localizations/utils/assertValidKey.js +10 -0
  38. package/build/commands/localizations/utils/assertValidLanguageCode.d.ts +2 -0
  39. package/build/commands/localizations/utils/assertValidLanguageCode.js +21 -0
  40. package/build/commands/localizations/utils/fetchLocalizations.d.ts +2 -0
  41. package/build/commands/localizations/utils/fetchLocalizations.js +20 -0
  42. package/build/commands/localizations/utils/readLocalizationFiles.d.ts +6 -0
  43. package/build/commands/localizations/utils/readLocalizationFiles.js +39 -0
  44. package/build/commands/localizations/utils/syncLocalizations.d.ts +2 -0
  45. package/build/commands/localizations/utils/syncLocalizations.js +46 -0
  46. package/build/commands/login.d.ts +37 -37
  47. package/build/commands/login.js +59 -59
  48. package/build/commands/sync.d.ts +55 -55
  49. package/build/commands/sync.js +107 -107
  50. package/build/commands/tasks/createrepo.d.ts +22 -22
  51. package/build/commands/tasks/createrepo.js +70 -70
  52. package/build/commands/tasks/delete.d.ts +10 -10
  53. package/build/commands/tasks/delete.js +29 -29
  54. package/build/commands/tasks/list.d.ts +8 -8
  55. package/build/commands/tasks/list.js +27 -27
  56. package/build/commands/tasks/sync.d.ts +56 -56
  57. package/build/commands/tasks/sync.js +122 -122
  58. package/build/commands/tasks/taskConfig.d.ts +24 -24
  59. package/build/commands/tasks/taskConfig.js +169 -169
  60. package/build/commands/tasks/util.d.ts +1 -1
  61. package/build/commands/tasks/util.js +27 -27
  62. package/build/commands/tasks.d.ts +5 -5
  63. package/build/commands/tasks.js +10 -10
  64. package/build/commands/templates/delete.d.ts +19 -19
  65. package/build/commands/templates/delete.js +48 -48
  66. package/build/commands/templates/get.d.ts +19 -19
  67. package/build/commands/templates/get.js +37 -37
  68. package/build/commands/templates/list.d.ts +9 -9
  69. package/build/commands/templates/list.js +25 -25
  70. package/build/commands/templates/sync.d.ts +22 -22
  71. package/build/commands/templates/sync.js +65 -65
  72. package/build/commands/templates/util/buildTemplates.d.ts +2 -2
  73. package/build/commands/templates/util/buildTemplates.js +50 -50
  74. package/build/commands/templates/util/readTemplateFiles.d.ts +3 -3
  75. package/build/commands/templates/util/readTemplateFiles.js +52 -52
  76. package/build/commands/templates/util/templateService.d.ts +8 -8
  77. package/build/commands/templates/util/templateService.js +18 -18
  78. package/build/commands/templates/util/uploadTemplate.d.ts +2 -2
  79. package/build/commands/templates/util/uploadTemplate.js +20 -20
  80. package/build/commands/templates/util/utils.d.ts +4 -4
  81. package/build/commands/templates/util/utils.js +22 -22
  82. package/build/commands/templates.d.ts +5 -5
  83. package/build/commands/templates.js +10 -10
  84. package/build/constants.d.ts +13 -13
  85. package/build/constants.js +37 -37
  86. package/build/exh.d.ts +3 -3
  87. package/build/exh.js +65 -65
  88. package/build/helpers/error.d.ts +2 -2
  89. package/build/helpers/error.js +6 -6
  90. package/build/helpers/repoConfig.d.ts +2 -2
  91. package/build/helpers/repoConfig.js +60 -60
  92. package/build/helpers/util.d.ts +4 -3
  93. package/build/helpers/util.js +42 -36
  94. package/build/index.d.ts +2 -2
  95. package/build/index.js +33 -33
  96. package/build/repositories/dispatchers.d.ts +8 -8
  97. package/build/repositories/dispatchers.js +31 -31
  98. package/build/repositories/functions.d.ts +24 -24
  99. package/build/repositories/functions.js +28 -28
  100. package/build/repositories/schemas.d.ts +44 -44
  101. package/build/repositories/schemas.js +86 -86
  102. package/build/services/dispatchers.d.ts +3 -3
  103. package/build/services/dispatchers.js +132 -132
  104. package/package.json +53 -53
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncLocalizations = void 0;
4
+ const chalk = require("chalk");
5
+ const getMissingLocalizations = (configLocalizations, fetchedLocalizations) => configLocalizations.filter(configLocalization => fetchedLocalizations.find(fetchedLocalization => fetchedLocalization.key === configLocalization.key) === undefined);
6
+ const getChangedLocalizations = (configLocalizations, fetchedLocalizations) => {
7
+ const changedLocalizations = [];
8
+ for (const configLocalization of configLocalizations) {
9
+ const knownLocalization = fetchedLocalizations.find(fetchedLocalization => fetchedLocalization.key === configLocalization.key);
10
+ if (knownLocalization) {
11
+ const localizationUpdateData = {
12
+ key: configLocalization.key,
13
+ text: {},
14
+ };
15
+ for (const [newLanguage, newText] of Object.entries(configLocalization.text)) {
16
+ const knownText = knownLocalization.text[newLanguage];
17
+ if (!knownText || knownText !== newText) {
18
+ localizationUpdateData.text[newLanguage] = newText;
19
+ }
20
+ }
21
+ if (Object.keys(localizationUpdateData.text).length > 0) {
22
+ changedLocalizations.push(localizationUpdateData);
23
+ }
24
+ }
25
+ }
26
+ return changedLocalizations;
27
+ };
28
+ const syncLocalizations = async (sdk, configLocalizations, fetchedLocalizations) => {
29
+ const localizationsToCreate = getMissingLocalizations(configLocalizations, fetchedLocalizations);
30
+ const localizationsToUpdate = getChangedLocalizations(configLocalizations, fetchedLocalizations);
31
+ console.log(`- Creating of ${localizationsToCreate.length} new localization key(s).`);
32
+ if (localizationsToCreate.length > 0) {
33
+ await sdk.localizations.create({
34
+ localizations: localizationsToCreate,
35
+ });
36
+ console.log(chalk.green('Successful!'));
37
+ }
38
+ console.log(`- Updating of ${localizationsToUpdate.length} new localization key(s).`);
39
+ if (localizationsToUpdate.length > 0) {
40
+ await sdk.localizations.update({
41
+ localizations: localizationsToUpdate,
42
+ });
43
+ console.log(chalk.green('Successful!'));
44
+ }
45
+ };
46
+ exports.syncLocalizations = syncLocalizations;
@@ -1,37 +1,37 @@
1
- /// <reference types="yargs" />
2
- export declare const command = "login";
3
- export declare const desc = "Retrieve credentials from ExH";
4
- export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "password" | "host" | "email" | "consumerKey" | "consumerSecret"> & import("yargs").InferredOptionTypes<{
5
- host: {
6
- demandOption: true;
7
- type: "string";
8
- describe: string;
9
- };
10
- email: {
11
- demandOption: true;
12
- type: "string";
13
- describe: string;
14
- };
15
- password: {
16
- demandOption: true;
17
- type: "string";
18
- describe: string;
19
- };
20
- consumerKey: {
21
- demandOption: true;
22
- type: "string";
23
- describe: string;
24
- };
25
- consumerSecret: {
26
- demandOption: true;
27
- type: "string";
28
- describe: string;
29
- };
30
- }>>;
31
- export declare const handler: ({ host, email, password, consumerKey, consumerSecret }: {
32
- host: string;
33
- email: string;
34
- password: string;
35
- consumerKey: string;
36
- consumerSecret: string;
37
- }) => Promise<void>;
1
+ /// <reference types="yargs" />
2
+ export declare const command = "login";
3
+ export declare const desc = "Retrieve credentials from ExH";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "password" | "host" | "email" | "consumerKey" | "consumerSecret"> & import("yargs").InferredOptionTypes<{
5
+ host: {
6
+ demandOption: true;
7
+ type: "string";
8
+ describe: string;
9
+ };
10
+ email: {
11
+ demandOption: true;
12
+ type: "string";
13
+ describe: string;
14
+ };
15
+ password: {
16
+ demandOption: true;
17
+ type: "string";
18
+ describe: string;
19
+ };
20
+ consumerKey: {
21
+ demandOption: true;
22
+ type: "string";
23
+ describe: string;
24
+ };
25
+ consumerSecret: {
26
+ demandOption: true;
27
+ type: "string";
28
+ describe: string;
29
+ };
30
+ }>>;
31
+ export declare const handler: ({ host, email, password, consumerKey, consumerSecret }: {
32
+ host: string;
33
+ email: string;
34
+ password: string;
35
+ consumerKey: string;
36
+ consumerSecret: string;
37
+ }) => Promise<void>;
@@ -1,59 +1,59 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const fs = require("fs/promises");
5
- const chalk = require("chalk");
6
- const constants_1 = require("../constants");
7
- const exh_1 = require("../exh");
8
- const util_1 = require("../helpers/util");
9
- exports.command = 'login';
10
- exports.desc = 'Retrieve credentials from ExH';
11
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
12
- host: {
13
- demandOption: true,
14
- type: 'string',
15
- describe: 'the address of your ExH cloud instance (eg. https://api.dev.my-instance.extrahorizon.io)',
16
- },
17
- email: {
18
- demandOption: true,
19
- type: 'string',
20
- describe: 'email address of your ExH account',
21
- },
22
- password: {
23
- demandOption: true,
24
- type: 'string',
25
- describe: 'password of your ExH account',
26
- },
27
- consumerKey: {
28
- demandOption: true,
29
- type: 'string',
30
- describe: 'Consumer key',
31
- },
32
- consumerSecret: {
33
- demandOption: true,
34
- type: 'string',
35
- describe: 'Consumer secret',
36
- },
37
- });
38
- exports.builder = builder;
39
- const handler = async ({ host, email, password, consumerKey, consumerSecret }) => {
40
- const sdk = (0, exh_1.sdkInitOnly)(host, consumerKey, consumerSecret);
41
- const response = await sdk.auth.authenticate({
42
- email,
43
- password,
44
- });
45
- try {
46
- await fs.stat(constants_1.EXH_CONFIG_FILE_DIR);
47
- }
48
- catch (err) {
49
- await fs.mkdir(constants_1.EXH_CONFIG_FILE_DIR);
50
- }
51
- await fs.writeFile(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
52
- API_OAUTH_CONSUMER_KEY=${consumerKey}
53
- API_OAUTH_CONSUMER_SECRET=${consumerSecret}
54
- API_OAUTH_TOKEN=${response.token}
55
- API_OAUTH_TOKEN_SECRET=${response.tokenSecret}
56
- `);
57
- console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
58
- };
59
- 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 fs = require("fs/promises");
5
+ const chalk = require("chalk");
6
+ const constants_1 = require("../constants");
7
+ const exh_1 = require("../exh");
8
+ const util_1 = require("../helpers/util");
9
+ exports.command = 'login';
10
+ exports.desc = 'Retrieve credentials from ExH';
11
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
12
+ host: {
13
+ demandOption: true,
14
+ type: 'string',
15
+ describe: 'the address of your ExH cloud instance (eg. https://api.dev.my-instance.extrahorizon.io)',
16
+ },
17
+ email: {
18
+ demandOption: true,
19
+ type: 'string',
20
+ describe: 'email address of your ExH account',
21
+ },
22
+ password: {
23
+ demandOption: true,
24
+ type: 'string',
25
+ describe: 'password of your ExH account',
26
+ },
27
+ consumerKey: {
28
+ demandOption: true,
29
+ type: 'string',
30
+ describe: 'Consumer key',
31
+ },
32
+ consumerSecret: {
33
+ demandOption: true,
34
+ type: 'string',
35
+ describe: 'Consumer secret',
36
+ },
37
+ });
38
+ exports.builder = builder;
39
+ const handler = async ({ host, email, password, consumerKey, consumerSecret }) => {
40
+ const sdk = (0, exh_1.sdkInitOnly)(host, consumerKey, consumerSecret);
41
+ const response = await sdk.auth.authenticate({
42
+ email,
43
+ password,
44
+ });
45
+ try {
46
+ await fs.stat(constants_1.EXH_CONFIG_FILE_DIR);
47
+ }
48
+ catch (err) {
49
+ await fs.mkdir(constants_1.EXH_CONFIG_FILE_DIR);
50
+ }
51
+ await fs.writeFile(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
52
+ API_OAUTH_CONSUMER_KEY=${consumerKey}
53
+ API_OAUTH_CONSUMER_SECRET=${consumerSecret}
54
+ API_OAUTH_TOKEN=${response.token}
55
+ API_OAUTH_TOKEN_SECRET=${response.tokenSecret}
56
+ `);
57
+ console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
58
+ };
59
+ exports.handler = handler;
@@ -1,55 +1,55 @@
1
- /// <reference types="yargs" />
2
- export declare const command = "sync";
3
- export declare const desc = "Upload all schemas, templates & tasks to the cloud environment";
4
- export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "path" | "schemas" | "tasks" | "dispatchers" | "templates" | "cleanDispatchers" | "ignoreSchemaVerificationErrors"> & import("yargs").InferredOptionTypes<{
5
- path: {
6
- demandOption: false;
7
- describe: string;
8
- type: "string";
9
- };
10
- schemas: {
11
- demandOption: false;
12
- describe: string;
13
- type: "boolean";
14
- default: boolean;
15
- };
16
- tasks: {
17
- demandOption: false;
18
- describe: string;
19
- type: "boolean";
20
- default: boolean;
21
- };
22
- templates: {
23
- demandOption: false;
24
- describe: string;
25
- type: "boolean";
26
- default: boolean;
27
- };
28
- dispatchers: {
29
- demandOption: false;
30
- describe: string;
31
- type: "boolean";
32
- default: boolean;
33
- };
34
- cleanDispatchers: {
35
- demandOption: false;
36
- describe: string;
37
- type: "boolean";
38
- };
39
- ignoreSchemaVerificationErrors: {
40
- demandOption: false;
41
- describe: string;
42
- type: "boolean";
43
- default: boolean;
44
- };
45
- }>>;
46
- export declare const handler: ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, ignoreSchemaVerificationErrors }: {
47
- sdk: any;
48
- path: any;
49
- schemas: any;
50
- tasks: any;
51
- templates: any;
52
- dispatchers: any;
53
- cleanDispatchers: any;
54
- ignoreSchemaVerificationErrors: any;
55
- }) => Promise<void>;
1
+ /// <reference types="yargs" />
2
+ export declare const command = "sync";
3
+ export declare const desc = "Upload all schemas, templates & tasks to the cloud environment";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "path" | "schemas" | "tasks" | "dispatchers" | "templates" | "cleanDispatchers" | "ignoreSchemaVerificationErrors"> & import("yargs").InferredOptionTypes<{
5
+ path: {
6
+ demandOption: false;
7
+ describe: string;
8
+ type: "string";
9
+ };
10
+ schemas: {
11
+ demandOption: false;
12
+ describe: string;
13
+ type: "boolean";
14
+ default: boolean;
15
+ };
16
+ tasks: {
17
+ demandOption: false;
18
+ describe: string;
19
+ type: "boolean";
20
+ default: boolean;
21
+ };
22
+ templates: {
23
+ demandOption: false;
24
+ describe: string;
25
+ type: "boolean";
26
+ default: boolean;
27
+ };
28
+ dispatchers: {
29
+ demandOption: false;
30
+ describe: string;
31
+ type: "boolean";
32
+ default: boolean;
33
+ };
34
+ cleanDispatchers: {
35
+ demandOption: false;
36
+ describe: string;
37
+ type: "boolean";
38
+ };
39
+ ignoreSchemaVerificationErrors: {
40
+ demandOption: false;
41
+ describe: string;
42
+ type: "boolean";
43
+ default: boolean;
44
+ };
45
+ }>>;
46
+ export declare const handler: ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, ignoreSchemaVerificationErrors }: {
47
+ sdk: any;
48
+ path: any;
49
+ schemas: any;
50
+ tasks: any;
51
+ templates: any;
52
+ dispatchers: any;
53
+ cleanDispatchers: any;
54
+ ignoreSchemaVerificationErrors: any;
55
+ }) => Promise<void>;
@@ -1,107 +1,107 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const fs_1 = require("fs");
5
- const fs = require("fs/promises");
6
- const ospath = require("path");
7
- const chalk = require("chalk");
8
- const repoConfig_1 = require("../helpers/repoConfig");
9
- const util_1 = require("../helpers/util");
10
- const dispatchers_1 = require("../services/dispatchers");
11
- const sync_1 = require("./data/schemas/sync");
12
- const sync_2 = require("./tasks/sync");
13
- const sync_3 = require("./templates/sync");
14
- exports.command = 'sync';
15
- exports.desc = 'Upload all schemas, templates & tasks to the cloud environment';
16
- const builder = (yargs) => (0, util_1.epilogue)(yargs)
17
- .options({
18
- path: {
19
- demandOption: false,
20
- describe: `Path to folder which needs to be synchronized. The target folder should contain a ${repoConfig_1.REPO_CONFIG_FILE} file.
21
- If not, the local directory is assumed with a default configuration which assumes tasks are in a 'tasks' folder, schemas in a 'schemas' folder and templates in a 'templates' folder`,
22
- type: 'string',
23
- },
24
- schemas: {
25
- demandOption: false,
26
- describe: 'Sync schemas only',
27
- type: 'boolean',
28
- default: false,
29
- },
30
- tasks: {
31
- demandOption: false,
32
- describe: 'Sync tasks only',
33
- type: 'boolean',
34
- default: false,
35
- },
36
- templates: {
37
- demandOption: false,
38
- describe: 'Sync templates only',
39
- type: 'boolean',
40
- default: false,
41
- },
42
- dispatchers: {
43
- demandOption: false,
44
- describe: 'Sync Dispatchers only',
45
- type: 'boolean',
46
- default: false,
47
- },
48
- cleanDispatchers: {
49
- demandOption: false,
50
- describe: 'Delete Dispatchers created using the CLI, that are no longer present in the local Dispatcher file',
51
- type: 'boolean',
52
- },
53
- ignoreSchemaVerificationErrors: {
54
- demandOption: false,
55
- describe: 'Allow schema synchronization to proceed with validation errors.',
56
- type: 'boolean',
57
- default: false,
58
- },
59
- }).check(async ({ path }) => {
60
- if (path !== undefined) {
61
- try {
62
- await fs.access(ospath.join(process.cwd(), path, repoConfig_1.REPO_CONFIG_FILE));
63
- }
64
- catch (err) {
65
- throw new Error(`Repository config file not found at ${path}`);
66
- }
67
- if (!(await fs.stat(ospath.join(process.cwd(), path, repoConfig_1.REPO_CONFIG_FILE))).isFile()) {
68
- throw new Error('please provide a valid repository config file');
69
- }
70
- }
71
- return true;
72
- });
73
- exports.builder = builder;
74
- const handler = async ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, ignoreSchemaVerificationErrors }) => {
75
- const targetPath = ospath.join(process.cwd(), path || '.');
76
- const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath, true);
77
- const syncAll = !(schemas || tasks || templates || dispatchers);
78
- if ((syncAll || schemas) && cfg.schemas) {
79
- console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
80
- for (const schema of cfg.schemas) {
81
- await (0, sync_1.syncTargetDir)(sdk, ospath.join(targetPath, schema), undefined, ignoreSchemaVerificationErrors);
82
- }
83
- }
84
- if ((syncAll || templates) && cfg.templates) {
85
- console.log(chalk.green('\n ⚙️ Syncing templates...'));
86
- for (const template of cfg.templates) {
87
- await (0, sync_3.handler)({ sdk, path: ospath.join(targetPath, template), template: null });
88
- }
89
- }
90
- if ((syncAll || tasks) && cfg.tasks) {
91
- console.log(chalk.green('\n ⚙️ Syncing tasks...'));
92
- for (const task of cfg.tasks) {
93
- await (0, sync_2.handler)({ sdk, path: ospath.join(targetPath, task) });
94
- }
95
- }
96
- if ((syncAll || dispatchers)) {
97
- const dispatchersPath = ospath.join(targetPath, 'dispatchers.json');
98
- const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
99
- if (isValidPath) {
100
- await (0, dispatchers_1.sync)(sdk, dispatchersPath, cleanDispatchers);
101
- }
102
- else {
103
- console.log(chalk.yellow('Warning: dispatchers.json not found'));
104
- }
105
- }
106
- };
107
- 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 fs_1 = require("fs");
5
+ const fs = require("fs/promises");
6
+ const ospath = require("path");
7
+ const chalk = require("chalk");
8
+ const repoConfig_1 = require("../helpers/repoConfig");
9
+ const util_1 = require("../helpers/util");
10
+ const dispatchers_1 = require("../services/dispatchers");
11
+ const sync_1 = require("./data/schemas/sync");
12
+ const sync_2 = require("./tasks/sync");
13
+ const sync_3 = require("./templates/sync");
14
+ exports.command = 'sync';
15
+ exports.desc = 'Upload all schemas, templates & tasks to the cloud environment';
16
+ const builder = (yargs) => (0, util_1.epilogue)(yargs)
17
+ .options({
18
+ path: {
19
+ demandOption: false,
20
+ describe: `Path to folder which needs to be synchronized. The target folder should contain a ${repoConfig_1.REPO_CONFIG_FILE} file.
21
+ If not, the local directory is assumed with a default configuration which assumes tasks are in a 'tasks' folder, schemas in a 'schemas' folder and templates in a 'templates' folder`,
22
+ type: 'string',
23
+ },
24
+ schemas: {
25
+ demandOption: false,
26
+ describe: 'Sync schemas only',
27
+ type: 'boolean',
28
+ default: false,
29
+ },
30
+ tasks: {
31
+ demandOption: false,
32
+ describe: 'Sync tasks only',
33
+ type: 'boolean',
34
+ default: false,
35
+ },
36
+ templates: {
37
+ demandOption: false,
38
+ describe: 'Sync templates only',
39
+ type: 'boolean',
40
+ default: false,
41
+ },
42
+ dispatchers: {
43
+ demandOption: false,
44
+ describe: 'Sync Dispatchers only',
45
+ type: 'boolean',
46
+ default: false,
47
+ },
48
+ cleanDispatchers: {
49
+ demandOption: false,
50
+ describe: 'Delete Dispatchers created using the CLI, that are no longer present in the local Dispatcher file',
51
+ type: 'boolean',
52
+ },
53
+ ignoreSchemaVerificationErrors: {
54
+ demandOption: false,
55
+ describe: 'Allow schema synchronization to proceed with validation errors.',
56
+ type: 'boolean',
57
+ default: false,
58
+ },
59
+ }).check(async ({ path }) => {
60
+ if (path !== undefined) {
61
+ try {
62
+ await fs.access(ospath.join(process.cwd(), path, repoConfig_1.REPO_CONFIG_FILE));
63
+ }
64
+ catch (err) {
65
+ throw new Error(`Repository config file not found at ${path}`);
66
+ }
67
+ if (!(await fs.stat(ospath.join(process.cwd(), path, repoConfig_1.REPO_CONFIG_FILE))).isFile()) {
68
+ throw new Error('please provide a valid repository config file');
69
+ }
70
+ }
71
+ return true;
72
+ });
73
+ exports.builder = builder;
74
+ const handler = async ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, ignoreSchemaVerificationErrors }) => {
75
+ const targetPath = ospath.join(process.cwd(), path || '.');
76
+ const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath, true);
77
+ const syncAll = !(schemas || tasks || templates || dispatchers);
78
+ if ((syncAll || schemas) && cfg.schemas) {
79
+ console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
80
+ for (const schema of cfg.schemas) {
81
+ await (0, sync_1.syncTargetDir)(sdk, ospath.join(targetPath, schema), undefined, ignoreSchemaVerificationErrors);
82
+ }
83
+ }
84
+ if ((syncAll || templates) && cfg.templates) {
85
+ console.log(chalk.green('\n ⚙️ Syncing templates...'));
86
+ for (const template of cfg.templates) {
87
+ await (0, sync_3.handler)({ sdk, path: ospath.join(targetPath, template), template: null });
88
+ }
89
+ }
90
+ if ((syncAll || tasks) && cfg.tasks) {
91
+ console.log(chalk.green('\n ⚙️ Syncing tasks...'));
92
+ for (const task of cfg.tasks) {
93
+ await (0, sync_2.handler)({ sdk, path: ospath.join(targetPath, task) });
94
+ }
95
+ }
96
+ if ((syncAll || dispatchers)) {
97
+ const dispatchersPath = ospath.join(targetPath, 'dispatchers.json');
98
+ const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
99
+ if (isValidPath) {
100
+ await (0, dispatchers_1.sync)(sdk, dispatchersPath, cleanDispatchers);
101
+ }
102
+ else {
103
+ console.log(chalk.yellow('Warning: dispatchers.json not found'));
104
+ }
105
+ }
106
+ };
107
+ exports.handler = handler;
@@ -1,22 +1,22 @@
1
- /// <reference types="yargs" />
2
- export declare const command = "create-repo <name>";
3
- export declare const desc = "Create a new task repository";
4
- export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{
5
- name: string;
6
- }, "repo" | "git"> & import("yargs").InferredOptionTypes<{
7
- repo: {
8
- description: string;
9
- type: "string";
10
- default: string;
11
- };
12
- git: {
13
- description: string;
14
- type: "boolean";
15
- default: boolean;
16
- };
17
- }>>;
18
- export declare const handler: ({ name, repo, git }: {
19
- name: any;
20
- repo: any;
21
- git: any;
22
- }) => Promise<void>;
1
+ /// <reference types="yargs" />
2
+ export declare const command = "create-repo <name>";
3
+ export declare const desc = "Create a new task repository";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{
5
+ name: string;
6
+ }, "repo" | "git"> & import("yargs").InferredOptionTypes<{
7
+ repo: {
8
+ description: string;
9
+ type: "string";
10
+ default: string;
11
+ };
12
+ git: {
13
+ description: string;
14
+ type: "boolean";
15
+ default: boolean;
16
+ };
17
+ }>>;
18
+ export declare const handler: ({ name, repo, git }: {
19
+ name: any;
20
+ repo: any;
21
+ git: any;
22
+ }) => Promise<void>;