@extrahorizon/exh-cli 1.5.0

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 (93) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/LICENSE +21 -0
  3. package/README.md +66 -0
  4. package/build/commands/completion.d.ts +5 -0
  5. package/build/commands/completion.js +38 -0
  6. package/build/commands/data/schemas/delete.d.ts +10 -0
  7. package/build/commands/data/schemas/delete.js +29 -0
  8. package/build/commands/data/schemas/list.d.ts +8 -0
  9. package/build/commands/data/schemas/list.js +20 -0
  10. package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -0
  11. package/build/commands/data/schemas/sync/statusHelpers.js +49 -0
  12. package/build/commands/data/schemas/sync.d.ts +35 -0
  13. package/build/commands/data/schemas/sync.js +72 -0
  14. package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -0
  15. package/build/commands/data/schemas/util/listFilesInDir.js +25 -0
  16. package/build/commands/data/schemas/util/metaschema.json +455 -0
  17. package/build/commands/data/schemas/util/readJson.d.ts +1 -0
  18. package/build/commands/data/schemas/util/readJson.js +11 -0
  19. package/build/commands/data/schemas/util/schemaverify.d.ts +28 -0
  20. package/build/commands/data/schemas/util/schemaverify.js +202 -0
  21. package/build/commands/data/schemas/util/syncSchema.d.ts +20 -0
  22. package/build/commands/data/schemas/util/syncSchema.js +276 -0
  23. package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -0
  24. package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -0
  25. package/build/commands/data/schemas/verify.d.ts +18 -0
  26. package/build/commands/data/schemas/verify.js +82 -0
  27. package/build/commands/data/schemas.d.ts +5 -0
  28. package/build/commands/data/schemas.js +10 -0
  29. package/build/commands/data.d.ts +5 -0
  30. package/build/commands/data.js +10 -0
  31. package/build/commands/dispatchers/sync.d.ts +21 -0
  32. package/build/commands/dispatchers/sync.js +24 -0
  33. package/build/commands/dispatchers.d.ts +5 -0
  34. package/build/commands/dispatchers.js +10 -0
  35. package/build/commands/login.d.ts +37 -0
  36. package/build/commands/login.js +59 -0
  37. package/build/commands/sync.d.ts +55 -0
  38. package/build/commands/sync.js +107 -0
  39. package/build/commands/tasks/createrepo.d.ts +22 -0
  40. package/build/commands/tasks/createrepo.js +70 -0
  41. package/build/commands/tasks/delete.d.ts +10 -0
  42. package/build/commands/tasks/delete.js +29 -0
  43. package/build/commands/tasks/list.d.ts +8 -0
  44. package/build/commands/tasks/list.js +27 -0
  45. package/build/commands/tasks/sync.d.ts +56 -0
  46. package/build/commands/tasks/sync.js +122 -0
  47. package/build/commands/tasks/taskConfig.d.ts +24 -0
  48. package/build/commands/tasks/taskConfig.js +169 -0
  49. package/build/commands/tasks/util.d.ts +1 -0
  50. package/build/commands/tasks/util.js +27 -0
  51. package/build/commands/tasks.d.ts +5 -0
  52. package/build/commands/tasks.js +10 -0
  53. package/build/commands/templates/delete.d.ts +19 -0
  54. package/build/commands/templates/delete.js +48 -0
  55. package/build/commands/templates/get.d.ts +19 -0
  56. package/build/commands/templates/get.js +37 -0
  57. package/build/commands/templates/list.d.ts +9 -0
  58. package/build/commands/templates/list.js +25 -0
  59. package/build/commands/templates/sync.d.ts +22 -0
  60. package/build/commands/templates/sync.js +65 -0
  61. package/build/commands/templates/util/buildTemplates.d.ts +2 -0
  62. package/build/commands/templates/util/buildTemplates.js +50 -0
  63. package/build/commands/templates/util/readTemplateFiles.d.ts +3 -0
  64. package/build/commands/templates/util/readTemplateFiles.js +52 -0
  65. package/build/commands/templates/util/templateService.d.ts +8 -0
  66. package/build/commands/templates/util/templateService.js +18 -0
  67. package/build/commands/templates/util/uploadTemplate.d.ts +2 -0
  68. package/build/commands/templates/util/uploadTemplate.js +20 -0
  69. package/build/commands/templates/util/utils.d.ts +4 -0
  70. package/build/commands/templates/util/utils.js +22 -0
  71. package/build/commands/templates.d.ts +5 -0
  72. package/build/commands/templates.js +10 -0
  73. package/build/constants.d.ts +13 -0
  74. package/build/constants.js +37 -0
  75. package/build/exh.d.ts +3 -0
  76. package/build/exh.js +65 -0
  77. package/build/helpers/error.d.ts +2 -0
  78. package/build/helpers/error.js +6 -0
  79. package/build/helpers/repoConfig.d.ts +2 -0
  80. package/build/helpers/repoConfig.js +60 -0
  81. package/build/helpers/util.d.ts +3 -0
  82. package/build/helpers/util.js +36 -0
  83. package/build/index.d.ts +2 -0
  84. package/build/index.js +33 -0
  85. package/build/repositories/dispatchers.d.ts +8 -0
  86. package/build/repositories/dispatchers.js +31 -0
  87. package/build/repositories/functions.d.ts +24 -0
  88. package/build/repositories/functions.js +28 -0
  89. package/build/repositories/schemas.d.ts +44 -0
  90. package/build/repositories/schemas.js +86 -0
  91. package/build/services/dispatchers.d.ts +3 -0
  92. package/build/services/dispatchers.js +132 -0
  93. package/package.json +53 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,53 @@
