@pega/dx-component-builder-sdk 0.1.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 (279) hide show
  1. package/.access_token +1 -0
  2. package/.agilestudio +3 -0
  3. package/.eslintrc.json +18 -0
  4. package/.prettierignore +2 -0
  5. package/.prettierrc.json +1 -0
  6. package/LICENSE +185 -0
  7. package/README.md +199 -0
  8. package/bin/index.js +5 -0
  9. package/cspell.json +26 -0
  10. package/package.json +67 -0
  11. package/src/cli.js +104 -0
  12. package/src/constants.js +134 -0
  13. package/src/tasks/authenticate/helper.js +60 -0
  14. package/src/tasks/authenticate/index.js +81 -0
  15. package/src/tasks/build/helper.js +125 -0
  16. package/src/tasks/build/index.js +52 -0
  17. package/src/tasks/bundle/builder/index.js +218 -0
  18. package/src/tasks/bundle/builder/modules.js +139 -0
  19. package/src/tasks/bundle/builder/paths.js +50 -0
  20. package/src/tasks/bundle/builder/webpack.config.js +336 -0
  21. package/src/tasks/bundle/index.js +65 -0
  22. package/src/tasks/create/index.js +380 -0
  23. package/src/tasks/create/template/config.json.mustache +62 -0
  24. package/src/tasks/create/template/demo.stories.jsx.mustache +44 -0
  25. package/src/tasks/create/template/index.jsx.mustache +55 -0
  26. package/src/tasks/create/template/styles.js.mustache +7 -0
  27. package/src/tasks/create/templates/Constellation/Field/Boolean/Boolean.js.mustache +38 -0
  28. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +26 -0
  29. package/src/tasks/create/templates/Constellation/Field/Boolean/config.json.mustache +145 -0
  30. package/src/tasks/create/templates/Constellation/Field/Boolean/event-utils.js.mustache +18 -0
  31. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +171 -0
  32. package/src/tasks/create/templates/Constellation/Field/Boolean/styles.js.mustache +7 -0
  33. package/src/tasks/create/templates/Constellation/Field/Date/config.json.mustache +195 -0
  34. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +327 -0
  35. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +44 -0
  36. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +254 -0
  37. package/src/tasks/create/templates/Constellation/Field/Date/styles.js.mustache +7 -0
  38. package/src/tasks/create/templates/Constellation/Field/Date/suggestions-handler.js +10 -0
  39. package/src/tasks/create/templates/Constellation/Field/DateTime/config.json.mustache +256 -0
  40. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +93 -0
  41. package/src/tasks/create/templates/Constellation/Field/DateTime/date-utils.js +286 -0
  42. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +327 -0
  43. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +44 -0
  44. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +252 -0
  45. package/src/tasks/create/templates/Constellation/Field/DateTime/styles.js.mustache +7 -0
  46. package/src/tasks/create/templates/Constellation/Field/DateTime/suggestions-handler.js +10 -0
  47. package/src/tasks/create/templates/Constellation/Field/Decimal/config.json.mustache +278 -0
  48. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +44 -0
  49. package/src/tasks/create/templates/Constellation/Field/Decimal/event-utils.js.mustache +18 -0
  50. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +272 -0
  51. package/src/tasks/create/templates/Constellation/Field/Decimal/styles.js.mustache +7 -0
  52. package/src/tasks/create/templates/Constellation/Field/Decimal/suggestions-handler.js +10 -0
  53. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/config.json.mustache +291 -0
  54. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +44 -0
  55. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/event-utils.js.mustache +18 -0
  56. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +300 -0
  57. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/styles.js.mustache +7 -0
  58. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/suggestions-handler.js +10 -0
  59. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/config.json.mustache +93 -0
  60. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +44 -0
  61. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/event-utils.js.mustache +18 -0
  62. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +275 -0
  63. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/styles.js.mustache +7 -0
  64. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/suggestions-handler.js +10 -0
  65. package/src/tasks/create/templates/Constellation/Field/Integer/config.json.mustache +347 -0
  66. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +44 -0
  67. package/src/tasks/create/templates/Constellation/Field/Integer/event-utils.js.mustache +18 -0
  68. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +335 -0
  69. package/src/tasks/create/templates/Constellation/Field/Integer/styles.js.mustache +7 -0
  70. package/src/tasks/create/templates/Constellation/Field/Integer/suggestions-handler.js +10 -0
  71. package/src/tasks/create/templates/Constellation/Field/Picklist/config.json.mustache +114 -0
  72. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +44 -0
  73. package/src/tasks/create/templates/Constellation/Field/Picklist/event-utils.js.mustache +18 -0
  74. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +308 -0
  75. package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +43 -0
  76. package/src/tasks/create/templates/Constellation/Field/Picklist/styles.js.mustache +7 -0
  77. package/src/tasks/create/templates/Constellation/Field/Picklist/suggestions-handler.js +10 -0
  78. package/src/tasks/create/templates/Constellation/Field/Text/config.json.mustache +62 -0
  79. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +44 -0
  80. package/src/tasks/create/templates/Constellation/Field/Text/index.jsx.mustache +60 -0
  81. package/src/tasks/create/templates/Constellation/Field/Text/styles.js.mustache +7 -0
  82. package/src/tasks/create/templates/Constellation/Field/Text-Email/config.json.mustache +111 -0
  83. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +44 -0
  84. package/src/tasks/create/templates/Constellation/Field/Text-Email/event-utils.js.mustache +18 -0
  85. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +189 -0
  86. package/src/tasks/create/templates/Constellation/Field/Text-Email/styles.js.mustache +7 -0
  87. package/src/tasks/create/templates/Constellation/Field/Text-Email/suggestions-handler.js +10 -0
  88. package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +43 -0
  89. package/src/tasks/create/templates/Constellation/Field/Text-Input/StatusWork.js +27 -0
  90. package/src/tasks/create/templates/Constellation/Field/Text-Input/config.json.mustache +111 -0
  91. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +44 -0
  92. package/src/tasks/create/templates/Constellation/Field/Text-Input/event-utils.js.mustache +18 -0
  93. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +196 -0
  94. package/src/tasks/create/templates/Constellation/Field/Text-Input/styles.js.mustache +7 -0
  95. package/src/tasks/create/templates/Constellation/Field/Text-Input/suggestions-handler.js +10 -0
  96. package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +43 -0
  97. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/config.json.mustache +111 -0
  98. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +44 -0
  99. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/event-utils.js.mustache +18 -0
  100. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +189 -0
  101. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/styles.js.mustache +7 -0
  102. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/suggestions-handler.js +10 -0
  103. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +43 -0
  104. package/src/tasks/create/templates/Constellation/Field/Text-Phone/config.json.mustache +123 -0
  105. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +44 -0
  106. package/src/tasks/create/templates/Constellation/Field/Text-Phone/event-utils.js.mustache +18 -0
  107. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +223 -0
  108. package/src/tasks/create/templates/Constellation/Field/Text-Phone/styles.js.mustache +7 -0
  109. package/src/tasks/create/templates/Constellation/Field/Text-Phone/suggestions-handler.js +10 -0
  110. package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +43 -0
  111. package/src/tasks/create/templates/Constellation/Field/Text-URL/config.json.mustache +237 -0
  112. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +44 -0
  113. package/src/tasks/create/templates/Constellation/Field/Text-URL/event-utils.js.mustache +18 -0
  114. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +232 -0
  115. package/src/tasks/create/templates/Constellation/Field/Text-URL/styles.js.mustache +7 -0
  116. package/src/tasks/create/templates/Constellation/Field/Text-URL/suggestions-handler.js +10 -0
  117. package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +172 -0
  118. package/src/tasks/create/templates/Constellation/Field/TimeofDay/config.json.mustache +185 -0
  119. package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +44 -0
  120. package/src/tasks/create/templates/Constellation/Field/TimeofDay/index.jsx.mustache +213 -0
  121. package/src/tasks/create/templates/Constellation/Field/TimeofDay/styles.js.mustache +7 -0
  122. package/src/tasks/create/templates/Constellation/Field/TimeofDay/suggestions-handler.js +10 -0
  123. package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +286 -0
  124. package/src/tasks/create/templates/Constellation/Template/DETAILS/OneColumnDetails.svg +22 -0
  125. package/src/tasks/create/templates/Constellation/Template/DETAILS/config.json.mustache +35 -0
  126. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +88 -0
  127. package/src/tasks/create/templates/Constellation/Template/DETAILS/styles.js.mustache +7 -0
  128. package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +155 -0
  129. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/TwoColumnDetails.svg +28 -0
  130. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/config.json.mustache +42 -0
  131. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +88 -0
  132. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/styles.js.mustache +7 -0
  133. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +155 -0
  134. package/src/tasks/create/templates/Constellation/Template/FORM/DefaultForm.svg +29 -0
  135. package/src/tasks/create/templates/Constellation/Template/FORM/config.json.mustache +45 -0
  136. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +49 -0
  137. package/src/tasks/create/templates/Constellation/Template/FORM/styles.js.mustache +7 -0
  138. package/src/tasks/create/templates/Constellation/Template/FORM-region/TwoColumn.svg +38 -0
  139. package/src/tasks/create/templates/Constellation/Template/FORM-region/config.json.mustache +27 -0
  140. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +51 -0
  141. package/src/tasks/create/templates/Constellation/Template/FORM-region/styles.js.mustache +7 -0
  142. package/src/tasks/create/templates/Constellation/Template/PAGE/GetNextWork.js.mustache +29 -0
  143. package/src/tasks/create/templates/Constellation/Template/PAGE/OneColumnPage.svg +36 -0
  144. package/src/tasks/create/templates/Constellation/Template/PAGE/config.json.mustache +32 -0
  145. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +68 -0
  146. package/src/tasks/create/templates/Constellation/Template/PAGE/localizations.json.mustache +4 -0
  147. package/src/tasks/create/templates/Constellation/Template/PAGE/styles.js.mustache +7 -0
  148. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +226 -0
  149. package/src/tasks/create/templates/Constellation/Widget/CASE/OneColumnPage.svg +36 -0
  150. package/src/tasks/create/templates/Constellation/Widget/CASE/config.json.mustache +23 -0
  151. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +75 -0
  152. package/src/tasks/create/templates/Constellation/Widget/CASE/styles.js.mustache +7 -0
  153. package/src/tasks/create/templates/Constellation/Widget/PAGE/OneColumnPage.svg +36 -0
  154. package/src/tasks/create/templates/Constellation/Widget/PAGE/config.json.mustache +59 -0
  155. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +48 -0
  156. package/src/tasks/create/templates/Constellation/Widget/PAGE/styles.js.mustache +7 -0
  157. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Avatar.js.mustache +73 -0
  158. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/OneColumnPage.svg +36 -0
  159. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Operator.js.mustache +239 -0
  160. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/config.json.mustache +66 -0
  161. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +110 -0
  162. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/styles.js.mustache +7 -0
  163. package/src/tasks/create/templates/SDK-Angular/Field/__components.md +4 -0
  164. package/src/tasks/create/templates/SDK-Angular/Template/__components.md +4 -0
  165. package/src/tasks/create/templates/SDK-Angular/Widget/__components.md +4 -0
  166. package/src/tasks/create/templates/SDK-React/Field/Boolean/config.json.mustache +73 -0
  167. package/src/tasks/create/templates/SDK-React/Field/Boolean/demo.stories.jsx.mustache +44 -0
  168. package/src/tasks/create/templates/SDK-React/Field/Boolean/index.tsx.mustache +109 -0
  169. package/src/tasks/create/templates/SDK-React/Field/Boolean/styles.js.mustache +7 -0
  170. package/src/tasks/create/templates/SDK-React/Field/Date/config.json.mustache +133 -0
  171. package/src/tasks/create/templates/SDK-React/Field/Date/demo.stories.jsx.mustache +44 -0
  172. package/src/tasks/create/templates/SDK-React/Field/Date/index.tsx.mustache +122 -0
  173. package/src/tasks/create/templates/SDK-React/Field/Date/styles.js.mustache +7 -0
  174. package/src/tasks/create/templates/SDK-React/Field/DateTime/config.json.mustache +190 -0
  175. package/src/tasks/create/templates/SDK-React/Field/DateTime/demo.stories.jsx.mustache +44 -0
  176. package/src/tasks/create/templates/SDK-React/Field/DateTime/index.tsx.mustache +112 -0
  177. package/src/tasks/create/templates/SDK-React/Field/DateTime/styles.js.mustache +7 -0
  178. package/src/tasks/create/templates/SDK-React/Field/Decimal/config.json.mustache +80 -0
  179. package/src/tasks/create/templates/SDK-React/Field/Decimal/demo.stories.jsx.mustache +44 -0
  180. package/src/tasks/create/templates/SDK-React/Field/Decimal/index.tsx.mustache +105 -0
  181. package/src/tasks/create/templates/SDK-React/Field/Decimal/styles.js.mustache +7 -0
  182. package/src/tasks/create/templates/SDK-React/Field/Decimal-Currency/config.json.mustache +111 -0
  183. package/src/tasks/create/templates/SDK-React/Field/Decimal-Currency/demo.stories.jsx.mustache +44 -0
  184. package/src/tasks/create/templates/SDK-React/Field/Decimal-Currency/index.tsx.mustache +131 -0
  185. package/src/tasks/create/templates/SDK-React/Field/Decimal-Currency/styles.js.mustache +7 -0
  186. package/src/tasks/create/templates/SDK-React/Field/Decimal-Percentage/config.json.mustache +80 -0
  187. package/src/tasks/create/templates/SDK-React/Field/Decimal-Percentage/demo.stories.jsx.mustache +44 -0
  188. package/src/tasks/create/templates/SDK-React/Field/Decimal-Percentage/index.tsx.mustache +128 -0
  189. package/src/tasks/create/templates/SDK-React/Field/Decimal-Percentage/styles.js.mustache +7 -0
  190. package/src/tasks/create/templates/SDK-React/Field/Integer/config.json.mustache +74 -0
  191. package/src/tasks/create/templates/SDK-React/Field/Integer/demo.stories.jsx.mustache +44 -0
  192. package/src/tasks/create/templates/SDK-React/Field/Integer/index.tsx.mustache +124 -0
  193. package/src/tasks/create/templates/SDK-React/Field/Integer/styles.js.mustache +7 -0
  194. package/src/tasks/create/templates/SDK-React/Field/Picklist/config.json.mustache +72 -0
  195. package/src/tasks/create/templates/SDK-React/Field/Picklist/demo.stories.jsx.mustache +44 -0
  196. package/src/tasks/create/templates/SDK-React/Field/Picklist/index.tsx.mustache +141 -0
  197. package/src/tasks/create/templates/SDK-React/Field/Picklist/styles.js.mustache +7 -0
  198. package/src/tasks/create/templates/SDK-React/Field/Text/config.json.mustache +69 -0
  199. package/src/tasks/create/templates/SDK-React/Field/Text/demo.stories.jsx.mustache +44 -0
  200. package/src/tasks/create/templates/SDK-React/Field/Text/index.tsx.mustache +119 -0
  201. package/src/tasks/create/templates/SDK-React/Field/Text/styles.js.mustache +7 -0
  202. package/src/tasks/create/templates/SDK-React/Field/Text-Email/config.json.mustache +69 -0
  203. package/src/tasks/create/templates/SDK-React/Field/Text-Email/demo.stories.jsx.mustache +44 -0
  204. package/src/tasks/create/templates/SDK-React/Field/Text-Email/index.tsx.mustache +121 -0
  205. package/src/tasks/create/templates/SDK-React/Field/Text-Email/styles.js.mustache +7 -0
  206. package/src/tasks/create/templates/SDK-React/Field/Text-Input/config.json.mustache +69 -0
  207. package/src/tasks/create/templates/SDK-React/Field/Text-Input/demo.stories.jsx.mustache +44 -0
  208. package/src/tasks/create/templates/SDK-React/Field/Text-Input/index.tsx.mustache +119 -0
  209. package/src/tasks/create/templates/SDK-React/Field/Text-Input/styles.js.mustache +7 -0
  210. package/src/tasks/create/templates/SDK-React/Field/Text-Paragraph/config.json.mustache +69 -0
  211. package/src/tasks/create/templates/SDK-React/Field/Text-Paragraph/demo.stories.jsx.mustache +44 -0
  212. package/src/tasks/create/templates/SDK-React/Field/Text-Paragraph/index.tsx.mustache +123 -0
  213. package/src/tasks/create/templates/SDK-React/Field/Text-Paragraph/styles.js.mustache +7 -0
  214. package/src/tasks/create/templates/SDK-React/Field/Text-Phone/config.json.mustache +81 -0
  215. package/src/tasks/create/templates/SDK-React/Field/Text-Phone/demo.stories.jsx.mustache +44 -0
  216. package/src/tasks/create/templates/SDK-React/Field/Text-Phone/index.tsx.mustache +147 -0
  217. package/src/tasks/create/templates/SDK-React/Field/Text-Phone/styles.js.mustache +7 -0
  218. package/src/tasks/create/templates/SDK-React/Field/Text-URL/config.json.mustache +111 -0
  219. package/src/tasks/create/templates/SDK-React/Field/Text-URL/demo.stories.jsx.mustache +44 -0
  220. package/src/tasks/create/templates/SDK-React/Field/Text-URL/index.tsx.mustache +98 -0
  221. package/src/tasks/create/templates/SDK-React/Field/Text-URL/styles.js.mustache +7 -0
  222. package/src/tasks/create/templates/SDK-React/Field/TimeofDay/config.json.mustache +121 -0
  223. package/src/tasks/create/templates/SDK-React/Field/TimeofDay/demo.stories.jsx.mustache +44 -0
  224. package/src/tasks/create/templates/SDK-React/Field/TimeofDay/index.tsx.mustache +120 -0
  225. package/src/tasks/create/templates/SDK-React/Field/TimeofDay/styles.js.mustache +7 -0
  226. package/src/tasks/create/templates/SDK-React/Template/DETAILS/DefaultForm.svg +29 -0
  227. package/src/tasks/create/templates/SDK-React/Template/DETAILS/config.json.mustache +21 -0
  228. package/src/tasks/create/templates/SDK-React/Template/DETAILS/index.tsx.mustache +45 -0
  229. package/src/tasks/create/templates/SDK-React/Template/DETAILS/styles.js.mustache +7 -0
  230. package/src/tasks/create/templates/SDK-React/Template/DETAILS-region/TwoColumnDetails.svg +28 -0
  231. package/src/tasks/create/templates/SDK-React/Template/DETAILS-region/config.json.mustache +27 -0
  232. package/src/tasks/create/templates/SDK-React/Template/DETAILS-region/index.tsx.mustache +53 -0
  233. package/src/tasks/create/templates/SDK-React/Template/DETAILS-region/styles.js.mustache +7 -0
  234. package/src/tasks/create/templates/SDK-React/Template/FORM/DefaultForm.css +25 -0
  235. package/src/tasks/create/templates/SDK-React/Template/FORM/DefaultForm.svg +29 -0
  236. package/src/tasks/create/templates/SDK-React/Template/FORM/config.json.mustache +45 -0
  237. package/src/tasks/create/templates/SDK-React/Template/FORM/index.tsx.mustache +63 -0
  238. package/src/tasks/create/templates/SDK-React/Template/FORM/styles.js.mustache +7 -0
  239. package/src/tasks/create/templates/SDK-React/Template/FORM-region/TwoColumn.svg +38 -0
  240. package/src/tasks/create/templates/SDK-React/Template/FORM-region/config.json.mustache +49 -0
  241. package/src/tasks/create/templates/SDK-React/Template/FORM-region/index.tsx.mustache +69 -0
  242. package/src/tasks/create/templates/SDK-React/Template/FORM-region/styles.js.mustache +7 -0
  243. package/src/tasks/create/templates/SDK-React/Template/PAGE/OneColumn.tsx.mustache +32 -0
  244. package/src/tasks/create/templates/SDK-React/Template/PAGE/OneColumnPage.svg +28 -0
  245. package/src/tasks/create/templates/SDK-React/Template/PAGE/config.json.mustache +32 -0
  246. package/src/tasks/create/templates/SDK-React/Template/PAGE/index.tsx.mustache +31 -0
  247. package/src/tasks/create/templates/SDK-React/Template/PAGE/styles.js.mustache +7 -0
  248. package/src/tasks/create/templates/SDK-React/Widget/CASE/OneColumnPage.svg +36 -0
  249. package/src/tasks/create/templates/SDK-React/Widget/CASE/config.json.mustache +23 -0
  250. package/src/tasks/create/templates/SDK-React/Widget/CASE/index.tsx.mustache +183 -0
  251. package/src/tasks/create/templates/SDK-React/Widget/CASE/styles.js.mustache +7 -0
  252. package/src/tasks/create/templates/SDK-React/Widget/PAGE/OneColumnPage.svg +36 -0
  253. package/src/tasks/create/templates/SDK-React/Widget/PAGE/config.json.mustache +59 -0
  254. package/src/tasks/create/templates/SDK-React/Widget/PAGE/index.tsx.mustache +78 -0
  255. package/src/tasks/create/templates/SDK-React/Widget/PAGE/styles.js.mustache +7 -0
  256. package/src/tasks/create/templates/SDK-React/Widget/PAGE-CASE/OneColumnPage.svg +36 -0
  257. package/src/tasks/create/templates/SDK-React/Widget/PAGE-CASE/config.json.mustache +66 -0
  258. package/src/tasks/create/templates/SDK-React/Widget/PAGE-CASE/index.tsx.mustache +239 -0
  259. package/src/tasks/create/templates/SDK-React/Widget/PAGE-CASE/styles.js.mustache +7 -0
  260. package/src/tasks/create/templates/SDK-WebComponents/Field/__components.md +4 -0
  261. package/src/tasks/create/templates/SDK-WebComponents/Template/__components.md +4 -0
  262. package/src/tasks/create/templates/SDK-WebComponents/Widget/__components.md +4 -0
  263. package/src/tasks/delete/helper.js +122 -0
  264. package/src/tasks/delete/index.js +45 -0
  265. package/src/tasks/delete-all/helper.js +177 -0
  266. package/src/tasks/delete-all/index.js +45 -0
  267. package/src/tasks/index.js +11 -0
  268. package/src/tasks/linter/index.js +46 -0
  269. package/src/tasks/list/helper.js +118 -0
  270. package/src/tasks/list/index.js +51 -0
  271. package/src/tasks/map/map.js +118 -0
  272. package/src/tasks/publish/helper.js +147 -0
  273. package/src/tasks/publish/index.js +72 -0
  274. package/src/tasks/publish-all/helper.js +139 -0
  275. package/src/tasks/publish-all/index.js +84 -0
  276. package/src/tasks/update/index.js +5 -0
  277. package/src/tasks/upgrade/index.js +31 -0
  278. package/src/tasks/validator/index.js +216 -0
  279. package/src/util.js +442 -0
