@contrail/cli 1.0.11 → 1.0.15

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.
@@ -1,6 +1,5 @@
1
1
  import { Entities, Request } from '@contrail/sdk';
2
- import { ReducedType, ReducedTypeProperties } from './interfaces';
3
- import { uploadOptionSets } from './option-set-uploader';
2
+ import { ReducedType, ReducedTypeProperty } from './interfaces';
4
3
  import chalk from 'chalk';
5
4
  import fs from 'fs';
6
5
  import { authUser } from '../auth/login';
@@ -14,10 +13,6 @@ export async function uploadTypes(args) {
14
13
  const userConfig = await authUser();
15
14
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
16
15
 
17
- console.log(`%s Uploading`, chalk.yellow.bold('OPTION SETS'));
18
- await uploadOptionSets();
19
- console.log(`%s Uploaded`, chalk.yellow.bold('OPTION SETS'));
20
-
21
16
  console.log(`%s Uploading`, chalk.yellow.bold('TYPES'));
22
17
  await uploadReducedTypes();
23
18
  console.log(`%s Uploaded`, chalk.yellow.bold('TYPES'));
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "test-app",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 1,
5
+ "requires": true,
6
+ "dependencies": {
7
+ "typescript": {
8
+ "version": "4.7.4",
9
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz",
10
+ "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==",
11
+ "dev": true
12
+ }
13
+ }
14
+ }
@@ -14,11 +14,13 @@
14
14
  "build": "tsc",
15
15
  "test": "echo \"Error: no test specified\" && exit 1"
16
16
  },
17
- "keywords": [
18
- ],
17
+ "keywords": [],
19
18
  "author": "",
20
19
  "license": "ISC",
21
20
  "dependencies": {
22
21
  "chalk": "^4.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "typescript": "^4.7.4"
23
25
  }
24
26
  }
