@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
@@ -1,18 +1,18 @@
1
- /// <reference types="yargs" />
2
- export declare const command = "verify";
3
- export declare const desc = "Syntactically verify a local schema";
4
- export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "file" | "dir"> & import("yargs").InferredOptionTypes<{
5
- file: {
6
- describe: string;
7
- type: "string";
8
- };
9
- dir: {
10
- describe: string;
11
- type: "string";
12
- };
13
- }>>;
14
- export declare const handler: ({ file, dir, ignoreVerificationErrors }: {
15
- file: any;
16
- dir: any;
17
- ignoreVerificationErrors: any;
18
- }) => Promise<void>;
1
+ /// <reference types="yargs" />
2
+ export declare const command = "verify";
3
+ export declare const desc = "Syntactically verify a local schema";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "file" | "dir"> & import("yargs").InferredOptionTypes<{
5
+ file: {
6
+ describe: string;
7
+ type: "string";
8
+ };
9
+ dir: {
10
+ describe: string;
11
+ type: "string";
12
+ };
13
+ }>>;
14
+ export declare const handler: ({ file, dir, ignoreVerificationErrors }: {
15
+ file: any;
16
+ dir: any;
17
+ ignoreVerificationErrors: any;
18
+ }) => Promise<void>;
@@ -1,82 +1,82 @@
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");
5
- const path = require("path");
6
- const ajv_1 = require("ajv");
7
- const chalk = require("chalk");
8
- const error_1 = require("../../../helpers/error");
9
- const util_1 = require("../../../helpers/util");
10
- const listFilesInDir_1 = require("./util/listFilesInDir");
11
- const metaschema = require("./util/metaschema.json");
12
- const schemaverify_1 = require("./util/schemaverify");
13
- exports.command = 'verify';
14
- exports.desc = 'Syntactically verify a local schema';
15
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
16
- file: {
17
- describe: 'schema json file which needs to be verified',
18
- type: 'string',
19
- },
20
- dir: {
21
- describe: 'directory containing schemas to be verified',
22
- type: 'string',
23
- },
24
- }).check(({ file, dir }) => {
25
- if (file && (!fs.existsSync(path.resolve(file)) || !fs.lstatSync(path.resolve(file)).isFile())) {
26
- throw new Error('Schema file does not exist, please make sure you provided the correct file path');
27
- }
28
- if (dir === undefined && file === undefined) {
29
- throw new Error('Must either specify --file or --dir');
30
- }
31
- else if (dir !== undefined && file !== undefined) {
32
- throw new Error('Cannot specify both --file and --dir');
33
- }
34
- return true;
35
- });
36
- exports.builder = builder;
37
- const handler = async ({ file, dir, ignoreVerificationErrors }) => {
38
- let files = [];
39
- if (dir) {
40
- files = await (0, listFilesInDir_1.flatListFiles)(dir, '.json');
41
- }
42
- else {
43
- files = [file];
44
- }
45
- const checkFile = (schemaPath) => {
46
- let schema = {};
47
- console.log(chalk.bold('Checking', schemaPath));
48
- try {
49
- schema = require(path.resolve(schemaPath));
50
- }
51
- catch (err) {
52
- console.log(chalk.red(`Failed to load schema file ${file}. Possibly not a valid JSON file`));
53
- console.log(err);
54
- return;
55
- }
56
- const ajv = new ajv_1.default();
57
- for (const result of (new schemaverify_1.SchemaVerify(ajv, schema, metaschema)).RunChecks()) {
58
- if (result.ok) {
59
- console.log(chalk.green(`${result.test}... ✓`));
60
- }
61
- else {
62
- console.log(chalk.red(`${result.test}... x`));
63
- for (const error of result.errors) {
64
- if (typeof error === 'object') {
65
- console.log('\t', chalk.red(JSON.stringify(error, null, 4)));
66
- }
67
- else {
68
- console.log('\t', chalk.red(error));
69
- }
70
- }
71
- if (!ignoreVerificationErrors) {
72
- throw new error_1.CommandError(`Schema ${schemaPath} contains error, please fix`);
73
- }
74
- }
75
- }
76
- console.log();
77
- };
78
- for (const f of files) {
79
- checkFile(f);
80
- }
81
- };
82
- 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");
5
+ const path = require("path");
6
+ const ajv_1 = require("ajv");
7
+ const chalk = require("chalk");
8
+ const error_1 = require("../../../helpers/error");
9
+ const util_1 = require("../../../helpers/util");
10
+ const listFilesInDir_1 = require("./util/listFilesInDir");
11
+ const metaschema = require("./util/metaschema.json");
12
+ const schemaverify_1 = require("./util/schemaverify");
13
+ exports.command = 'verify';
14
+ exports.desc = 'Syntactically verify a local schema';
15
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
16
+ file: {
17
+ describe: 'schema json file which needs to be verified',
18
+ type: 'string',
19
+ },
20
+ dir: {
21
+ describe: 'directory containing schemas to be verified',
22
+ type: 'string',
23
+ },
24
+ }).check(({ file, dir }) => {
25
+ if (file && (!fs.existsSync(path.resolve(file)) || !fs.lstatSync(path.resolve(file)).isFile())) {
26
+ throw new Error('Schema file does not exist, please make sure you provided the correct file path');
27
+ }
28
+ if (dir === undefined && file === undefined) {
29
+ throw new Error('Must either specify --file or --dir');
30
+ }
31
+ else if (dir !== undefined && file !== undefined) {
32
+ throw new Error('Cannot specify both --file and --dir');
33
+ }
34
+ return true;
35
+ });
36
+ exports.builder = builder;
37
+ const handler = async ({ file, dir, ignoreVerificationErrors }) => {
38
+ let files = [];
39
+ if (dir) {
40
+ files = await (0, listFilesInDir_1.flatListFiles)(dir, '.json');
41
+ }
42
+ else {
43
+ files = [file];
44
+ }
45
+ const checkFile = (schemaPath) => {
46
+ let schema = {};
47
+ console.log(chalk.bold('Checking', schemaPath));
48
+ try {
49
+ schema = require(path.resolve(schemaPath));
50
+ }
51
+ catch (err) {
52
+ console.log(chalk.red(`Failed to load schema file ${file}. Possibly not a valid JSON file`));
53
+ console.log(err);
54
+ return;
55
+ }
56
+ const ajv = new ajv_1.default();
57
+ for (const result of (new schemaverify_1.SchemaVerify(ajv, schema, metaschema)).RunChecks()) {
58
+ if (result.ok) {
59
+ console.log(chalk.green(`${result.test}... ✓`));
60
+ }
61
+ else {
62
+ console.log(chalk.red(`${result.test}... x`));
63
+ for (const error of result.errors) {
64
+ if (typeof error === 'object') {
65
+ console.log('\t', chalk.red(JSON.stringify(error, null, 4)));
66
+ }
67
+ else {
68
+ console.log('\t', chalk.red(error));
69
+ }
70
+ }
71
+ if (!ignoreVerificationErrors) {
72
+ throw new error_1.CommandError(`Schema ${schemaPath} contains error, please fix`);
73
+ }
74
+ }
75
+ }
76
+ console.log();
77
+ };
78
+ for (const f of files) {
79
+ checkFile(f);
80
+ }
81
+ };
82
+ exports.handler = handler;
@@ -1,5 +1,5 @@
1
- /// <reference types="yargs" />
2
- export declare const command = "schemas <command>";
3
- export declare const desc = "Manage data schemas";
4
- export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
5
- export declare const handler: () => void;
1
+ /// <reference types="yargs" />
2
+ export declare const command = "schemas <command>";
3
+ export declare const desc = "Manage data schemas";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
5
+ export declare const handler: () => void;
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const util_1 = require("../../helpers/util");
5
- exports.command = 'schemas <command>';
6
- exports.desc = 'Manage data schemas';
7
- const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('schemas');
8
- exports.builder = builder;
9
- const handler = () => { };
10
- 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 util_1 = require("../../helpers/util");
5
+ exports.command = 'schemas <command>';
6
+ exports.desc = 'Manage data schemas';
7
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('schemas');
8
+ exports.builder = builder;
9
+ const handler = () => { };
10
+ exports.handler = handler;
@@ -1,5 +1,5 @@
1
- /// <reference types="yargs" />
2
- export declare const command = "data <command>";
3
- export declare const desc = "Manage data";
4
- export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
5
- export declare const handler: () => void;
1
+ /// <reference types="yargs" />
2
+ export declare const command = "data <command>";
3
+ export declare const desc = "Manage data";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
5
+ export declare const handler: () => void;
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const util_1 = require("../helpers/util");
5
- exports.command = 'data <command>';
6
- exports.desc = 'Manage data';
7
- const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('data');
8
- exports.builder = builder;
9
- const handler = () => { };
10
- 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 util_1 = require("../helpers/util");
5
+ exports.command = 'data <command>';
6
+ exports.desc = 'Manage data';
7
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('data');
8
+ exports.builder = builder;
9
+ const handler = () => { };
10
+ exports.handler = handler;
@@ -1,21 +1,21 @@
1
- import { OAuth1Client } from '@extrahorizon/javascript-sdk';
2
- import { Argv } from 'yargs';
3
- export declare const command = "sync";
4
- export declare const desc = "Synchronize Dispatchers, if a declared Dispatcher does not exist, it will be created";
5
- export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "file" | "clean"> & import("yargs").InferredOptionTypes<{
6
- file: {
7
- demandOption: true;
8
- describe: string;
9
- type: "string";
10
- };
11
- clean: {
12
- demandOption: false;
13
- describe: string;
14
- type: "boolean";
15
- };
16
- }>>;
17
- export declare const handler: ({ sdk, file, clean }: {
18
- sdk: OAuth1Client;
19
- file: string;
20
- clean: boolean;
21
- }) => Promise<void>;
1
+ import { OAuth1Client } from '@extrahorizon/javascript-sdk';
2
+ import { Argv } from 'yargs';
3
+ export declare const command = "sync";
4
+ export declare const desc = "Synchronize Dispatchers, if a declared Dispatcher does not exist, it will be created";
5
+ export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "file" | "clean"> & import("yargs").InferredOptionTypes<{
6
+ file: {
7
+ demandOption: true;
8
+ describe: string;
9
+ type: "string";
10
+ };
11
+ clean: {
12
+ demandOption: false;
13
+ describe: string;
14
+ type: "boolean";
15
+ };
16
+ }>>;
17
+ export declare const handler: ({ sdk, file, clean }: {
18
+ sdk: OAuth1Client;
19
+ file: string;
20
+ clean: boolean;
21
+ }) => Promise<void>;
@@ -1,24 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const util_1 = require("../../helpers/util");
5
- const dispatchersService = require("../../services/dispatchers");
6
- exports.command = 'sync';
7
- exports.desc = 'Synchronize Dispatchers, if a declared Dispatcher does not exist, it will be created';
8
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
9
- file: {
10
- demandOption: true,
11
- describe: 'Path to the file containing the Dispatcher(s) configuration',
12
- type: 'string',
13
- },
14
- clean: {
15
- demandOption: false,
16
- describe: 'Delete Dispatchers created using the CLI, that are no longer present in the local Dispatcher file',
17
- type: 'boolean',
18
- },
19
- });
20
- exports.builder = builder;
21
- const handler = async ({ sdk, file, clean }) => {
22
- await dispatchersService.sync(sdk, file, clean);
23
- };
24
- 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 util_1 = require("../../helpers/util");
5
+ const dispatchersService = require("../../services/dispatchers");
6
+ exports.command = 'sync';
7
+ exports.desc = 'Synchronize Dispatchers, if a declared Dispatcher does not exist, it will be created';
8
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
9
+ file: {
10
+ demandOption: true,
11
+ describe: 'Path to the file containing the Dispatcher(s) configuration',
12
+ type: 'string',
13
+ },
14
+ clean: {
15
+ demandOption: false,
16
+ describe: 'Delete Dispatchers created using the CLI, that are no longer present in the local Dispatcher file',
17
+ type: 'boolean',
18
+ },
19
+ });
20
+ exports.builder = builder;
21
+ const handler = async ({ sdk, file, clean }) => {
22
+ await dispatchersService.sync(sdk, file, clean);
23
+ };
24
+ exports.handler = handler;
@@ -1,5 +1,5 @@
1
- import { Argv } from 'yargs';
2
- export declare const command = "dispatchers <command>";
3
- export declare const desc = "Manage Dispatchers within Extra Horizon";
4
- export declare const builder: (yargs: Argv) => Argv<{}>;
5
- export declare const handler: () => void;
1
+ import { Argv } from 'yargs';
2
+ export declare const command = "dispatchers <command>";
3
+ export declare const desc = "Manage Dispatchers within Extra Horizon";
4
+ export declare const builder: (yargs: Argv) => Argv<{}>;
5
+ export declare const handler: () => void;
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const util_1 = require("../helpers/util");
5
- exports.command = 'dispatchers <command>';
6
- exports.desc = 'Manage Dispatchers within Extra Horizon';
7
- const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('dispatchers');
8
- exports.builder = builder;
9
- const handler = () => { };
10
- 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 util_1 = require("../helpers/util");
5
+ exports.command = 'dispatchers <command>';
6
+ exports.desc = 'Manage Dispatchers within Extra Horizon';
7
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('dispatchers');
8
+ exports.builder = builder;
9
+ const handler = () => { };
10
+ exports.handler = handler;
@@ -0,0 +1,29 @@
1
+ /// <reference types="yargs" />
2
+ import { OAuth1Client } from '@extrahorizon/javascript-sdk';
3
+ export declare const command = "sync";
4
+ export declare const desc = "Sync all localizations in a directory with the ExH cloud";
5
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "keys" | "path" | "languages"> & import("yargs").InferredOptionTypes<{
6
+ path: {
7
+ demandOption: false;
8
+ describe: string;
9
+ type: "string";
10
+ };
11
+ keys: {
12
+ demandOption: false;
13
+ describe: string;
14
+ type: "string";
15
+ };
16
+ languages: {
17
+ demandOption: false;
18
+ describe: string;
19
+ type: "string";
20
+ };
21
+ }>>;
22
+ interface HandlerInput {
23
+ sdk: OAuth1Client;
24
+ path?: string;
25
+ languages?: string;
26
+ keys?: string;
27
+ }
28
+ export declare const handler: ({ keys: rawKeys, languages: rawLanguages, path, sdk }: HandlerInput) => Promise<void>;
29
+ export {};
@@ -0,0 +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");
5
+ const ospath = require("path");
6
+ const util_1 = require("../../helpers/util");
7
+ const assertValidKey_1 = require("./utils/assertValidKey");
8
+ const assertValidLanguageCode_1 = require("./utils/assertValidLanguageCode");
9
+ const fetchLocalizations_1 = require("./utils/fetchLocalizations");
10
+ const readLocalizationFiles_1 = require("./utils/readLocalizationFiles");
11
+ const syncLocalizations_1 = require("./utils/syncLocalizations");
12
+ exports.command = 'sync';
13
+ exports.desc = 'Sync all localizations 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 localizations which need to be synced in a JSON format. By Default: /locales',
18
+ type: 'string',
19
+ },
20
+ keys: {
21
+ demandOption: false,
22
+ describe: 'The keys separated by a "," to sync',
23
+ type: 'string',
24
+ },
25
+ languages: {
26
+ demandOption: false,
27
+ describe: 'The languages separated by a "," to sync',
28
+ type: 'string',
29
+ },
30
+ }).check(({ path, keys: rawKeys, languages: rawLanguages }) => {
31
+ if (path && !fs.existsSync(ospath.join(process.cwd(), path))) {
32
+ throw new Error('please provide a valid file path for your localizations');
33
+ }
34
+ if (rawLanguages) {
35
+ const languageCodes = rawLanguages.toLocaleUpperCase().split(',');
36
+ for (const languageCode of languageCodes) {
37
+ (0, assertValidLanguageCode_1.assertValidLanguageCode)(languageCode);
38
+ }
39
+ }
40
+ if (rawKeys) {
41
+ const keys = rawKeys.split(',');
42
+ for (const key of keys) {
43
+ (0, assertValidKey_1.assertValidKey)(key);
44
+ }
45
+ }
46
+ return true;
47
+ });
48
+ exports.builder = builder;
49
+ const handler = async ({ keys: rawKeys, languages: rawLanguages, path, sdk }) => {
50
+ const keys = rawKeys?.split(',');
51
+ const selectedLanguageCodes = rawLanguages?.toUpperCase().split(',');
52
+ const fullPath = ospath.join(process.cwd(), path ?? 'locales');
53
+ console.log(`- Reading the localization configuration from ${fullPath}`);
54
+ const { localizations, languageCodes } = (0, readLocalizationFiles_1.readLocalizationFiles)(fullPath, keys, selectedLanguageCodes);
55
+ console.log('- Fetching the localization configuration from the localizations service');
56
+ const savedLocalizations = await (0, fetchLocalizations_1.fetchLocalizations)(sdk, localizations.map(localization => localization.key), languageCodes);
57
+ await (0, syncLocalizations_1.syncLocalizations)(sdk, localizations, savedLocalizations);
58
+ };
59
+ exports.handler = handler;
@@ -0,0 +1 @@
1
+ export declare const assertValidKey: (key: string) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertValidKey = void 0;
4
+ const assertValidKey = (key) => {
5
+ const validKeyRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/;
6
+ if (!validKeyRegex.test(key)) {
7
+ throw new Error(`The key ${key} is not valid! Must follow the pattern ${validKeyRegex}!`);
8
+ }
9
+ };
10
+ exports.assertValidKey = assertValidKey;
@@ -0,0 +1,2 @@
1
+ export declare const availableLanguagesCodes: string[];
2
+ export declare const assertValidLanguageCode: (languageCode: string) => void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertValidLanguageCode = exports.availableLanguagesCodes = void 0;
4
+ exports.availableLanguagesCodes = [
5
+ 'EN', 'AA', 'AB', 'AE', 'AF', 'AK', 'AM', 'AN', 'AR', 'AS', 'AV', 'AY', 'AZ', 'BA', 'BE', 'BG', 'BH', 'BI', 'BM', 'BN', 'BO',
6
+ 'BR', 'BS', 'CA', 'CE', 'CH', 'CO', 'CR', 'CS', 'CU', 'CV', 'CY', 'DA', 'DE', 'DV', 'DZ', 'EE', 'EL', 'EO', 'ES', 'ET', 'EU',
7
+ 'FA', 'FF', 'FI', 'FJ', 'FO', 'FR', 'FY', 'GA', 'GD', 'GL', 'GN', 'GU', 'GV', 'HA', 'HE', 'HI', 'HO', 'HR', 'HT', 'HU', 'HY',
8
+ 'HZ', 'IA', 'ID', 'IE', 'IG', 'II', 'IK', 'IN', 'IO', 'IS', 'IT', 'IW', 'IU', 'JA', 'JI', 'JW', 'JV', 'KA', 'KG', 'KI', 'KJ',
9
+ 'KK', 'KL', 'KM', 'KN', 'KO', 'KR', 'KS', 'KU', 'KV', 'KW', 'KY', 'LA', 'LB', 'LG', 'LI', 'LN', 'LO', 'LT', 'LU', 'LV', 'MG',
10
+ 'MH', 'MI', 'MK', 'ML', 'MN', 'MO', 'MR', 'MS', 'MT', 'MY', 'NA', 'NB', 'ND', 'NE', 'NG', 'NL', 'NN', 'NO', 'NR', 'NV', 'NY',
11
+ 'OC', 'OJ', 'OM', 'OR', 'OS', 'PA', 'PI', 'PL', 'PS', 'PT', 'QU', 'RM', 'RN', 'RO', 'RU', 'RW', 'SA', 'SC', 'SD', 'SE', 'SG',
12
+ 'SH', 'SI', 'SK', 'SL', 'SM', 'SN', 'SO', 'SQ', 'SR', 'SS', 'ST', 'SU', 'SV', 'SW', 'TA', 'TE', 'TG', 'TH', 'TI', 'TK', 'TL',
13
+ 'TN', 'TO', 'TR', 'TS', 'TT', 'TW', 'TY', 'UG', 'UK', 'UR', 'UZ', 'VE', 'VI', 'VO', 'WA', 'WO', 'XH', 'YI', 'YO', 'ZA', 'ZH',
14
+ 'ZU',
15
+ ];
16
+ const assertValidLanguageCode = (languageCode) => {
17
+ if (!exports.availableLanguagesCodes.includes(languageCode)) {
18
+ throw new Error(`The language code ${languageCode} is not available! The available language codes are [${exports.availableLanguagesCodes.join(', ')}]`);
19
+ }
20
+ };
21
+ exports.assertValidLanguageCode = assertValidLanguageCode;
@@ -0,0 +1,2 @@
1
+ import { Localization, OAuth1Client } from '@extrahorizon/javascript-sdk';
2
+ export declare const fetchLocalizations: (sdk: OAuth1Client, keys: string[], languageCodes: string[]) => Promise<Localization[]>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchLocalizations = void 0;
4
+ const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
5
+ const lodash_1 = require("lodash");
6
+ const fetchLocalizations = async (sdk, keys, languageCodes) => {
7
+ const localizations = [];
8
+ const keyChunks = (0, lodash_1.chunk)(keys, 5);
9
+ for (const keyChunk of keyChunks) {
10
+ const result = await sdk.localizations.find({
11
+ rql: (0, javascript_sdk_1.rqlBuilder)()
12
+ .in('key', keyChunk)
13
+ .select(['key'].concat(languageCodes.map(languageCode => `text.${languageCode}`)))
14
+ .build(),
15
+ });
16
+ localizations.push(...result.data);
17
+ }
18
+ return localizations;
19
+ };
20
+ exports.fetchLocalizations = fetchLocalizations;
@@ -0,0 +1,6 @@
1
+ import { Localization } from '@extrahorizon/javascript-sdk';
2
+ export interface LocalizationFilesOutput {
3
+ localizations: Pick<Localization, 'key' | 'text'>[];
4
+ languageCodes: string[];
5
+ }
6
+ export declare const readLocalizationFiles: (path: string, keys?: string[], languageCodes?: string[]) => LocalizationFilesOutput;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readLocalizationFiles = void 0;
4
+ const fs_1 = require("fs");
5
+ const ospath = require("path");
6
+ const util_1 = require("../../../helpers/util");
7
+ const assertValidLanguageCode_1 = require("./assertValidLanguageCode");
8
+ const readLocalizationFiles = (path, keys, languageCodes) => {
9
+ const uniqueLanguageCodes = new Set();
10
+ const localizationMap = {};
11
+ const fileNames = (0, fs_1.readdirSync)(path);
12
+ for (const fileName of fileNames) {
13
+ const parsedFileName = ospath.parse(fileName);
14
+ const languageCode = parsedFileName.name.toUpperCase();
15
+ (0, assertValidLanguageCode_1.assertValidLanguageCode)(languageCode);
16
+ if (parsedFileName.ext !== '.json') {
17
+ continue;
18
+ }
19
+ if (languageCodes && !languageCodes.includes(languageCode)) {
20
+ continue;
21
+ }
22
+ uniqueLanguageCodes.add(languageCode);
23
+ const localizationJson = (0, util_1.readJsonFileSync)(ospath.join(path, fileName));
24
+ for (const [key, text] of Object.entries(localizationJson)) {
25
+ if (keys && !keys.includes(key)) {
26
+ continue;
27
+ }
28
+ if (!(key in localizationMap)) {
29
+ localizationMap[key] = { key, text: {} };
30
+ }
31
+ localizationMap[key].text[languageCode] = text;
32
+ }
33
+ }
34
+ return {
35
+ localizations: Object.values(localizationMap),
36
+ languageCodes: [...uniqueLanguageCodes.values()],
37
+ };
38
+ };
39
+ exports.readLocalizationFiles = readLocalizationFiles;
@@ -0,0 +1,2 @@
1
+ import { Localization, OAuth1Client } from '@extrahorizon/javascript-sdk';
2
+ export declare const syncLocalizations: (sdk: OAuth1Client, configLocalizations: Pick<Localization, 'key' | 'text'>[], fetchedLocalizations: Localization[]) => Promise<void>;