@contrail/cli 1.0.15 → 1.0.17

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.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Installation
2
+ `cd contrail-cli && npm i && npm run build && npm i -g`
3
+
4
+ ## Usage
5
+ `contrail COMMAND`
package/lib/cli.js CHANGED
@@ -3,9 +3,12 @@ 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
5
  import { UploadOptionSets } from './types/option-set-uploader';
6
+ import { ParseOptionSetsLocalFiles } from './types/option-set-parser';
6
7
  import { MergeOptionSets } from './types/option-set-merger';
7
8
  import { MergeTypeProperties } from './types/types-properties-merger';
8
9
  import { ParseTypesFromFiles, ParseTypesFromLocalFiles } from './types/parse-types';
10
+ import { loadColors } from './colors/color-loader';
11
+ import { listConfig, removeConfig } from './config/configCommands';
9
12
  const cliUsage = require('command-line-usage');
10
13
  /**
11
14
  * Built using documentation here:
@@ -65,6 +68,10 @@ export async function cli(args) {
65
68
  UploadOptionSets(args);
66
69
  break;
67
70
  }
71
+ case 'parseOptionSetsLocalFiles': {
72
+ ParseOptionSetsLocalFiles(args);
73
+ break;
74
+ }
68
75
  case 'parseTypesFromLocalFiles': {
69
76
  ParseTypesFromLocalFiles(args);
70
77
  break;
@@ -87,6 +94,42 @@ export async function cli(args) {
87
94
  }
88
95
  break;
89
96
  }
97
+ case 'colors': {
98
+ switch (command) {
99
+ case 'load': {
100
+ await loadColors();
101
+ break;
102
+ }
103
+ // case 'delete': {
104
+ // await deleteColors();
105
+ // break;
106
+ // }
107
+ default: {
108
+ printIllegalCommand();
109
+ }
110
+ }
111
+ break;
112
+ }
113
+ case 'config': {
114
+ switch (command) {
115
+ case 'list': {
116
+ await listConfig();
117
+ break;
118
+ }
119
+ case 'remove': {
120
+ await removeConfig(args);
121
+ break;
122
+ }
123
+ // case 'delete': {
124
+ // await deleteColors();
125
+ // break;
126
+ // }
127
+ default: {
128
+ printIllegalCommand();
129
+ }
130
+ }
131
+ break;
132
+ }
90
133
  case 'help':
91
134
  case '-help':
92
135
  case '--help': {
@@ -132,6 +175,13 @@ const helpSections = [
132
175
  'remove Remove your app.',
133
176
  ],
134
177
  },
178
+ {
179
+ header: 'Colors Commands - Domain: colors',
180
+ content: [
181
+ 'load Load colors from a CSV. Headers (name, hex, red,',
182
+ '. green, blue) are required.',
183
+ ],
184
+ },
135
185
  {
136
186
  header: 'Type Commands - Domain: types',
137
187
  content: [
@@ -140,6 +190,7 @@ const helpSections = [
140
190
  '. Types are uploaded from types.yml\n',
141
191
  'uploadOptionSets Upload OptionSets for your Org.',
142
192
  '. OptionSets are loaded from option_sets.yml\n',
193
+ 'parseOptionSetsLocalFiles <File Paths> Parse CSV files into OptionSets',
143
194
  'parseTypesFromLocalFiles <File Paths> Parse CSV files into Types and ',
144
195
  '. OptionSets from local files.\n',
145
196
  'parseTypesFromFiles <fileIds> Parse CSV files into Types and ',
@@ -0,0 +1,2 @@
1
+ export declare function deleteColors(): Promise<void>;
2
+ export declare function loadColors(): Promise<void>;
@@ -0,0 +1,94 @@
1
+ import { Entities } from '@contrail/sdk';
2
+ import chalk from 'chalk';
3
+ import { authUser } from '../auth/login';
4
+ import { getSeparatorByPlatform } from '../common';
5
+ const csv = require('csvtojson');
6
+ export async function deleteColors() {
7
+ try {
8
+ await authUser();
9
+ const colors = await getExistingColors();
10
+ console.log("Deleting %s colors", colors.length);
11
+ for (const color of colors) {
12
+ await deleteColor(color);
13
+ }
14
+ }
15
+ catch (e) {
16
+ console.log(`%s Loading Colors Failed. ${e}`, chalk.red.bold('FAIL'));
17
+ return;
18
+ }
19
+ console.log('%s Deleting Colors Complete.', chalk.green.bold('COMPLETE'));
20
+ }
21
+ export async function loadColors() {
22
+ try {
23
+ await authUser();
24
+ console.log(`%s Getting Existing Colors`, chalk.yellow.bold('COLORS'));
25
+ console.log(`%s Uploading`, chalk.yellow.bold('COLORS'));
26
+ await uploadColors();
27
+ console.log(`%s Uploaded`, chalk.yellow.bold('COLORS'));
28
+ }
29
+ catch (e) {
30
+ console.log(`%s Loading Colors Failed. ${e}`, chalk.red.bold('FAIL'));
31
+ return;
32
+ }
33
+ console.log('%s Loading Colors Complete.', chalk.green.bold('COMPLETE'));
34
+ }
35
+ async function getLocalColors() {
36
+ console.log("loading colors from local file");
37
+ const TARGET_DIR = process.cwd();
38
+ try {
39
+ const separator = getSeparatorByPlatform();
40
+ const csvFilePath = TARGET_DIR + separator + 'colors.csv';
41
+ return await csv().fromFile(csvFilePath);
42
+ }
43
+ catch (e) {
44
+ throw new Error(`ERROR PARSING COLORS CSV: ${e}`);
45
+ }
46
+ }
47
+ async function getExistingColors() {
48
+ console.log(`%s Getting Existing Colors`, chalk.yellow.bold('COLORS'));
49
+ try {
50
+ return new Entities().get({ entityName: 'color' }); //, useSearch: false }); Not in EntitiesClientGetOptions yet
51
+ }
52
+ catch (e) {
53
+ throw new Error(`ERROR DOWNLOADING COLORS: ${e}`);
54
+ }
55
+ }
56
+ async function deleteColor(color) {
57
+ try {
58
+ await new Entities().delete({ entityName: 'color', id: color.id });
59
+ }
60
+ catch (e) {
61
+ throw new Error(`ERROR DOWNLOADING COLORS: ${e}`);
62
+ }
63
+ }
64
+ async function uploadColors() {
65
+ const colors = await getLocalColors();
66
+ const existingColors = await getExistingColors();
67
+ const existingNamesValues = existingColors.filter(x => x.name).map(x => x.name);
68
+ for (const color of colors) {
69
+ if (existingNamesValues.includes(color.name)) {
70
+ console.log(`%s SKIPPING %s (%s)`, chalk.yellow.bold('COLORS'), color.hex, color.name);
71
+ continue;
72
+ }
73
+ if (color.hex.length > 1 && color.hex[0] === '#') {
74
+ color.hex = color.hex.substring(1);
75
+ }
76
+ const o = {
77
+ hex: color.hex,
78
+ name: color.name
79
+ };
80
+ if (color.red) {
81
+ o.red = color.red;
82
+ }
83
+ if (color.green) {
84
+ o.green = color.green;
85
+ }
86
+ if (color.blue) {
87
+ o.blue = color.blue;
88
+ }
89
+ await new Entities().create({
90
+ entityName: 'color',
91
+ object: o
92
+ });
93
+ }
94
+ }
@@ -2,4 +2,5 @@ export declare function initializeVibeIQConfig(): Promise<void>;
2
2
  export declare function readVibeIQConfig(): Promise<any>;
3
3
  export declare function writeVibeIQConfig(config: Object): Promise<void>;
4
4
  export declare function getConfig(): Promise<any>;
5
- export declare function storeConfig(incomingConfig: Object): Promise<void>;
5
+ export declare function deleteConfigs(configNames: string[]): Promise<void>;
6
+ export declare function storeConfig(incomingConfig: Object, merge?: boolean): Promise<void>;
@@ -29,8 +29,7 @@ export async function readVibeIQConfig() {
29
29
  console.debug(`failed to open config file (${configFileLocation}) for reading.`);
30
30
  console.debug('trying to initialize config file');
31
31
  await initializeVibeIQConfig();
32
- console.error(`Could not open config file (${configFileLocation}) for reading.`);
33
- throw e;
32
+ fileContent = await fsPromises.readFile(configFileLocation);
34
33
  }
35
34
  try {
36
35
  return JSON.parse(fileContent);
@@ -52,8 +51,20 @@ export async function getConfig() {
52
51
  console.debug("getting config from file system");
53
52
  return await readVibeIQConfig();
54
53
  }
55
- export async function storeConfig(incomingConfig) {
56
- const config = await readVibeIQConfig();
57
- const newConfig = Object.assign(Object.assign({}, config), incomingConfig);
58
- await writeVibeIQConfig(newConfig);
54
+ export async function deleteConfigs(configNames) {
55
+ const currentConfig = await readVibeIQConfig();
56
+ for (const configName of configNames) {
57
+ delete currentConfig[configName];
58
+ }
59
+ await storeConfig(currentConfig, false);
60
+ }
61
+ export async function storeConfig(incomingConfig, merge = true) {
62
+ let config;
63
+ if (merge) {
64
+ config = Object.assign(Object.assign({}, await readVibeIQConfig()), incomingConfig);
65
+ }
66
+ else {
67
+ config = incomingConfig;
68
+ }
69
+ await writeVibeIQConfig(config);
59
70
  }
@@ -0,0 +1,2 @@
1
+ export declare function listConfig(): Promise<void>;
2
+ export declare function removeConfig(args: any): Promise<void>;
@@ -0,0 +1,10 @@
1
+ import { deleteConfigs, readVibeIQConfig } from './config';
2
+ export async function listConfig() {
3
+ console.log(await readVibeIQConfig());
4
+ }
5
+ export async function removeConfig(args) {
6
+ if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
7
+ throw new Error('At least one configuration must be included to be removed.');
8
+ }
9
+ await deleteConfigs(args.slice(3));
10
+ }
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export declare function ParseOptionSetsLocalFiles(args: any): Promise<void>;
@@ -0,0 +1,46 @@
1
+ import fs from 'fs';
2
+ import { getSeparatorByPlatform } from '../common';
3
+ import { parseOptionSets } from '@contrail/types';
4
+ import chalk from 'chalk';
5
+ const csv = require('csvtojson');
6
+ const yaml = require('js-yaml');
7
+ export async function ParseOptionSetsLocalFiles(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 PARSE'));
13
+ const fileLocation = args[3];
14
+ console.log('Using File: ', fileLocation);
15
+ await parseOptionSetsLocalFiles(fileLocation);
16
+ console.log(`%s Parsed`, chalk.yellow.bold('OPTION SET PARSE'));
17
+ }
18
+ catch (e) {
19
+ console.log(`%s PARSE Failed. ${e}`, chalk.red.bold('FAIL'));
20
+ return;
21
+ }
22
+ console.log('%s PARSE Complete.', chalk.green.bold('COMPLETE'));
23
+ }
24
+ async function loadOptionSetCSV(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
+ return await csv().fromFile(fullPath);
31
+ }
32
+ catch (e) {
33
+ throw new Error(`ERROR PARSING CSV: ${e}`);
34
+ }
35
+ }
36
+ async function parseOptionSetsLocalFiles(fileLocation) {
37
+ const uploadedOptionData = await loadOptionSetCSV(fileLocation);
38
+ const parsedOptionSets = parseOptionSets(uploadedOptionData);
39
+ saveData({ optionSets: parsedOptionSets });
40
+ }
41
+ function saveData(data) {
42
+ const yamlStr = yaml.dump(data);
43
+ const CURRENT_DIR = process.cwd();
44
+ const separator = getSeparatorByPlatform();
45
+ fs.writeFileSync(CURRENT_DIR + separator + 'parsed_local_optionSets.yml', yamlStr, 'utf8');
46
+ }
@@ -1,9 +1,10 @@
1
- import { TypeProcessor } from '@contrail/sdk';
1
+ import { GetSuggestedTypes } from '@contrail/types';
2
2
  import chalk from 'chalk';
3
3
  import fs from 'fs';
4
4
  import { getSeparatorByPlatform } from '../common';
5
5
  import * as csvToJson from 'csvtojson';
6
6
  import { authUser } from '../auth/login';
7
+ import { getCSVFromFile } from './csv-parser';
7
8
  const yaml = require('js-yaml');
8
9
  export async function ParseTypesFromLocalFiles(args) {
9
10
  try {
@@ -39,7 +40,7 @@ export async function ParseTypesFromFiles(args) {
39
40
  }
40
41
  console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
41
42
  }
42
- async function loadDataFromCSV(fileName) {
43
+ async function loadDataFromLocalCSV(fileName) {
43
44
  const CURRENT_DIR = process.cwd();
44
45
  try {
45
46
  const separator = getSeparatorByPlatform();
@@ -57,7 +58,7 @@ async function parseTypesFromLocalFiles(fileLocations) {
57
58
  for (const fileLocation of fileLocations) {
58
59
  try {
59
60
  console.log('Getting data for fileLocation: ', fileLocation);
60
- const csvData = await loadDataFromCSV(fileLocation);
61
+ const csvData = await loadDataFromLocalCSV(fileLocation);
61
62
  console.log(`CSV import was successful. ${csvData === null || csvData === void 0 ? void 0 : csvData.length} rows found. Adding to total rows.`);
62
63
  csvJSONData.push(...csvData);
63
64
  }
@@ -67,13 +68,28 @@ async function parseTypesFromLocalFiles(fileLocations) {
67
68
  }
68
69
  }
69
70
  console.log(`CSV imports were successful. ${csvJSONData === null || csvJSONData === void 0 ? void 0 : csvJSONData.length} total rows found.`);
70
- const suggestions = await new TypeProcessor().GetSuggestedTypes(csvJSONData);
71
+ const suggestions = GetSuggestedTypes(csvJSONData);
71
72
  saveData({ optionSets: suggestions.OptionSets }, 'parsed_optionSets.yml');
72
73
  saveData({ typeProperties: suggestions.TypeProperties }, 'parsed_typeProperties.yml');
73
74
  }
74
75
  async function parseTypesFromFiles(fileIds) {
75
76
  await authUser();
76
- const suggestions = await new TypeProcessor().GetSuggestedTypesFromFiles({ loadFileIds: fileIds });
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);
77
93
  saveData({ optionSets: suggestions.OptionSets }, 'parsed_optionSets.yml');
78
94
  saveData({ typeProperties: suggestions.TypeProperties }, 'parsed_typeProperties.yml');
79
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
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.152",
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/cli.ts CHANGED
@@ -4,9 +4,12 @@ import { deployApp, removeApp } from './apps/deploy-app/deploy';
4
4
  import { getTypes } from './types/types-extractor';
5
5
  import { uploadTypes } from './types/types-uploader';
6
6
  import { UploadOptionSets } from './types/option-set-uploader';
7
+ import { ParseOptionSetsLocalFiles } from './types/option-set-parser';
7
8
  import { MergeOptionSets } from './types/option-set-merger';
8
9
  import { MergeTypeProperties } from './types/types-properties-merger';
9
10
  import { ParseTypesFromFiles, ParseTypesFromLocalFiles } from './types/parse-types';
11
+ import { loadColors, deleteColors } from './colors/color-loader';
12
+ import {listConfig, removeConfig} from './config/configCommands'
10
13
 
11
14
  const cliUsage = require('command-line-usage');
12
15
 
@@ -73,6 +76,10 @@ export async function cli(args) {
73
76
  UploadOptionSets(args);
74
77
  break;
75
78
  }
79
+ case 'parseOptionSetsLocalFiles': {
80
+ ParseOptionSetsLocalFiles(args);
81
+ break;
82
+ }
76
83
  case 'parseTypesFromLocalFiles': {
77
84
  ParseTypesFromLocalFiles(args);
78
85
  break;
@@ -95,6 +102,43 @@ export async function cli(args) {
95
102
  }
96
103
  break;
97
104
  }
105
+
106
+ case 'colors': {
107
+ switch (command) {
108
+ case 'load': {
109
+ await loadColors();
110
+ break;
111
+ }
112
+ // case 'delete': {
113
+ // await deleteColors();
114
+ // break;
115
+ // }
116
+ default: {
117
+ printIllegalCommand();
118
+ }
119
+ }
120
+ break;
121
+ }
122
+ case 'config': {
123
+ switch (command) {
124
+ case 'list': {
125
+ await listConfig();
126
+ break;
127
+ }
128
+ case 'remove': {
129
+ await removeConfig(args);
130
+ break;
131
+ }
132
+ // case 'delete': {
133
+ // await deleteColors();
134
+ // break;
135
+ // }
136
+ default: {
137
+ printIllegalCommand();
138
+ }
139
+ }
140
+ break;
141
+ }
98
142
  case 'help':
99
143
  case '-help':
100
144
  case '--help': {
@@ -145,6 +189,14 @@ const helpSections = [
145
189
  'remove Remove your app.',
146
190
  ],
147
191
  },
192
+ {
193
+ header: 'Colors Commands - Domain: colors',
194
+ content: [
195
+ 'load Load colors from a CSV. Headers (name, hex, red,',
196
+ '. green, blue) are required.',
197
+ // 'delete Delete all colors.',
198
+ ],
199
+ },
148
200
  {
149
201
  header: 'Type Commands - Domain: types',
150
202
  content: [
@@ -153,6 +205,7 @@ const helpSections = [
153
205
  '. Types are uploaded from types.yml\n',
154
206
  'uploadOptionSets Upload OptionSets for your Org.',
155
207
  '. OptionSets are loaded from option_sets.yml\n',
208
+ 'parseOptionSetsLocalFiles <File Paths> Parse CSV files into OptionSets',
156
209
  'parseTypesFromLocalFiles <File Paths> Parse CSV files into Types and ',
157
210
  '. OptionSets from local files.\n',
158
211
  'parseTypesFromFiles <fileIds> Parse CSV files into Types and ',