@contrail/cli 1.0.16 → 1.0.18
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 +5 -0
- package/lib/cli.js +51 -0
- package/lib/colors/color-loader.d.ts +2 -0
- package/lib/colors/color-loader.js +94 -0
- package/lib/config/config.d.ts +2 -1
- package/lib/config/config.js +17 -6
- package/lib/config/configCommands.d.ts +2 -0
- package/lib/config/configCommands.js +10 -0
- package/lib/types/option-set-parser.d.ts +1 -0
- package/lib/types/option-set-parser.js +50 -0
- package/package.json +1 -1
- package/src/cli.ts +53 -0
- package/src/colors/color-example.csv +866 -0
- package/src/colors/color-loader.ts +110 -0
- package/src/config/config.ts +20 -9
- package/src/config/configCommands.ts +13 -0
- package/src/types/option-set-parser.ts +61 -0
package/README.md
ADDED
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,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
|
+
}
|
package/lib/config/config.d.ts
CHANGED
|
@@ -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
|
|
5
|
+
export declare function deleteConfigs(configNames: string[]): Promise<void>;
|
|
6
|
+
export declare function storeConfig(incomingConfig: Object, merge?: boolean): Promise<void>;
|
package/lib/config/config.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
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,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 ParseOptionSetsLocalFiles(args: any): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
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 newData = [];
|
|
39
|
+
// for (const row of uploadedOptionData) {
|
|
40
|
+
// newData.push({[row.optionSetName]: row.displayName});
|
|
41
|
+
// }
|
|
42
|
+
const parsedOptionSets = parseOptionSets(uploadedOptionData);
|
|
43
|
+
saveData({ optionSets: parsedOptionSets });
|
|
44
|
+
}
|
|
45
|
+
function saveData(data) {
|
|
46
|
+
const yamlStr = yaml.dump(data);
|
|
47
|
+
const CURRENT_DIR = process.cwd();
|
|
48
|
+
const separator = getSeparatorByPlatform();
|
|
49
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'parsed_local_optionSets.yml', yamlStr, 'utf8');
|
|
50
|
+
}
|
package/package.json
CHANGED
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 ',
|