messages.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { translateRuntimeText } from '@mavis/shared/runtime-i18n';
  2. export function mcodePrefixActivationScheduledMessage(
  3. _environment: NodeJS.ProcessEnv = process.env,
  4. ): string {
  5. return 'A staged MCode update will activate after this process exits.';
  6. }
  7. export function mcodePrefixJournalScheduleFailedMessage(
  8. _environment: NodeJS.ProcessEnv = process.env,
  9. ): string {
  10. return 'MCode update was staged, but its activation journal could not be scheduled.';
  11. }
  12. export function mcodePrefixNonPrefixPlanMessage(_environment: NodeJS.ProcessEnv): string {
  13. return 'MCode npm prefix updater received a non-prefix plan.';
  14. }
  15. export function mcodePrefixOwnershipMissingMessage(_environment: NodeJS.ProcessEnv): string {
  16. return 'MCode npm prefix ownership metadata is missing.';
  17. }
  18. export function mcodePrefixPendingActivationMessage(
  19. version: string,
  20. options: {
  21. readonly blockingSessionCount?: number;
  22. readonly environment?: NodeJS.ProcessEnv;
  23. } = {},
  24. ): string {
  25. if (options.blockingSessionCount === undefined) {
  26. return `MCode ${version} is already staged. Restarting will resume activation after running MCode sessions exit.`;
  27. }
  28. const blockingSessionCount = Math.max(0, Math.trunc(options.blockingSessionCount));
  29. if (blockingSessionCount > 0) {
  30. return `MCode ${version} is already staged. Activation will wait for ${String(blockingSessionCount)} other MCode ${blockingSessionCount === 1 ? 'session' : 'sessions'} to exit.`;
  31. }
  32. return `MCode ${version} is already staged. It will activate after this process exits.`;
  33. }
  34. export function mcodePrefixPendingCleanupMessage(
  35. version: string,
  36. options: {
  37. readonly blockingSessionCount?: number;
  38. readonly environment?: NodeJS.ProcessEnv;
  39. } = {},
  40. ): string {
  41. if (options.blockingSessionCount === undefined) {
  42. return `MCode ${version} is already active. Restarting will finish update cleanup after running MCode sessions exit.`;
  43. }
  44. const blockingSessionCount = Math.max(0, Math.trunc(options.blockingSessionCount));
  45. if (blockingSessionCount > 0) {
  46. return `MCode ${version} is already active. Update cleanup will wait for ${String(blockingSessionCount)} other MCode ${blockingSessionCount === 1 ? 'session' : 'sessions'} to exit.`;
  47. }
  48. return `MCode ${version} is already active. Restarting will finish update cleanup.`;
  49. }
  50. export function mcodePrefixStagedVersionMismatchMessage(
  51. actualVersion: string,
  52. expectedVersion: string,
  53. _environment: NodeJS.ProcessEnv,
  54. ): string {
  55. return `MCode update staged ${actualVersion}; expected ${expectedVersion}.`;
  56. }
  57. export function mcodePrefixStagedMessage(
  58. version: string,
  59. options: {
  60. readonly blockingSessionCount?: number;
  61. readonly environment?: NodeJS.ProcessEnv;
  62. } = {},
  63. ): string {
  64. if (options.blockingSessionCount === undefined) {
  65. return `MCode ${version} is downloaded and staged safely. Waiting for running MCode sessions to exit before activation.`;
  66. }
  67. const blockingSessionCount = Math.max(0, Math.trunc(options.blockingSessionCount));
  68. if (blockingSessionCount > 0) {
  69. return `MCode ${version} is downloaded and staged safely. Waiting for ${String(blockingSessionCount)} other MCode ${blockingSessionCount === 1 ? 'session' : 'sessions'} to exit before activation.`;
  70. }
  71. return `MCode ${version} is downloaded and staged safely. It will activate after this process exits.`;
  72. }
  73. export function mcodePrefixVersionedInstalledMessage(
  74. version: string,
  75. environment: NodeJS.ProcessEnv = process.env,
  76. ): string {
  77. const locale = environment.LC_ALL || environment.LC_MESSAGES || environment.LANG;
  78. return translateRuntimeText(locale, 'update.versionedInstalled').replace('{version}', version);
  79. }
  80. export function mcodePrefixNotStagedMessage(
  81. version: string,
  82. reason: string,
  83. _environment: NodeJS.ProcessEnv,
  84. ): string {
  85. return `MCode ${version} was not staged; the active installation is unchanged: ${reason}`;
  86. }