@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
@@ -0,0 +1,49 @@
1
+ import chalk from 'chalk';
2
+ import {command, help, namespace, option, param} from 'oo-cli';
3
+ import {die} from '../../lib/die';
4
+ import {formatError} from '../../lib/formatError';
5
+ import {formatJobStatus} from '../../lib/formatJobStatus';
6
+ import {timestampToDurationString} from '../../lib/formatTimstamp';
7
+ import { jobRuntime } from '../../lib/jobRuntime';
8
+ import {Rivendell} from '../../lib/Rivendell';
9
+
10
+ @namespace('jobs')
11
+ export class RuntimeStatusCommand {
12
+
13
+ @param
14
+ @help('ID of Job to get the runtime status for')
15
+ private jobId!: string;
16
+
17
+ @option('a')
18
+ @help('The availability zone that will be targeted (default: us)')
19
+ private availability: string = '';
20
+
21
+ @command
22
+ @help('Show the runtime status of a job')
23
+ public async runtimeStatus(): Promise<void> {
24
+ try {
25
+ const job = await Rivendell.fetchJob(this.jobId, this.availability);
26
+ const status = await Rivendell.fetchJobRuntimeStatus(this.jobId, this.availability);
27
+ if (status.status) {
28
+ const jsonStatus = JSON.parse(status.status);
29
+ console.log(`\n${chalk.cyanBright('Id')}\t\t\t${job.id}`);
30
+ console.log(`${chalk.cyanBright('Status')}\t\t\t${formatJobStatus(job.status)}`);
31
+ console.log(`${chalk.cyanBright('Triggered At')}\t\t${job.triggeredAt}`);
32
+
33
+ if (job.completedAt) {
34
+ console.log(`${chalk.cyanBright('Completed At')}\t\t${job.completedAt}`);
35
+ } else if (job.terminatedAt) {
36
+ console.log(`${chalk.cyanBright('Terminated At')}\t\t${job.terminatedAt}`);
37
+ }
38
+
39
+ console.log(`${chalk.cyanBright('Duration')}\t\t${timestampToDurationString(jobRuntime(job))}`);
40
+ console.log(`${chalk.cyanBright('Runtime Status\n')}${JSON.stringify(jsonStatus, null, 2)}\n`);
41
+ } else {
42
+ die(`Runtime Status not available. This is normal for jobs that are not running.`);
43
+ }
44
+
45
+ } catch (e) {
46
+ die(formatError(e));
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,29 @@
1
+ import chalk from 'chalk';
2
+ import {command, help, namespace, option, param} from 'oo-cli';
3
+ import {die} from '../../lib/die';
4
+ import {formatError} from '../../lib/formatError';
5
+ import {Rivendell} from '../../lib/Rivendell';
6
+
7
+ @namespace('jobs')
8
+ export class TerminateCommand {
9
+
10
+ @param
11
+ @help('ID of Job to terminate')
12
+ private jobId!: string;
13
+
14
+ @option('a')
15
+ @help('The availability zone that will be targeted (default: us)')
16
+ private availability: string = '';
17
+
18
+ @command
19
+ @help('Terminate a job')
20
+ public async terminate(): Promise<void> {
21
+ try {
22
+ await Rivendell.terminateJob(this.jobId, this.availability);
23
+ } catch (e) {
24
+ die(formatError(e));
25
+ }
26
+
27
+ console.log(chalk.green(`Terminated job with ID ${this.jobId} (${this.availability || 'us'}).`));
28
+ }
29
+ }
@@ -0,0 +1,41 @@
1
+ import chalk from 'chalk';
2
+ import {command, help, namespace, option, param} from 'oo-cli';
3
+ import {die} from '../../lib/die';
4
+ import {formatError} from '../../lib/formatError';
5
+ import {Rivendell} from '../../lib/Rivendell';
6
+
7
+ @namespace('jobs')
8
+ export class TriggerCommand {
9
+
10
+ @param
11
+ @help('The App ID (e.g. my_app)')
12
+ public appId!: string;
13
+
14
+ @param
15
+ @help('The Job Name')
16
+ public jobName!: string;
17
+
18
+ @param
19
+ @help('The Tracker ID to trigger the job for')
20
+ public trackerId!: string;
21
+
22
+ @option
23
+ @help('Parameters to pass to the Job')
24
+ public parameters: string = '{}';
25
+
26
+ @option('a')
27
+ @help('The availability zone that will be targeted (default: us)')
28
+ private availability: string = '';
29
+
30
+ @command
31
+ @help('Trigger a job')
32
+ public async trigger(): Promise<void> {
33
+ try {
34
+ await Rivendell.triggerJob(this.appId, this.jobName, this.trackerId, this.parameters, this.availability);
35
+ } catch (e) {
36
+ die(formatError(e));
37
+ }
38
+
39
+ console.log(chalk.green(`Triggered job for ${this.appId} ${this.jobName} ${this.trackerId} (${this.availability || 'us'}).`));
40
+ }
41
+ }
@@ -0,0 +1,76 @@
1
+ import chalk from 'chalk';
2
+ import {command, help, namespace, optional, param} from 'oo-cli';
3
+ import * as semver from 'semver';
4
+ import * as table from 'text-table';
5
+ import {die} from '../../lib/die';
6
+ import {styledStringLength} from '../../lib/StringUtils';
7
+ import {Rivendell} from '../../lib/Rivendell';
8
+ import {formatReviewStatus} from '../../lib/formatReviewStatus';
9
+ import {formatError} from '../../lib/formatError';
10
+ import AppVersion = Rivendell.AppVersion;
11
+ import AppVersionSearchCriteria = Rivendell.AppVersionSearchCriteria;
12
+ import AppVersionState = Rivendell.AppVersionState;
13
+ import ReviewStatus = Rivendell.ReviewStatus;
14
+
15
+ @namespace('review')
16
+ export class ListCommand {
17
+ @param
18
+ @optional
19
+ @help('A specific App ID to filter down to (lists all apps by default)')
20
+ private appId!: string;
21
+
22
+ @command
23
+ @help('List app versions currently under review')
24
+ public async list(): Promise<void> {
25
+ try {
26
+ const criteria: AppVersionSearchCriteria = {
27
+ states: [AppVersionState.PUBLISHED],
28
+ reviewStatuses: [ReviewStatus.IN_REVIEW, ReviewStatus.APPROVED]
29
+ };
30
+
31
+ if (this.appId) {
32
+ criteria.appId = this.appId;
33
+ }
34
+ this.render(await Rivendell.searchAppVersions(criteria, 'us'));
35
+ } catch (e) {
36
+ die(formatError(e));
37
+ }
38
+ }
39
+
40
+ private render(appVersions: AppVersion[]) {
41
+ const header = ['App ID', 'Version', 'Review Status', 'Created At', 'Updated At'].map((item) => chalk.grey(item));
42
+ const rows = appVersions
43
+ .sort((lhs, rhs) => {
44
+ let result = lhs.id.appId.localeCompare(rhs.id.appId);
45
+ if (result === 0) {
46
+ const lhsVersion = lhs.id.version;
47
+ const rhsVersion = rhs.id.version;
48
+ if (lhsVersion !== rhsVersion) {
49
+ result = semver.gt(lhsVersion, rhsVersion) ? -1 : 1;
50
+ }
51
+ }
52
+ return result;
53
+ })
54
+ .map((appVersion) => [
55
+ appVersion.id.appId,
56
+ appVersion.id.version,
57
+ formatReviewStatus(
58
+ appVersion.reviewStatus as Rivendell.ReviewStatus
59
+ ),
60
+ appVersion.createdAt,
61
+ appVersion.updatedAt
62
+ ]);
63
+
64
+ const t = table(
65
+ [
66
+ header,
67
+ ...rows
68
+ ],
69
+ {
70
+ hsep: ' '.repeat(8),
71
+ stringLength: styledStringLength
72
+ }
73
+ );
74
+ console.log(`\n${t}\n`);
75
+ }
76
+ }
@@ -0,0 +1,28 @@
1
+ import chalk from 'chalk';
2
+ import {command, help, namespace, param} from 'oo-cli';
3
+ import {die} from '../../lib/die';
4
+ import {Rivendell} from '../../lib/Rivendell';
5
+ import {formatError} from '../../lib/formatError';
6
+ import AppReview = Rivendell.AppReview;
7
+ import open = require('open');
8
+
9
+ @namespace('review')
10
+ export class OpenCommand {
11
+ @param
12
+ @help('App version of the review to open')
13
+ private appVersion!: string;
14
+
15
+ @command
16
+ @help('Open a review in your browser')
17
+ public async open() {
18
+ try {
19
+ const appReview = await Rivendell.getReviewUrl(this.appVersion);
20
+ const reviewUrl = (appReview as AppReview).url;
21
+ console.log(chalk.gray(`Review URL: ${chalk.white(`${reviewUrl}`)}`));
22
+ await open(reviewUrl);
23
+ console.log(chalk.gray(`Opened review of app ${this.appVersion}`));
24
+ } catch (e) {
25
+ die(formatError(e));
26
+ }
27
+ }
28
+ }
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { Runner } from 'oo-cli';
2
+ import * as path from 'path';
3
+ import { showEnvironment } from './lib/EnvironmentalOutput';
4
+ import { checkForUpdate } from './lib/checkForUpdate';
5
+
6
+ function run() {
7
+ showEnvironment();
8
+
9
+ const manifest = require(path.join(__dirname, './oo-cli.manifest.json'));
10
+ checkForUpdate(manifest)
11
+ .then(() => new Runner(__dirname, manifest).run())
12
+ .catch((e) => console.log(e.message));
13
+ }
14
+
15
+ run();
@@ -0,0 +1,47 @@
1
+ import * as fs from 'fs';
2
+ import * as jsYaml from 'js-yaml';
3
+ import * as path from 'path';
4
+
5
+ export interface AppContext {
6
+ appId?: string;
7
+ displayName?: string;
8
+ version?: string;
9
+ vendor?: string;
10
+ runtime?: string;
11
+ }
12
+
13
+ export function appContext(appId?: string, vendor?: string, runtime?: string): AppContext {
14
+ if (appId) {
15
+ if (appId.includes('@')) {
16
+ const [id, version] = appId.split('@');
17
+ return {
18
+ appId: id,
19
+ version,
20
+ vendor,
21
+ runtime
22
+ };
23
+ } else {
24
+ return {appId, vendor, runtime};
25
+ }
26
+ }
27
+
28
+ const yaml = readAppYaml();
29
+ if (yaml && yaml.meta) {
30
+ return {
31
+ appId: yaml.meta.app_id,
32
+ displayName: yaml.meta.display_name,
33
+ version: yaml.meta.version,
34
+ vendor: yaml.meta.vendor,
35
+ runtime: yaml.runtime
36
+ };
37
+ }
38
+ return {};
39
+ }
40
+
41
+ export function readAppYaml() {
42
+ const file = path.join(process.cwd(), 'app.yml');
43
+ if (fs.existsSync(file)) {
44
+ return jsYaml.safeLoad(fs.readFileSync(file, 'utf8'));
45
+ }
46
+ return false;
47
+ }
@@ -0,0 +1,47 @@
1
+ import * as AdmZip from 'adm-zip';
2
+ import chalk from 'chalk';
3
+ import * as child_process from 'child_process';
4
+ import * as fs from 'fs';
5
+ import * as glob from 'glob';
6
+ import * as path from 'path';
7
+
8
+ export class AppPackager {
9
+ private rootPath: string;
10
+
11
+ constructor(rootPath: string) {
12
+ this.rootPath = path.resolve(rootPath);
13
+ }
14
+
15
+ public package() {
16
+ console.log(chalk.gray(`Packaging files in ${this.rootPath}`));
17
+ const files = glob.sync('**/*', {
18
+ cwd: this.rootPath,
19
+ dot: true,
20
+ ignore: ['node_modules/**/*', '*.zip', '.git/**/*'],
21
+ nodir: true
22
+ }).filter(this.filterGitIgnored);
23
+
24
+ return this.createZip(this.rootPath, files);
25
+ }
26
+
27
+ private createZip(srcPath: string, files: string[]): Buffer {
28
+ const zip = new AdmZip();
29
+ files.forEach((file) => {
30
+ const filePath = path.join(srcPath, file);
31
+ if (fs.existsSync(filePath)) {
32
+ console.log(chalk.gray(`${file}`));
33
+ zip.addFile(file, fs.readFileSync(filePath));
34
+ }
35
+ });
36
+
37
+ return zip.toBuffer();
38
+ }
39
+
40
+ private filterGitIgnored = (file: string) => {
41
+ return child_process.spawnSync(
42
+ 'git',
43
+ ['check-ignore', '-q', file],
44
+ {cwd: this.rootPath}
45
+ ).status === 1;
46
+ }
47
+ }
@@ -0,0 +1,177 @@
1
+ import chalk from 'chalk';
2
+ import * as child_process from 'child_process';
3
+ import fetch from 'node-fetch';
4
+ import {compare, major} from 'semver';
5
+ import {getDependencyFileUrl} from './Config';
6
+ import {styledStringLength} from './StringUtils';
7
+ import {TerminalPassthru} from './TeminalPassthru';
8
+ import {TerminalConfirm} from './TerminalConfirm';
9
+ import table = require('text-table');
10
+
11
+ export namespace AppUpdater {
12
+ /**
13
+ * Assumes working dir is app dir
14
+ */
15
+ export async function ensureDependencies(
16
+ requireUpToDate: boolean, upgradeDeps: boolean, runtime: string, ignoreDevUpdates: boolean = true
17
+ ) {
18
+ ensurePublicPackageUsage();
19
+
20
+ const response = await fetch(getDependencyFileUrl(runtime));
21
+ const zipModules = await response.json();
22
+ const projectProdDeps = AppUpdater.getPackageDependencies(true);
23
+
24
+ // build a table of updates if any dependencies are missing or outdated
25
+ const updates: string[][] = [];
26
+ const prodUpdates: string[] = [];
27
+ for (const module of Object.keys(zipModules)) {
28
+ const moduleMajorVersion = Object.keys(module).map((i) => parseInt(i, 10)).sort().reverse()[0];
29
+ const projectModuleVersion = projectProdDeps[module];
30
+ const majorVersion = (projectModuleVersion ? major(projectModuleVersion) : moduleMajorVersion).toString();
31
+ if (!(majorVersion in zipModules[module])) {
32
+ console.log(chalk.red(
33
+ `Major version of ${module} not supported. Please use one of supported major versions.`
34
+ ));
35
+ process.exit(1);
36
+ }
37
+ const stable = zipModules[module][majorVersion]['stable'];
38
+ const rc = zipModules[module][majorVersion]['rc'];
39
+ if (!projectModuleVersion || !isCurrent(stable, rc, projectModuleVersion)) {
40
+ prodUpdates.push(`${module}@${stable}`);
41
+ updates.push([
42
+ module,
43
+ projectModuleVersion ? chalk.yellow(projectModuleVersion) : chalk.red('missing'),
44
+ '=>',
45
+ chalk.green(stable)
46
+ ]);
47
+ }
48
+ }
49
+
50
+ const devDependencies: any = {
51
+ '@zaiusinc/app-dev-runtime': 'latest'
52
+ };
53
+
54
+ const projectDevDeps = AppUpdater.getPackageDependencies();
55
+ const devUpdates: string[] = [];
56
+ if (!ignoreDevUpdates) {
57
+ for (const name of Object.keys(devDependencies)) {
58
+ const currentVersion = devDependencies[name];
59
+ let updated = false;
60
+ if (projectDevDeps[name] && currentVersion === 'latest') {
61
+ // skip it
62
+ continue;
63
+ } else if (!projectDevDeps[name] && currentVersion === 'latest') {
64
+ devUpdates.push(`${name}`);
65
+ updated = true;
66
+ } else if (!projectDevDeps[name] || compare(zipModules[name], projectDevDeps[name]) !== 0) {
67
+ devUpdates.push(`${name}@${currentVersion}`);
68
+ updated = true;
69
+ }
70
+
71
+ if (updated) {
72
+ updates.push([
73
+ name,
74
+ projectDevDeps[name] ? chalk.yellow(projectDevDeps[name]) : chalk.red('missing'),
75
+ '=>',
76
+ chalk.green(devDependencies[name])
77
+ ]);
78
+ }
79
+ }
80
+ }
81
+ if (updates.length > 0) {
82
+ console.log(chalk.yellow('\nThe following dependencies are out of date:'));
83
+ const t = table(
84
+ [
85
+ ['Module', 'Your Version', '', 'Current Version'],
86
+ ...updates
87
+ ],
88
+ {
89
+ hsep: ' ',
90
+ stringLength: styledStringLength
91
+ }
92
+ );
93
+ console.log(`\n${t}\n`);
94
+ if (upgradeDeps || await TerminalConfirm.ask('Do you want to update now?')) {
95
+ const updateCommand = `yarn add ${prodUpdates.join(' ')}`;
96
+ if (prodUpdates.length > 0 && !TerminalPassthru.exec(updateCommand)) {
97
+ console.log(chalk.red(
98
+ `Failed to update dependencies. Run \`${chalk.white(updateCommand)}\` to update manually.`
99
+ ));
100
+ process.exit(1);
101
+ }
102
+ console.log('');
103
+
104
+ const updateDev = `yarn add --dev ${devUpdates.join(' ')}`;
105
+ if (devUpdates.length > 0 && !TerminalPassthru.exec(updateDev)) {
106
+ console.log(chalk.red(
107
+ `Failed to update dev dependencies. Run \`${chalk.white(updateDev)}\` to update manually.`
108
+ ));
109
+ process.exit(1);
110
+ }
111
+ console.log('');
112
+ } else {
113
+ console.log(chalk.yellow('OCP apps always build and run against the current versions of the SDKs.'));
114
+ console.log(chalk.yellow('You must update your dependencies before uploading or remote validating your app.'));
115
+ if (requireUpToDate) {
116
+ process.exit(1);
117
+ } else {
118
+ console.log('');
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ export function getPackageDependencies(prod: boolean = false): {[name: string]: string} {
125
+ try {
126
+ const result = child_process.spawnSync(
127
+ `yarn --no-progress ${prod ? '--prod ' : ''}-s list --json --pattern=@zaiusinc/`,
128
+ {cwd: process.cwd(), shell: true}
129
+ );
130
+
131
+ if (result.status === 0) {
132
+ const tree = JSON.parse(result.stdout.toString());
133
+ const output: {[name: string]: string} = {};
134
+ for (const item of tree.data.trees) {
135
+ const [name, version] = item.name.split(/(?!^)@/);
136
+ output[name] = version;
137
+ }
138
+ return output;
139
+ } else {
140
+ console.error(result.stderr.toString());
141
+ }
142
+ } catch (e) {
143
+ console.error(e);
144
+ }
145
+ console.log(chalk.red("Unable to get package dependencies. Are you in your app's working directory?"));
146
+ process.exit(1);
147
+ }
148
+
149
+ function isCurrent(stable: string, rc: string, version: string) {
150
+ return compare(stable, version) === 0 || (rc && compare(rc, version) === 0);
151
+ }
152
+
153
+ function ensurePublicPackageUsage() {
154
+ const result = child_process.spawnSync(
155
+ 'yarn --no-progress --prod -s list --json --pattern="@zaius/app-sdk|@zaius/node-sdk"',
156
+ {cwd: process.cwd(), shell: true}
157
+ );
158
+
159
+ if (result.status === 0) {
160
+ const tree = JSON.parse(result.stdout.toString());
161
+ if (!tree.data.trees.length) {
162
+ return;
163
+ }
164
+
165
+ console.log(
166
+ chalk.red(
167
+ '@zaius/app-sdk & @zaius/node-sdk are no longer supported. ' +
168
+ 'Please update your package.json to use the @zaiusinc scope for these packages.'
169
+ )
170
+ );
171
+ process.exit(1);
172
+ }
173
+
174
+ console.log(chalk.red("Unable to get package dependencies. Are you in your app's working directory?"));
175
+ process.exit(1);
176
+ }
177
+ }
@@ -0,0 +1,39 @@
1
+ import * as AWS from 'aws-sdk';
2
+ import chalk from 'chalk';
3
+ import * as crypto from 'crypto';
4
+ import {AppContext} from './AppContext';
5
+ import {runtimeConfig} from './Config';
6
+ import {Rivendell} from './Rivendell';
7
+
8
+ export class AppUploader {
9
+ constructor(private context: AppContext, private packageData: Buffer) {
10
+ }
11
+
12
+ public async upload(): Promise<string> {
13
+ console.log(chalk.gray('Uploading package...'));
14
+ const {vendor, appId, version} = this.context;
15
+ const md5 = crypto.createHash('md5').update(this.packageData).digest('hex');
16
+ const bucket = runtimeConfig().uploadBucket;
17
+ const s3Key = `${vendor}/${appId}@${version}-${md5}.zip`;
18
+ const credentials = await Rivendell.uploadCredentials(vendor!, appId!, version!, md5);
19
+
20
+ AWS.config.update({
21
+ region: runtimeConfig().awsRegion,
22
+ credentials: new AWS.Credentials(
23
+ credentials.accessKeyId,
24
+ credentials.secretAccessKey,
25
+ credentials.sessionToken
26
+ )
27
+ });
28
+
29
+ await new AWS.S3()
30
+ .putObject( {
31
+ Bucket: bucket,
32
+ Key: s3Key,
33
+ Body: this.packageData
34
+ })
35
+ .promise();
36
+
37
+ return `s3://${bucket}/${s3Key}`;
38
+ }
39
+ }
@@ -0,0 +1,60 @@
1
+ import * as fs from 'fs';
2
+ import * as jsYaml from 'js-yaml';
3
+ import * as os from 'os';
4
+ import * as path from 'path';
5
+
6
+ import * as dotenv from 'dotenv';
7
+
8
+ dotenv.config({path: path.join(os.homedir(), '.ocp/.env')});
9
+
10
+ const CREDENTIAL_FILE = 'credentials.json';
11
+
12
+ const environmentConfig: EnvironmentConfig = {
13
+ rivendell: process.env.RIVENDELL || 'https://rivendell.zaius.com',
14
+ awsRegion: process.env.AWS_REGION || 'us-east-1',
15
+ uploadBucket: process.env.UPLOAD_BUCKET || 'zaius-apps'
16
+ };
17
+
18
+ export interface EnvironmentConfig {
19
+ rivendell: string;
20
+ awsRegion: string;
21
+ uploadBucket: string;
22
+ }
23
+
24
+ export interface Credential {
25
+ apiKey?: string;
26
+ }
27
+
28
+ export interface CredentialConfig {
29
+ [key: string]: Partial<Credential>;
30
+ }
31
+
32
+ export function getEnv() {
33
+ return process.env.OCP_ENV || 'production';
34
+ }
35
+
36
+ export function getDependencyFileUrl(runtime: string) {
37
+ return `http://s3.amazonaws.com/zaius-public/zip/.env/${getEnv()}/${runtime}/dependencies.json`;
38
+ }
39
+
40
+ export function runtimeConfig(): EnvironmentConfig {
41
+ return environmentConfig;
42
+ }
43
+
44
+ let cachedCredential: Credential;
45
+ export function getActiveCredential(): Credential {
46
+ if (cachedCredential) {
47
+ return cachedCredential;
48
+ }
49
+ const file = path.join(os.homedir(), `.ocp/${CREDENTIAL_FILE}`);
50
+ if (fs.existsSync(file)) {
51
+ try {
52
+ const creds: CredentialConfig = jsYaml.safeLoad(fs.readFileSync(file, 'utf8')) || {};
53
+ cachedCredential = creds || {};
54
+ } catch (e) {
55
+ console.error(`Unable to parse credential file.`);
56
+ process.exit(1);
57
+ }
58
+ }
59
+ return cachedCredential || {};
60
+ }
@@ -0,0 +1,18 @@
1
+ import chalk from 'chalk';
2
+ import { existsSync } from 'fs';
3
+ import { join } from 'path';
4
+ import {getEnv} from './Config';
5
+
6
+ const envColors = {
7
+ staging: chalk.yellow,
8
+ production: chalk.red,
9
+ other: chalk.gray
10
+ };
11
+
12
+ export function showEnvironment() {
13
+ if (existsSync(join(__dirname, '../commands/env'))) {
14
+ const env = getEnv();
15
+ const color = envColors[env as keyof typeof envColors] || envColors['other'];
16
+ console.log(chalk.gray(`Active environment: ${color(env)}`));
17
+ }
18
+ }