@contrail/cli 1.0.70 → 2.0.0

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 (270) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1034 -5
  3. package/bin/dev +17 -0
  4. package/bin/dev.cmd +3 -0
  5. package/bin/run +5 -0
  6. package/bin/run.cmd +3 -0
  7. package/{lib → dist}/api/apps.d.ts +13 -13
  8. package/dist/api/apps.js +96 -0
  9. package/{lib → dist}/api/event-workflow-action-definition.d.ts +1 -1
  10. package/dist/api/event-workflow-action-definition.js +11 -0
  11. package/{lib → dist}/api/event-workflow-template-definition.d.ts +6 -6
  12. package/dist/api/event-workflow-template-definition.js +26 -0
  13. package/{lib → dist}/api/event-workflow-templates.d.ts +7 -7
  14. package/dist/api/event-workflow-templates.js +32 -0
  15. package/dist/api/types.d.ts +7 -0
  16. package/dist/api/types.js +52 -0
  17. package/{lib → dist}/auth/auth.d.ts +9 -9
  18. package/dist/auth/auth.js +6 -0
  19. package/{lib → dist}/auth/login.d.ts +2 -2
  20. package/{lib → dist}/auth/login.js +146 -141
  21. package/dist/commands/app/create.d.ts +6 -0
  22. package/dist/commands/app/create.js +15 -0
  23. package/dist/commands/app/delete.d.ts +7 -0
  24. package/dist/commands/app/delete.js +38 -0
  25. package/dist/commands/app/install.d.ts +11 -0
  26. package/dist/commands/app/install.js +117 -0
  27. package/dist/commands/app/publish.d.ts +7 -0
  28. package/dist/commands/app/publish.js +45 -0
  29. package/dist/commands/app/uninstall.d.ts +10 -0
  30. package/dist/commands/app/uninstall.js +58 -0
  31. package/dist/commands/app/upgrade.d.ts +11 -0
  32. package/dist/commands/app/upgrade.js +79 -0
  33. package/dist/commands/colors/deleteAll.d.ts +6 -0
  34. package/dist/commands/colors/deleteAll.js +30 -0
  35. package/dist/commands/colors/load.d.ts +6 -0
  36. package/dist/commands/colors/load.js +29 -0
  37. package/dist/commands/config/list.d.ts +6 -0
  38. package/dist/commands/config/list.js +15 -0
  39. package/dist/commands/config/remove.d.ts +14 -0
  40. package/dist/commands/config/remove.js +26 -0
  41. package/dist/commands/config/set.d.ts +13 -0
  42. package/dist/commands/config/set.js +29 -0
  43. package/dist/commands/loader-process/load.d.ts +9 -0
  44. package/dist/commands/loader-process/load.js +33 -0
  45. package/dist/commands/loader-process/upload-and-load.d.ts +10 -0
  46. package/dist/commands/loader-process/upload-and-load.js +35 -0
  47. package/dist/commands/projects/export.d.ts +10 -0
  48. package/dist/commands/projects/export.js +34 -0
  49. package/dist/commands/projects/list.d.ts +6 -0
  50. package/dist/commands/projects/list.js +34 -0
  51. package/dist/commands/projects/load.d.ts +9 -0
  52. package/{lib/projects/project-uploader.js → dist/commands/projects/load.js} +106 -105
  53. package/dist/commands/types/exportOptionSetHierarchies.d.ts +7 -0
  54. package/{lib/types/option-set-hierarchy-exporter.js → dist/commands/types/exportOptionSetHierarchies.js} +130 -113
  55. package/{lib/types/types-extractor.d.ts → dist/commands/types/getAll.d.ts} +29 -27
  56. package/{lib/types/types-extractor.js → dist/commands/types/getAll.js} +267 -318
  57. package/dist/commands/types/loadAll.d.ts +7 -0
  58. package/dist/commands/types/loadAll.js +41 -0
  59. package/dist/commands/types/mergeOptionSets.d.ts +9 -0
  60. package/{lib/types/option-set-merger.js → dist/commands/types/mergeOptionSets.js} +114 -105
  61. package/dist/commands/types/mergeTypeProperties.d.ts +11 -0
  62. package/dist/commands/types/mergeTypeProperties.js +89 -0
  63. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +10 -0
  64. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +112 -0
  65. package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +14 -0
  66. package/dist/commands/types/parseOptionSetsLocalFiles.js +153 -0
  67. package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +10 -0
  68. package/dist/commands/types/parseOptionSetsToFolderStructure.js +104 -0
  69. package/dist/commands/types/parseTypesFromFiles.d.ts +10 -0
  70. package/dist/commands/types/parseTypesFromFiles.js +34 -0
  71. package/dist/commands/types/parseTypesFromLocalFiles.d.ts +10 -0
  72. package/dist/commands/types/parseTypesFromLocalFiles.js +34 -0
  73. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +11 -0
  74. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +36 -0
  75. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +10 -0
  76. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +35 -0
  77. package/dist/commands/types/uploadOptionSetHierarchies.d.ts +7 -0
  78. package/{lib/types/option-set-hierarchy-uploader.js → dist/commands/types/uploadOptionSetHierarchies.js} +130 -113
  79. package/dist/commands/types/uploadOptionSets.d.ts +7 -0
  80. package/{lib/types/option-set-uploader.js → dist/commands/types/uploadOptionSets.js} +115 -98
  81. package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +11 -0
  82. package/{lib/types/option-set-hierarchy-parser.js → dist/commands/types/uploadOptionSetsHierarchyLocalFile.js} +128 -140
  83. package/dist/commands/types/uploadRuleSets.d.ts +7 -0
  84. package/{lib/types/rule-set-uploader.js → dist/commands/types/uploadRuleSets.js} +189 -172
  85. package/dist/commands/types/uploadTypePropertyPolicies.d.ts +7 -0
  86. package/{lib/types/type-property-policy-uploader.js → dist/commands/types/uploadTypePropertyPolicies.js} +195 -178
  87. package/dist/commands/types/uploadUsageInfo.d.ts +7 -0
  88. package/{lib/types/usage-info-uploader.js → dist/commands/types/uploadUsageInfo.js} +149 -132
  89. package/dist/commands/users/export.d.ts +9 -0
  90. package/dist/commands/users/export.js +60 -0
  91. package/dist/commands/users/upload.d.ts +9 -0
  92. package/dist/commands/users/upload.js +65 -0
  93. package/dist/commands/workflow-template-definitions/install.d.ts +6 -0
  94. package/dist/commands/workflow-template-definitions/install.js +17 -0
  95. package/dist/commands/workflow-template-definitions/list.d.ts +6 -0
  96. package/dist/commands/workflow-template-definitions/list.js +17 -0
  97. package/dist/commands/workflow-templates/delete.d.ts +6 -0
  98. package/dist/commands/workflow-templates/delete.js +17 -0
  99. package/dist/commands/workflow-templates/list.d.ts +6 -0
  100. package/dist/commands/workflow-templates/list.js +17 -0
  101. package/dist/commands/workflow-templates/load.d.ts +9 -0
  102. package/dist/commands/workflow-templates/load.js +21 -0
  103. package/{lib → dist}/common.d.ts +1 -1
  104. package/dist/common.js +9 -0
  105. package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.d.ts +11 -11
  106. package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.js +122 -114
  107. package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.d.ts +8 -8
  108. package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.js +98 -93
  109. package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.d.ts +7 -7
  110. package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.js +43 -38
  111. package/dist/helpers/app/load-app-config.d.ts +1 -0
  112. package/dist/helpers/app/load-app-config.js +18 -0
  113. package/dist/helpers/app/setup-template.d.ts +1 -0
  114. package/dist/helpers/app/setup-template.js +38 -0
  115. package/dist/helpers/colors/helpers.d.ts +4 -0
  116. package/dist/helpers/colors/helpers.js +74 -0
  117. package/{lib → dist/helpers}/config/config.d.ts +6 -6
  118. package/dist/helpers/config/config.js +76 -0
  119. package/dist/helpers/loader-process/helpers.d.ts +2 -0
  120. package/{lib/loader-process/loader-process.js → dist/helpers/loader-process/helpers.js} +98 -120
  121. package/dist/helpers/projects/helpers.d.ts +2 -0
  122. package/{lib/projects/project-exporter.js → dist/helpers/projects/helpers.js} +165 -187
  123. package/{lib → dist/helpers}/types/csv-parser.d.ts +1 -1
  124. package/{lib → dist/helpers}/types/csv-parser.js +56 -51
  125. package/dist/helpers/types/type-extractor.d.ts +1 -0
  126. package/dist/helpers/types/type-extractor.js +32 -0
  127. package/dist/helpers/types/type-parser.d.ts +4 -0
  128. package/dist/helpers/types/type-parser.js +118 -0
  129. package/{lib/types/types-uploader.d.ts → dist/helpers/types/type-uploader.d.ts} +1 -1
  130. package/{lib/types/types-uploader.js → dist/helpers/types/type-uploader.js} +244 -239
  131. package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
  132. package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.js +156 -151
  133. package/{lib/workflow-templates/local-workflow-template-deployer.d.ts → dist/helpers/workflow-templates/helper.d.ts} +17 -11
  134. package/dist/helpers/workflow-templates/helper.js +166 -0
  135. package/dist/index.d.ts +1 -0
  136. package/dist/index.js +5 -0
  137. package/{lib → dist}/interfaces.d.ts +323 -191
  138. package/dist/interfaces.js +63 -0
  139. package/{templates → dist/templates}/typescript/Dockerfile +15 -15
  140. package/{templates → dist/templates}/typescript/README.md +10 -10
  141. package/{templates → dist/templates}/typescript/app.yml +49 -49
  142. package/{templates → dist/templates}/typescript/docker_deploy.bat +1 -1
  143. package/{templates → dist/templates}/typescript/package.json +54 -54
  144. package/{templates → dist/templates}/typescript/src/actions/logItem.ts +25 -25
  145. package/{templates → dist/templates}/typescript/src/framework/action-dispatcher.ts +89 -89
  146. package/{templates → dist/templates}/typescript/src/framework/app-config.ts +26 -26
  147. package/{templates → dist/templates}/typescript/src/framework/index.ts +2 -2
  148. package/{templates → dist/templates}/typescript/src/framework/interfaces.ts +32 -32
  149. package/{templates → dist/templates}/typescript/tsconfig.json +28 -28
  150. package/oclif.manifest.json +821 -0
  151. package/package.json +116 -72
  152. package/.eslintrc.js +0 -53
  153. package/.vscode/settings.json +0 -6
  154. package/bin/init +0 -4
  155. package/lib/api/apps.js +0 -85
  156. package/lib/api/event-workflow-action-definition.js +0 -7
  157. package/lib/api/event-workflow-template-definition.js +0 -20
  158. package/lib/api/event-workflow-templates.js +0 -25
  159. package/lib/apps/create-app/create.d.ts +0 -1
  160. package/lib/apps/create-app/create.js +0 -60
  161. package/lib/apps/create-app/setup-template.d.ts +0 -1
  162. package/lib/apps/create-app/setup-template.js +0 -34
  163. package/lib/apps/deploy-app/deploy.d.ts +0 -2
  164. package/lib/apps/deploy-app/deploy.js +0 -58
  165. package/lib/apps/install-app/app-installer.d.ts +0 -2
  166. package/lib/apps/install-app/app-installer.js +0 -120
  167. package/lib/apps/upgrade-app/app-upgrader.d.ts +0 -3
  168. package/lib/apps/upgrade-app/app-upgrader.js +0 -126
  169. package/lib/auth/auth.js +0 -2
  170. package/lib/cli.d.ts +0 -5
  171. package/lib/cli.js +0 -524
  172. package/lib/colors/color-loader.d.ts +0 -2
  173. package/lib/colors/color-loader.js +0 -96
  174. package/lib/common.js +0 -5
  175. package/lib/config/config.js +0 -70
  176. package/lib/config/configCommands.d.ts +0 -3
  177. package/lib/config/configCommands.js +0 -34
  178. package/lib/interfaces.js +0 -25
  179. package/lib/loader-process/loader-process.d.ts +0 -2
  180. package/lib/projects/interfaces.d.ts +0 -77
  181. package/lib/projects/interfaces.js +0 -23
  182. package/lib/projects/project-exporter.d.ts +0 -2
  183. package/lib/projects/project-uploader.d.ts +0 -1
  184. package/lib/types/allUploader.d.ts +0 -1
  185. package/lib/types/allUploader.js +0 -24
  186. package/lib/types/interfaces.d.ts +0 -55
  187. package/lib/types/interfaces.js +0 -1
  188. package/lib/types/option-set-hierarchy-exporter.d.ts +0 -1
  189. package/lib/types/option-set-hierarchy-parser.d.ts +0 -2
  190. package/lib/types/option-set-hierarchy-uploader.d.ts +0 -1
  191. package/lib/types/option-set-merger.d.ts +0 -1
  192. package/lib/types/option-set-parser.d.ts +0 -3
  193. package/lib/types/option-set-parser.js +0 -140
  194. package/lib/types/option-set-uploader.d.ts +0 -1
  195. package/lib/types/parse-types.d.ts +0 -4
  196. package/lib/types/parse-types.js +0 -189
  197. package/lib/types/rule-set-uploader.d.ts +0 -1
  198. package/lib/types/type-property-policy-uploader.d.ts +0 -1
  199. package/lib/types/types-properties-merger.d.ts +0 -1
  200. package/lib/types/types-properties-merger.js +0 -75
  201. package/lib/types/usage-info-uploader.d.ts +0 -1
  202. package/lib/users/user-exporter.d.ts +0 -1
  203. package/lib/users/user-exporter.js +0 -41
  204. package/lib/users/user-uploader.d.ts +0 -1
  205. package/lib/users/user-uploader.js +0 -45
  206. package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +0 -2
  207. package/lib/workflow-template-definitions/workflow-template-definition-commands.js +0 -10
  208. package/lib/workflow-templates/local-workflow-template-deployer.js +0 -102
  209. package/lib/workflow-templates/workflow-template-commands.d.ts +0 -4
  210. package/lib/workflow-templates/workflow-template-commands.js +0 -51
  211. package/lib/workflow-templates/workflow-template-deployer.d.ts +0 -4
  212. package/lib/workflow-templates/workflow-template-deployer.js +0 -26
  213. package/publish.bat +0 -5
  214. package/publish.sh +0 -5
  215. package/src/api/apps.ts +0 -97
  216. package/src/api/event-workflow-action-definition.ts +0 -8
  217. package/src/api/event-workflow-template-definition.ts +0 -23
  218. package/src/api/event-workflow-templates.ts +0 -29
  219. package/src/apps/create-app/create.ts +0 -74
  220. package/src/apps/create-app/setup-template.ts +0 -38
  221. package/src/apps/deploy-app/actions-deployer.ts +0 -140
  222. package/src/apps/deploy-app/app-deployer.ts +0 -105
  223. package/src/apps/deploy-app/app-template-parsers.ts +0 -44
  224. package/src/apps/deploy-app/deploy.ts +0 -66
  225. package/src/apps/install-app/app-installer.ts +0 -126
  226. package/src/apps/upgrade-app/app-upgrader.ts +0 -132
  227. package/src/auth/auth.ts +0 -10
  228. package/src/auth/login.ts +0 -155
  229. package/src/cli.ts +0 -540
  230. package/src/colors/color-loader.ts +0 -112
  231. package/src/colors/colors.csv +0 -866
  232. package/src/common.ts +0 -5
  233. package/src/config/config.ts +0 -74
  234. package/src/config/configCommands.ts +0 -38
  235. package/src/interfaces.ts +0 -200
  236. package/src/loader-process/loader-process.ts +0 -152
  237. package/src/projects/interfaces.ts +0 -73
  238. package/src/projects/project-exporter.ts +0 -225
  239. package/src/projects/project-uploader.ts +0 -131
  240. package/src/types/allUploader.ts +0 -28
  241. package/src/types/csv-parser.ts +0 -59
  242. package/src/types/interfaces.ts +0 -58
  243. package/src/types/option-set-hierarchy-exporter.ts +0 -125
  244. package/src/types/option-set-hierarchy-parser.ts +0 -169
  245. package/src/types/option-set-hierarchy-uploader.ts +0 -122
  246. package/src/types/option-set-merger.ts +0 -124
  247. package/src/types/option-set-parser.ts +0 -166
  248. package/src/types/option-set-uploader.ts +0 -108
  249. package/src/types/parse-types.ts +0 -227
  250. package/src/types/rule-set-uploader.ts +0 -187
  251. package/src/types/type-property-policy-uploader.ts +0 -192
  252. package/src/types/types-extractor.ts +0 -369
  253. package/src/types/types-properties-merger.ts +0 -90
  254. package/src/types/types-uploader.ts +0 -271
  255. package/src/types/usage-info-uploader.ts +0 -139
  256. package/src/users/user-exporter.ts +0 -52
  257. package/src/users/user-uploader.ts +0 -58
  258. package/src/workflow-template-definitions/workflow-template-definition-commands.ts +0 -13
  259. package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +0 -184
  260. package/src/workflow-templates/local-workflow-template-deployer.ts +0 -126
  261. package/src/workflow-templates/workflow-template-commands.ts +0 -59
  262. package/src/workflow-templates/workflow-template-deployer.ts +0 -30
  263. package/templates/javascript/actions/example/action.js +0 -38
  264. package/templates/javascript/app.yml +0 -53
  265. package/templates/javascript/package.json +0 -23
  266. package/templates/typescript/package-lock.json +0 -14
  267. package/tsconfig.json +0 -32
  268. /package/{templates → dist/templates}/typescript/src/framework/handler.ts +0 -0
  269. /package/{templates → dist/templates}/typescript/src/framework/logger.ts +0 -0
  270. /package/{templates → dist/templates}/typescript/src/framework/mock-server.ts +0 -0
