@optimizely/ocp-cli 1.0.0-beta.2

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 (283) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +18 -0
  3. package/bin/opti.js +3 -0
  4. package/dist/commands/accounts/Whoami.d.ts +3 -0
  5. package/dist/commands/accounts/Whoami.js +34 -0
  6. package/dist/commands/accounts/Whoami.js.map +1 -0
  7. package/dist/commands/accounts/Whois.d.ts +6 -0
  8. package/dist/commands/accounts/Whois.js +65 -0
  9. package/dist/commands/accounts/Whois.js.map +1 -0
  10. package/dist/commands/app/BaseBuildCommand.d.ts +23 -0
  11. package/dist/commands/app/BaseBuildCommand.js +227 -0
  12. package/dist/commands/app/BaseBuildCommand.js.map +1 -0
  13. package/dist/commands/app/Init.d.ts +20 -0
  14. package/dist/commands/app/Init.js +285 -0
  15. package/dist/commands/app/Init.js.map +1 -0
  16. package/dist/commands/app/Logs.d.ts +19 -0
  17. package/dist/commands/app/Logs.js +230 -0
  18. package/dist/commands/app/Logs.js.map +1 -0
  19. package/dist/commands/app/Package.d.ts +4 -0
  20. package/dist/commands/app/Package.js +51 -0
  21. package/dist/commands/app/Package.js.map +1 -0
  22. package/dist/commands/app/Prepare.d.ts +8 -0
  23. package/dist/commands/app/Prepare.js +112 -0
  24. package/dist/commands/app/Prepare.js.map +1 -0
  25. package/dist/commands/app/Register.d.ts +7 -0
  26. package/dist/commands/app/Register.js +58 -0
  27. package/dist/commands/app/Register.js.map +1 -0
  28. package/dist/commands/app/Validate.d.ts +4 -0
  29. package/dist/commands/app/Validate.js +27 -0
  30. package/dist/commands/app/Validate.js.map +1 -0
  31. package/dist/commands/availability/List.d.ts +4 -0
  32. package/dist/commands/availability/List.js +47 -0
  33. package/dist/commands/availability/List.js.map +1 -0
  34. package/dist/commands/directory/Info.d.ts +7 -0
  35. package/dist/commands/directory/Info.js +92 -0
  36. package/dist/commands/directory/Info.js.map +1 -0
  37. package/dist/commands/directory/Install.d.ts +6 -0
  38. package/dist/commands/directory/Install.js +54 -0
  39. package/dist/commands/directory/Install.js.map +1 -0
  40. package/dist/commands/directory/List.d.ts +8 -0
  41. package/dist/commands/directory/List.js +102 -0
  42. package/dist/commands/directory/List.js.map +1 -0
  43. package/dist/commands/directory/ListFunctions.d.ts +7 -0
  44. package/dist/commands/directory/ListFunctions.js +77 -0
  45. package/dist/commands/directory/ListFunctions.js.map +1 -0
  46. package/dist/commands/directory/ListGlobalFunctions.d.ts +6 -0
  47. package/dist/commands/directory/ListGlobalFunctions.js +72 -0
  48. package/dist/commands/directory/ListGlobalFunctions.js.map +1 -0
  49. package/dist/commands/directory/ListInstalls.d.ts +8 -0
  50. package/dist/commands/directory/ListInstalls.js +81 -0
  51. package/dist/commands/directory/ListInstalls.js.map +1 -0
  52. package/dist/commands/directory/Publish.d.ts +8 -0
  53. package/dist/commands/directory/Publish.js +180 -0
  54. package/dist/commands/directory/Publish.js.map +1 -0
  55. package/dist/commands/directory/Status.d.ts +5 -0
  56. package/dist/commands/directory/Status.js +60 -0
  57. package/dist/commands/directory/Status.js.map +1 -0
  58. package/dist/commands/directory/Uninstall.d.ts +6 -0
  59. package/dist/commands/directory/Uninstall.js +50 -0
  60. package/dist/commands/directory/Uninstall.js.map +1 -0
  61. package/dist/commands/directory/Unpublish.d.ts +10 -0
  62. package/dist/commands/directory/Unpublish.js +181 -0
  63. package/dist/commands/directory/Unpublish.js.map +1 -0
  64. package/dist/commands/directory/Uprade.d.ts +8 -0
  65. package/dist/commands/directory/Uprade.js +100 -0
  66. package/dist/commands/directory/Uprade.js.map +1 -0
  67. package/dist/commands/env/GetEnvironment.d.ts +3 -0
  68. package/dist/commands/env/GetEnvironment.js +28 -0
  69. package/dist/commands/env/GetEnvironment.js.map +1 -0
  70. package/dist/commands/env/SetEnvironment.d.ts +4 -0
  71. package/dist/commands/env/SetEnvironment.js +63 -0
  72. package/dist/commands/env/SetEnvironment.js.map +1 -0
  73. package/dist/commands/jobs/List.d.ts +21 -0
  74. package/dist/commands/jobs/List.js +268 -0
  75. package/dist/commands/jobs/List.js.map +1 -0
  76. package/dist/commands/jobs/RuntimeStatus.d.ts +5 -0
  77. package/dist/commands/jobs/RuntimeStatus.js +65 -0
  78. package/dist/commands/jobs/RuntimeStatus.js.map +1 -0
  79. package/dist/commands/jobs/Terminate.d.ts +5 -0
  80. package/dist/commands/jobs/Terminate.js +45 -0
  81. package/dist/commands/jobs/Terminate.js.map +1 -0
  82. package/dist/commands/jobs/Trigger.d.ts +8 -0
  83. package/dist/commands/jobs/Trigger.js +58 -0
  84. package/dist/commands/jobs/Trigger.js.map +1 -0
  85. package/dist/commands/review/List.d.ts +5 -0
  86. package/dist/commands/review/List.js +81 -0
  87. package/dist/commands/review/List.js.map +1 -0
  88. package/dist/commands/review/Open.d.ts +4 -0
  89. package/dist/commands/review/Open.js +42 -0
  90. package/dist/commands/review/Open.js.map +1 -0
  91. package/dist/index.d.ts +1 -0
  92. package/dist/index.js +15 -0
  93. package/dist/index.js.map +1 -0
  94. package/dist/lib/AppContext.d.ts +9 -0
  95. package/dist/lib/AppContext.js +43 -0
  96. package/dist/lib/AppContext.js.map +1 -0
  97. package/dist/lib/AppPackager.d.ts +8 -0
  98. package/dist/lib/AppPackager.js +40 -0
  99. package/dist/lib/AppPackager.js.map +1 -0
  100. package/dist/lib/AppUpdater.d.ts +9 -0
  101. package/dist/lib/AppUpdater.js +155 -0
  102. package/dist/lib/AppUpdater.js.map +1 -0
  103. package/dist/lib/AppUploader.d.ts +8 -0
  104. package/dist/lib/AppUploader.js +36 -0
  105. package/dist/lib/AppUploader.js.map +1 -0
  106. package/dist/lib/Config.d.ts +15 -0
  107. package/dist/lib/Config.js +47 -0
  108. package/dist/lib/Config.js.map +1 -0
  109. package/dist/lib/EnvironmentalOutput.d.ts +1 -0
  110. package/dist/lib/EnvironmentalOutput.js +21 -0
  111. package/dist/lib/EnvironmentalOutput.js.map +1 -0
  112. package/dist/lib/Moria.d.ts +51 -0
  113. package/dist/lib/Moria.js +30 -0
  114. package/dist/lib/Moria.js.map +1 -0
  115. package/dist/lib/MoriaApi.d.ts +22 -0
  116. package/dist/lib/MoriaApi.js +75 -0
  117. package/dist/lib/MoriaApi.js.map +1 -0
  118. package/dist/lib/Rivendell.d.ts +351 -0
  119. package/dist/lib/Rivendell.js +328 -0
  120. package/dist/lib/Rivendell.js.map +1 -0
  121. package/dist/lib/RivendellApi.d.ts +22 -0
  122. package/dist/lib/RivendellApi.js +90 -0
  123. package/dist/lib/RivendellApi.js.map +1 -0
  124. package/dist/lib/Shards.d.ts +3 -0
  125. package/dist/lib/Shards.js +34 -0
  126. package/dist/lib/Shards.js.map +1 -0
  127. package/dist/lib/StringUtils.d.ts +1 -0
  128. package/dist/lib/StringUtils.js +9 -0
  129. package/dist/lib/StringUtils.js.map +1 -0
  130. package/dist/lib/TeminalPassthru.d.ts +5 -0
  131. package/dist/lib/TeminalPassthru.js +12 -0
  132. package/dist/lib/TeminalPassthru.js.map +1 -0
  133. package/dist/lib/TerminalConfirm.d.ts +3 -0
  134. package/dist/lib/TerminalConfirm.js +26 -0
  135. package/dist/lib/TerminalConfirm.js.map +1 -0
  136. package/dist/lib/TerminalInput.d.ts +32 -0
  137. package/dist/lib/TerminalInput.js +207 -0
  138. package/dist/lib/TerminalInput.js.map +1 -0
  139. package/dist/lib/TerminalMenu.d.ts +34 -0
  140. package/dist/lib/TerminalMenu.js +186 -0
  141. package/dist/lib/TerminalMenu.js.map +1 -0
  142. package/dist/lib/TerminalOutput.d.ts +5 -0
  143. package/dist/lib/TerminalOutput.js +12 -0
  144. package/dist/lib/TerminalOutput.js.map +1 -0
  145. package/dist/lib/TerminalSpinner.d.ts +15 -0
  146. package/dist/lib/TerminalSpinner.js +71 -0
  147. package/dist/lib/TerminalSpinner.js.map +1 -0
  148. package/dist/lib/build.d.ts +5 -0
  149. package/dist/lib/build.js +35 -0
  150. package/dist/lib/build.js.map +1 -0
  151. package/dist/lib/checkForUpdate.d.ts +2 -0
  152. package/dist/lib/checkForUpdate.js +58 -0
  153. package/dist/lib/checkForUpdate.js.map +1 -0
  154. package/dist/lib/dev/app.d.ts +8 -0
  155. package/dist/lib/dev/app.js +53 -0
  156. package/dist/lib/dev/app.js.map +1 -0
  157. package/dist/lib/dev/index.d.ts +1 -0
  158. package/dist/lib/dev/index.js +14 -0
  159. package/dist/lib/dev/index.js.map +1 -0
  160. package/dist/lib/dev/logger.d.ts +15 -0
  161. package/dist/lib/dev/logger.js +58 -0
  162. package/dist/lib/dev/logger.js.map +1 -0
  163. package/dist/lib/die.d.ts +5 -0
  164. package/dist/lib/die.js +14 -0
  165. package/dist/lib/die.js.map +1 -0
  166. package/dist/lib/directoryExists.d.ts +1 -0
  167. package/dist/lib/directoryExists.js +9 -0
  168. package/dist/lib/directoryExists.js.map +1 -0
  169. package/dist/lib/formatBuildState.d.ts +2 -0
  170. package/dist/lib/formatBuildState.js +23 -0
  171. package/dist/lib/formatBuildState.js.map +1 -0
  172. package/dist/lib/formatError.d.ts +1 -0
  173. package/dist/lib/formatError.js +45 -0
  174. package/dist/lib/formatError.js.map +1 -0
  175. package/dist/lib/formatJobStatus.d.ts +3 -0
  176. package/dist/lib/formatJobStatus.js +28 -0
  177. package/dist/lib/formatJobStatus.js.map +1 -0
  178. package/dist/lib/formatReviewStatus.d.ts +4 -0
  179. package/dist/lib/formatReviewStatus.js +28 -0
  180. package/dist/lib/formatReviewStatus.js.map +1 -0
  181. package/dist/lib/formatTimstamp.d.ts +1 -0
  182. package/dist/lib/formatTimstamp.js +25 -0
  183. package/dist/lib/formatTimstamp.js.map +1 -0
  184. package/dist/lib/formatVersionState.d.ts +2 -0
  185. package/dist/lib/formatVersionState.js +35 -0
  186. package/dist/lib/formatVersionState.js.map +1 -0
  187. package/dist/lib/gatherAppEnv.d.ts +3 -0
  188. package/dist/lib/gatherAppEnv.js +71 -0
  189. package/dist/lib/gatherAppEnv.js.map +1 -0
  190. package/dist/lib/handleInterrupt.d.ts +1 -0
  191. package/dist/lib/handleInterrupt.js +17 -0
  192. package/dist/lib/handleInterrupt.js.map +1 -0
  193. package/dist/lib/jobRuntime.d.ts +3 -0
  194. package/dist/lib/jobRuntime.js +16 -0
  195. package/dist/lib/jobRuntime.js.map +1 -0
  196. package/dist/lib/parseDate.d.ts +2 -0
  197. package/dist/lib/parseDate.js +26 -0
  198. package/dist/lib/parseDate.js.map +1 -0
  199. package/dist/lib/templating/TemplateRenderer.d.ts +13 -0
  200. package/dist/lib/templating/TemplateRenderer.js +62 -0
  201. package/dist/lib/templating/TemplateRenderer.js.map +1 -0
  202. package/dist/lib/templating/fetchTemplatesManifest.d.ts +1 -0
  203. package/dist/lib/templating/fetchTemplatesManifest.js +10 -0
  204. package/dist/lib/templating/fetchTemplatesManifest.js.map +1 -0
  205. package/dist/lib/templating/types.d.ts +27 -0
  206. package/dist/lib/templating/types.js +3 -0
  207. package/dist/lib/templating/types.js.map +1 -0
  208. package/dist/oo-cli.manifest.json +1142 -0
  209. package/dist/test/setup.d.ts +0 -0
  210. package/dist/test/setup.js +4 -0
  211. package/dist/test/setup.js.map +1 -0
  212. package/package.json +94 -0
  213. package/src/commands/accounts/Whoami.ts +19 -0
  214. package/src/commands/accounts/Whois.ts +51 -0
  215. package/src/commands/app/BaseBuildCommand.ts +266 -0
  216. package/src/commands/app/Init.ts +303 -0
  217. package/src/commands/app/Logs.ts +241 -0
  218. package/src/commands/app/Package.ts +39 -0
  219. package/src/commands/app/Prepare.ts +108 -0
  220. package/src/commands/app/Register.ts +41 -0
  221. package/src/commands/app/Validate.ts +13 -0
  222. package/src/commands/availability/List.ts +37 -0
  223. package/src/commands/directory/Info.ts +83 -0
  224. package/src/commands/directory/Install.ts +37 -0
  225. package/src/commands/directory/List.ts +96 -0
  226. package/src/commands/directory/ListFunctions.ts +60 -0
  227. package/src/commands/directory/ListGlobalFunctions.ts +54 -0
  228. package/src/commands/directory/ListInstalls.ts +73 -0
  229. package/src/commands/directory/Publish.ts +179 -0
  230. package/src/commands/directory/Status.ts +45 -0
  231. package/src/commands/directory/Uninstall.ts +32 -0
  232. package/src/commands/directory/Unpublish.ts +173 -0
  233. package/src/commands/directory/Uprade.ts +85 -0
  234. package/src/commands/env/GetEnvironment.ts +14 -0
  235. package/src/commands/env/SetEnvironment.ts +52 -0
  236. package/src/commands/jobs/List.ts +278 -0
  237. package/src/commands/jobs/RuntimeStatus.ts +49 -0
  238. package/src/commands/jobs/Terminate.ts +29 -0
  239. package/src/commands/jobs/Trigger.ts +41 -0
  240. package/src/commands/review/List.ts +76 -0
  241. package/src/commands/review/Open.ts +28 -0
  242. package/src/index.ts +15 -0
  243. package/src/lib/AppContext.ts +47 -0
  244. package/src/lib/AppPackager.ts +47 -0
  245. package/src/lib/AppUpdater.ts +177 -0
  246. package/src/lib/AppUploader.ts +39 -0
  247. package/src/lib/Config.ts +60 -0
  248. package/src/lib/EnvironmentalOutput.ts +18 -0
  249. package/src/lib/Moria.ts +66 -0
  250. package/src/lib/MoriaApi.ts +86 -0
  251. package/src/lib/Rivendell.ts +572 -0
  252. package/src/lib/RivendellApi.ts +99 -0
  253. package/src/lib/Shards.ts +37 -0
  254. package/src/lib/StringUtils.ts +4 -0
  255. package/src/lib/TeminalPassthru.ts +7 -0
  256. package/src/lib/TerminalConfirm.ts +27 -0
  257. package/src/lib/TerminalInput.ts +236 -0
  258. package/src/lib/TerminalMenu.ts +221 -0
  259. package/src/lib/TerminalOutput.ts +7 -0
  260. package/src/lib/TerminalSpinner.ts +76 -0
  261. package/src/lib/build.ts +36 -0
  262. package/src/lib/checkForUpdate.ts +63 -0
  263. package/src/lib/dev/app.ts +58 -0
  264. package/src/lib/dev/index.ts +1 -0
  265. package/src/lib/dev/logger.ts +77 -0
  266. package/src/lib/die.ts +10 -0
  267. package/src/lib/directoryExists.ts +5 -0
  268. package/src/lib/formatBuildState.ts +20 -0
  269. package/src/lib/formatError.ts +39 -0
  270. package/src/lib/formatJobStatus.ts +24 -0
  271. package/src/lib/formatReviewStatus.ts +27 -0
  272. package/src/lib/formatTimstamp.ts +21 -0
  273. package/src/lib/formatVersionState.ts +31 -0
  274. package/src/lib/gatherAppEnv.ts +75 -0
  275. package/src/lib/handleInterrupt.ts +13 -0
  276. package/src/lib/jobRuntime.ts +12 -0
  277. package/src/lib/parseDate.ts +21 -0
  278. package/src/lib/templating/TemplateRenderer.ts +65 -0
  279. package/src/lib/templating/fetchTemplatesManifest.ts +6 -0
  280. package/src/lib/templating/types.ts +30 -0
  281. package/src/test/setup.ts +2 -0
  282. package/src/types/columnify.d.ts +27 -0
  283. package/src/types/gitignore-parser.d.ts +11 -0