@@ -0,0 +1,46 @@
1
+ import { ESLint } from 'eslint';
2
+ import chalk from 'chalk';
3
+
4
+ export const lintComponent = async (dirToLint) => {
5
+ // console.log("in dx-component-builder-sdk: lintComponent - dirToLint: " + dirToLint);
6
+ console.log(chalk.green(` linting ${dirToLint}`));
7
+
8
+ // 1. Create an instance.
9
+ const eslint = new ESLint();
10
+
11
+ // 2. Lint files.
12
+ const results = await eslint.lintFiles([dirToLint]);
13
+
14
+ // 3. Format the results.
15
+ const formatter = await eslint.loadFormatter("stylish");
16
+ const resultText = formatter.format(results);
17
+
18
+ // 4. Output it.
19
+ // console.log(`lint resultText: ${resultText}`);
20
+ console.log(resultText);
21
+
22
+ // Indicate linting is complete
23
+ console.log(chalk.green(` linting complete...`));
24
+ };
25
+
26
+ // inpsired by https://eslint.org/docs/latest/developer-guide/nodejs-api
27
+
28
+ // (async function main() {
29
+ // // 1. Create an instance.
30
+ // const eslint = new ESLint();
31
+
32
+ // // 2. Lint files.
33
+ // const results = await eslint.lintFiles(["lib/**/*.js"]);
34
+
35
+ // // 3. Format the results.
36
+ // const formatter = await eslint.loadFormatter("stylish");
37
+ // const resultText = formatter.format(results);
38
+
39
+ // // 4. Output it.
40
+ // console.log(resultText);
41
+ // })().catch((error) => {
42
+ // process.exitCode = 1;
43
+ // console.error(error);
44
+ // });
45
+
46
+ export default lintComponent;
@@ -0,0 +1,118 @@
1
+ import fs from 'fs';
2
+ import https from 'https';
3
+
4
+ import chalk from 'chalk';
5
+ import fetch from 'node-fetch';
6
+
7
+ import { LIST_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
8
+ import { constructCompleteUrl, getComponents, getPegaServerConfig } from '../../util.js';
9
+
10
+ export const SOURCE_OF_COMPONENT_TYPES = {
11
+ SERVER: 'Server',
12
+ LOCAL: 'Local'
13
+ };
14
+
15
+ export const getListComponentsQuestions = async (options, sourceOfComponentsOption) => {
16
+ const defaultPegaServerConfig = await getPegaServerConfig();
17
+
18
+ return [
19
+ {
20
+ name: 'sourceOfComponents',
21
+ type: 'rawlist',
22
+ message: 'List components from Server or Local ?',
23
+ choices: Object.values(SOURCE_OF_COMPONENT_TYPES),
24
+ default: defaultPegaServerConfig.sourceOfComponents,
25
+ when() {
26
+ return !options.params[3];
27
+ }
28
+ }
29
+ ];
30
+ };
31
+
32
+ export const listLocalComponents = async sourceOfComponents => {
33
+ let localComponents = await getComponents();
34
+ localComponents = localComponents.map(name => ({ 'Rule name': name }));
35
+ if (localComponents.length > 0) {
36
+ console.log(chalk.bold.blueBright(`List of custom components in ${sourceOfComponents}`));
37
+ console.table(localComponents, ['Rule name']);
38
+ } else {
39
+ console.log(chalk.bold.redBright(`No custom components in ${sourceOfComponents}`));
40
+ }
41
+ };
42
+
43
+ export const getComponentsFromServer = async data => {
44
+ const defaultPegaServerConfig = await getPegaServerConfig();
45
+ const url = constructCompleteUrl(
46
+ defaultPegaServerConfig.server,
47
+ LIST_COMPONENT_SERVICE_REST_ENDPOINT
48
+ );
49
+ return new Promise((resolve, reject) => {
50
+ try {
51
+ fs.readFile(TOKEN_PATH, 'utf8', (err, data) => {
52
+ if (err) {
53
+ reject(
54
+ `\n${chalk.bold.red(
55
+ 'Error occured in authentication. Please regenerate using authenticate'
56
+ )}`
57
+ );
58
+ }
59
+ if (data) {
60
+ const {
61
+ access_token: accessToken,
62
+ token_type: tokenType,
63
+ refresh_token: refreshToken
64
+ } = JSON.parse(data);
65
+ let status = 500;
66
+ fetch(url, {
67
+ method: 'GET',
68
+ agent: new https.Agent({ rejectUnauthorized: false }),
69
+ headers: {
70
+ Authorization: `${tokenType} ${accessToken}`
71
+ }
72
+ })
73
+ .then(response => {
74
+ status = response.status;
75
+ return response.text();
76
+ })
77
+ .then(resp => {
78
+ const respData = JSON.parse(resp);
79
+ if (status === 401) {
80
+ throw new Error(
81
+ 'Error occured in authentication. Please regenerate using authenticate'
82
+ );
83
+ // console.log(accessTokenUri, refreshToken);
84
+ /* TODO - Handle refresh_token */
85
+ } else if (status == 200) {
86
+ resolve(resp);
87
+ } else {
88
+ throw new Error(`${respData.message}`);
89
+ }
90
+ })
91
+ .catch(e => reject(`${chalk.bold.red(e)}`));
92
+ }
93
+ });
94
+ } catch (error) {
95
+ console.log(`\n${chalk.bold.red(error)}`);
96
+ reject(`${chalk.bold.red(error)}`);
97
+ }
98
+ });
99
+ };
100
+
101
+ export const displayServerComponents = async data => {
102
+ const defaultPegaServerConfig = await getPegaServerConfig();
103
+ const parsedData = JSON.parse(data);
104
+ const componentList = parsedData.pxResults?.map(({ label, pyRuleSet, pyRuleSetVersion }) => ({
105
+ 'Rule name': label,
106
+ 'Ruleset name': pyRuleSet,
107
+ 'Ruleset version': pyRuleSetVersion
108
+ }));
109
+
110
+ if (componentList && componentList.length > 0) {
111
+ console.log(
112
+ chalk.bold.blueBright(`List of custom components in ${defaultPegaServerConfig.server}`)
113
+ );
114
+ console.table(componentList, ['Rule name', 'Ruleset name', 'Ruleset version']);
115
+ } else {
116
+ console.log(chalk.bold.redBright(`No custom components in ${defaultPegaServerConfig.server}`));
117
+ }
118
+ };
@@ -0,0 +1,51 @@
1
+ import inquirer from 'inquirer';
2
+ import ora from 'ora';
3
+ import chalk from 'chalk';
4
+
5
+ import {
6
+ listLocalComponents,
7
+ SOURCE_OF_COMPONENT_TYPES,
8
+ getComponentsFromServer,
9
+ displayServerComponents,
10
+ getListComponentsQuestions
11
+ } from './helper.js';
12
+
13
+ const getList = async (sourceOfComponents, answers) => {
14
+ switch (sourceOfComponents) {
15
+ case SOURCE_OF_COMPONENT_TYPES.LOCAL: {
16
+ await listLocalComponents(sourceOfComponents);
17
+ break;
18
+ }
19
+ case SOURCE_OF_COMPONENT_TYPES.SERVER: {
20
+ const spinner = ora('Fetching components from server\n').start();
21
+ const data = await getComponentsFromServer(answers);
22
+ spinner.stop();
23
+ await displayServerComponents(data, answers);
24
+
25
+ break;
26
+ }
27
+ default: {
28
+ console.log('Source of components needs to be either Local or Server');
29
+ break;
30
+ }
31
+ }
32
+ };
33
+
34
+ export default async options => {
35
+ let sourceOfComponentsOption = SOURCE_OF_COMPONENT_TYPES.LOCAL;
36
+
37
+ if (options.params[3] === SOURCE_OF_COMPONENT_TYPES.LOCAL) {
38
+ sourceOfComponentsOption = options.params[3];
39
+ await getList(sourceOfComponentsOption);
40
+ } else if (options.params[3] === SOURCE_OF_COMPONENT_TYPES.SERVER) {
41
+ sourceOfComponentsOption = options.params[3];
42
+ const questions = await getListComponentsQuestions(options, sourceOfComponentsOption);
43
+ const answers = await inquirer.prompt(questions);
44
+ await getList(sourceOfComponentsOption, answers);
45
+ } else {
46
+ const questions = await getListComponentsQuestions(options);
47
+ const answers = await inquirer.prompt(questions);
48
+ const { sourceOfComponents } = answers;
49
+ await getList(sourceOfComponents, answers);
50
+ }
51
+ };
@@ -0,0 +1,118 @@
1
+
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { join } from 'path';
5
+
6
+ import {
7
+ convertIntoPascalCase,
8
+ removeComponentPrefix
9
+ } from '../../util.js';
10
+
11
+ import {
12
+ COMPONENTS_DIRECTORY_PATH,
13
+ DXCB_CONFIG_JSON_FILENAME
14
+ } from '../../constants.js';
15
+
16
+ export const SDK_LOCAL_COMPONENT_MAP_FILENAME = "sdk-local-component-map.js";
17
+ export const COMPONENT_PATH = "./src/components";
18
+ export const IMPORT_END_TAG = "/*import end";
19
+ export const MAP_END_TAG = "/*map end";
20
+
21
+ export const updateComponentMap = async (componentKey, category = "custom") => {
22
+
23
+ const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
24
+ const pegaLocalComponentMapPath = path.join(path.resolve(), SDK_LOCAL_COMPONENT_MAP_FILENAME);
25
+ const categoryDirectory = join("/", category.toLowerCase());
26
+
27
+ const componentNameNoPrefix = removeComponentPrefix(componentKey);
28
+ const componentName = convertIntoPascalCase(componentNameNoPrefix);
29
+
30
+ let mapData = fs.readFileSync(pegaLocalComponentMapPath, { encoding: 'utf8' });
31
+
32
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
33
+ data = JSON.parse(data);
34
+
35
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
36
+ console.error(
37
+ `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
38
+ );
39
+ process.exit(1);
40
+ }
41
+
42
+ let importComponent = join(data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
43
+ importComponent = "./".concat(importComponent);
44
+
45
+ let importFull = "import ".concat(componentName).concat(" from '").concat(importComponent).concat("/';");
46
+ let mapFull = "\"".concat(componentNameNoPrefix).concat("\" : " ).concat(componentName).concat(",");
47
+
48
+ if (mapData.indexOf(importComponent) < 0) {
49
+ // not present so we can add
50
+
51
+ // add import
52
+ let endImportIndex = mapData.indexOf(IMPORT_END_TAG);
53
+ let mapDataStart = mapData.substring(0, endImportIndex);
54
+ let mapDataEnd = mapData.substring(endImportIndex);
55
+
56
+ mapData = mapDataStart.concat(importFull).concat("\n").concat(mapDataEnd);
57
+
58
+
59
+
60
+ // add map
61
+ let endMapIndex = mapData.indexOf(MAP_END_TAG);
62
+ mapDataStart = mapData.substring(0, endMapIndex);
63
+ mapDataEnd = mapData.substring(endMapIndex);
64
+
65
+ mapData = mapDataStart.concat(" ").concat(mapFull).concat("\n").concat(mapDataEnd);
66
+
67
+
68
+ //console.log(mapData);
69
+
70
+ //console.log("update");
71
+
72
+ fs.writeFileSync(pegaLocalComponentMapPath, mapData, { encoding: 'utf8' });
73
+
74
+
75
+ }
76
+
77
+
78
+ };
79
+
80
+ export const deleteFromComponentMap = async (componentKey, category = "custom") => {
81
+ const pegaLocalComponentMapPath = path.join(path.resolve(), SDK_LOCAL_COMPONENT_MAP_FILENAME);
82
+ const categoryDirectory = join("/", category.toLowerCase());
83
+
84
+ const componentNameNoPrefix = removeComponentPrefix(componentKey);
85
+ const componentName = convertIntoPascalCase(componentNameNoPrefix);
86
+
87
+ let mapData = fs.readFileSync(pegaLocalComponentMapPath, { encoding: 'utf8' });
88
+
89
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
90
+ data = JSON.parse(data);
91
+
92
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
93
+ console.error(
94
+ `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
95
+ );
96
+ process.exit(1);
97
+ }
98
+
99
+ let importComponent = join("./", data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
100
+
101
+ let importFull = "import ".concat(componentName).concat(" from '").concat(importComponent).concat("/';");
102
+ let mapFull = "\"".concat(componentNameNoPrefix).concat("\" : " ).concat(componentName).concat(",");
103
+
104
+
105
+ if (mapData.indexOf(importFull) >= 0) {
106
+
107
+ let removeImport = importFull.concat("\n");
108
+ let removeMap = " ".concat(mapFull).concat("\n");
109
+
110
+ mapData = mapData.replace(removeImport, "");
111
+ mapData = mapData.replace(removeMap, "");
112
+
113
+ fs.writeFileSync(pegaLocalComponentMapPath, mapData, { encoding: 'utf8' });
114
+
115
+ }
116
+
117
+
118
+ };
@@ -0,0 +1,147 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import https from 'https';
4
+
5
+ import fetch from 'node-fetch';
6
+ import AdmZip from 'adm-zip';
7
+ import chalk from 'chalk';
8
+
9
+ import {
10
+ constructCompleteUrl,
11
+ getComponentDirectoryPath,
12
+ getComponents,
13
+ getComponentsObj,
14
+ getComponentsAndSubDirectory,
15
+ getPegaServerConfig,
16
+ validateRulesetVersion
17
+ } from '../../util.js';
18
+ import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
19
+
20
+ export const getPublishComponentQuestions = async () => {
21
+ const components = await getComponentsObj(true);
22
+ const defaultPegaConfig = await getPegaServerConfig();
23
+
24
+ return [
25
+ {
26
+ name: 'componentKey',
27
+ type: 'rawlist',
28
+ message: 'Select component to publish',
29
+ choices: components
30
+ },
31
+ {
32
+ name: 'rulesetName',
33
+ message: 'Enter ruleset name',
34
+ default: defaultPegaConfig.rulesetName,
35
+ validate: value => {
36
+ if (value.trim()) {
37
+ return true;
38
+ }
39
+ return 'Ruleset name cannot be empty';
40
+ }
41
+ },
42
+ {
43
+ name: 'rulesetVersion',
44
+ message: 'Enter ruleset version',
45
+ default: defaultPegaConfig.rulesetVersion,
46
+ validate: value => {
47
+ if (validateRulesetVersion(value)) {
48
+ return true;
49
+ }
50
+ return 'Please provide compatible version e.g 01-01-01';
51
+ }
52
+ },
53
+ {
54
+ name: 'sourceMap',
55
+ message: 'Generate source map ?',
56
+ default: defaultPegaConfig.sourceMap,
57
+ when: () => false && !process.env.SOURCE_MAP
58
+ },
59
+ {
60
+ name: 'devBuild',
61
+ message: 'Generate development build ?',
62
+ default: defaultPegaConfig.devBuild
63
+ }
64
+ ];
65
+ };
66
+
67
+ export const zipComponent = async componentKey => {
68
+ const srcDirectory = await getComponentDirectoryPath(componentKey);
69
+ const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
70
+ const configJson = `${srcDirectory}/config.json`;
71
+
72
+ const zip = new AdmZip();
73
+
74
+ zip.addLocalFolder(srcDirectory, 'src/');
75
+ zip.addLocalFile(configJson);
76
+ zip.addLocalFolder(buildDirectory);
77
+ const zipContent = zip.toBuffer().toString('base64');
78
+
79
+ const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
80
+ fs.rmdir('dist', { recursive: true }, err => {
81
+ if (err) {
82
+ throw err;
83
+ }
84
+ });
85
+ return { zipContent, configContent };
86
+ };
87
+
88
+ export const publishComponentToServer = async data => {
89
+ const { configContent, zipContent, componentKey, rulesetName, rulesetVersion } = data;
90
+
91
+ const apiBody = {
92
+ configContent,
93
+ zipContent,
94
+ componentKey: JSON.parse(configContent).componentKey,
95
+ publishFor: 'constellation',
96
+ rulesetName,
97
+ rulesetVersion,
98
+ category: ''
99
+ };
100
+ const defaultPegaConfig = await getPegaServerConfig();
101
+ const url = constructCompleteUrl(
102
+ defaultPegaConfig.server,
103
+ PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
104
+ );
105
+ try {
106
+ const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
107
+ if (OauthData) {
108
+ const {
109
+ access_token: accessToken,
110
+ token_type: tokenType,
111
+ refresh_token: refreshToken
112
+ } = JSON.parse(OauthData);
113
+ let status = 500;
114
+ fetch(url, {
115
+ method: 'POST',
116
+ agent: new https.Agent({ rejectUnauthorized: false }),
117
+ headers: {
118
+ Authorization: `${tokenType} ${accessToken}`
119
+ },
120
+ body: JSON.stringify(apiBody)
121
+ })
122
+ .then(response => {
123
+ status = response.status;
124
+ return response.text();
125
+ })
126
+ .then(resp => {
127
+ const respData = JSON.parse(resp);
128
+ if (status === 401) {
129
+ throw new Error(
130
+ 'Error occured in authentication. Please regenerate using authenticate'
131
+ );
132
+ // console.log(accessTokenUri, refreshToken);
133
+ /* TODO - Handle refresh_token */
134
+ } else if (status == 200) {
135
+ console.log(chalk.bold.green(`Success : ${respData.message}`));
136
+ } else {
137
+ throw new Error(`${respData.message}`);
138
+ }
139
+ })
140
+ .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
141
+ } else {
142
+ throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
143
+ }
144
+ } catch (err) {
145
+ throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
146
+ }
147
+ };
@@ -0,0 +1,72 @@
1
+ import inquirer from 'inquirer';
2
+ import Listr from 'listr';
3
+ import chalk from 'chalk';
4
+
5
+ import validate from '../validator/index.js';
6
+ import { getComponentDirectoryPath } from '../../util.js';
7
+ import bundleComponent from '../bundle/index.js';
8
+ import { updateComponentMap } from '../map/map.js';
9
+ import { lintComponent } from '../linter/index.js';
10
+
11
+ import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
12
+
13
+ export default async options => {
14
+ const questions = await getPublishComponentQuestions();
15
+ const answers = await inquirer.prompt(questions);
16
+ const { componentKey, sourceMap, devBuild } = answers;
17
+
18
+ let content = {
19
+ ...answers
20
+ };
21
+
22
+ const tasks = new Listr(
23
+ [
24
+ {
25
+ title: 'Validate config schema',
26
+ task: async () => {
27
+ await validate(componentKey);
28
+ }
29
+ },
30
+ {
31
+ title: 'Lint component',
32
+ task: async () => {
33
+ const targetDirectory = await getComponentDirectoryPath(componentKey);
34
+ // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
35
+ await lintComponent(targetDirectory);
36
+ }
37
+ },
38
+ {
39
+ title: 'Bundle Component',
40
+ task: async () => await bundleComponent(componentKey, sourceMap, devBuild),
41
+ skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
42
+ },
43
+ {
44
+ title: 'Update Component Map',
45
+ task: async () => {
46
+ await updateComponentMap(componentKey);
47
+ }
48
+ },
49
+ {
50
+ title: 'Zip Component',
51
+ task: async () => {
52
+ const output = await zipComponent(componentKey);
53
+ content = { ...content, ...output };
54
+ }
55
+ },
56
+ {
57
+ title: 'Publish Component',
58
+ task: async () => {
59
+ await publishComponentToServer(content);
60
+ }
61
+ }
62
+ ],
63
+ {
64
+ exitOnError: true
65
+ }
66
+ );
67
+
68
+ await tasks.run().catch(err => {
69
+ console.log(chalk.bold.red(err.toString()));
70
+ });
71
+ return true;
72
+ };
@@ -0,0 +1,139 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import https from 'https';
4
+
5
+ import fetch from 'node-fetch';
6
+ import AdmZip from 'adm-zip';
7
+ import chalk from 'chalk';
8
+
9
+ import {
10
+ constructCompleteUrl,
11
+ getComponentDirectoryPath,
12
+ getComponentsObj,
13
+ getPegaServerConfig,
14
+ validateRulesetVersion
15
+ } from '../../util.js';
16
+ import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
17
+
18
+ export const getPublishComponentQuestions = async () => {
19
+ const components = await getComponentsObj();
20
+ const defaultPegaConfig = await getPegaServerConfig();
21
+
22
+ return [
23
+ {
24
+ name: 'rulesetName',
25
+ message: 'Enter ruleset name',
26
+ default: defaultPegaConfig.rulesetName,
27
+ validate: value => {
28
+ if (value.trim()) {
29
+ return true;
30
+ }
31
+ return 'Ruleset name cannot be empty';
32
+ }
33
+ },
34
+ {
35
+ name: 'rulesetVersion',
36
+ message: 'Enter ruleset version',
37
+ default: defaultPegaConfig.rulesetVersion,
38
+ validate: value => {
39
+ if (validateRulesetVersion(value)) {
40
+ return true;
41
+ }
42
+ return 'Please provide compatible version e.g 01-01-01';
43
+ }
44
+ },
45
+ {
46
+ name: 'sourceMap',
47
+ message: 'Generate source map ?',
48
+ default: defaultPegaConfig.sourceMap,
49
+ when: () => false && !process.env.SOURCE_MAP
50
+ },
51
+ {
52
+ name: 'devBuild',
53
+ message: 'Generate development build ?',
54
+ default: defaultPegaConfig.devBuild
55
+ }
56
+ ];
57
+ };
58
+
59
+ export const zipComponent = async componentKey => {
60
+ const srcDirectory = await getComponentDirectoryPath(componentKey);
61
+ const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
62
+ const configJson = `${srcDirectory}/config.json`;
63
+
64
+ const zip = new AdmZip();
65
+
66
+ zip.addLocalFolder(srcDirectory, 'src/');
67
+ zip.addLocalFile(configJson);
68
+ zip.addLocalFolder(buildDirectory);
69
+ const zipContent = zip.toBuffer().toString('base64');
70
+
71
+ const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
72
+ fs.rmdir('dist', { recursive: true }, err => {
73
+ if (err) {
74
+ throw err;
75
+ }
76
+ });
77
+ return { zipContent, configContent };
78
+ };
79
+
80
+ export const publishComponentToServer = async data => {
81
+ const { configContent, zipContent, componentKey, rulesetName, rulesetVersion } = data;
82
+
83
+ const apiBody = {
84
+ configContent,
85
+ zipContent,
86
+ componentKey: JSON.parse(configContent).componentKey,
87
+ publishFor: 'constellation',
88
+ rulesetName,
89
+ rulesetVersion,
90
+ category: ''
91
+ };
92
+ const defaultPegaConfig = await getPegaServerConfig();
93
+ const url = constructCompleteUrl(
94
+ defaultPegaConfig.server,
95
+ PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
96
+ );
97
+ try {
98
+ const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
99
+ if (OauthData) {
100
+ const {
101
+ access_token: accessToken,
102
+ token_type: tokenType,
103
+ refresh_token: refreshToken
104
+ } = JSON.parse(OauthData);
105
+ let status = 500;
106
+ fetch(url, {
107
+ method: 'POST',
108
+ agent: new https.Agent({ rejectUnauthorized: false }),
109
+ headers: {
110
+ Authorization: `${tokenType} ${accessToken}`
111
+ },
112
+ body: JSON.stringify(apiBody)
113
+ })
114
+ .then(response => {
115
+ status = response.status;
116
+ return response.text();
117
+ })
118
+ .then(resp => {
119
+ const respData = JSON.parse(resp);
120
+ if (status === 401) {
121
+ throw new Error(
122
+ 'Error occured in authentication. Please regenerate using authenticate'
123
+ );
124
+ // console.log(accessTokenUri, refreshToken);
125
+ /* TODO - Handle refresh_token */
126
+ } else if (status == 200) {
127
+ console.log(chalk.bold.green(`Success : ${respData.message}`));
128
+ } else {
129
+ throw new Error(`${respData.message}`);
130
+ }
131
+ })
132
+ .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
133
+ } else {
134
+ throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
135
+ }
136
+ } catch (err) {
137
+ throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
138
+ }
139
+ };