@@ -1,2 +0,0 @@
1
- export declare function parseOptionSet(args: any): Promise<void>;
2
- export declare function parseOptionSets(fileName: any): Promise<void>;
@@ -1,79 +0,0 @@
1
- import { StringUtil } from '@contrail/util';
2
- import chalk from 'chalk';
3
- import fs from 'fs';
4
- import { getSeparatorByPlatform } from '../common';
5
- import * as csvToJson from 'csvtojson';
6
- const yaml = require('js-yaml');
7
- export async function parseOptionSet(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 Parsing`, chalk.yellow.bold('OPTION SETS'));
13
- await parseOptionSets(args[3]);
14
- console.log(`%s Parsed`, chalk.yellow.bold('OPTION SETS'));
15
- }
16
- catch (e) {
17
- console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
18
- return;
19
- }
20
- console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
21
- }
22
- async function loadDataFromCSV(fileName) {
23
- const CURRENT_DIR = process.cwd();
24
- try {
25
- const separator = getSeparatorByPlatform();
26
- const csvData = await csvToJson.default().fromFile(CURRENT_DIR + separator + fileName);
27
- return csvData;
28
- }
29
- catch (e) {
30
- throw new Error(`ERROR PARSING CSV: ${e}`);
31
- }
32
- }
33
- export async function parseOptionSets(fileName) {
34
- const csvData = await loadDataFromCSV(fileName);
35
- const removedFields = new Set();
36
- const valuesByFieldName = {};
37
- for (const row of csvData) {
38
- for (const [key, value] of Object.entries(row)) {
39
- // Dont parse boolean fields - later log removed fields
40
- if (value.toLowerCase() === 'false' || value.toLowerCase() === 'true') {
41
- removedFields.add(key);
42
- continue;
43
- }
44
- if (!value) {
45
- continue;
46
- }
47
- if (!valuesByFieldName[key]) {
48
- valuesByFieldName[key] = new Set();
49
- }
50
- valuesByFieldName[key].add(value);
51
- }
52
- }
53
- for (const removed of removedFields.values()) {
54
- console.log(`Removed Boolean Field: ${removed}`);
55
- }
56
- const reducedOptionSets = [];
57
- for (const [key, value] of Object.entries(valuesByFieldName)) {
58
- const optionSet = [];
59
- for (const entry of value.values()) {
60
- optionSet.push({
61
- value: StringUtil.convertToCamelCase(entry),
62
- display: isUpperCase(entry) ? entry : StringUtil.convertToTitleCase(entry),
63
- });
64
- }
65
- const reducedOptionSet = {
66
- name: StringUtil.convertToTitleCase(key),
67
- isArchived: false,
68
- optionSet,
69
- };
70
- reducedOptionSets.push(reducedOptionSet);
71
- }
72
- const yamlStr = yaml.dump(reducedOptionSets);
73
- const CURRENT_DIR = process.cwd();
74
- const separator = getSeparatorByPlatform();
75
- fs.writeFileSync(CURRENT_DIR + separator + 'parsed_option_sets.yml', yamlStr, 'utf8');
76
- }
77
- function isUpperCase(str) {
78
- return str === str.toUpperCase();
79
- }
@@ -1,96 +0,0 @@
1
- import { StringUtil } from '@contrail/util';
2
- import { ReducedOptionSet } from './interfaces';
3
- import chalk from 'chalk';
4
- import fs from 'fs';
5
- import { getSeparatorByPlatform } from '../common';
6
- import * as csvToJson from 'csvtojson';
7
-
8
- const yaml = require('js-yaml');
9
-
10
- export async function parseOptionSet(args) {
11
- try {
12
- if (args?.length < 4) {
13
- throw new Error('File name must be included.');
14
- }
15
- console.log(`%s Parsing`, chalk.yellow.bold('OPTION SETS'));
16
- await parseOptionSets(args[3]);
17
- console.log(`%s Parsed`, chalk.yellow.bold('OPTION SETS'));
18
-
19
- }
20
- catch (e) {
21
- console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
22
- return;
23
- }
24
-
25
- console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
26
- }
27
-
28
- async function loadDataFromCSV(fileName) {
29
- const CURRENT_DIR = process.cwd();
30
- try {
31
- const separator = getSeparatorByPlatform();
32
- const csvData = await csvToJson.default().fromFile(CURRENT_DIR + separator + fileName);
33
-
34
- return csvData;
35
- } catch (e) {
36
- throw new Error(`ERROR PARSING CSV: ${e}`);
37
- }
38
- }
39
-
40
- export async function parseOptionSets(fileName) {
41
- const csvData = await loadDataFromCSV(fileName);
42
-
43
- const removedFields = new Set<string>();
44
- const valuesByFieldName = {};
45
- for (const row of csvData) {
46
- for (const [key, value] of Object.entries(row)) {
47
-
48
- // Dont parse boolean fields - later log removed fields
49
- if ((value as string).toLowerCase() === 'false' || (value as string).toLowerCase() === 'true') {
50
- removedFields.add(key);
51
- continue;
52
- }
53
-
54
- if (!value) {
55
- continue;
56
- }
57
-
58
- if (!valuesByFieldName[key]) {
59
- valuesByFieldName[key] = new Set<string>();
60
- }
61
- (valuesByFieldName[key] as Set<string>).add(value as string);
62
- }
63
- }
64
-
65
- for (const removed of removedFields.values()) {
66
- console.log(`Removed Boolean Field: ${removed}`);
67
- }
68
-
69
- const reducedOptionSets = [];
70
- for (const [key, value] of Object.entries(valuesByFieldName)) {
71
- const optionSet = [];
72
- for (const entry of (value as Set<string>).values()) {
73
- optionSet.push({
74
- value: StringUtil.convertToCamelCase(entry),
75
- display: isUpperCase(entry) ? entry : StringUtil.convertToTitleCase(entry), // if all uppercase dont convert
76
- });
77
- }
78
-
79
- const reducedOptionSet: ReducedOptionSet = {
80
- name: StringUtil.convertToTitleCase(key),
81
- isArchived: false,
82
- optionSet,
83
- };
84
-
85
- reducedOptionSets.push(reducedOptionSet);
86
- }
87
-
88
- const yamlStr = yaml.dump(reducedOptionSets);
89
- const CURRENT_DIR = process.cwd();
90
- const separator = getSeparatorByPlatform();
91
- fs.writeFileSync(CURRENT_DIR + separator + 'parsed_option_sets.yml', yamlStr, 'utf8');
92
- }
93
-
94
- function isUpperCase(str) {
95
- return str === str.toUpperCase();
96
- }