@contrail/cli 2.0.3 → 2.0.4

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 (31) hide show
  1. package/README.md +289 -186
  2. package/dist/commands/instance/export.d.ts +10 -0
  3. package/dist/commands/instance/export.js +24 -0
  4. package/dist/commands/instance/import.d.ts +9 -0
  5. package/dist/commands/instance/import.js +23 -0
  6. package/dist/commands/types/getAll.d.ts +5 -1
  7. package/dist/commands/types/getAll.js +31 -11
  8. package/dist/commands/types/loadAll.d.ts +5 -2
  9. package/dist/commands/types/loadAll.js +17 -13
  10. package/dist/commands/types/uploadOptionSetHierarchies.d.ts +4 -1
  11. package/dist/commands/types/uploadOptionSetHierarchies.js +13 -9
  12. package/dist/commands/types/uploadOptionSets.d.ts +4 -1
  13. package/dist/commands/types/uploadOptionSets.js +13 -9
  14. package/dist/commands/types/uploadRuleSets.d.ts +4 -1
  15. package/dist/commands/types/uploadRuleSets.js +12 -8
  16. package/dist/commands/types/uploadTypePropertyPolicies.d.ts +4 -1
  17. package/dist/commands/types/uploadTypePropertyPolicies.js +12 -8
  18. package/dist/commands/types/uploadUsageInfo.d.ts +4 -1
  19. package/dist/commands/types/uploadUsageInfo.js +9 -6
  20. package/dist/commands/users/export.d.ts +2 -0
  21. package/dist/commands/users/export.js +14 -6
  22. package/dist/commands/users/upload.d.ts +1 -0
  23. package/dist/commands/users/upload.js +2 -0
  24. package/dist/helpers/file-helpers.d.ts +1 -0
  25. package/dist/helpers/file-helpers.js +23 -0
  26. package/dist/helpers/types/type-uploader.d.ts +1 -1
  27. package/dist/helpers/types/type-uploader.js +8 -8
  28. package/dist/templates/typescript/src/actions/logItem.ts +3 -8
  29. package/dist/templates/typescript/src/framework/app-config.ts +1 -4
  30. package/oclif.manifest.json +147 -11
  31. package/package.json +8 -3
@@ -0,0 +1 @@
1
+ export declare function safeFileOverwrite(fileLocation: string, overwrite: boolean): Promise<boolean>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.safeFileOverwrite = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
6
+ const PASS_FORCE_TO_OVERWRITE = 'Pass --force to overwrite without prompting';
7
+ //throws an error if the user declines to overwrite the file
8
+ async function safeFileOverwrite(fileLocation, overwrite) {
9
+ if (overwrite) {
10
+ console.log(`overwriting ${fileLocation}`);
11
+ return true;
12
+ }
13
+ const answers = await inquirer_1.default.prompt([{
14
+ type: 'confirm',
15
+ name: 'shouldOverwrite',
16
+ message: `The file ${fileLocation} already exists. Do you wish to overwrite it?\n${PASS_FORCE_TO_OVERWRITE}`,
17
+ default: false
18
+ }]);
19
+ if (!answers.shouldOverwrite) {
20
+ throw new Error('File was not overwritten. Cancelling process...');
21
+ }
22
+ }
23
+ exports.safeFileOverwrite = safeFileOverwrite;
@@ -1 +1 @@
1
- export declare function uploadTypes(): Promise<void>;
1
+ export declare function uploadTypes(dir: string): Promise<void>;
@@ -9,12 +9,12 @@ const path = tslib_1.__importStar(require("path"));
9
9
  const _ = tslib_1.__importStar(require("lodash"));
10
10
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
11
11
  const login_1 = require("../../auth/login");