1
+ # Extra Horizon CLI changelog
2
+
3
+ ### v1.5.0
4
+ * Updated the supported runtimes for task functions
5
+ * `exh data schemas verify` and `exh tasks create-repo` no longer require you to be authenticated
6
+ * `@extra-horizon/javascript-sdk` has been updated to `8.2.0`
7
+ * Unused dependencies have been removed
8
+
9
+ ### v1.4.0
10
+ * Added a validation check for `id` properties in objects within arrays in data schemas, this will now be reported as an error if present.
11
+ * Added validation for duplicate transition names in data schemas, this will now be reported as an error if present.
12
+ * Changed the strictness of validation for properties of input conditions. Modifiers such as `enum`, `minLength`, `maxLength`, etc... will no longer produce an error if not present in the condition property.
13
+
14
+ ### v1.3.0
15
+ * Added a command to synchronize Dispatchers `exh dispatchers sync --file=<path>` the file argument must point to a JSON file containing an array of Dispatchers to be synchronized.
16
+ * Added Dispatchers to the general `exh sync` command, this will synchronize all Dispatchers within a file named `dispatchers.json` in the working directory or within the provided `path` argument directory.
17
+ * Added an argument `exh sync --dispatchers` to synchronize only Dispatchers.
18
+ * Added arguments to clean up Extra Horizon Dispatchers during synchronization `exh dispatchers sync --clean` and `exh sync --cleanDispatchers`. These arguments will remove all Dispatchers created by the CLI that are no longer present in the local Dispatchers file.
19
+
20
+ ### v1.2.0
21
+ * Added a sync argument `exh sync ... --ignoreSchemaVerificationErrors` to bypass schema verification errors, this allows schemas to be synced even if errors are reported
22
+ * Added a schema sync argument `exh data schemas sync ... --ignoreVerificationErrors` to bypass schema verification errors, this allows schemas to be synced even if errors are reported
23
+ * Fixed an issue synchronizing statuses with an existing schema, excess properties should now be correctly removed from statuses
24
+ * Updated the supported runtimes for tasks
25
+ * The `--help` information now correctly displays `exh` rather than `index.js` as the command.
26
+
27
+ ### v1.1.0
28
+ * Added single file sync command for schemas with `exh data schemas sync --file=<path>`
29
+ * Added a dry run argument for schema sync `exh data schemas sync --file=<path> --dry`. This will report the properties to be added, removed and updated in the terminal, without persisting schema changes.
30
+ * Added verification and validation for statuses that are defined, but not present in transitions.
31
+ * Added validation to ensure that properties in a creation transition exist in the schema properties.
32
+ * Added verification and validation of transition conditions.
33
+ * Added terminal notifications for if a newer release of the CLI available.
34
+
35
+ ### v1.0.4
36
+ * Security update
37
+
38
+ ### v1.0.3
39
+ * Fix setting of execution permission
40
+ * Set credentials as environment variables as well, but only if they're not defined yet
41
+
42
+ ### v1.0.2
43
+ * Fix JSON schema for transition where `configuration` was marked as mandatory
44
+
45
+ ### v1.0.1
46
+ * Fixed broken environment variables
47
+
48
+ ### v1.0.0
49
+
50
+ * Add support for setting execution permission when syncing a task. Options are `permissionRequired`, `allUsers` or `public`.
51
+ * Remove implicit settings from task config syncing: some settings, such as `memoryLimit` or `timeLimit`, were given default values when not specified in task config. This can give undesired results, for example overriding custom values in the backend. __This change causes the backend defaults to be used if not specified in the task-config.json. Please verify that this is the desired behaviour__
52
+ * Add support for setting `retryPolicy` in task-config.json.
53
+ * Example task-config.json can be found [here](examples/task-config.example.json).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 ExtraHorizon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Extra Horizon CLI
2
+
3
+ This is the command-line interface to the Extra Horizon platform. It allows you to manage schemas & tasks for now, but
4
+ will be extended with additional functionality.
5
+
6
+ See [changelog](CHANGELOG.md) for the latest changes.
7
+
8
+ ## Installation
9
+
10
+ ### Configuring .npmrc
11
+ Assuming you've created a project (using npm init or equivalent), you need to create a file called .npmrc at the root level of your project and add the following lines:
12
+ ```
13
+ @extrahorizon:registry=https://npm.pkg.github.com
14
+ //npm.pkg.github.com/:_authToken=${AUTH_TOKEN}
15
+ ```
16
+ Replace ${AUTH_TOKEN} with your personal access token. You can get a new one at https://github.com/settings/tokens/new. Make sure you enable the read:packages scope.
17
+ Explanation from GitHub on how to add your token can be found here: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-to-github-packages
18
+
19
+ You can also add the .npmrc to your home directory. In which case it will apply to all your projects.
20
+
21
+ ### Install
22
+ *Note: The exh-cli requires at least node version 14*
23
+
24
+ To install in your project:
25
+
26
+ Using `npm`:
27
+
28
+ ```
29
+ npm install -D @extrahorizon/exh-cli
30
+ ```
31
+ With `yarn`:
32
+ ```
33
+ yarn add -D @extrahorizon/exh-cli
34
+ ```
35
+
36
+ It's easier to install it globally so you can use it in all your ExH projects:
37
+
38
+ ```
39
+ npm install -g @extrahorizon/exh-cli
40
+ ```
41
+ or
42
+ ```
43
+ yarn global add @extrahorizon/exh-cli
44
+ ```
45
+
46
+
47
+ ## Shell completion
48
+
49
+ Once installed, you can enable shell completion. With shell completion you get command and option suggestions whenever you use <tab> while typing a command.
50
+
51
+ For zsh, do
52
+ ```
53
+ exh completion >> ~/.zshrc
54
+ ```
55
+
56
+ Bash
57
+ ```
58
+ exh completion >> ~/.bashrc
59
+ ```
60
+
61
+ You will need to reload your configuration file (or open a new shell) for the changes to take effect.
62
+
63
+ ## Documentation
64
+
65
+ For full documentation, please have a look at [Extra Horizon Documentation](https://docs.extrahorizon.com/cli/)
66
+
@@ -0,0 +1,5 @@
1
+ /// <reference types="yargs" />
2
+ export declare const command = "completion";
3
+ export declare const desc = "Install shell completion for bash & zsh";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, never> & import("yargs").InferredOptionTypes<{}>>;
5
+ export declare const handler: () => Promise<void>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
+ const readline = require("readline");
5
+ const util_1 = require("../helpers/util");
6
+ exports.command = 'completion';
7
+ exports.desc = 'Install shell completion for bash & zsh';
8
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({});
9
+ exports.builder = builder;
10
+ const handler = async () => {
11
+ const isZsh = (process.env.SHELL?.includes('zsh') || process.env.ZSH_NAME?.includes('zsh')) ?? false;
12
+ try {
13
+ const result = await (0, util_1.asyncExec)(`grep yargs_completions ${isZsh ? '~/.zshrc' : '~/.bashrc'}`);
14
+ if (result.length > 0) {
15
+ console.log('Completion already present ✅');
16
+ return;
17
+ }
18
+ }
19
+ catch (err) { }
20
+ const rl = readline.createInterface({
21
+ input: process.stdin,
22
+ output: process.stdout,
23
+ });
24
+ rl.question('Do you want to add completion to your shell (Y/n)? ', async (yesno) => {
25
+ if (!yesno || yesno.toLowerCase() === 'y') {
26
+ console.log(await (0, util_1.asyncExec)(`exh generate_completion >> ${isZsh ? '~/.zshrc' : '~/.bashrc'}`));
27
+ console.log('Completion added ✅');
28
+ }
29
+ else {
30
+ console.log('Completion not added ❌');
31
+ }
32
+ rl.close();
33
+ });
34
+ rl.on('close', () => {
35
+ process.exit(0);
36
+ });
37
+ };
38
+ exports.handler = handler;
@@ -0,0 +1,10 @@
1
+ /// <reference types="yargs" />
2
+ export declare const command = "delete";
3
+ export declare const desc = "Delete a schema";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<{
5
+ id: string;
6
+ }>;
7
+ export declare const handler: ({ sdk, id }: {
8
+ sdk: any;
9
+ id: any;
10
+ }) => Promise<void>;
@@ -0,0 +1,29 @@
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
+ const schemaRepository = require("../../../repositories/schemas");
7
+ exports.command = 'delete';
8
+ exports.desc = 'Delete a schema';
9
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).option('id', {
10
+ demandOption: true,
11
+ description: 'The ID of the schema',
12
+ type: 'string',
13
+ });
14
+ exports.builder = builder;
15
+ const handler = async ({ sdk, id }) => {
16
+ const disableResponse = await schemaRepository.disable(sdk, id);
17
+ if (disableResponse.affectedRecords !== 1) {
18
+ console.log(chalk.red('Failed to delete schema', id));
19
+ return;
20
+ }
21
+ const deleteResponse = await schemaRepository.remove(sdk, id);
22
+ if (deleteResponse.affectedRecords) {
23
+ console.log(chalk.green('Successfully deleted schema', id));
24
+ }
25
+ else {
26
+ console.log(chalk.red('Failed to delete schema', id));
27
+ }
28
+ };
29
+ exports.handler = handler;
@@ -0,0 +1,8 @@
1
+ /// <reference types="yargs" />
2
+ export declare const command = "list";
3
+ export declare const desc = "List all schemas";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
5
+ export declare const handler: ({ sdk, isTTY }: {
6
+ sdk: any;
7
+ isTTY: any;
8
+ }) => Promise<void>;
@@ -0,0 +1,20 @@
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 = 'list';
6
+ exports.desc = 'List all schemas';
7
+ const builder = (yargs) => (0, util_1.epilogue)(yargs);
8
+ exports.builder = builder;
9
+ const handler = async function list({ sdk, isTTY }) {
10
+ const schemaListResponse = await sdk.raw.get('/data/v1/');
11
+ if (schemaListResponse.data.data.length !== 0) {
12
+ if (isTTY) {
13
+ console.table(schemaListResponse.data.data.map((c) => ({ Id: c.id, Name: c.name, Description: c.description || '<none>' })));
14
+ }
15
+ else {
16
+ schemaListResponse.data.data.forEach((f) => (console.log([f.id, f.name].join(','))));
17
+ }
18
+ }
19
+ };
20
+ exports.handler = handler;
@@ -0,0 +1,3 @@
1
+ import { Changes } from '../util/syncSchema';
2
+ export declare function compareStatuses(localSchema: any, cloudSchema: any): Changes;
3
+ export declare function calculateStatusUpdateData(localStatus: any, cloudStatus: any): Record<string, string>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateStatusUpdateData = exports.compareStatuses = void 0;
4
+ const lodash_1 = require("lodash");
5
+ function compareStatuses(localSchema, cloudSchema) {
6
+ const changes = {
7
+ toAdd: [],
8
+ toUpdate: [],
9
+ toRemove: [],
10
+ };
11
+ const cloudStatuses = cloudSchema.statuses;
12
+ const localStatuses = localSchema.statuses;
13
+ for (const statusName of Object.keys(localStatuses)) {
14
+ const cloudStatus = cloudStatuses[statusName];
15
+ const localStatus = localStatuses[statusName];
16
+ const isNewStatus = localStatus && !cloudStatus;
17
+ if (isNewStatus) {
18
+ changes.toAdd.push(statusName);
19
+ }
20
+ const isUpdatedStatus = localStatus && cloudStatus && !(0, lodash_1.isEqual)(localStatus, cloudStatus);
21
+ if (isUpdatedStatus) {
22
+ changes.toUpdate.push(statusName);
23
+ }
24
+ }
25
+ for (const statusName of Object.keys(cloudStatuses)) {
26
+ const cloudStatus = cloudStatuses[statusName];
27
+ const localStatus = localStatuses[statusName];
28
+ const isExcessStatus = !localStatus && cloudStatus;
29
+ if (isExcessStatus) {
30
+ changes.toRemove.push(statusName);
31
+ }
32
+ }
33
+ return changes;
34
+ }
35
+ exports.compareStatuses = compareStatuses;
36
+ function calculateStatusUpdateData(localStatus, cloudStatus) {
37
+ const result = {};
38
+ for (const key of Object.keys(localStatus)) {
39
+ result[key] = localStatus[key];
40
+ }
41
+ for (const key of Object.keys(cloudStatus)) {
42
+ const isExcessProperty = !localStatus[key];
43
+ if (isExcessProperty) {
44
+ result[key] = null;
45
+ }
46
+ }
47
+ return result;
48
+ }
49
+ exports.calculateStatusUpdateData = calculateStatusUpdateData;
@@ -0,0 +1,35 @@
1
+ /// <reference types="yargs" />
2
+ export declare const command = "sync";
3
+ export declare const desc = "Sync all schemas in a directory with the ExH cloud";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "file" | "dir" | "ignoreVerificationErrors" | "dry"> & import("yargs").InferredOptionTypes<{
5
+ dir: {
6
+ demandOption: false;
7
+ describe: string;
8
+ type: "string";
9
+ };
10
+ file: {
11
+ demandOption: false;
12
+ describe: string;
13
+ type: "string";
14
+ };
15
+ dry: {
16
+ demandOption: false;
17
+ describe: string;
18
+ type: "boolean";
19
+ };
20
+ ignoreVerificationErrors: {
21
+ demandOption: false;
22
+ describe: string;
23
+ type: "boolean";
24
+ default: boolean;
25
+ };
26
+ }>>;
27
+ export declare const handler: ({ sdk, dir, file, dry, ignoreVerificationErrors }: {
28
+ sdk: any;
29
+ dir: any;
30
+ file: any;
31
+ dry: any;
32
+ ignoreVerificationErrors: any;
33
+ }) => Promise<void>;
34
+ export declare function syncTargetFile(sdk: any, targetFile: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
35
+ export declare function syncTargetDir(sdk: any, targetDir: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncTargetDir = exports.syncTargetFile = exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
+ const path = require("path");
5
+ const chalk = require("chalk");
6
+ const util_1 = require("../../../helpers/util");
7
+ const listFilesInDir_1 = require("./util/listFilesInDir");
8
+ const readJson_1 = require("./util/readJson");
9
+ const syncSchema_1 = require("./util/syncSchema");
10
+ const verify_1 = require("./verify");
11
+ exports.command = 'sync';
12
+ exports.desc = 'Sync all schemas in a directory with the ExH cloud';
13
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
14
+ dir: {
15
+ demandOption: false,
16
+ describe: 'Directory containing the schemas which need to be synced',
17
+ type: 'string',
18
+ },
19
+ file: {
20
+ demandOption: false,
21
+ describe: 'File containing a schema which needs to be synced',
22
+ type: 'string',
23
+ },
24
+ dry: {
25
+ demandOption: false,
26
+ describe: 'When set, a dry-run will be performed. Only output will be printed, but no changes will be pushed to the back-end.',
27
+ type: 'boolean',
28
+ },
29
+ ignoreVerificationErrors: {
30
+ demandOption: false,
31
+ describe: 'Allow synchronization to proceed with validation errors.',
32
+ type: 'boolean',
33
+ default: false,
34
+ },
35
+ });
36
+ exports.builder = builder;
37
+ const handler = async ({ sdk, dir, file, dry, ignoreVerificationErrors }) => {
38
+ if (!file && !dir) {
39
+ console.log(chalk.red('No target is chosen to be synced. Please use flags "--file" or "--dir" when syncing'));
40
+ process.exit(1);
41
+ }
42
+ if (dir) {
43
+ await syncTargetDir(sdk, path.resolve(dir || '.'), dry, ignoreVerificationErrors);
44
+ }
45
+ if (file) {
46
+ await syncTargetFile(sdk, path.resolve(file), dry, ignoreVerificationErrors);
47
+ }
48
+ };
49
+ exports.handler = handler;
50
+ async function syncTargetFile(sdk, targetFile, dry, ignoreVerificationErrors) {
51
+ await (0, verify_1.handler)({ dir: null, file: targetFile, ignoreVerificationErrors });
52
+ const filePath = path.resolve(targetFile);
53
+ if (!filePath.endsWith('.json')) {
54
+ console.log(`Ignored ${path.basename(filePath)}, not a JSON file (needs .json extension)`);
55
+ }
56
+ else {
57
+ console.log(chalk.bold(`Synchronizing ${path.basename(filePath)}`));
58
+ const targetSchema = await (0, readJson_1.readJsonFile)(filePath);
59
+ const syncSchema = syncSchema_1.SyncSchema.createSchemaSync(sdk, dry);
60
+ await syncSchema.sync(targetSchema);
61
+ }
62
+ }
63
+ exports.syncTargetFile = syncTargetFile;
64
+ async function syncTargetDir(sdk, targetDir, dry, ignoreVerificationErrors) {
65
+ await (0, verify_1.handler)({ dir: targetDir, file: null, ignoreVerificationErrors });
66
+ const targetFiles = (0, listFilesInDir_1.flatListFiles)(targetDir, '.json');
67
+ for (const filePath of targetFiles) {
68
+ await syncTargetFile(sdk, filePath, dry, ignoreVerificationErrors);
69
+ process.stdout.write('\n');
70
+ }
71
+ }
72
+ exports.syncTargetDir = syncTargetDir;
@@ -0,0 +1 @@
1
+ export declare function flatListFiles(dirPath: string, extensionFilter?: string): string[];
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flatListFiles = void 0;
4
+ const fs_1 = require("fs");
5
+ const path = require("path");
6
+ function flatListFiles(dirPath, extensionFilter) {
7
+ const files = (0, fs_1.readdirSync)(dirPath);
8
+ return files.flatMap(file => {
9
+ const filePath = path.join(dirPath, file);
10
+ const fileStat = (0, fs_1.statSync)(filePath);
11
+ if (fileStat.isDirectory()) {
12
+ return flatListFiles(filePath, extensionFilter);
13
+ }
14
+ if (fileStat.isFile()) {
15
+ if (!extensionFilter) {
16
+ return filePath;
17
+ }
18
+ if (filePath.endsWith(extensionFilter)) {
19
+ return filePath;
20
+ }
21
+ }
22
+ return null;
23
+ }).filter(file => file);
24
+ }
25
+ exports.flatListFiles = flatListFiles;