File without changes
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // silence expected console.error()
3
+ jest.spyOn(global.console, 'error').mockImplementation(() => jest.fn());
4
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/test/setup.ts"],"names":[],"mappings":";AAAA,mCAAmC;AACnC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@optimizely/ocp-cli",
3
+ "version": "1.0.0-beta.2",
4
+ "description": "Optimizely Connect Platform command line interface",
5
+ "repository": "https://github.com/ZaiusInc/ocp-cli",
6
+ "license": "Apache-2.0",
7
+ "licenses": [
8
+ {
9
+ "type": "Apache-2.0",
10
+ "url": "http://www.apache.org/licenses/LICENSE-2.0"
11
+ }
12
+ ],
13
+ "author": "Optimizely, Inc.",
14
+ "publishConfig": {
15
+ "registry": "https://registry.npmjs.org",
16
+ "access": "public"
17
+ },
18
+ "main": "./dist/index.js",
19
+ "bin": {
20
+ "ocp": "./bin/ocp.js"
21
+ },
22
+ "files": [
23
+ "bin/",
24
+ "dist/",
25
+ "src/"
26
+ ],
27
+ "scripts": {
28
+ "build": "npx rimraf remove ./dist/ && npx tsc -p . && node ./node_modules/oo-cli/dist/build.js",
29
+ "build-watch": "npx rimraf remove ./dist/ && npx nodemon -e ts,json --watch src --exec 'tsc -p . && node ./node_modules/oo-cli/dist/build.js'",
30
+ "lint": "npx tslint --project .",
31
+ "test": "npx jest",
32
+ "release": "release-it"
33
+ },
34
+ "dependencies": {
35
+ "@zaiusinc/app-sdk": "^0.17.5",
36
+ "@zaiusinc/node-sdk": "^0.8.2",
37
+ "adm-zip": "^0.4.13",
38
+ "aws-sdk": "^2.479.0",
39
+ "chalk": "^2.4.2",
40
+ "cli-spinners": "^2.2.0",
41
+ "columnify": "^1.5.4",
42
+ "date-fns": "^2.29.3",
43
+ "deepmerge": "^4.0.0",
44
+ "dotenv": "^10.0.0",
45
+ "glob": "^7.1.4",
46
+ "js-yaml": "3.13.1",
47
+ "marked": "^0.7.0",
48
+ "marked-terminal": "^3.3.0",
49
+ "mustache": "^3.1.0",
50
+ "node-fetch": "^2.6.0",
51
+ "oo-cli": "0.2.1",
52
+ "parse-duration": "^0.4.4",
53
+ "semver": "^6.3.0",
54
+ "terminal-kit": ">=1.28.42 <1.44.0",
55
+ "text-table": "0.2.0",
56
+ "title-case": "^2.1.1",
57
+ "open": "^8.4.0"
58
+ },
59
+ "devDependencies": {
60
+ "@types/adm-zip": "^0.4.32",
61
+ "@types/aws-sdk": "^2.7.0",
62
+ "@types/chalk": "^2.2.0",
63
+ "@types/cli-spinners": "^1.3.0",
64
+ "@types/deepmerge": "^2.2.0",
65
+ "@types/glob": "^7.1.1",
66
+ "@types/google-protobuf": "^3.7.1",
67
+ "@types/jest": "^24.0.11",
68
+ "@types/js-yaml": "3.12.1",
69
+ "@types/marked": "^0.6.5",
70
+ "@types/marked-terminal": "^3.1.1",
71
+ "@types/mustache": "^0.8.32",
72
+ "@types/node": "^13.7.0",
73
+ "@types/node-fetch": "^2.5.0",
74
+ "@types/semver": "^6.0.1",
75
+ "@types/terminal-kit": "^1.28.0",
76
+ "@types/text-table": "0.2.0",
77
+ "@zaiusinc/tslint-presets": "^1.0.0",
78
+ "copy": "^0.3.2",
79
+ "jest": "^24.7.1",
80
+ "nodemon": "^1.18.11",
81
+ "release-it": "^15.10.1",
82
+ "rimraf": "^3.0.2",
83
+ "ts-jest": "^24.0.2",
84
+ "tslint": "^5.16.0",
85
+ "typescript": "^3.7.5"
86
+ },
87
+ "resolutions": {
88
+ "@types/babel__traverse": "7.18.2",
89
+ "@types/marked": "^0.6.5"
90
+ },
91
+ "engines": {
92
+ "node": ">=16.0.0"
93
+ }
94
+ }
@@ -0,0 +1,19 @@
1
+ import {command, help, namespace} from 'oo-cli';
2
+ import {die} from '../../lib/die';
3
+ import {formatError} from '../../lib/formatError';
4
+ import {Rivendell} from '../../lib/Rivendell';
5
+ import chalk from 'chalk';
6
+
7
+ @namespace('accounts')
8
+ export class WhoamiCommand {
9
+ @command
10
+ @help('Show your account information')
11
+ public async whoami() {
12
+ try {
13
+ const me = await Rivendell.whoami();
14
+ console.log(chalk.gray(require('js-yaml').dump(me)));
15
+ } catch (e) {
16
+ die(formatError(e));
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,51 @@
1
+ import {command, help, namespace, option, param} from 'oo-cli';
2
+ import {die} from '../../lib/die';
3
+ import {formatError} from '../../lib/formatError';
4
+ import {Rivendell} from '../../lib/Rivendell';
5
+ import Account = Rivendell.Account;
6
+ import chalk from 'chalk';
7
+ import * as table from 'text-table';
8
+ import {styledStringLength} from '../../lib/StringUtils';
9
+
10
+ @namespace('accounts')
11
+ export class WhoisCommand {
12
+ @param
13
+ @help('The search term (e.g. 1.web)')
14
+ public term!: string;
15
+
16
+ @option('a')
17
+ @help('The availability zone that will be targeted (default: us)')
18
+ private availability: string = '';
19
+
20
+ @command
21
+ @help('Look up basic account information')
22
+ public async whois() {
23
+ try {
24
+ const accounts = await Rivendell.searchAccounts(this.term, this.availability);
25
+ if (accounts.length) {
26
+ this.render(accounts);
27
+ } else {
28
+ const zone = this.availability || 'us';
29
+ console.log(chalk.yellow(`No accounts matching search term '${this.term}' found in ${zone}.`));
30
+ }
31
+ } catch (e) {
32
+ die(formatError(e));
33
+ }
34
+ }
35
+
36
+ private render(accounts: Account[]) {
37
+ const header = ['id', 'tracker Id', 'name'].map((item) => chalk.grey(item));
38
+ const rows = accounts.map((account) => [account.id, account.trackerId, account.name]);
39
+ const t = table(
40
+ [
41
+ header,
42
+ ...rows
43
+ ],
44
+ {
45
+ hsep: ' '.repeat(8),
46
+ stringLength: styledStringLength
47
+ }
48
+ );
49
+ console.log(`\n${t}\n`);
50
+ }
51
+ }
@@ -0,0 +1,266 @@
1
+ import chalk from 'chalk';
2
+ import {execSync} from 'child_process';
3
+ import {DotenvParseOutput} from 'dotenv';
4
+ import {defaultValue, flag, help, param} from 'oo-cli';
5
+ import {AppContext, appContext} from '../../lib/AppContext';
6
+ import {AppPackager} from '../../lib/AppPackager';
7
+ import {AppUpdater} from '../../lib/AppUpdater';
8
+ import {AppUploader} from '../../lib/AppUploader';
9
+ import {die} from '../../lib/die';
10
+ import {directoryExists} from '../../lib/directoryExists';
11
+ import {formatBuildState} from '../../lib/formatBuildState';
12
+ import {gatherAppEnv, validateAppEnvs} from '../../lib/gatherAppEnv';
13
+ import {handleInterrupt} from '../../lib/handleInterrupt';
14
+ import {TerminalSpinner} from '../../lib/TerminalSpinner';
15
+ import {ErrorList, watchBuild} from '../../lib/build';
16
+ import {Rivendell} from '../../lib/Rivendell';
17
+ import {formatError} from '../../lib/formatError';
18
+ import {RivendellApi} from '../../lib/RivendellApi';
19
+ import {applicableShards, targetShards} from '../../lib/Shards';
20
+ import ApiError = RivendellApi.ApiError;
21
+ import Build = Rivendell.Build;
22
+ import BuildState = Rivendell.BuildState;
23
+ import AppVersion = Rivendell.AppVersion;
24
+ import AppVersionState = Rivendell.AppVersionState;
25
+ import ReviewStatus = Rivendell.ReviewStatus;
26
+
27
+ export abstract class BaseBuildCommand {
28
+ @flag('no-progress')
29
+ @help("Don't display any progress indicators")
30
+ public noProgress!: boolean;
31
+
32
+ @flag('upgrade-deps')
33
+ @help('Automatically update dependencies')
34
+ public upgradeDeps!: boolean;
35
+
36
+ @param
37
+ @help('The root directory of the app')
38
+ @defaultValue('./')
39
+ public path!: string;
40
+
41
+ protected async run(upload: boolean, publish: boolean, usePreviousAppEnvValues: boolean) {
42
+ handleInterrupt();
43
+
44
+ if (!directoryExists(this.path)) {
45
+ die('Specified path to app does not exist');
46
+ }
47
+ process.chdir(this.path);
48
+
49
+ const context = appContext();
50
+ if (!context.appId || !context.version || !context.runtime) {
51
+ die('Unable to read App ID or version info. Ensure you are uploading the right directory.');
52
+ return;
53
+ }
54
+
55
+ if (!usePreviousAppEnvValues) {
56
+ validateAppEnvs(await targetShards());
57
+ }
58
+ const shards: string[] = await applicableShards();
59
+
60
+ await AppUpdater.ensureDependencies(upload, this.upgradeDeps, context.runtime);
61
+
62
+ console.log(chalk.gray('Performing local validation...'));
63
+ try {
64
+ execSync('yarn --silent validate', {stdio: 'inherit'});
65
+ } catch (e) {
66
+ process.exit(1);
67
+ }
68
+ if (upload) {
69
+ console.log(chalk.gray('Verifying upload constraints...'));
70
+ try {
71
+ execSync('git rev-parse --is-inside-work-tree');
72
+ } catch (e) {
73
+ console.log(chalk.red('\nApp must be in an initialized Git repository'));
74
+ process.exit(1);
75
+ }
76
+
77
+ try {
78
+ const version = await this.fetchAppVersion(context, 'us');
79
+ const packageUrl = version?.state === AppVersionState.RUNNING
80
+ ? version?.packageUrl
81
+ : await this.uploadPackage(context);
82
+
83
+ for (const shard of shards) {
84
+ let appEnv = gatherAppEnv(shard);
85
+ if (usePreviousAppEnvValues && Object.keys(appEnv).length > 0) {
86
+ console.log(chalk.yellow('\n--use-previous-app-env-values is on. Ignoring values from .env file'));
87
+ appEnv = {};
88
+ }
89
+ await this.registerOrUpdateVersion(context, packageUrl, appEnv, usePreviousAppEnvValues, shard);
90
+ }
91
+
92
+ if (version?.state !== AppVersionState.RUNNING) {
93
+ await this.build(context, publish);
94
+ }
95
+ } catch (e) {
96
+ die(formatError(e));
97
+ }
98
+ }
99
+ }
100
+
101
+ protected async fetchAppVersion(context: AppContext, shard: string): Promise<AppVersion | null> {
102
+ try {
103
+ return await Rivendell.fetchAppVersion(context, shard);
104
+ } catch (e) {
105
+ if (e instanceof ApiError && e.response?.status === 404) {
106
+ console.log(chalk.gray('Existing version not found...'));
107
+ return null;
108
+ }
109
+
110
+ throw e;
111
+ }
112
+ }
113
+
114
+ protected isRelease(appVersionId: string) {
115
+ return !this.isDevVersion(appVersionId);
116
+ }
117
+
118
+ protected isDevVersion(appVersionId?: string) {
119
+ return appVersionId?.includes('-dev');
120
+ }
121
+
122
+ protected async reviewAppVersion(appId: string, version: string) {
123
+ if (await this.requiresReview(version)) {
124
+ const appVersion = await this.fetchAppVersion({appId, version}, 'us');
125
+ if (appVersion?.state === AppVersionState.PUBLISHED && appVersion.reviewStatus !== ReviewStatus.NOT_REQUIRED) {
126
+ await Rivendell.reviewAppVersion(appId, version);
127
+ }
128
+ }
129
+ }
130
+
131
+ protected async isInReview(appId: string, version: string) {
132
+ const appVersion = await this.fetchAppVersion({appId, version}, 'us');
133
+ if (appVersion) {
134
+ const reviewStatus = appVersion.reviewStatus as ReviewStatus;
135
+ return reviewStatus === ReviewStatus.IN_REVIEW;
136
+ } else {
137
+ return false;
138
+ }
139
+ }
140
+
141
+ protected async requiresReview(version: string) {
142
+ return !await this.isAdmin() && this.isRelease(version);
143
+ }
144
+
145
+ private async uploadPackage(context: AppContext): Promise<string> {
146
+ try {
147
+ await Rivendell.fetchApp(context.appId!);
148
+ const packageData = new AppPackager('./').package();
149
+ return await new AppUploader(context, packageData).upload();
150
+ } catch (e) {
151
+ console.log('App ID must be registered before it can be uploaded. Try:');
152
+ console.log(' ocp app register');
153
+ throw e;
154
+ }
155
+ }
156
+
157
+ private async build(context: AppContext, publish: boolean) {
158
+ try {
159
+ const build = await this.startBuild(context, publish);
160
+ await this.watchForBuildCompletion(context, build.id, publish);
161
+ } catch (e) {
162
+ console.log('App ID must be registered before it can be uploaded. Try:');
163
+ console.log(' ocp app register');
164
+ throw e;
165
+ }
166
+ }
167
+
168
+ private async registerOrUpdateVersion(
169
+ context: AppContext,
170
+ packageUrl: string,
171
+ appEnv: DotenvParseOutput,
172
+ usePreviousAppEnvValues: boolean,
173
+ shard: string)
174
+ : Promise<void> {
175
+ try {
176
+ console.log(chalk.gray(`Checking for existing version (${shard})...`));
177
+ const version = await this.fetchAppVersion(context, shard);
178
+ if (version?.state === AppVersionState.RUNNING) {
179
+ console.log(`AppVersion already running (${shard})`);
180
+ } else if (version) {
181
+ await this.updateVersion(context, packageUrl, appEnv, usePreviousAppEnvValues, shard);
182
+ } else {
183
+ await this.registerVersion(context, packageUrl, appEnv, usePreviousAppEnvValues, shard);
184
+ }
185
+ } catch (e) {
186
+ die(`${formatError(e)} (${shard})`);
187
+ }
188
+ }
189
+
190
+ private async registerVersion(
191
+ context: AppContext,
192
+ packageUrl: string,
193
+ appEnv: DotenvParseOutput,
194
+ usePreviousAppEnvValues: boolean,
195
+ shard: string
196
+ ): Promise<void> {
197
+ console.log(chalk.gray(`Registering a new version (${shard})...`));
198
+ await Rivendell.registerAppVersion(
199
+ context.appId!!,
200
+ context.version!!,
201
+ packageUrl,
202
+ appEnv,
203
+ usePreviousAppEnvValues,
204
+ shard
205
+ );
206
+ }
207
+
208
+ private async updateVersion(
209
+ context: AppContext,
210
+ packageUrl: string,
211
+ appEnv: DotenvParseOutput,
212
+ usePreviousAppEnvValues: boolean,
213
+ shard: string)
214
+ : Promise<void> {
215
+ console.log(chalk.gray(`Updating existing version (${shard})...`));
216
+ await Rivendell.updateAppVersion(
217
+ context.appId!!,
218
+ context.version!!,
219
+ packageUrl,
220
+ appEnv,
221
+ usePreviousAppEnvValues,
222
+ shard
223
+ );
224
+ }
225
+
226
+ private async startBuild(context: AppContext, publish: boolean): Promise<Build> {
227
+ console.log(chalk.gray(`Starting ${publish ? 'build' : 'validation '}...`));
228
+ return publish
229
+ ? await Rivendell.build(context.appId!, context.version!)
230
+ : await Rivendell.verify(context.appId!, context.version!);
231
+ }
232
+
233
+ private async watchForBuildCompletion(context: AppContext, id: number, publish: boolean) {
234
+ console.log(
235
+ chalk.gray(`Waiting for ${publish ? 'build' : 'validation'} (id=${id}) to complete... CTRL+C to stop checking.`)
236
+ );
237
+
238
+ const spinner = this.noProgress ? null :
239
+ new TerminalSpinner().start(`Status: ${formatBuildState(BuildState.NEW)}`);
240
+ const requiresReview = await this.requiresReview(context.version as string);
241
+
242
+ return watchBuild(id, (state) => {
243
+ spinner?.update(`Status: ${formatBuildState(state)}`);
244
+ }).then((errors: ErrorList) => {
245
+ spinner?.stop();
246
+ if (errors) {
247
+ die(`${publish ? 'Build' : 'Validation'} failed:\n${errors.map((e) => ` * ${e}`).join('\n')}`);
248
+ } else if (publish) {
249
+ if (requiresReview) {
250
+ console.log(chalk.green('Build complete.'));
251
+ } else {
252
+ console.log(chalk.green('Build complete. Ready to be published.'));
253
+ }
254
+ } else {
255
+ console.log(chalk.green('Validation complete. No errors found.'));
256
+ }
257
+ }).catch((err) => {
258
+ die(formatError(err));
259
+ });
260
+ }
261
+
262
+ private async isAdmin() {
263
+ const me = await Rivendell.whoami();
264
+ return me.role === 'administrator' || me.role === 'app_administrator';
265
+ }
266
+ }