@contrail/cli 1.0.12 → 1.0.16

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 (43) hide show
  1. package/lib/auth/login.js +14 -13
  2. package/lib/cli.js +39 -6
  3. package/lib/types/csv-parser.d.ts +1 -0
  4. package/lib/types/csv-parser.js +51 -0
  5. package/lib/types/interfaces.d.ts +2 -2
  6. package/lib/types/option-set-merger.d.ts +1 -0
  7. package/lib/types/option-set-merger.js +102 -0
  8. package/lib/types/option-set-uploader.d.ts +1 -1
  9. package/lib/types/option-set-uploader.js +17 -1
  10. package/lib/types/parse-types.d.ts +2 -0
  11. package/lib/types/parse-types.js +101 -0
  12. package/lib/types/types-extractor.d.ts +1 -0
  13. package/lib/types/types-extractor.js +10 -6
  14. package/lib/types/types-properties-merger.d.ts +1 -0
  15. package/lib/types/types-properties-merger.js +69 -0
  16. package/lib/types/types-uploader.js +0 -4
  17. package/package.json +3 -2
  18. package/src/auth/login.ts +14 -15
  19. package/src/cli.ts +40 -6
  20. package/src/types/csv-parser.ts +59 -0
  21. package/src/types/interfaces.ts +2 -2
  22. package/src/types/option-set-merger.ts +123 -0
  23. package/src/types/option-set-uploader.ts +21 -1
  24. package/src/types/parse-types.ts +121 -0
  25. package/src/types/types-extractor.ts +12 -10
  26. package/src/types/types-properties-merger.ts +85 -0
  27. package/src/types/types-uploader.ts +1 -6
  28. package/.eslint.js +0 -54
  29. package/.eslintrc.js +0 -20
  30. package/lib/types/parse-optionSet.d.ts +0 -2
  31. package/lib/types/parse-optionSet.js +0 -79
  32. package/option_sets.yml +0 -15
  33. package/src/types/parse-optionSet.ts +0 -96
  34. package/test/actions/exampleAction.d.ts +0 -1
  35. package/test/actions/exampleAction.js +0 -40
  36. package/test/actions/exampleAction.ts +0 -39
  37. package/test/app.yml +0 -46
  38. package/test/option_sets.yml +0 -15
  39. package/test/package-lock.json +0 -57
  40. package/test/package.json +0 -26
  41. package/test/tsconfig.json +0 -31
  42. package/test/types.yml +0 -1621
  43. package/types.yml +0 -1621
package/lib/auth/login.js CHANGED
@@ -91,22 +91,23 @@ export async function authUser() {
91
91
  });
92
92
  }
