@contrail/cli 1.0.31 → 1.0.32
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/.eslintrc.js +53 -0
- package/lib/apps/deploy-app/actions-deployer.js +12 -3
- package/lib/apps/deploy-app/app-deployer.js +2 -3
- package/lib/apps/deploy-app/app-template-parsers.js +1 -1
- package/lib/apps/deploy-app/docker-action-builder.d.ts +10 -0
- package/lib/apps/deploy-app/docker-action-builder.js +97 -0
- package/lib/apps/deploy-app/interfaces.d.ts +76 -0
- package/lib/apps/deploy-app/interfaces.js +4 -0
- package/lib/apps/deploy-app/workflow-definition-deployer.js +1 -1
- package/lib/apps/deploy-app/workflow-deployer.d.ts +10 -0
- package/lib/apps/deploy-app/workflow-deployer.js +87 -0
- package/lib/auth/login.js +5 -5
- package/lib/cli.js +2 -1
- package/lib/colors/color-loader.js +8 -8
- package/lib/config/config.js +2 -2
- package/lib/interfaces.d.ts +2 -2
- package/lib/types/interfaces.js +1 -0
- package/lib/types/option-set-merger.js +2 -2
- package/lib/types/option-set-parser.js +2 -2
- package/lib/types/option-set-uploader.js +2 -2
- package/lib/types/parse-types.js +6 -6
- package/lib/types/types-extractor.js +4 -4
- package/lib/types/types-properties-merger.js +2 -2
- package/lib/types/types-uploader.d.ts +1 -1
- package/lib/types/types-uploader.js +6 -6
- package/package.json +7 -5
- package/src/apps/deploy-app/actions-deployer.ts +17 -10
- package/src/apps/deploy-app/app-deployer.ts +3 -4
- package/src/apps/deploy-app/workflow-definition-deployer.ts +3 -3
- package/src/auth/login.ts +124 -124
- package/src/cli.ts +115 -115
- package/src/colors/color-loader.ts +16 -16
- package/src/config/config.ts +9 -11
- package/src/config/configCommands.ts +1 -1
- package/src/interfaces.ts +9 -10
- package/src/types/csv-parser.ts +1 -1
- package/src/types/option-set-merger.ts +9 -9
- package/src/types/option-set-parser.ts +5 -6
- package/src/types/option-set-uploader.ts +2 -2
- package/src/types/parse-types.ts +9 -9
- package/src/types/types-extractor.ts +5 -5
- package/src/types/types-properties-merger.ts +6 -6
- package/src/types/types-uploader.ts +31 -31
- package/src/workflows/workflow-template-deployer.ts +2 -4
- package/src/workflows/workflowCommands.ts +0 -1
- package/templates/javascript/actions/example/action.js +37 -37
- package/templates/typescript/actions/exampleAction.ts +1 -1
- package/templates/typescript/app.yml +1 -1
package/src/cli.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { MergeOptionSets } from './types/option-set-merger';
|
|
|
9
9
|
import { MergeTypeProperties } from './types/types-properties-merger';
|
|
10
10
|
import { ParseTypesFromFiles, ParseTypesFromLocalFiles, ParseTypesFromTemplateFromLocalFiles } from './types/parse-types';
|
|
11
11
|
import { loadColors, deleteColors } from './colors/color-loader';
|
|
12
|
-
import {listConfig, removeConfig} from './config/configCommands'
|
|
12
|
+
import {listConfig, removeConfig} from './config/configCommands';
|
|
13
13
|
import {deleteWorkflowTemplate, deployWorkflowTemplate, listWorkflowTemplate} from './workflows/workflowCommands';
|
|
14
14
|
const cliUsage = require('command-line-usage');
|
|
15
15
|
|
|
@@ -42,132 +42,132 @@ export async function cli(args) {
|
|
|
42
42
|
command = commandParts[1];
|
|
43
43
|
|
|
44
44
|
switch (domain) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case 'deploy': {
|
|
52
|
-
deployApp(args);
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case 'remove': {
|
|
56
|
-
removeApp(args);
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
default: {
|
|
60
|
-
printIllegalCommand();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
45
|
+
case 'app': {
|
|
46
|
+
switch (command) {
|
|
47
|
+
case 'create': {
|
|
48
|
+
create(args);
|
|
63
49
|
break;
|
|
64
50
|
}
|
|
65
|
-
case '
|
|
66
|
-
|
|
67
|
-
case 'getAll': {
|
|
68
|
-
getTypes(args);
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
case 'uploadTypes': {
|
|
72
|
-
uploadTypes(args);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
case 'uploadOptionSets': {
|
|
76
|
-
UploadOptionSets(args);
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case 'parseOptionSetsLocalFiles': {
|
|
80
|
-
ParseOptionSetsLocalFiles(args);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
case 'parseTypesFromLocalFiles': {
|
|
84
|
-
ParseTypesFromLocalFiles(args);
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case 'parseTypesFromTemplateFromLocalFiles': {
|
|
88
|
-
ParseTypesFromTemplateFromLocalFiles(args);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
case 'parseTypesFromFiles': {
|
|
92
|
-
ParseTypesFromFiles(args);
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
case 'mergeOptionSets': {
|
|
96
|
-
MergeOptionSets(args);
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
case 'mergeTypeProperties': {
|
|
100
|
-
MergeTypeProperties(args);
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
default: {
|
|
104
|
-
printIllegalCommand();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
51
|
+
case 'deploy': {
|
|
52
|
+
deployApp(args);
|
|
107
53
|
break;
|
|
108
54
|
}
|
|
55
|
+
case 'remove': {
|
|
56
|
+
removeApp(args);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
default: {
|
|
60
|
+
printIllegalCommand();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case 'types': {
|
|
66
|
+
switch (command) {
|
|
67
|
+
case 'getAll': {
|
|
68
|
+
getTypes(args);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case 'uploadTypes': {
|
|
72
|
+
uploadTypes();
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'uploadOptionSets': {
|
|
76
|
+
UploadOptionSets(args);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 'parseOptionSetsLocalFiles': {
|
|
80
|
+
ParseOptionSetsLocalFiles(args);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case 'parseTypesFromLocalFiles': {
|
|
84
|
+
ParseTypesFromLocalFiles(args);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'parseTypesFromTemplateFromLocalFiles': {
|
|
88
|
+
ParseTypesFromTemplateFromLocalFiles(args);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'parseTypesFromFiles': {
|
|
92
|
+
ParseTypesFromFiles(args);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'mergeOptionSets': {
|
|
96
|
+
MergeOptionSets(args);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 'mergeTypeProperties': {
|
|
100
|
+
MergeTypeProperties(args);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
default: {
|
|
104
|
+
printIllegalCommand();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
case 'delete': {
|
|
117
|
-
await deleteColors();
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
default: {
|
|
121
|
-
printIllegalCommand();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
110
|
+
case 'colors': {
|
|
111
|
+
switch (command) {
|
|
112
|
+
case 'load': {
|
|
113
|
+
await loadColors();
|
|
124
114
|
break;
|
|
125
115
|
}
|
|
126
|
-
case '
|
|
127
|
-
|
|
128
|
-
case 'load': {
|
|
129
|
-
await deployWorkflowTemplate();
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
case 'delete': {
|
|
133
|
-
await deleteWorkflowTemplate();
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
case 'list': {
|
|
137
|
-
await listWorkflowTemplate();
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
default: {
|
|
141
|
-
printIllegalCommand();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
116
|
+
case 'delete': {
|
|
117
|
+
await deleteColors();
|
|
144
118
|
break;
|
|
145
119
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
120
|
+
default: {
|
|
121
|
+
printIllegalCommand();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case 'workflow-templates': {
|
|
127
|
+
switch (command) {
|
|
128
|
+
case 'load': {
|
|
129
|
+
await deployWorkflowTemplate();
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case 'delete': {
|
|
133
|
+
await deleteWorkflowTemplate();
|
|
160
134
|
break;
|
|
161
135
|
}
|
|
162
|
-
case '
|
|
163
|
-
|
|
164
|
-
case '--help': {
|
|
165
|
-
printHelp();
|
|
136
|
+
case 'list': {
|
|
137
|
+
await listWorkflowTemplate();
|
|
166
138
|
break;
|
|
167
139
|
}
|
|
168
140
|
default: {
|
|
169
141
|
printIllegalCommand();
|
|
170
142
|
}
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case 'config': {
|
|
147
|
+
switch (command) {
|
|
148
|
+
case 'list': {
|
|
149
|
+
await listConfig();
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'remove': {
|
|
153
|
+
await removeConfig(args);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
default: {
|
|
157
|
+
printIllegalCommand();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 'help':
|
|
163
|
+
case '-help':
|
|
164
|
+
case '--help': {
|
|
165
|
+
printHelp();
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
default: {
|
|
169
|
+
printIllegalCommand();
|
|
170
|
+
}
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -244,13 +244,13 @@ const helpSections = [
|
|
|
244
244
|
'parseTypesFromFiles <fileIds> Parse CSV files into Types and ',
|
|
245
245
|
'. OptionSets from VibeIQ Files.\n',
|
|
246
246
|
'mergeOptionSets <File Path> Merge the OptionSets from an existing',
|
|
247
|
-
'. org and the OptionSets passed in.',
|
|
247
|
+
'. org and the OptionSets passed in.',
|
|
248
248
|
'. File must be .yml\n',
|
|
249
|
-
'mergeTypeProperties <File Path> <TypePaths> ',
|
|
249
|
+
'mergeTypeProperties <File Path> <TypePaths> ',
|
|
250
250
|
'. Merge the TypeProperties from an existing',
|
|
251
251
|
'. org and the TypeProperties passed in.',
|
|
252
|
-
'. Add to Types via TypePath',
|
|
252
|
+
'. Add to Types via TypePath',
|
|
253
253
|
'. File must be .yml\n',
|
|
254
254
|
],
|
|
255
255
|
},
|
|
256
|
-
];
|
|
256
|
+
];
|
|
@@ -3,7 +3,7 @@ import chalk from 'chalk';
|
|
|
3
3
|
import { authUser } from '../auth/login';
|
|
4
4
|
import { getSeparatorByPlatform } from '../common';
|
|
5
5
|
|
|
6
|
-
const csv = require('csvtojson')
|
|
6
|
+
const csv = require('csvtojson');
|
|
7
7
|
|
|
8
8
|
interface Color {
|
|
9
9
|
name: string;
|
|
@@ -17,7 +17,7 @@ export async function deleteColors() {
|
|
|
17
17
|
try {
|
|
18
18
|
await authUser();
|
|
19
19
|
const colors = await getExistingColors();
|
|
20
|
-
console.log(
|
|
20
|
+
console.log('Deleting %s colors', colors.length);
|
|
21
21
|
for (const color of colors) {
|
|
22
22
|
await deleteColor(color);
|
|
23
23
|
}
|
|
@@ -32,10 +32,10 @@ export async function deleteColors() {
|
|
|
32
32
|
export async function loadColors() {
|
|
33
33
|
try {
|
|
34
34
|
await authUser();
|
|
35
|
-
console.log(
|
|
36
|
-
console.log(
|
|
35
|
+
console.log('%s Getting Existing Colors', chalk.yellow.bold('COLORS'));
|
|
36
|
+
console.log('%s Uploading', chalk.yellow.bold('COLORS'));
|
|
37
37
|
await uploadColors();
|
|
38
|
-
console.log(
|
|
38
|
+
console.log('%s Uploaded', chalk.yellow.bold('COLORS'));
|
|
39
39
|
|
|
40
40
|
}
|
|
41
41
|
catch (e) {
|
|
@@ -47,23 +47,23 @@ export async function loadColors() {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
async function getLocalColors() {
|
|
50
|
-
console.log(
|
|
50
|
+
console.log('loading colors from local file');
|
|
51
51
|
const TARGET_DIR = process.cwd();
|
|
52
52
|
try {
|
|
53
53
|
const separator = getSeparatorByPlatform();
|
|
54
54
|
|
|
55
|
-
const csvFilePath = TARGET_DIR + separator + 'colors.csv'
|
|
56
|
-
return await csv().fromFile(csvFilePath)
|
|
55
|
+
const csvFilePath = TARGET_DIR + separator + 'colors.csv';
|
|
56
|
+
return await csv().fromFile(csvFilePath);
|
|
57
57
|
} catch (e) {
|
|
58
58
|
throw new Error(`ERROR PARSING COLORS CSV: ${e}`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
async function getExistingColors() {
|
|
63
|
-
console.log(
|
|
63
|
+
console.log('%s Getting Existing Colors', chalk.yellow.bold('COLORS'));
|
|
64
64
|
try {
|
|
65
65
|
const result = await new Entities().get({ entityName: 'color', take: 3000}); //, useSearch: false }); Not in EntitiesClientGetOptions yet
|
|
66
|
-
console.log(
|
|
66
|
+
console.log('Found %s existing colors', result.length);
|
|
67
67
|
return result;
|
|
68
68
|
} catch (e) {
|
|
69
69
|
throw new Error(`ERROR DOWNLOADING COLORS: ${e}`);
|
|
@@ -81,10 +81,10 @@ async function deleteColor(color) {
|
|
|
81
81
|
async function uploadColors() {
|
|
82
82
|
const colors: Color[] = await getLocalColors();
|
|
83
83
|
const existingColors = await getExistingColors();
|
|
84
|
-
const existingNamesValues = existingColors.filter(x => x.name).map(x => x.name)
|
|
84
|
+
const existingNamesValues = existingColors.filter(x => x.name).map(x => x.name);
|
|
85
85
|
for (const color of colors) {
|
|
86
86
|
if (existingNamesValues.includes(color.name)) {
|
|
87
|
-
console.log(
|
|
87
|
+
console.log('%s SKIPPING %s (%s)', chalk.yellow.bold('COLORS'), color.hex, color.name);
|
|
88
88
|
continue;
|
|
89
89
|
}
|
|
90
90
|
if (color.hex.length > 1 && color.hex[0] === '#') {
|
|
@@ -93,15 +93,15 @@ async function uploadColors() {
|
|
|
93
93
|
const o: any = {
|
|
94
94
|
hex: color.hex,
|
|
95
95
|
name: color.name
|
|
96
|
-
}
|
|
96
|
+
};
|
|
97
97
|
if (color.red) {
|
|
98
|
-
o.red = color.red
|
|
98
|
+
o.red = color.red;
|
|
99
99
|
}
|
|
100
100
|
if (color.green) {
|
|
101
|
-
o.green = color.green
|
|
101
|
+
o.green = color.green;
|
|
102
102
|
}
|
|
103
103
|
if (color.blue) {
|
|
104
|
-
o.blue = color.blue
|
|
104
|
+
o.blue = color.blue;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
await new Entities().create({
|
package/src/config/config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { promises as fsPromises } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import {homedir} from 'os';
|
|
4
4
|
const userHomeDir = homedir();
|
|
@@ -7,16 +7,16 @@ const configFileLocation = join(configDirectoryLocation, 'config.json');
|
|
|
7
7
|
|
|
8
8
|
export async function initializeVibeIQConfig() {
|
|
9
9
|
try{
|
|
10
|
-
await fsPromises.mkdir(configDirectoryLocation, {recursive: true})
|
|
10
|
+
await fsPromises.mkdir(configDirectoryLocation, {recursive: true});
|
|
11
11
|
} catch (e) {
|
|
12
|
-
console.error(
|
|
13
|
-
throw e
|
|
12
|
+
console.error('could not initialize vibeiq directory');
|
|
13
|
+
throw e;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
try {
|
|
17
17
|
await fsPromises.writeFile(configFileLocation, '{}');
|
|
18
18
|
} catch (e) {
|
|
19
|
-
console.error(`could not initialize config file (${configFileLocation}).`)
|
|
19
|
+
console.error(`could not initialize config file (${configFileLocation}).`);
|
|
20
20
|
throw e;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -38,18 +38,17 @@ export async function readVibeIQConfig() {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
41
|
export async function writeVibeIQConfig(config: Object) {
|
|
43
42
|
try {
|
|
44
43
|
await fsPromises.writeFile(configFileLocation, JSON.stringify(config, null, 2));
|
|
45
44
|
} catch (e) {
|
|
46
45
|
console.error(`Could not open config file (${configFileLocation}) for writing.`);
|
|
47
|
-
throw e
|
|
46
|
+
throw e;
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
export async function getConfig() {
|
|
52
|
-
console.debug(
|
|
51
|
+
console.debug('getting config from file system');
|
|
53
52
|
return await readVibeIQConfig();
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -67,10 +66,9 @@ export async function storeConfig(incomingConfig: Object, merge=true) {
|
|
|
67
66
|
config = {
|
|
68
67
|
... await readVibeIQConfig(),
|
|
69
68
|
... incomingConfig
|
|
70
|
-
}
|
|
69
|
+
};
|
|
71
70
|
} else {
|
|
72
|
-
config = incomingConfig
|
|
71
|
+
config = incomingConfig;
|
|
73
72
|
}
|
|
74
73
|
await writeVibeIQConfig(config);
|
|
75
74
|
}
|
|
76
|
-
|
package/src/interfaces.ts
CHANGED
|
@@ -15,7 +15,6 @@ export interface AppDeclaration {
|
|
|
15
15
|
appConfiguration: ConfigPropertyElements;
|
|
16
16
|
triggers: { [key: string]: AppTriggerDeclaration };
|
|
17
17
|
workflows?: { [key: string]: WorkflowDefinition|WorkflowTemplateDeclaration };
|
|
18
|
-
isDockerBased?: boolean;
|
|
19
18
|
dockerImageRef?: string;
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -35,6 +34,7 @@ export interface AppActionDeclaration {
|
|
|
35
34
|
name: string;
|
|
36
35
|
description?: string;
|
|
37
36
|
actionConfiguration?: ConfigPropertyElements;
|
|
37
|
+
async?: boolean; // defaults to false
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export interface AppTriggerDeclaration {
|
|
@@ -44,7 +44,6 @@ export interface AppTriggerDeclaration {
|
|
|
44
44
|
description?: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
47
|
export interface WorkflowDefinition {
|
|
49
48
|
id?: string;
|
|
50
49
|
identifier: string;
|
|
@@ -105,10 +104,10 @@ export interface App {
|
|
|
105
104
|
}
|
|
106
105
|
|
|
107
106
|
export class ConfigProperty {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
slug: string;
|
|
108
|
+
propertyType: string;
|
|
109
|
+
options?: any[];
|
|
110
|
+
label: string;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
export interface EventWorkflowActionDefinition {
|
|
@@ -119,12 +118,12 @@ export interface EventWorkflowActionDefinition {
|
|
|
119
118
|
ownerKey?: string;
|
|
120
119
|
public?: boolean;
|
|
121
120
|
configProperties?: ConfigProperty[];
|
|
122
|
-
|
|
121
|
+
async?: boolean;
|
|
123
122
|
}
|
|
124
123
|
|
|
125
124
|
export class TriggerKeyDefinition {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
name: string;
|
|
126
|
+
description?: string;
|
|
127
|
+
triggerKey: string;
|
|
129
128
|
external?: boolean;
|
|
130
129
|
}
|
package/src/types/csv-parser.ts
CHANGED
|
@@ -11,12 +11,12 @@ export async function MergeOptionSets(args) {
|
|
|
11
11
|
if (args?.length < 4) {
|
|
12
12
|
throw new Error('File name must be included.');
|
|
13
13
|
}
|
|
14
|
-
console.log(
|
|
14
|
+
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET MERGE'));
|
|
15
15
|
const fileLocation = args[3];
|
|
16
16
|
console.log('Using File: ', fileLocation);
|
|
17
17
|
|
|
18
18
|
await mergeOptionSets(fileLocation);
|
|
19
|
-
console.log(
|
|
19
|
+
console.log('%s Merged', chalk.yellow.bold('OPTION SET MERGE'));
|
|
20
20
|
|
|
21
21
|
}
|
|
22
22
|
catch (e) {
|
|
@@ -66,7 +66,7 @@ async function mergeOptionSets(fileLocation) {
|
|
|
66
66
|
uploadedOptionSetsByName[optionSet.name] = optionSet;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
const mergedOptionSets: any[] = []
|
|
69
|
+
const mergedOptionSets: any[] = [];
|
|
70
70
|
for (const uploadedOptionSet of uploadedOptionSets) {
|
|
71
71
|
const existing = currentOptionSetsByName[uploadedOptionSet.name];
|
|
72
72
|
if (!existing) {
|
|
@@ -91,7 +91,7 @@ async function mergeOptionSets(fileLocation) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
saveData({optionSets: mergedOptionSets})
|
|
94
|
+
saveData({optionSets: mergedOptionSets});
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
function mergeOptionSet(existingOptionSet: ReducedOptionSet, uploadedOptionSet: ReducedOptionSet) {
|
|
@@ -99,15 +99,15 @@ function mergeOptionSet(existingOptionSet: ReducedOptionSet, uploadedOptionSet:
|
|
|
99
99
|
name: uploadedOptionSet.name,
|
|
100
100
|
optionSet: uploadedOptionSet.optionSet,
|
|
101
101
|
isArchived: uploadedOptionSet.isArchived,
|
|
102
|
-
}
|
|
102
|
+
};
|
|
103
103
|
|
|
104
104
|
for (const keyVal of existingOptionSet.optionSet) {
|
|
105
|
-
const value = keyVal.value
|
|
106
|
-
const display = keyVal.display
|
|
105
|
+
const value = keyVal.value;
|
|
106
|
+
const display = keyVal.display;
|
|
107
107
|
|
|
108
|
-
const found = merged.optionSet.find(keyVal => keyVal.value === value)
|
|
108
|
+
const found = merged.optionSet.find(keyVal => keyVal.value === value);
|
|
109
109
|
if (!found) {
|
|
110
|
-
merged.optionSet.push({value, display})
|
|
110
|
+
merged.optionSet.push({value, display});
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { ReducedOptionSet } from './interfaces';
|
|
2
1
|
import fs from 'fs';
|
|
3
2
|
import { getSeparatorByPlatform } from '../common';
|
|
4
3
|
import { parseOptionSets } from '@contrail/types';
|
|
5
4
|
import chalk from 'chalk';
|
|
6
|
-
const csv = require('csvtojson')
|
|
5
|
+
const csv = require('csvtojson');
|
|
7
6
|
const yaml = require('js-yaml');
|
|
8
7
|
|
|
9
8
|
export async function ParseOptionSetsLocalFiles(args) {
|
|
@@ -11,12 +10,12 @@ export async function ParseOptionSetsLocalFiles(args) {
|
|
|
11
10
|
if (args?.length < 4) {
|
|
12
11
|
throw new Error('File name must be included.');
|
|
13
12
|
}
|
|
14
|
-
console.log(
|
|
13
|
+
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET PARSE'));
|
|
15
14
|
const fileLocation = args[3];
|
|
16
15
|
console.log('Using File: ', fileLocation);
|
|
17
16
|
|
|
18
17
|
await parseOptionSetsLocalFiles(fileLocation);
|
|
19
|
-
console.log(
|
|
18
|
+
console.log('%s Parsed', chalk.yellow.bold('OPTION SET PARSE'));
|
|
20
19
|
|
|
21
20
|
}
|
|
22
21
|
catch (e) {
|
|
@@ -35,7 +34,7 @@ async function loadOptionSetCSV(fileLocation) {
|
|
|
35
34
|
const fullPath = TARGET_DIR + separator + fileLocation;
|
|
36
35
|
console.log('Getting file from path: ', fullPath);
|
|
37
36
|
|
|
38
|
-
return await csv().fromFile(fullPath)
|
|
37
|
+
return await csv().fromFile(fullPath);
|
|
39
38
|
} catch (e) {
|
|
40
39
|
throw new Error(`ERROR PARSING CSV: ${e}`);
|
|
41
40
|
}
|
|
@@ -50,7 +49,7 @@ async function parseOptionSetsLocalFiles(fileLocation) {
|
|
|
50
49
|
// }
|
|
51
50
|
|
|
52
51
|
const parsedOptionSets = parseOptionSets(uploadedOptionData);
|
|
53
|
-
saveData({optionSets: parsedOptionSets})
|
|
52
|
+
saveData({optionSets: parsedOptionSets});
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
function saveData(data) {
|
|
@@ -12,9 +12,9 @@ export async function UploadOptionSets(args) {
|
|
|
12
12
|
const userConfig = await authUser();
|
|
13
13
|
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
14
14
|
|
|
15
|
-
console.log(
|
|
15
|
+
console.log('%s Uploading', chalk.yellow.bold('OPTION SETS'));
|
|
16
16
|
await uploadOptionSets();
|
|
17
|
-
console.log(
|
|
17
|
+
console.log('%s Uploaded', chalk.yellow.bold('OPTION SETS'));
|
|
18
18
|
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
package/src/types/parse-types.ts
CHANGED
|
@@ -14,12 +14,12 @@ export async function ParseTypesFromLocalFiles(args) {
|
|
|
14
14
|
if (args?.length < 4) {
|
|
15
15
|
throw new Error('File names must be included.');
|
|
16
16
|
}
|
|
17
|
-
console.log(
|
|
17
|
+
console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
18
18
|
const fileLocations = (args as Array<string>).slice(3);
|
|
19
19
|
console.log('Using File Location(s): ', fileLocations);
|
|
20
20
|
|
|
21
21
|
await parseTypesFromLocalFiles(fileLocations);
|
|
22
|
-
console.log(
|
|
22
|
+
console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
23
23
|
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
@@ -36,12 +36,12 @@ export async function ParseTypesFromFiles(args) {
|
|
|
36
36
|
if (args?.length < 4) {
|
|
37
37
|
throw new Error('File ids must be included.');
|
|
38
38
|
}
|
|
39
|
-
console.log(
|
|
39
|
+
console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
40
40
|
const fileIds = (args as Array<string>).slice(3);
|
|
41
41
|
console.log('Using FileId(s): ', fileIds);
|
|
42
42
|
|
|
43
43
|
await parseTypesFromFiles(fileIds);
|
|
44
|
-
console.log(
|
|
44
|
+
console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
45
45
|
|
|
46
46
|
}
|
|
47
47
|
catch (e) {
|
|
@@ -58,14 +58,14 @@ export async function ParseTypesFromTemplateFromLocalFiles(args) {
|
|
|
58
58
|
if (args?.length < 5) {
|
|
59
59
|
throw new Error('File names must be included.');
|
|
60
60
|
}
|
|
61
|
-
console.log(
|
|
61
|
+
console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
62
62
|
const templateFileLocation = args[3];
|
|
63
63
|
const dataFileLocation = args[4];
|
|
64
64
|
console.log('Using Template File Location: ', templateFileLocation);
|
|
65
65
|
console.log('Using Data File Location: ', dataFileLocation);
|
|
66
66
|
|
|
67
67
|
await parseTypesFromTemplateFromLocalFiles(templateFileLocation, dataFileLocation);
|
|
68
|
-
console.log(
|
|
68
|
+
console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
69
69
|
|
|
70
70
|
}
|
|
71
71
|
catch (e) {
|
|
@@ -109,7 +109,7 @@ async function parseTypesFromLocalFiles(fileLocations: string[]) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
console.log(`CSV imports were successful. ${csvJSONData?.length} total rows found.`);
|
|
112
|
-
const suggestions = GetSuggestedTypes(csvJSONData)
|
|
112
|
+
const suggestions = GetSuggestedTypes(csvJSONData);
|
|
113
113
|
saveData({ optionSets: suggestions.OptionSets }, 'parsed_optionSets.yml');
|
|
114
114
|
saveData({ typeProperties: suggestions.TypeProperties }, 'parsed_typeProperties.yml');
|
|
115
115
|
}
|
|
@@ -132,7 +132,7 @@ async function parseTypesFromTemplateFromLocalFiles(templateFileLocation: string
|
|
|
132
132
|
throw e;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
const types = GetTypesFromTemplate(templateCSVData, dataCSVData)
|
|
135
|
+
const types = GetTypesFromTemplate(templateCSVData, dataCSVData);
|
|
136
136
|
saveData({ optionSets: types.OptionSets }, 'parsed_optionSets.yml');
|
|
137
137
|
saveData({ TypePropertiesByEntity: types.TypePropertiesByEntity }, 'parsed_TypePropertiesByEntity.yml');
|
|
138
138
|
}
|
|
@@ -156,7 +156,7 @@ async function parseTypesFromFiles(fileIds: string[]) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
console.log(`CSV downloads were successful. ${csvJSONData?.length} total rows found.`);
|
|
159
|
-
const suggestions = GetSuggestedTypes(csvJSONData)
|
|
159
|
+
const suggestions = GetSuggestedTypes(csvJSONData);
|
|
160
160
|
|
|
161
161
|
saveData({ optionSets: suggestions.OptionSets }, 'parsed_optionSets.yml');
|
|
162
162
|
saveData({ typeProperties: suggestions.TypeProperties }, 'parsed_typeProperties.yml');
|