12
- async function uploadTypes() {
12
+ async function uploadTypes(dir) {
13
13
  try {
14
14
  const userConfig = await (0, login_1.authUser)();
15
15
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk_1.default.blue.bold('START'));
16
16
  console.log('%s Uploading', chalk_1.default.yellow.bold('TYPES'));
17
- await uploadReducedTypes();
17
+ await uploadReducedTypes(dir);
18
18
  console.log('%s Uploaded', chalk_1.default.yellow.bold('TYPES'));
19
19
  }
20
20
  catch (e) {
@@ -24,13 +24,13 @@ async function uploadTypes() {
24
24
  console.log('%s Types Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
25
25
  }
26
26
  exports.uploadTypes = uploadTypes;
27
- function loadReducedTypes() {
28
- const TARGET_DIR = process.cwd();
27
+ function loadReducedTypes(fromDir) {
29
28
  try {
30
- const files = fs_1.default.readdirSync(path.join(TARGET_DIR, 'types'));
29
+ const dir = path.resolve(path.join(fromDir, 'types'));
30
+ const files = fs_1.default.readdirSync(dir);
31
31
  const types = [];
32
32
  for (const file of files) {
33
- types.push(...js_yaml_1.default.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
33
+ types.push(...js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
34
34
  }
35
35
  return types;
36
36
  }
@@ -38,8 +38,8 @@ function loadReducedTypes() {
38
38
  throw new Error(`ERROR PARSING YAML: ${e}`);
39
39
  }
40
40
  }
41
- async function uploadReducedTypes() {
42
- const types = loadReducedTypes();
41
+ async function uploadReducedTypes(dir) {
42
+ const types = loadReducedTypes(dir);
43
43
  const currentTypesWithoutProperties = await new sdk_1.Entities().get({
44
44
  entityName: 'type',
45
45
  });
@@ -1,21 +1,16 @@
1
- import { login, Entities, setAppCredentials } from "@contrail/sdk";
1
+ import { Entities } from "@contrail/sdk";
2
2
  import { AppActionCallBack, AppActionCallbackStatus } from "../framework";
3
3
  import { Logger } from "../framework/logger";
4
4
 
5
5
  export async function execute(event, config: any, logger: Logger): Promise<AppActionCallBack> {
6
6
  logger.log('Starting Example Action');
7
-
8
-
9
- logger.log('Loggin in');
10
- // Fetch items from the SDK
11
- await setAppCredentials(config.apiKey, config.orgSlug);
12
7
  logger.log('Getting item from SDK');
13
8
 
14
9
  const item = await new Entities().get({
15
10
  entityName: 'item',
16
11
  id: event.id,
17
- })
18
- logger.log('Got item: ', item);
12
+ });
13
+ logger.log('Got item: ', item);
19
14
 
20
15
  return {
21
16
  output: {
@@ -1,19 +1,16 @@
1
- /**
1
+ /**
2
2
  * WARNING: Do not modify this file, it is part of the generic runtime handling logic
3
3
  * for VibeIQ app actions.
4
4
  */
5
5
 
6
-
7
6
  import fs from 'fs';
8
7
  const yaml = require('js-yaml');
9
8
 
10
9
  export function loadAppConfig(){
11
10
  const TARGET_DIR = process.cwd();
12
- console.log("TARGET_DIR: ", TARGET_DIR)
13
11
  try {
14
12
  const separator = getSeparatorByPlatform();
15
13
  const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'app.yml', 'utf8'));
16
- console.log(doc);
17
14
  return doc;
18
15
  } catch (e) {
19
16
  throw new Error(`ERROR PARSING YAML: ${e}`);
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.3",
2
+ "version": "2.0.4",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
@@ -287,6 +287,59 @@
287
287
  },
288
288
  "args": {}
289
289
  },
290
+ "instance:export": {
291
+ "id": "instance:export",
292
+ "description": "Exports an data of an instance including types and users",
293
+ "strict": true,
294
+ "pluginName": "@contrail/cli",
295
+ "pluginAlias": "@contrail/cli",
296
+ "pluginType": "core",
297
+ "aliases": [],
298
+ "examples": [
299
+ "$ contrail instance export\n"
300
+ ],
301
+ "flags": {
302
+ "outDir": {
303
+ "name": "outDir",
304
+ "type": "option",
305
+ "description": "The directory to which to export the instance data. Defaults to the current directory",
306
+ "required": false,
307
+ "multiple": false,
308
+ "default": "."
309
+ },
310
+ "overwrite": {
311
+ "name": "overwrite",
312
+ "type": "boolean",
313
+ "description": "Replaces any existing export files in outDir",
314
+ "required": false,
315
+ "allowNo": false
316
+ }
317
+ },
318
+ "args": {}
319
+ },
320
+ "instance:import": {
321
+ "id": "instance:import",
322
+ "description": "Import the data to an instance, including types and users",
323
+ "strict": true,
324
+ "pluginName": "@contrail/cli",
325
+ "pluginAlias": "@contrail/cli",
326
+ "pluginType": "core",
327
+ "aliases": [],
328
+ "examples": [
329
+ "$ contrail instance import\n"
330
+ ],
331
+ "flags": {
332
+ "dir": {
333
+ "name": "dir",
334
+ "type": "option",
335
+ "description": "The directory from which to export the instance data. Defaults to the current directory",
336
+ "required": false,
337
+ "multiple": false,
338
+ "default": "."
339
+ }
340
+ },
341
+ "args": {}
342
+ },
290
343
  "loader-process:load": {
291
344
  "id": "loader-process:load",
292
345
  "description": "Upload a csv file and kick off a load job for the uploaded file. The config path must be a reference to a .json or a .yml file.",
@@ -411,21 +464,47 @@
411
464
  "examples": [
412
465
  "$ contrail types getAll\n"
413
466
  ],
414
- "flags": {},
467
+ "flags": {
468
+ "outDir": {
469
+ "name": "outDir",
470
+ "type": "option",
471
+ "description": "The directory to which to export the type data. Defaults to the current directory",
472
+ "required": false,
473
+ "multiple": false,
474
+ "default": "."
475
+ },
476
+ "overwrite": {
477
+ "name": "overwrite",
478
+ "type": "boolean",
479
+ "description": "Replaces any existing export files in outDir",
480
+ "required": false,
481
+ "allowNo": false
482
+ }
483
+ },
415
484
  "args": {}
416
485
  },
417
486
  "types:loadAll": {
418
487
  "id": "types:loadAll",
419
- "description": "Get all Types and associated data for your Org",
488
+ "description": "loads all the type data that has been exported by getAll",
420
489
  "strict": true,
421
490
  "pluginName": "@contrail/cli",
422
491
  "pluginAlias": "@contrail/cli",
423
492
  "pluginType": "core",
424
493
  "aliases": [],
425
494
  "examples": [
426
- "$ contrail types getAll\n"
495
+ "$ contrail types loadAll\n"
427
496
  ],
428
- "flags": {},
497
+ "flags": {
498
+ "dir": {
499
+ "name": "dir",
500
+ "type": "option",
501
+ "char": "d",
502
+ "description": "The directory from which to load the types data. Defaults to the current directory.",
503
+ "required": false,
504
+ "multiple": false,
505
+ "default": "."
506
+ }
507
+ },
429
508
  "args": {}
430
509
  },
431
510
  "types:mergeOptionSets": {
@@ -636,7 +715,7 @@
636
715
  },
637
716
  "types:uploadOptionSetHierarchies": {
638
717
  "id": "types:uploadOptionSetHierarchies",
639
- "description": "Upload OptionSets for your Org. OptionSets are loaded from .yml files in the option-sets directory.",
718
+ "description": "Upload Option Set Hierarchies for your Org. Option set hierarchies are loaded from .yml files in the option-set-hierarchies directory.",
640
719
  "strict": true,
641
720
  "pluginName": "@contrail/cli",
642
721
  "pluginAlias": "@contrail/cli",
@@ -645,7 +724,17 @@
645
724
  "examples": [
646
725
  "$ contrail types uploadOptionSetHierarchies\n"
647
726
  ],
648
- "flags": {},
727
+ "flags": {
728
+ "dir": {
729
+ "name": "dir",
730
+ "type": "option",
731
+ "char": "d",
732
+ "description": "The directory from which to export the option set hierarchies data. Defaults to the current directory. The option set data will be loaded from $dir/option-set-hierarchies",
733
+ "required": false,
734
+ "multiple": false,
735
+ "default": "."
736
+ }
737
+ },
649
738
  "args": {}
650
739
  },
651
740
  "types:uploadOptionSets": {
@@ -659,7 +748,17 @@
659
748
  "examples": [
660
749
  "$ contrail types uploadOptionSets\n"
661
750
  ],
662
- "flags": {},
751
+ "flags": {
752
+ "dir": {
753
+ "name": "dir",
754
+ "type": "option",
755
+ "char": "d",
756
+ "description": "The directory from which to export the option set data. Defaults to the current directory. The option set data will be loaded from $dir/option-sets",
757
+ "required": false,
758
+ "multiple": false,
759
+ "default": "."
760
+ }
761
+ },
663
762
  "args": {}
664
763
  },
665
764
  "types:uploadOptionSetsHierarchyLocalFile": {
@@ -698,7 +797,17 @@
698
797
  "examples": [
699
798
  "$ contrail types uploadRuleSets\n"
700
799
  ],
701
- "flags": {},
800
+ "flags": {
801
+ "dir": {
802
+ "name": "dir",
803
+ "type": "option",
804
+ "char": "d",
805
+ "description": "The directory from which to export the rule set data. Defaults to the current directory. The rule set data will be loaded from $dir/rule-sets/*.yml",
806
+ "required": false,
807
+ "multiple": false,
808
+ "default": "."
809
+ }
810
+ },
702
811
  "args": {}
703
812
  },
704
813
  "types:uploadTypePropertyPolicies": {
@@ -712,7 +821,17 @@
712
821
  "examples": [
713
822
  "$ contrail types uploadTypePropertyPolicies\n"
714
823
  ],
715
- "flags": {},
824
+ "flags": {
825
+ "dir": {
826
+ "name": "dir",
827
+ "type": "option",
828
+ "char": "d",
829
+ "description": "The directory from which to export the type property policy data. Defaults to the current directory. The type property policy data will be loaded from $dir/type-property-policies/*.yml",
830
+ "required": false,
831
+ "multiple": false,
832
+ "default": "."
833
+ }
834
+ },
716
835
  "args": {}
717
836
  },
718
837
  "types:uploadUsageInfo": {
@@ -726,7 +845,17 @@
726
845
  "examples": [
727
846
  "$ contrail types uploadUsageInfo\n"
728
847
  ],
729
- "flags": {},
848
+ "flags": {
849
+ "dir": {
850
+ "name": "dir",
851
+ "type": "option",
852
+ "char": "d",
853
+ "description": "The directory from which to export the usage info data. Defaults to the current directory. The option set data will be loaded from $dir/usage-info.yml",
854
+ "required": false,
855
+ "multiple": false,
856
+ "default": "."
857
+ }
858
+ },
730
859
  "args": {}
731
860
  },
732
861
  "users:export": {
@@ -748,6 +877,13 @@
748
877
  "description": "The location for the file to be saved",
749
878
  "required": false,
750
879
  "multiple": false
880
+ },
881
+ "overwrite": {
882
+ "name": "overwrite",
883
+ "type": "boolean",
884
+ "description": "Replaces existing files if they exist",
885
+ "required": false,
886
+ "allowNo": false
751
887
  }
752
888
  },
753
889
  "args": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",
@@ -26,6 +26,7 @@
26
26
  "@contrail/types": "^3.0.20",
27
27
  "@contrail/util": "^1.0.17",
28
28
  "@oclif/core": "^2",
29
+ "@oclif/plugin-autocomplete": "^2.1.4",
29
30
  "@oclif/plugin-help": "^5",
30
31
  "@oclif/plugin-plugins": "^2.3.2",
31
32
  "@typescript-eslint/eslint-plugin": "^5.54.1",
@@ -64,12 +65,13 @@
64
65
  "typescript": "^4.9.5"
65
66
  },
66
67
  "oclif": {
67
- "bin": "contrail-cli",
68
+ "bin": "contrail",
68
69
  "dirname": "contrail-cli",
69
70
  "commands": "./dist/commands",
70
71
  "plugins": [
71
72
  "@oclif/plugin-help",
72
- "@oclif/plugin-plugins"
73
+ "@oclif/plugin-plugins",
74
+ "@oclif/plugin-autocomplete"
73
75
  ],
74
76
  "topicSeparator": " ",
75
77
  "topics": {
@@ -96,6 +98,9 @@
96
98
  },
97
99
  "workflow-templates": {
98
100
  "description": "Manage workflow templates"
101
+ },
102
+ "instance": {
103
+ "description": "Manage instance (org) configuration data"
99
104
  }
100
105
  }
101
106
  },