@@ -1,140 +1,128 @@
1
- import fs from 'fs';
2
- import { getSeparatorByPlatform } from '../common';
3
- import chalk from 'chalk';
4
- const csv = require('csvtojson');
5
- import { Entities } from '@contrail/sdk';
6
- import { StringUtil } from '@contrail/util';
7
- import { authUser } from '../auth/login';
8
- export async function ParseOptionSetsHierarchyLocalFile(args) {
9
- try {
10
- await authUser();
11
- if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
12
- throw new Error('File name must be included.');
13
- }
14
- console.log('%s Importing local file', chalk.yellow.bold('OPTION SET HIERARCHY PARSE'));
15
- const fileLocation = args[3];
16
- console.log('Using File: ', fileLocation);
17
- await parseAndSaveOptionSetHierarchiesLocalFile(fileLocation);
18
- console.log('%s Parsed', chalk.yellow.bold('OPTION SET HIERARCHY PARSE'));
19
- }
20
- catch (e) {
21
- console.log(`%s PARSE Failed. ${e}`, chalk.red.bold('FAIL'));
22
- return;
23
- }
24
- console.log('%s PARSE Complete.', chalk.green.bold('COMPLETE'));
25
- }
26
- export async function UploadOptionSetsHierarchyLocalFile(args) {
27
- try {
28
- await authUser();
29
- if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
30
- throw new Error('File name must be included.');
31
- }
32
- console.log('%s Importing local file', chalk.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
33
- const fileLocation = args[3];
34
- const name = args[4];
35
- console.log('Using File: ', fileLocation);
36
- console.log('Using Name: ', name);
37
- await uploadOptionSetHierarchiesLocalFile(fileLocation, name);
38
- console.log('%s Uploaded', chalk.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
39
- }
40
- catch (e) {
41
- console.log(`%s UPLOAD Failed. ${e}`, chalk.red.bold('FAIL'));
42
- return;
43
- }
44
- console.log('%s UPLOAD Complete.', chalk.green.bold('COMPLETE'));
45
- }
46
- async function loadOptionSetHierarchyCSV(fileLocation) {
47
- const TARGET_DIR = process.cwd();
48
- try {
49
- const separator = getSeparatorByPlatform();
50
- const fullPath = TARGET_DIR + separator + fileLocation;
51
- console.log('Getting file from path: ', fullPath);
52
- return await csv().fromFile(fullPath);
53
- }
54
- catch (e) {
55
- throw new Error(`ERROR PARSING CSV: ${e}`);
56
- }
57
- }
58
- async function parseOptionSetHierarchiesLocalFile(fileLocation) {
59
- const uploadedOptionHierarchyData = await loadOptionSetHierarchyCSV(fileLocation);
60
- const optionSetHierarchy = {
61
- hierarchy: [],
62
- maxDepth: 0,
63
- name: 'No Name',
64
- options: []
65
- };
66
- if (!((uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length) > 0)) {
67
- return optionSetHierarchy;
68
- }
69
- const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
70
- const currentOptionSets = await new Entities().get({
71
- entityName: 'type-property-option-set',
72
- });
73
- const currentOptionSetsByName = {};
74
- for (const currentOptionSet of currentOptionSets) {
75
- currentOptionSetsByName[StringUtil.convertToCamelCase(currentOptionSet.name)] = currentOptionSet;
76
- }
77
- const optionSetIds = [];
78
- for (const key of keysInOrder) {
79
- if (currentOptionSetsByName[key]) {
80
- optionSetIds.push(currentOptionSetsByName[key].id);
81
- }
82
- else {
83
- throw new Error(`No OptionSet found for ${key}`);
84
- }
85
- }
86
- optionSetHierarchy.maxDepth = keysInOrder.length;
87
- optionSetHierarchy.hierarchy = optionSetIds;
88
- for (const row of uploadedOptionHierarchyData) {
89
- addRowToOptions(optionSetHierarchy, keysInOrder, row);
90
- }
91
- return optionSetHierarchy;
92
- }
93
- async function parseAndSaveOptionSetHierarchiesLocalFile(fileLocation) {
94
- const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
95
- saveData(optionSetHierarchy.options);
96
- }
97
- async function uploadOptionSetHierarchiesLocalFile(fileLocation, name) {
98
- const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
99
- optionSetHierarchy.name = name;
100
- const currentOptionSetHierarchies = await new Entities().get({
101
- entityName: 'option-set-hierarchy',
102
- });
103
- const existing = currentOptionSetHierarchies.find(osh => osh.name === name);
104
- if (existing) {
105
- console.log('Updating: ', optionSetHierarchy.name);
106
- await new Entities().update({
107
- entityName: 'option-set-hierarchy',
108
- id: existing.id,
109
- object: optionSetHierarchy,
110
- });
111
- }
112
- else {
113
- console.log('Creating: ', optionSetHierarchy.name);
114
- await new Entities().create({
115
- entityName: 'option-set-hierarchy',
116
- object: optionSetHierarchy,
117
- });
118
- }
119
- }
120
- function addRowToOptions(optionSetHierarchy, keysInOrder, row) {
121
- let options = optionSetHierarchy.options;
122
- for (let i = 0; i < keysInOrder.length; i++) {
123
- const optionValues = options.map(op => op.value);
124
- const value = row[keysInOrder[i]];
125
- if (!optionValues.includes(value)) {
126
- const obj = i === (keysInOrder.length - 1) ? { value: value } : { value: value, options: [] };
127
- options.push(obj);
128
- options = obj.options;
129
- }
130
- else {
131
- const optionObj = options.find(op => op.value === value);
132
- options = optionObj.options;
133
- }
134
- }
135
- }
136
- function saveData(data) {
137
- const CURRENT_DIR = process.cwd();
138
- const separator = getSeparatorByPlatform();
139
- fs.writeFileSync(CURRENT_DIR + separator + 'parsed_local_optionSetHierarchy.json', JSON.stringify(data), 'utf8');
140
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadOptionSetsHierarchyLocalFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const csv = require('csvtojson');
8
+ const sdk_1 = require("@contrail/sdk");
9
+ const util_1 = require("@contrail/util");
10
+ const login_1 = require("../../auth/login");
11
+ const core_1 = require("@oclif/core");
12
+ class UploadOptionSetsHierarchyLocalFile extends core_1.Command {
13
+ async run() {
14
+ const { args, flags } = await this.parse(UploadOptionSetsHierarchyLocalFile);
15
+ await uploadOptionSetsHierarchyLocalFile(args.file, args.name);
16
+ }
17
+ }
18
+ exports.default = UploadOptionSetsHierarchyLocalFile;
19
+ UploadOptionSetsHierarchyLocalFile.description = 'upload CSV file into OptionSetHierarchy';
20
+ UploadOptionSetsHierarchyLocalFile.examples = [
21
+ `$ contrail types uploadOptionSetsHierarchyLocalFile <File Path> <name>
22
+ `,
23
+ ];
24
+ UploadOptionSetsHierarchyLocalFile.args = {
25
+ file: core_1.Args.string({ description: 'File to parse', required: true }),
26
+ name: core_1.Args.string({ description: 'The name to be give to the option set hierarchy', required: true }),
27
+ };
28
+ async function uploadOptionSetsHierarchyLocalFile(fileLocation, name) {
29
+ try {
30
+ await (0, login_1.authUser)();
31
+ console.log('%s Importing local file', chalk_1.default.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
32
+ console.log('Using File: ', fileLocation);
33
+ console.log('Using Name: ', name);
34
+ await uploadOptionSetHierarchiesLocalFile(fileLocation, name);
35
+ console.log('%s Uploaded', chalk_1.default.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
36
+ }
37
+ catch (e) {
38
+ console.log(`%s UPLOAD Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
39
+ return;
40
+ }
41
+ console.log('%s UPLOAD Complete.', chalk_1.default.green.bold('COMPLETE'));
42
+ }
43
+ exports.uploadOptionSetsHierarchyLocalFile = uploadOptionSetsHierarchyLocalFile;
44
+ async function loadOptionSetHierarchyCSV(fileLocation) {
45
+ const TARGET_DIR = process.cwd();
46
+ try {
47
+ const fullPath = path.resolve(path.join(TARGET_DIR, fileLocation));
48
+ console.log('Getting file from path: ', fullPath);
49
+ return await csv().fromFile(fullPath);
50
+ }
51
+ catch (e) {
52
+ throw new Error(`ERROR PARSING CSV: ${e}`);
53
+ }
54
+ }
55
+ async function parseOptionSetHierarchiesLocalFile(fileLocation) {
56
+ const uploadedOptionHierarchyData = await loadOptionSetHierarchyCSV(fileLocation);
57
+ const optionSetHierarchy = {
58
+ hierarchy: [],
59
+ maxDepth: 0,
60
+ name: 'No Name',
61
+ options: []
62
+ };
63
+ if (!((uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length) > 0)) {
64
+ return optionSetHierarchy;
65
+ }
66
+ const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
67
+ const currentOptionSets = await new sdk_1.Entities().get({
68
+ entityName: 'type-property-option-set',
69
+ });
70
+ const currentOptionSetsByName = {};
71
+ for (const currentOptionSet of currentOptionSets) {
72
+ currentOptionSetsByName[util_1.StringUtil.convertToCamelCase(currentOptionSet.name)] = currentOptionSet;
73
+ }
74
+ const optionSetIds = [];
75
+ for (const key of keysInOrder) {
76
+ if (currentOptionSetsByName[key]) {
77
+ optionSetIds.push(currentOptionSetsByName[key].id);
78
+ }
79
+ else {
80
+ throw new Error(`No OptionSet found for ${key}`);
81
+ }
82
+ }
83
+ optionSetHierarchy.maxDepth = keysInOrder.length;
84
+ optionSetHierarchy.hierarchy = optionSetIds;
85
+ for (const row of uploadedOptionHierarchyData) {
86
+ addRowToOptions(optionSetHierarchy, keysInOrder, row);
87
+ }
88
+ return optionSetHierarchy;
89
+ }
90
+ async function uploadOptionSetHierarchiesLocalFile(fileLocation, name) {
91
+ const optionSetHierarchy = await parseOptionSetHierarchiesLocalFile(fileLocation);
92
+ optionSetHierarchy.name = name;
93
+ const currentOptionSetHierarchies = await new sdk_1.Entities().get({
94
+ entityName: 'option-set-hierarchy',
95
+ });
96
+ const existing = currentOptionSetHierarchies.find(osh => osh.name === name);
97
+ if (existing) {
98
+ console.log('Updating: ', optionSetHierarchy.name);
99
+ await new sdk_1.Entities().update({
100
+ entityName: 'option-set-hierarchy',
101
+ id: existing.id,
102
+ object: optionSetHierarchy,
103
+ });
104
+ }
105
+ else {
106
+ console.log('Creating: ', optionSetHierarchy.name);
107
+ await new sdk_1.Entities().create({
108
+ entityName: 'option-set-hierarchy',
109
+ object: optionSetHierarchy,
110
+ });
111
+ }
112
+ }
113
+ function addRowToOptions(optionSetHierarchy, keysInOrder, row) {
114
+ let options = optionSetHierarchy.options;
115
+ for (let i = 0; i < keysInOrder.length; i++) {
116
+ const optionValues = options.map(op => op.value);
117
+ const value = row[keysInOrder[i]];
118
+ if (!optionValues.includes(value)) {
119
+ const obj = i === (keysInOrder.length - 1) ? { value: value } : { value: value, options: [] };
120
+ options.push(obj);
121
+ options = obj.options;
122
+ }
123
+ else {
124
+ const optionObj = options.find(op => op.value === value);
125
+ options = optionObj.options;
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,7 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class UploadRuleSets extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
7
+ export declare function uploadRuleSets(): Promise<void>;