93
93
  async function setAuthContext(user, params) {
94
- // TODO Dont allow user to set this - they could set dev
95
- const questions = [];
96
- questions.push({
97
- type: 'list',
98
- name: 'environment',
99
- message: 'Which environment would you like to use?',
100
- choices: ['Dev', 'Prod'],
101
- default: 'Dev',
102
- });
94
+ const config = await getConfig();
103
95
  let apiGateway;
104
- const answers = await inquirer.prompt(questions);
105
- if (answers.environment === 'Dev') {
106
- apiGateway = 'https://api.vibeiq.com/dev/api';
96
+ console.log(config.environments);
97
+ if (config.environments) {
98
+ const questions = [];
99
+ questions.push({
100
+ type: 'list',
101
+ name: 'environment',
102
+ message: 'Which environment would you like to use?',
103
+ choices: Object.keys(config.environments),
104
+ default: Object.keys(config.environments)[0],
105
+ });
106
+ const answers = await inquirer.prompt(questions);
107
+ apiGateway = config.environments[answers.environment];
107
108
  }
108
109
  else {
109
- apiGateway = 'https://api.dev.vibeiq.com/dev/api';
110
+ apiGateway = 'https://api.vibeiq.com/prod/api';
110
111
  }
111
112
  // Set Auth Config
112
113
  Auth.config = {
package/lib/cli.js CHANGED
@@ -2,7 +2,10 @@ import { create } from './apps/create-app/create';
2
2
  import { deployApp, removeApp } from './apps/deploy-app/deploy';
3
3
  import { getTypes } from './types/types-extractor';
4
4
  import { uploadTypes } from './types/types-uploader';
5
- import { parseOptionSet } from './types/parse-optionSet';
5
+ import { UploadOptionSets } from './types/option-set-uploader';
6
+ import { MergeOptionSets } from './types/option-set-merger';
7
+ import { MergeTypeProperties } from './types/types-properties-merger';
8
+ import { ParseTypesFromFiles, ParseTypesFromLocalFiles } from './types/parse-types';
6
9
  const cliUsage = require('command-line-usage');
7
10
  /**
8
11
  * Built using documentation here:
@@ -54,12 +57,28 @@ export async function cli(args) {
54
57
  getTypes(args);
55
58
  break;
56
59
  }
57
- case 'upload': {
60
+ case 'uploadTypes': {
58
61
  uploadTypes(args);
59
62
  break;
60
63
  }
61
- case 'parseOptionSet': {
62
- parseOptionSet(args);
64
+ case 'uploadOptionSets': {
65
+ UploadOptionSets(args);
66
+ break;
67
+ }
68
+ case 'parseTypesFromLocalFiles': {
69
+ ParseTypesFromLocalFiles(args);
70
+ break;
71
+ }
72
+ case 'parseTypesFromFiles': {
73
+ ParseTypesFromFiles(args);
74
+ break;
75
+ }
76
+ case 'mergeOptionSets': {
77
+ MergeOptionSets(args);
78
+ break;
79
+ }
80
+ case 'mergeTypeProperties': {
81
+ MergeTypeProperties(args);
63
82
  break;
64
83
  }
65
84
  default: {
@@ -117,8 +136,22 @@ const helpSections = [
117
136
  header: 'Type Commands - Domain: types',
118
137
  content: [
119
138
  'getAll Get all OptionSets and Types for your Org.',
120
- 'upload Upload OptionSets and Types for your Org.',
121
- 'parseOptionSet <File Path> Parse a CSV file into OptionSets.',
139
+ 'uploadTypes Upload Types for your Org.',
140
+ '. Types are uploaded from types.yml\n',
141
+ 'uploadOptionSets Upload OptionSets for your Org.',
142
+ '. OptionSets are loaded from option_sets.yml\n',
143
+ 'parseTypesFromLocalFiles <File Paths> Parse CSV files into Types and ',
144
+ '. OptionSets from local files.\n',
145
+ 'parseTypesFromFiles <fileIds> Parse CSV files into Types and ',
146
+ '. OptionSets from VibeIQ Files.\n',
147
+ 'mergeOptionSets <File Path> Merge the OptionSets from an existing',
148
+ '. org and the OptionSets passed in.',
149
+ '. File must be .yml\n',
150
+ 'mergeTypeProperties <File Path> <TypePaths> ',
151
+ '. Merge the TypeProperties from an existing',
152
+ '. org and the TypeProperties passed in.',
153
+ '. Add to Types via TypePath',
154
+ '. File must be .yml\n',
122
155
  ],
123
156
  },
124
157
  ];
@@ -0,0 +1 @@
1
+ export declare function getCSVFromFile(loadFileId: string): Promise<any[]>;
@@ -0,0 +1,51 @@
1
+ import csvToJson from 'csvtojson';
2
+ import * as client from 'https';
3
+ import { Entities } from '@contrail/sdk';
4
+ export async function getCSVFromFile(loadFileId) {
5
+ let file;
6
+ try {
7
+ file = await new Entities().get({ entityName: 'file', id: loadFileId });
8
+ console.log('Got file: ', file);
9
+ }
10
+ catch (e) {
11
+ console.log(`Failed to get file: ${loadFileId}`, JSON.stringify(e));
12
+ throw new Error(`Failed to get file: ${loadFileId} - ` + JSON.stringify(e));
13
+ }
14
+ if (!file || !file.downloadUrl) {
15
+ console.log(`File: ${loadFileId} does not have a downloadUrl`);
16
+ throw new Error(`File: ${loadFileId} does not have a downloadUrl`);
17
+ }
18
+ // get csv
19
+ let response;
20
+ try {
21
+ response = await new Promise((resolve, reject) => {
22
+ client.get(file.downloadUrl, function (res) {
23
+ console.log('Status code:', res.statusCode);
24
+ console.log('Status text:', res.statusMessage);
25
+ let body = '';
26
+ res.on('data', (data) => {
27
+ body += data.toString();
28
+ });
29
+ res.on('end', () => {
30
+ console.log('Response body:');
31
+ //console.log(body);
32
+ resolve(body);
33
+ });
34
+ }).on('error', function (e) {
35
+ console.error(e);
36
+ reject(e);
37
+ });
38
+ });
39
+ }
40
+ catch (e) {
41
+ console.log(`Failed to get data from downloadUrl: ${file.downloadUrl}`, e);
42
+ throw e;
43
+ }
44
+ if (!response) {
45
+ console.log('Response is empty');
46
+ throw new Error('Response is empty');
47
+ }
48
+ const csvJson = await csvToJson({ flatKeys: true }).fromString(response);
49
+ // console.log('csvJson', csvJson);
50
+ return csvJson;
51
+ }
@@ -3,9 +3,9 @@ export interface ReducedType {
3
3
  label: string;
4
4
  typePath: string;
5
5
  isArchived: boolean;
6
- typeProperties: ReducedType[];
6
+ typeProperties: ReducedTypeProperty[];
7
7
  }
8
- export interface ReducedTypeProperties {
8
+ export interface ReducedTypeProperty {
9
9
  id: string;
10
10
  isArchived: boolean;
11
11
  propertyType: PropertyType;
@@ -0,0 +1 @@
1
+ export declare function MergeOptionSets(args: any): Promise<void>;
@@ -0,0 +1,102 @@
1
+ import { Entities } from '@contrail/sdk';
2
+ import fs from 'fs';
3
+ import { getSeparatorByPlatform } from '../common';
4
+ import { authUser } from '../auth/login';
5
+ import chalk from 'chalk';
6
+ const yaml = require('js-yaml');
7
+ export async function MergeOptionSets(args) {
8
+ try {
9
+ if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
10
+ throw new Error('File name must be included.');
11
+ }
12
+ console.log(`%s Importing local file`, chalk.yellow.bold('OPTION SET MERGE'));
13
+ const fileLocation = args[3];
14
+ console.log('Using File: ', fileLocation);
15
+ await mergeOptionSets(fileLocation);
16
+ console.log(`%s Merged`, chalk.yellow.bold('OPTION SET MERGE'));
17
+ }
18
+ catch (e) {
19
+ console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
20
+ return;
21
+ }
22
+ console.log('%s Merge Complete.', chalk.green.bold('COMPLETE'));
23
+ }
24
+ function loadOptionSets(fileLocation) {
25
+ const TARGET_DIR = process.cwd();
26
+ try {
27
+ const separator = getSeparatorByPlatform();
28
+ const fullPath = TARGET_DIR + separator + fileLocation;
29
+ console.log('Getting file from path: ', fullPath);
30
+ const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + fileLocation, 'utf8'));
31
+ return doc.optionSets;
32
+ }
33
+ catch (e) {
34
+ throw new Error(`ERROR PARSING YAML: ${e}`);
35
+ }
36
+ }
37
+ async function mergeOptionSets(fileLocation) {
38
+ const uploadedOptionSets = loadOptionSets(fileLocation);
39
+ await authUser();
40
+ const currentOptionSetsFull = await new Entities().get({
41
+ entityName: 'type-property-option-set',
42
+ });
43
+ const currentOptionSets = currentOptionSetsFull.map(os => Object.assign({}, {
44
+ name: os.name,
45
+ isArchived: os.isArchived,
46
+ optionSet: os.optionSet,
47
+ }));
48
+ const currentOptionSetsByName = {};
49
+ for (const currentOptionSet of currentOptionSets) {
50
+ currentOptionSetsByName[currentOptionSet.name] = currentOptionSet;
51
+ }
52
+ const uploadedOptionSetsByName = {};
53
+ for (const optionSet of uploadedOptionSets) {
54
+ uploadedOptionSetsByName[optionSet.name] = optionSet;
55
+ }
56
+ const mergedOptionSets = [];
57
+ for (const uploadedOptionSet of uploadedOptionSets) {
58
+ const existing = currentOptionSetsByName[uploadedOptionSet.name];
59
+ if (!existing) {
60
+ if (!uploadedOptionSet.optionSet) {
61
+ console.log('No OptionSet for: ', uploadedOptionSet.name);
62
+ continue;
63
+ }
64
+ console.log('Adding New: ', uploadedOptionSet.name);
65
+ mergedOptionSets.push(uploadedOptionSet);
66
+ }
67
+ else {
68
+ console.log('Merging: ', uploadedOptionSet.name);
69
+ mergedOptionSets.push(mergeOptionSet(existing, uploadedOptionSet));
70
+ }
71
+ }
72
+ for (const currentOptionSet of currentOptionSets) {
73
+ const found = uploadedOptionSetsByName[currentOptionSet.name];
74
+ if (!found) {
75
+ console.log('Adding Existing: ', currentOptionSet.name);
76
+ mergedOptionSets.push(currentOptionSet);
77
+ }
78
+ }
79
+ saveData({ optionSets: mergedOptionSets });
80
+ }
81
+ function mergeOptionSet(existingOptionSet, uploadedOptionSet) {
82
+ const merged = {
83
+ name: uploadedOptionSet.name,
84
+ optionSet: uploadedOptionSet.optionSet,
85
+ isArchived: uploadedOptionSet.isArchived,
86
+ };
87
+ for (const keyVal of existingOptionSet.optionSet) {
88
+ const value = keyVal.value;
89
+ const display = keyVal.display;
90
+ const found = merged.optionSet.find(keyVal => keyVal.value === value);
91
+ if (!found) {
92
+ merged.optionSet.push({ value, display });
93
+ }
94
+ }
95
+ return merged;
96
+ }
97
+ function saveData(data) {
98
+ const yamlStr = yaml.dump(data);
99
+ const CURRENT_DIR = process.cwd();
100
+ const separator = getSeparatorByPlatform();
101
+ fs.writeFileSync(CURRENT_DIR + separator + 'merged_optionSets.yml', yamlStr, 'utf8');
102
+ }
@@ -1 +1 @@
1
- export declare function uploadOptionSets(): Promise<void>;
1
+ export declare function UploadOptionSets(args: any): Promise<void>;
@@ -1,7 +1,23 @@
1
1
  import { Entities } from '@contrail/sdk';
2
2
  import fs from 'fs';
3
3
  import { getSeparatorByPlatform } from '../common';
4
+ import { authUser } from '../auth/login';
5
+ import chalk from 'chalk';
4
6
  const yaml = require('js-yaml');
7
+ export async function UploadOptionSets(args) {
8
+ try {
9
+ const userConfig = await authUser();
10
+ console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
11
+ console.log(`%s Uploading`, chalk.yellow.bold('OPTION SETS'));
12
+ await uploadOptionSets();
13
+ console.log(`%s Uploaded`, chalk.yellow.bold('OPTION SETS'));
14
+ }
15
+ catch (e) {
16
+ console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
17
+ return;
18
+ }
19
+ console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
20
+ }
5
21
  function loadOptionSets() {
6
22
  const TARGET_DIR = process.cwd();
7
23
  try {
@@ -13,7 +29,7 @@ function loadOptionSets() {
13
29
  throw new Error(`ERROR PARSING YAML: ${e}`);
14
30
  }
15
31
  }
16
- export async function uploadOptionSets() {
32
+ async function uploadOptionSets() {
17
33
  const optionSets = loadOptionSets();
18
34
  const currentOptionSets = await new Entities().get({
19
35
  entityName: 'type-property-option-set',
@@ -0,0 +1,2 @@
1
+ export declare function ParseTypesFromLocalFiles(args: any): Promise<void>;
2
+ export declare function ParseTypesFromFiles(args: any): Promise<void>;
@@ -0,0 +1,101 @@
1
+ import { GetSuggestedTypes } from '@contrail/types';
2
+ import chalk from 'chalk';
3
+ import fs from 'fs';
4
+ import { getSeparatorByPlatform } from '../common';
5
+ import * as csvToJson from 'csvtojson';
6
+ import { authUser } from '../auth/login';
7
+ import { getCSVFromFile } from './csv-parser';
8
+ const yaml = require('js-yaml');
9
+ export async function ParseTypesFromLocalFiles(args) {
10
+ try {
11
+ if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
12
+ throw new Error('File names must be included.');
13
+ }
14
+ console.log(`%s Parsing`, chalk.yellow.bold('TYPES AND OPTION SETS'));
15
+ const fileLocations = args.slice(3);
16
+ console.log('Using File Location(s): ', fileLocations);
17
+ await parseTypesFromLocalFiles(fileLocations);
18
+ console.log(`%s Parsed`, chalk.yellow.bold('TYPES AND OPTION SETS'));
19
+ }
20
+ catch (e) {
21
+ console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
22
+ return;
23
+ }
24
+ console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
25
+ }
26
+ export async function ParseTypesFromFiles(args) {
27
+ try {
28
+ if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
29
+ throw new Error('File ids must be included.');
30
+ }
31
+ console.log(`%s Parsing`, chalk.yellow.bold('TYPES AND OPTION SETS'));
32
+ const fileIds = args.slice(3);
33
+ console.log('Using FileId(s): ', fileIds);
34
+ await parseTypesFromFiles(fileIds);
35
+ console.log(`%s Parsed`, chalk.yellow.bold('TYPES AND OPTION SETS'));
36
+ }
37
+ catch (e) {
38
+ console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
39
+ return;
40
+ }
41
+ console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
42
+ }
43
+ async function loadDataFromLocalCSV(fileName) {
44
+ const CURRENT_DIR = process.cwd();
45
+ try {
46
+ const separator = getSeparatorByPlatform();
47
+ const fullPath = CURRENT_DIR + separator + fileName;
48
+ console.log('Getting file from path: ', fullPath);
49
+ const csvData = await csvToJson.default().fromFile(fullPath);
50
+ return csvData;
51
+ }
52
+ catch (e) {
53
+ throw new Error(`ERROR PARSING CSV: ${e}`);
54
+ }
55
+ }
56
+ async function parseTypesFromLocalFiles(fileLocations) {
57
+ const csvJSONData = [];
58
+ for (const fileLocation of fileLocations) {
59
+ try {
60
+ console.log('Getting data for fileLocation: ', fileLocation);
61
+ const csvData = await loadDataFromLocalCSV(fileLocation);
62
+ console.log(`CSV import was successful. ${csvData === null || csvData === void 0 ? void 0 : csvData.length} rows found. Adding to total rows.`);
63
+ csvJSONData.push(...csvData);
64
+ }
65
+ catch (e) {
66
+ console.log('Error importing csv data.', e);
67
+ throw e;
68
+ }
69
+ }
70
+ console.log(`CSV imports were successful. ${csvJSONData === null || csvJSONData === void 0 ? void 0 : csvJSONData.length} total rows found.`);
71
+ const suggestions = GetSuggestedTypes(csvJSONData);
72
+ saveData({ optionSets: suggestions.OptionSets }, 'parsed_optionSets.yml');
73
+ saveData({ typeProperties: suggestions.TypeProperties }, 'parsed_typeProperties.yml');
74
+ }
75
+ async function parseTypesFromFiles(fileIds) {
76
+ await authUser();
77
+ // get csv data
78
+ const csvJSONData = [];
79
+ for (const loadFileId of fileIds) {
80
+ try {
81
+ console.log('Getting data for fileId: ', loadFileId);
82
+ const csvJSON = await getCSVFromFile(loadFileId);
83
+ console.log(`CSV download was successful. ${csvJSON === null || csvJSON === void 0 ? void 0 : csvJSON.length} rows found. Adding to total rows`);
84
+ csvJSONData.push(...csvJSON);
85
+ }
86
+ catch (e) {
87
+ console.log('Error retrieving csv data', e);
88
+ throw e;
89
+ }
90
+ }
91
+ console.log(`CSV downloads were successful. ${csvJSONData === null || csvJSONData === void 0 ? void 0 : csvJSONData.length} total rows found.`);
92
+ const suggestions = GetSuggestedTypes(csvJSONData);
93
+ saveData({ optionSets: suggestions.OptionSets }, 'parsed_optionSets.yml');
94
+ saveData({ typeProperties: suggestions.TypeProperties }, 'parsed_typeProperties.yml');
95
+ }
96
+ function saveData(data, name) {
97
+ const yamlStr = yaml.dump(data);
98
+ const CURRENT_DIR = process.cwd();
99
+ const separator = getSeparatorByPlatform();
100
+ fs.writeFileSync(CURRENT_DIR + separator + name, yamlStr, 'utf8');
101
+ }
@@ -1 +1,2 @@
1
1
  export declare function getTypes(args: any): Promise<void>;
2
+ export declare function getReducedTypes(optionSets: any): Promise<any[]>;
@@ -15,7 +15,11 @@ export async function getTypes(args) {
15
15
  await getOptionSets(optionSets);
16
16
  console.log(`%s Retrieved`, chalk.yellow.bold('OPTION SETS'));
17
17
  console.log(`%s Retrieving`, chalk.yellow.bold('TYPES'));
18
- await getReducedTypes(optionSets);
18
+ const reducedTypes = await getReducedTypes(optionSets);
19
+ const typesHolder = {
20
+ types: reducedTypes,
21
+ };
22
+ saveData(typesHolder);
19
23
  console.log(`%s Retrieved`, chalk.yellow.bold('TYPES'));
20
24
  }
21
25
  catch (e) {
@@ -43,7 +47,7 @@ async function getOptionSets(optionSets) {
43
47
  const yamlStr = yaml.dump(optionSetsHolder);
44
48
  fs.writeFileSync(CURRENT_DIR + separator + 'option_sets.yml', yamlStr, 'utf8');
45
49
  }
46
- async function getReducedTypes(optionSets) {
50
+ export async function getReducedTypes(optionSets) {
47
51
  const types = await new Entities().get({
48
52
  entityName: 'type',
49
53
  });
@@ -90,11 +94,11 @@ async function getReducedTypes(optionSets) {
90
94
  reducedTypes.push(reducedType);
91
95
  }
92
96
  reducedTypes = reducedTypes.sort((one, two) => (one.typePath < two.typePath ? -1 : 1));
93
- const typesHolder = {
94
- types: reducedTypes,
95
- };
97
+ return reducedTypes;
98
+ }
99
+ function saveData(data) {
100
+ const yamlStr = yaml.dump(data);
96
101
  const CURRENT_DIR = process.cwd();
97
102
  const separator = getSeparatorByPlatform();
98
- const yamlStr = yaml.dump(typesHolder);
99
103
  fs.writeFileSync(CURRENT_DIR + separator + 'types.yml', yamlStr, 'utf8');
100
104
  }
@@ -0,0 +1 @@
1
+ export declare function MergeTypeProperties(args: any): Promise<void>;
@@ -0,0 +1,69 @@
1
+ import { Entities } from '@contrail/sdk';
2
+ import { getReducedTypes } from './types-extractor';
3
+ import fs from 'fs';
4
+ import { getSeparatorByPlatform } from '../common';
5
+ import { authUser } from '../auth/login';
6
+ import chalk from 'chalk';
7
+ const yaml = require('js-yaml');
8
+ export async function MergeTypeProperties(args) {
9
+ try {
10
+ if ((args === null || args === void 0 ? void 0 : args.length) < 5) {
11
+ throw new Error('File name must be included along with a type path.');
12
+ }
13
+ console.log(`%s Importing local file`, chalk.yellow.bold('TYPE PROPERTIES MERGE'));
14
+ const fileLocation = args[3];
15
+ console.log('Using File: ', fileLocation);
16
+ const typePaths = args.slice(4);
17
+ console.log('Using TypePaths: ', typePaths);
18
+ await mergeTypeProperties(fileLocation, typePaths);
19
+ console.log(`%s Merged`, chalk.yellow.bold('TYPE PROPERTIES MERGE'));
20
+ }
21
+ catch (e) {
22
+ console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
23
+ return;
24
+ }
25
+ console.log('%s Merge Complete.', chalk.green.bold('COMPLETE'));
26
+ }
27
+ function loadTypeProperties(fileLocation) {
28
+ const TARGET_DIR = process.cwd();
29
+ try {
30
+ const separator = getSeparatorByPlatform();
31
+ const fullPath = TARGET_DIR + separator + fileLocation;
32
+ console.log('Getting file from path: ', fullPath);
33
+ const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + fileLocation, 'utf8'));
34
+ return doc.typeProperties;
35
+ }
36
+ catch (e) {
37
+ throw new Error(`ERROR PARSING YAML: ${e}`);
38
+ }
39
+ }
40
+ async function mergeTypeProperties(fileLocation, typePaths) {
41
+ const uploadedTypeProperties = loadTypeProperties(fileLocation);
42
+ await authUser();
43
+ const optionSets = await new Entities().get({
44
+ entityName: 'type-property-option-set',
45
+ });
46
+ const reducedTypes = await getReducedTypes(optionSets);
47
+ for (const typePath of typePaths) {
48
+ const foundType = reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
49
+ if (!foundType) {
50
+ console.log(`%s No Type found for: ${typePath}`, chalk.red.bold('WARNING'));
51
+ }
52
+ mergeType(foundType, uploadedTypeProperties);
53
+ }
54
+ saveData({ types: reducedTypes });
55
+ }
56
+ function mergeType(reducedType, typePropertiesToAdd) {
57
+ for (const typeProperty of typePropertiesToAdd) {
58
+ const found = reducedType.typeProperties.find(tp => tp.slug === typeProperty.slug);
59
+ if (!found) {
60
+ reducedType.typeProperties.push(typeProperty);
61
+ }
62
+ }
63
+ }
64
+ function saveData(data) {
65
+ const yamlStr = yaml.dump(data);
66
+ const CURRENT_DIR = process.cwd();
67
+ const separator = getSeparatorByPlatform();
68
+ fs.writeFileSync(CURRENT_DIR + separator + 'merged_types.yml', yamlStr, 'utf8');
69
+ }
@@ -1,5 +1,4 @@
1
1
  import { Entities, Request } from '@contrail/sdk';
2
- import { uploadOptionSets } from './option-set-uploader';
3
2
  import chalk from 'chalk';
4
3
  import fs from 'fs';
5
4
  import { authUser } from '../auth/login';
@@ -10,9 +9,6 @@ export async function uploadTypes(args) {
10
9
  try {
11
10
  const userConfig = await authUser();
12
11
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
13
- console.log(`%s Uploading`, chalk.yellow.bold('OPTION SETS'));
14
- await uploadOptionSets();
15
- console.log(`%s Uploaded`, chalk.yellow.bold('OPTION SETS'));
16
12
  console.log(`%s Uploading`, chalk.yellow.bold('TYPES'));
17
13
  await uploadReducedTypes();
18
14
  console.log(`%s Uploaded`, chalk.yellow.bold('TYPES'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "1.0.12",
3
+ "version": "1.0.16",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -23,7 +23,8 @@
23
23
  "author": "",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@contrail/sdk": "^1.0.91",
26
+ "@contrail/sdk": "^1.0.154",
27
+ "@contrail/types": "^2.0.61",
27
28
  "@contrail/util": "^1.0.17",
28
29
  "amazon-cognito-identity-js": "^5.2.3",
29
30
  "arg": "^4.0.1",
package/src/auth/login.ts CHANGED
@@ -103,23 +103,22 @@ export async function authUser(): Promise<AuthContext> {
103
103
  }
104
104
 
105
105
  async function setAuthContext(user, params): Promise<AuthContext> {
106
-
107
- // TODO Dont allow user to set this - they could set dev
108
- const questions = [];
109
- questions.push({
110
- type: 'list',
111
- name: 'environment',
112
- message: 'Which environment would you like to use?',
113
- choices: ['Dev', 'Prod'],
114
- default: 'Dev',
115
- });
116
-
106
+ const config = await getConfig();
117
107
  let apiGateway;
118
- const answers = await inquirer.prompt(questions);
119
- if (answers.environment === 'Dev') {
120
- apiGateway = 'https://api.vibeiq.com/dev/api';
108
+ console.log(config.environments)
109
+ if(config.environments) {
110
+ const questions = [];
111
+ questions.push({
112
+ type: 'list',
113
+ name: 'environment',
114
+ message: 'Which environment would you like to use?',
115
+ choices: Object.keys(config.environments),
116
+ default: Object.keys(config.environments)[0],
117
+ });
118
+ const answers = await inquirer.prompt(questions);
119
+ apiGateway = config.environments[answers.environment]
121
120
  } else {
122
- apiGateway = 'https://api.dev.vibeiq.com/dev/api';
121
+ apiGateway = 'https://api.vibeiq.com/prod/api';
123
122
  }
124
123
 
125
124
  // Set Auth Config