@cbnventures/nova 0.38.0 → 0.39.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 (174) hide show
  1. package/build/package.json +1 -1
  2. package/build/scaffold-versions.json +20 -0
  3. package/build/src/api/app-store-connect.d.ts +17 -2
  4. package/build/src/api/app-store-connect.d.ts.map +1 -1
  5. package/build/src/api/app-store-connect.js +654 -171
  6. package/build/src/api/app-store-connect.js.map +1 -1
  7. package/build/src/api/github-runner-images.d.ts +13 -0
  8. package/build/src/api/github-runner-images.d.ts.map +1 -0
  9. package/build/src/api/github-runner-images.js +238 -0
  10. package/build/src/api/github-runner-images.js.map +1 -0
  11. package/build/src/cli/generate/github/workflows-blueprint-validate.d.ts +2 -2
  12. package/build/src/cli/generate/github/workflows-blueprint-validate.d.ts.map +1 -1
  13. package/build/src/cli/generate/github/workflows-blueprint-validate.js +210 -3
  14. package/build/src/cli/generate/github/workflows-blueprint-validate.js.map +1 -1
  15. package/build/src/cli/generate/github/workflows-blueprint.d.ts +6 -4
  16. package/build/src/cli/generate/github/workflows-blueprint.d.ts.map +1 -1
  17. package/build/src/cli/generate/github/workflows-blueprint.js +685 -70
  18. package/build/src/cli/generate/github/workflows-blueprint.js.map +1 -1
  19. package/build/src/cli/generate/must-haves/agent-conventions.d.ts.map +1 -1
  20. package/build/src/cli/generate/must-haves/agent-conventions.js +1 -0
  21. package/build/src/cli/generate/must-haves/agent-conventions.js.map +1 -1
  22. package/build/src/cli/index.js +12 -1
  23. package/build/src/cli/index.js.map +1 -1
  24. package/build/src/cli/integration/app-store-connect.d.ts +10 -0
  25. package/build/src/cli/integration/app-store-connect.d.ts.map +1 -1
  26. package/build/src/cli/integration/app-store-connect.js +701 -80
  27. package/build/src/cli/integration/app-store-connect.js.map +1 -1
  28. package/build/src/cli/scaffold/package/pfsense.d.ts +3 -0
  29. package/build/src/cli/scaffold/package/pfsense.d.ts.map +1 -1
  30. package/build/src/cli/scaffold/package/pfsense.js +140 -6
  31. package/build/src/cli/scaffold/package/pfsense.js.map +1 -1
  32. package/build/src/cli/scaffold/tool/serverless.d.ts +2 -0
  33. package/build/src/cli/scaffold/tool/serverless.d.ts.map +1 -1
  34. package/build/src/cli/scaffold/tool/serverless.js +35 -1
  35. package/build/src/cli/scaffold/tool/serverless.js.map +1 -1
  36. package/build/src/cli/utility/changelog.d.ts +7 -0
  37. package/build/src/cli/utility/changelog.d.ts.map +1 -1
  38. package/build/src/cli/utility/changelog.js +800 -7
  39. package/build/src/cli/utility/changelog.js.map +1 -1
  40. package/build/src/cli/utility/configure.d.ts +3 -1
  41. package/build/src/cli/utility/configure.d.ts.map +1 -1
  42. package/build/src/cli/utility/configure.js +196 -20
  43. package/build/src/cli/utility/configure.js.map +1 -1
  44. package/build/src/lib/docker-packaging.d.ts +1 -0
  45. package/build/src/lib/docker-packaging.d.ts.map +1 -1
  46. package/build/src/lib/docker-packaging.js +39 -2
  47. package/build/src/lib/docker-packaging.js.map +1 -1
  48. package/build/src/lib/env-namespace.d.ts.map +1 -1
  49. package/build/src/lib/env-namespace.js +2 -1
  50. package/build/src/lib/env-namespace.js.map +1 -1
  51. package/build/src/lib/item.d.ts +2 -1
  52. package/build/src/lib/item.d.ts.map +1 -1
  53. package/build/src/lib/item.js +18 -0
  54. package/build/src/lib/item.js.map +1 -1
  55. package/build/src/lib/nova-config.d.ts.map +1 -1
  56. package/build/src/lib/nova-config.js +46 -2
  57. package/build/src/lib/nova-config.js.map +1 -1
  58. package/build/src/lib/regex.d.ts +14 -0
  59. package/build/src/lib/regex.d.ts.map +1 -1
  60. package/build/src/lib/regex.js +14 -0
  61. package/build/src/lib/regex.js.map +1 -1
  62. package/build/src/lib/scaffold.d.ts +3 -3
  63. package/build/src/lib/scaffold.d.ts.map +1 -1
  64. package/build/src/lib/scaffold.js +111 -8
  65. package/build/src/lib/scaffold.js.map +1 -1
  66. package/build/src/lib/workflow-templates.d.ts +4 -1
  67. package/build/src/lib/workflow-templates.d.ts.map +1 -1
  68. package/build/src/lib/workflow-templates.js +60 -2
  69. package/build/src/lib/workflow-templates.js.map +1 -1
  70. package/build/src/types/api/app-store-connect.d.ts +476 -33
  71. package/build/src/types/api/github-runner-images.d.ts +199 -0
  72. package/build/src/types/cli/generate/github/workflows-blueprint-validate.d.ts +69 -8
  73. package/build/src/types/cli/generate/github/workflows-blueprint.d.ts +132 -9
  74. package/build/src/types/cli/integration/app-store-connect.d.ts +470 -6
  75. package/build/src/types/cli/scaffold/package/pfsense.d.ts +83 -0
  76. package/build/src/types/cli/scaffold/tool/serverless.d.ts +30 -0
  77. package/build/src/types/cli/utility/changelog.d.ts +327 -1
  78. package/build/src/types/cli/utility/configure.d.ts +92 -4
  79. package/build/src/types/lib/docker-packaging.d.ts +25 -1
  80. package/build/src/types/lib/env-namespace.d.ts +4 -1
  81. package/build/src/types/lib/item.d.ts +7 -0
  82. package/build/src/types/lib/nova-config.d.ts +24 -0
  83. package/build/src/types/lib/regex.d.ts +91 -0
  84. package/build/src/types/lib/scaffold.d.ts +48 -4
  85. package/build/src/types/lib/workflow-templates.d.ts +26 -0
  86. package/build/src/types/shared.d.ts +241 -2
  87. package/build/src/types/tests/api/app-store-connect.test.d.ts +162 -0
  88. package/build/src/types/tests/api/github-runner-images.test.d.ts +113 -0
  89. package/build/src/types/tests/cli/generate/github/workflows-blueprint-generate.test.d.ts +19 -0
  90. package/build/src/types/tests/cli/generate/github/workflows-blueprint-parity.test.d.ts +0 -9
  91. package/build/src/types/tests/cli/generate/github/workflows-blueprint-publish-parity.test.d.ts +109 -26
  92. package/build/src/types/tests/cli/generate/github/workflows-blueprint-validate.test.d.ts +123 -30
  93. package/build/src/types/tests/cli/generate/github/workflows-blueprint.test.d.ts +45 -0
  94. package/build/src/types/tests/cli/generate/github/workflows-version-contract.test.d.ts +2 -2
  95. package/build/src/types/tests/cli/generate/must-haves/agent-conventions.test.d.ts +2 -0
  96. package/build/src/types/tests/cli/integration/app-store-connect.test.d.ts +876 -0
  97. package/build/src/types/tests/cli/scaffold/tool/serverless.test.d.ts +21 -0
  98. package/build/src/types/tests/cli/utility/changelog-android.test.d.ts +14 -0
  99. package/build/src/types/tests/cli/utility/changelog-apple.test.d.ts +21 -0
  100. package/build/src/types/tests/cli/utility/changelog-fold.test.d.ts +350 -0
  101. package/build/src/types/tests/cli/utility/changelog.test.d.ts +50 -0
  102. package/build/src/types/tests/cli/utility/configure.test.d.ts +55 -0
  103. package/build/src/types/tests/lib/nova-config.test.d.ts +28 -0
  104. package/build/src/types/tests/lib/scaffold.test.d.ts +59 -2
  105. package/build/src/types/tests/scaffold-output-contract.test.d.ts +79 -0
  106. package/build/templates/generators/must-haves/agent-conventions/AGENTS.md +1 -0
  107. package/build/templates/generators/must-haves/agent-conventions/CLAUDE.md +1 -0
  108. package/build/templates/generators/must-haves/agent-conventions/conventions/pfsense.md +311 -0
  109. package/build/templates/scaffold/app/android/package.json +1 -1
  110. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-ios-1024.png +0 -0
  111. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-128.png +0 -0
  112. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-128@2x.png +0 -0
  113. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-16.png +0 -0
  114. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-16@2x.png +0 -0
  115. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-256.png +0 -0
  116. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-256@2x.png +0 -0
  117. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-32.png +0 -0
  118. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-32@2x.png +0 -0
  119. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-512.png +0 -0
  120. package/build/templates/scaffold/app/apple/Sources/Assets.xcassets/AppIcon.appiconset/AppIcon-mac-512@2x.png +0 -0
  121. package/build/templates/scaffold/app/apple/package.json +1 -1
  122. package/build/templates/scaffold/app/astro/package.json +1 -1
  123. package/build/templates/scaffold/app/discord-bot/package.json +1 -1
  124. package/build/templates/scaffold/app/express/package.json +1 -1
  125. package/build/templates/scaffold/app/nextjs/package.json +1 -1
  126. package/build/templates/scaffold/app/vite/package.json +1 -1
  127. package/build/templates/scaffold/docs/docusaurus/package.json +2 -2
  128. package/build/templates/scaffold/package/github-action/package.json +1 -1
  129. package/build/templates/scaffold/package/homebridge/package.json +1 -1
  130. package/build/templates/scaffold/package/pfsense/package.json +1 -1
  131. package/build/templates/scaffold/package/pfsense/port/Makefile.template +16 -1
  132. package/build/templates/scaffold/package/pfsense/port/files/usr/local/pkg/[__WORKSPACE_NAME__]/FileLock.php +93 -0
  133. package/build/templates/scaffold/package/pfsense/port/files/usr/local/pkg/[__WORKSPACE_NAME__]/PackagePaths.php +40 -0
  134. package/build/templates/scaffold/package/pfsense/port/files/usr/local/pkg/[__WORKSPACE_NAME__]/UpdateManager.php +1667 -0
  135. package/build/templates/scaffold/package/pfsense/port/files/usr/local/pkg/[__WORKSPACE_NAME__].inc +161 -13
  136. package/build/templates/scaffold/package/pfsense/port/files/usr/local/pkg/[__WORKSPACE_NAME__].xml +37 -0
  137. package/build/templates/scaffold/package/pfsense/port/files/usr/local/sbin/[__WORKSPACE_NAME__] +203 -8
  138. package/build/templates/scaffold/package/pfsense/port/files/usr/local/share/pfSense-pkg-[__WORKSPACE_IDENTIFIER__]/logo.svg +12 -0
  139. package/build/templates/scaffold/package/pfsense/port/files/usr/local/share/pfSense-pkg-[__WORKSPACE_IDENTIFIER__]/release-signing.pub +9 -0
  140. package/build/templates/scaffold/package/pfsense/port/files/usr/local/www/[__WORKSPACE_NAME__]-about.php +437 -0
  141. package/build/templates/scaffold/package/pfsense/port/pkg-plist +6 -0
  142. package/build/templates/scaffold/package/pfsense/scripts/build-package.sh +54 -0
  143. package/build/templates/scaffold/package/pfsense/scripts/check-package.mjs +114 -1
  144. package/build/templates/scaffold/package/pfsense/scripts/regex.mjs +10 -0
  145. package/build/templates/scaffold/package/pfsense/tests/updates.php +695 -0
  146. package/build/templates/scaffold-options/app/android-native/app/src/main/res/drawable/ic_launcher_background.xml +1 -1
  147. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
  148. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
  149. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
  150. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
  151. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
  152. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
  153. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
  154. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
  155. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
  156. package/build/templates/scaffold-options/app/android-native/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
  157. package/build/templates/scaffold-options/docker-image/common/Dockerfile +7 -0
  158. package/build/templates/scaffold-options/tool/serverless/cloudflare-workers/package.json +1 -1
  159. package/build/templates/scaffold-options/tool/serverless/cloudflare-workers/src/types/worker/index.test.d.ts +40 -2
  160. package/build/templates/scaffold-options/tool/serverless/cloudflare-workers/src/types/worker/landing-page.d.ts +23 -0
  161. package/build/templates/scaffold-options/tool/serverless/cloudflare-workers/src/worker/index.test.ts +119 -4
  162. package/build/templates/scaffold-options/tool/serverless/cloudflare-workers/src/worker/index.ts +25 -3
  163. package/build/templates/scaffold-options/tool/serverless/cloudflare-workers/src/worker/landing-page.ts +278 -0
  164. package/build/templates/scaffold-options/tool/serverless/vercel-functions/api/index.test.ts +121 -6
  165. package/build/templates/scaffold-options/tool/serverless/vercel-functions/api/index.ts +49 -12
  166. package/build/templates/scaffold-options/tool/serverless/vercel-functions/package.json +3 -1
  167. package/build/templates/scaffold-options/tool/serverless/vercel-functions/src/function/landing-page.ts +278 -0
  168. package/build/templates/scaffold-options/tool/serverless/vercel-functions/src/types/api/index.d.ts +17 -2
  169. package/build/templates/scaffold-options/tool/serverless/vercel-functions/src/types/api/index.test.d.ts +40 -2
  170. package/build/templates/scaffold-options/tool/serverless/vercel-functions/src/types/function/landing-page.d.ts +23 -0
  171. package/build/templates/scaffold-options/tool/serverless/vercel-functions/tsconfig.functions.json +3 -1
  172. package/build/templates/scaffold-options/tool/serverless/vercel-functions/vercel.json +7 -1
  173. package/package.json +1 -1
  174. package/build/templates/scaffold/package/pfsense-root/.github/workflows/pfsense-[__WORKSPACE_NAME__].yml +0 -62
@@ -4,9 +4,9 @@ import chalk from 'chalk';
4
4
  import prompts from 'prompts';
5
5
  import { LIB_CONSTANTS_DOCS_BASE_URL } from '../../lib/constants.js';
6
6
  import { Runner as LibDockerPackaging } from '../../lib/docker-packaging.js';
7
- import { libItemChangelogAdjectives, libItemChangelogCategoryBumpMap, libItemChangelogNouns, libItemChangelogOrderedCategories, libItemChangelogValidBumps, libItemChangelogValidCategories, libItemChangelogVerbs, libItemSkipDirectories, } from '../../lib/item.js';
7
+ import { libItemChangelogAdjectives, libItemChangelogCategoryBumpMap, libItemChangelogCategoryOpeningWords, libItemChangelogNouns, libItemChangelogOrderedCategories, libItemChangelogValidBumps, libItemChangelogValidCategories, libItemChangelogVerbs, libItemSkipDirectories, } from '../../lib/item.js';
8
8
  import { Runner as LibNovaConfig } from '../../lib/nova-config.js';
9
- import { LIB_REGEX_ANDROID_GRADLE_VERSION_CODE, LIB_REGEX_ANDROID_GRADLE_VERSION_NAME, LIB_REGEX_APPLE_PBXPROJ_CURRENT_PROJECT_VERSION, LIB_REGEX_APPLE_PBXPROJ_MARKETING_VERSION, LIB_REGEX_APPLE_XCODEGEN_CURRENT_PROJECT_VERSION, LIB_REGEX_APPLE_XCODEGEN_MARKETING_VERSION, LIB_REGEX_PATTERN_CSHARP_SINCE_UNRELEASED, LIB_REGEX_PATTERN_DEPRECATED_UNRELEASED, LIB_REGEX_PATTERN_EXACT_SEMVER, LIB_REGEX_PATTERN_GO_SINCE_UNRELEASED, LIB_REGEX_PATTERN_INLINE_DEPRECATED_UNRELEASED, LIB_REGEX_PATTERN_INLINE_SINCE_UNRELEASED, LIB_REGEX_PATTERN_LEADING_NEWLINES, LIB_REGEX_PATTERN_PYTHON_SINCE_UNRELEASED, LIB_REGEX_PATTERN_RUST_SINCE_UNRELEASED, LIB_REGEX_PATTERN_SINCE_UNRELEASED, LIB_REGEX_PATTERN_SWIFT_SINCE_UNRELEASED, } from '../../lib/regex.js';
9
+ import { LIB_REGEX_ANDROID_GRADLE_VERSION_CODE, LIB_REGEX_ANDROID_GRADLE_VERSION_NAME, LIB_REGEX_APPLE_PBXPROJ_CURRENT_PROJECT_VERSION, LIB_REGEX_APPLE_PBXPROJ_MARKETING_VERSION, LIB_REGEX_APPLE_XCODEGEN_CURRENT_PROJECT_VERSION, LIB_REGEX_APPLE_XCODEGEN_MARKETING_VERSION, LIB_REGEX_PATTERN_CHANGELOG_CAPITAL_START, LIB_REGEX_PATTERN_CHANGELOG_FIRST_WORD, LIB_REGEX_PATTERN_CSHARP_SINCE_UNRELEASED, LIB_REGEX_PATTERN_DEPRECATED_UNRELEASED, LIB_REGEX_PATTERN_EXACT_SEMVER, LIB_REGEX_PATTERN_GO_SINCE_UNRELEASED, LIB_REGEX_PATTERN_INLINE_DEPRECATED_UNRELEASED, LIB_REGEX_PATTERN_INLINE_SINCE_UNRELEASED, LIB_REGEX_PATTERN_LEADING_NEWLINES, LIB_REGEX_PATTERN_PYTHON_SINCE_UNRELEASED, LIB_REGEX_PATTERN_RUST_SINCE_UNRELEASED, LIB_REGEX_PATTERN_SINCE_UNRELEASED, LIB_REGEX_PATTERN_SWIFT_SINCE_UNRELEASED, } from '../../lib/regex.js';
10
10
  import { Runner as LibReleaseHistory } from '../../lib/release-history.js';
11
11
  import { Runner as LibVersionContract } from '../../lib/version-contract.js';
12
12
  import { Logger } from '../../toolkit/index.js';
@@ -19,11 +19,31 @@ export class Runner {
19
19
  purpose: 'options',
20
20
  }).warn('Dry run enabled. File changes will not be made in this session.');
21
21
  }
22
- if (options['record'] === true && options['release'] === true) {
22
+ if (Number(options['record'] === true)
23
+ + Number(options['release'] === true)
24
+ + Number(options['fold'] === true)
25
+ > 1) {
23
26
  Logger.customize({
24
27
  name: 'Runner.run',
25
28
  purpose: 'validate',
26
- }).error('Cannot use --record and --release together.');
29
+ }).error('Cannot use --record, --release, and --fold together.');
30
+ process.exitCode = 1;
31
+ return;
32
+ }
33
+ if (options['fold'] !== true
34
+ && (options['add'] === true
35
+ || options['edit'] === true
36
+ || options['remove'] === true
37
+ || options['entry'] !== undefined
38
+ || options['match'] !== undefined
39
+ || options['mergeFrom'] !== undefined
40
+ || options['uncategorizedAs'] !== undefined
41
+ || options['version'] !== undefined
42
+ || options['buildBump'] === false)) {
43
+ Logger.customize({
44
+ name: 'Runner.run',
45
+ purpose: 'validate',
46
+ }).error('Fold action flags require --fold.');
27
47
  process.exitCode = 1;
28
48
  return;
29
49
  }
@@ -49,6 +69,10 @@ export class Runner {
49
69
  await Runner.release(options);
50
70
  return;
51
71
  }
72
+ if (options['fold'] === true) {
73
+ await Runner.fold(options);
74
+ return;
75
+ }
52
76
  const modeOutput = await Runner.promptWithCancel({
53
77
  type: 'select',
54
78
  name: 'action',
@@ -58,6 +82,10 @@ export class Runner {
58
82
  title: 'Record a change',
59
83
  value: 'record',
60
84
  },
85
+ {
86
+ title: 'Fold an existing changelog section',
87
+ value: 'fold',
88
+ },
61
89
  {
62
90
  title: 'Release',
63
91
  value: 'release',
@@ -74,9 +102,597 @@ export class Runner {
74
102
  if (modeOutputResult.action === 'record') {
75
103
  await Runner.record(options);
76
104
  }
77
- else {
105
+ else if (modeOutputResult.action === 'release') {
78
106
  await Runner.release(options);
79
107
  }
108
+ else {
109
+ await Runner.fold(options);
110
+ }
111
+ return;
112
+ }
113
+ static async fold(options) {
114
+ const isDryRun = options['dryRun'] === true;
115
+ if (options['bump'] !== undefined) {
116
+ Runner.failFold('--bump is only valid when recording a pending changelog entry.');
117
+ return;
118
+ }
119
+ const config = await new LibNovaConfig().load();
120
+ const workspaces = config['workspaces'] ?? {};
121
+ const versionStrategy = (config['settings'] !== undefined && config['settings']['versionStrategy'] !== undefined) ? config['settings']['versionStrategy'] : 'semver';
122
+ try {
123
+ await LibReleaseHistory.validateStrategy(config, process.cwd());
124
+ }
125
+ catch (error) {
126
+ Runner.failFold((error instanceof Error) ? error.message : 'Unable to validate the configured version strategy.');
127
+ return;
128
+ }
129
+ const eligibleWorkspaces = Object.entries(workspaces).filter((workspace) => {
130
+ const filterWorkspaceConfig = workspace[1];
131
+ const filterWorkspaceConfigPolicy = filterWorkspaceConfig['policy'];
132
+ return filterWorkspaceConfigPolicy !== 'freezable';
133
+ });
134
+ if (eligibleWorkspaces.length === 0) {
135
+ Runner.failFold('No eligible (non-freezable) workspaces found in "nova.config.json".');
136
+ return;
137
+ }
138
+ let selectedPackage = undefined;
139
+ if (options['package'] !== undefined) {
140
+ const validPackageEntry = eligibleWorkspaces.find((eligibleWorkspace) => {
141
+ const findEligibleWorkspaceConfig = eligibleWorkspace[1];
142
+ const findEligibleWorkspaceConfigName = findEligibleWorkspaceConfig['name'];
143
+ return findEligibleWorkspaceConfigName === options['package'];
144
+ });
145
+ if (validPackageEntry === undefined) {
146
+ Runner.failFold(`Package "${options['package']}" is not a valid non-freezable workspace.`);
147
+ return;
148
+ }
149
+ selectedPackage = validPackageEntry[1]['name'];
150
+ }
151
+ else if (eligibleWorkspaces.length === 1 && eligibleWorkspaces[0] !== undefined) {
152
+ selectedPackage = eligibleWorkspaces[0][1]['name'];
153
+ Logger.customize({
154
+ name: 'Runner.fold',
155
+ purpose: 'package',
156
+ }).info(`Auto-selected package: ${selectedPackage}`);
157
+ }
158
+ else {
159
+ const packageOutput = await Runner.promptWithCancel({
160
+ type: 'select',
161
+ name: 'package',
162
+ message: 'Select a package.',
163
+ choices: eligibleWorkspaces.map((eligibleWorkspace) => {
164
+ const mapEligibleWorkspaceConfig = eligibleWorkspace[1];
165
+ const mapEligibleWorkspaceConfigName = mapEligibleWorkspaceConfig['name'];
166
+ const mapEligibleWorkspaceConfigRole = mapEligibleWorkspaceConfig['role'];
167
+ const mapEligibleWorkspaceConfigPolicy = mapEligibleWorkspaceConfig['policy'];
168
+ return {
169
+ title: mapEligibleWorkspaceConfigName,
170
+ description: `${mapEligibleWorkspaceConfigRole} · ${mapEligibleWorkspaceConfigPolicy}`,
171
+ value: mapEligibleWorkspaceConfigName,
172
+ };
173
+ }),
174
+ });
175
+ if (packageOutput['cancelled'] === true) {
176
+ return;
177
+ }
178
+ const packageOutputResult = packageOutput['result'];
179
+ if (packageOutputResult.package === undefined) {
180
+ return;
181
+ }
182
+ selectedPackage = packageOutputResult.package;
183
+ }
184
+ const workspaceEntry = Object.entries(workspaces).find((workspace) => {
185
+ const findWorkspaceConfig = workspace[1];
186
+ const findWorkspaceConfigName = findWorkspaceConfig['name'];
187
+ return findWorkspaceConfigName === selectedPackage;
188
+ });
189
+ if (workspaceEntry === undefined) {
190
+ Runner.failFold(`Package "${selectedPackage}" was not found in "nova.config.json".`);
191
+ return;
192
+ }
193
+ const workspacePath = workspaceEntry[0];
194
+ const currentDirectory = process.cwd();
195
+ const packageDirectory = resolve(currentDirectory, workspacePath);
196
+ const packageJsonPath = join(packageDirectory, 'package.json');
197
+ const changelogPath = join(packageDirectory, 'CHANGELOG.md');
198
+ let fileContents = undefined;
199
+ try {
200
+ fileContents = await Promise.all([
201
+ fs.readFile(packageJsonPath, 'utf-8'),
202
+ fs.readFile(changelogPath, 'utf-8'),
203
+ ]);
204
+ }
205
+ catch (error) {
206
+ Runner.failFold((error instanceof Error) ? error.message : `Unable to read "${packageJsonPath}" and "${changelogPath}".`);
207
+ return;
208
+ }
209
+ if (fileContents === undefined) {
210
+ return;
211
+ }
212
+ const packageJsonRaw = fileContents[0];
213
+ const existingContent = fileContents[1];
214
+ let packageJson = undefined;
215
+ let document = undefined;
216
+ try {
217
+ packageJson = JSON.parse(packageJsonRaw);
218
+ document = Runner.parseChangelog(existingContent);
219
+ }
220
+ catch (error) {
221
+ Runner.failFold((error instanceof Error) ? error.message : `Unable to parse "${packageJsonPath}" or "${changelogPath}".`);
222
+ return;
223
+ }
224
+ if (packageJson === undefined || document === undefined) {
225
+ return;
226
+ }
227
+ const currentVersion = (typeof packageJson['version'] === 'string') ? packageJson['version'] : undefined;
228
+ if (currentVersion === undefined) {
229
+ Runner.failFold(`No "version" field found in "${packageJsonPath}".`);
230
+ return;
231
+ }
232
+ try {
233
+ Runner.validateVersion(currentVersion, versionStrategy, packageJsonPath);
234
+ }
235
+ catch (error) {
236
+ Runner.failFold((error instanceof Error) ? error.message : `Unable to validate the version in "${packageJsonPath}".`);
237
+ return;
238
+ }
239
+ if (document['sections'].length === 0 || document['sections'][0] === undefined) {
240
+ Runner.failFold(`No existing version sections were found in "${changelogPath}".`);
241
+ return;
242
+ }
243
+ const targetVersion = options['version'] ?? document['sections'][0]['version'];
244
+ const targetSections = document['sections'].filter((section) => section['version'] === targetVersion);
245
+ if (targetSections.length === 0) {
246
+ Runner.failFold(`Version "${targetVersion}" was not found in "${changelogPath}".`);
247
+ return;
248
+ }
249
+ if (targetSections.length > 1 || targetSections[0] === undefined) {
250
+ Runner.failFold(`Version "${targetVersion}" is ambiguous because it appears more than once in "${changelogPath}".`);
251
+ return;
252
+ }
253
+ const targetSection = targetSections[0];
254
+ const requestedActions = [];
255
+ if (options['add'] === true) {
256
+ requestedActions.push('add');
257
+ }
258
+ if (options['edit'] === true) {
259
+ requestedActions.push('edit');
260
+ }
261
+ if (options['remove'] === true) {
262
+ requestedActions.push('remove');
263
+ }
264
+ if (options['mergeFrom'] !== undefined) {
265
+ requestedActions.push('merge');
266
+ }
267
+ if (requestedActions.length > 1) {
268
+ Runner.failFold('Choose only one fold action: --add, --edit, --remove, or --merge-from.');
269
+ return;
270
+ }
271
+ let action = requestedActions[0];
272
+ if (action === undefined) {
273
+ const actionOutput = await Runner.promptWithCancel({
274
+ type: 'select',
275
+ name: 'action',
276
+ message: `How should version ${targetVersion} change?`,
277
+ choices: [
278
+ {
279
+ title: 'Add an entry',
280
+ value: 'add',
281
+ },
282
+ {
283
+ title: 'Edit an entry',
284
+ value: 'edit',
285
+ },
286
+ {
287
+ title: 'Remove an entry',
288
+ value: 'remove',
289
+ },
290
+ {
291
+ title: 'Merge older sections',
292
+ value: 'merge',
293
+ },
294
+ ],
295
+ });
296
+ if (actionOutput['cancelled'] === true) {
297
+ return;
298
+ }
299
+ const actionOutputResult = actionOutput['result'];
300
+ if (actionOutputResult.action === undefined) {
301
+ return;
302
+ }
303
+ action = actionOutputResult.action;
304
+ }
305
+ if (action !== 'merge' && options['uncategorizedAs'] !== undefined) {
306
+ Runner.failFold('--uncategorized-as is only valid when merging changelog sections.');
307
+ return;
308
+ }
309
+ let beforeSections = [targetSection];
310
+ let beforeSectionContent = '';
311
+ if (action === 'merge') {
312
+ if (options['category'] !== undefined
313
+ || options['entry'] !== undefined
314
+ || options['match'] !== undefined
315
+ || options['message'] !== undefined) {
316
+ Runner.failFold('--merge-from cannot be combined with --category, --entry, --match, or --message.');
317
+ return;
318
+ }
319
+ let sourceVersions = [];
320
+ if (options['mergeFrom'] !== undefined) {
321
+ sourceVersions = options['mergeFrom']
322
+ .split(',')
323
+ .map((sourceVersion) => sourceVersion.trim())
324
+ .filter((sourceVersion) => sourceVersion !== '');
325
+ }
326
+ else {
327
+ if (document['sections'].every((section) => section['version'] === targetVersion) === true) {
328
+ Runner.failFold(`No other version sections are available to merge into version "${targetVersion}".`);
329
+ return;
330
+ }
331
+ const mergeOutput = await Runner.promptWithCancel({
332
+ type: 'multiselect',
333
+ name: 'versions',
334
+ message: `Select versions to merge into ${targetVersion}.`,
335
+ choices: document['sections']
336
+ .filter((section) => section['version'] !== targetVersion)
337
+ .map((section) => ({
338
+ title: section['version'],
339
+ value: section['version'],
340
+ })),
341
+ min: 1,
342
+ });
343
+ if (mergeOutput['cancelled'] === true) {
344
+ return;
345
+ }
346
+ const mergeOutputResult = mergeOutput['result'];
347
+ sourceVersions = mergeOutputResult.versions ?? [];
348
+ }
349
+ const uniqueSourceVersions = [...new Set(sourceVersions)];
350
+ if (uniqueSourceVersions.length === 0) {
351
+ Runner.failFold('Select at least one source version to merge.');
352
+ return;
353
+ }
354
+ const sourceSections = [];
355
+ for (const sourceVersion of uniqueSourceVersions) {
356
+ if (sourceVersion === targetVersion) {
357
+ Runner.failFold(`Version "${sourceVersion}" cannot be merged into itself.`);
358
+ return;
359
+ }
360
+ const matchingSections = document['sections'].filter((section) => section['version'] === sourceVersion);
361
+ if (matchingSections.length === 0) {
362
+ Runner.failFold(`Merge source version "${sourceVersion}" was not found in "${changelogPath}".`);
363
+ return;
364
+ }
365
+ if (matchingSections.length > 1 || matchingSections[0] === undefined) {
366
+ Runner.failFold(`Merge source version "${sourceVersion}" is ambiguous in "${changelogPath}".`);
367
+ return;
368
+ }
369
+ sourceSections.push(matchingSections[0]);
370
+ }
371
+ beforeSections = document['sections'].filter((section) => section === targetSection || sourceSections.includes(section));
372
+ beforeSectionContent = beforeSections.map((section) => Runner.formatChangelogSection(section)).join('\n\n');
373
+ let uncategorizedCategory = undefined;
374
+ if (options['uncategorizedAs'] !== undefined) {
375
+ const validUncategorizedCategory = libItemChangelogValidCategories.find((libItemChangelogValidCategory) => libItemChangelogValidCategory === options['uncategorizedAs']);
376
+ if (validUncategorizedCategory === undefined) {
377
+ Runner.failFold(`Uncategorized category "${options['uncategorizedAs']}" is invalid. Use: ${libItemChangelogValidCategories.join(', ')}.`);
378
+ return;
379
+ }
380
+ uncategorizedCategory = validUncategorizedCategory;
381
+ }
382
+ const uncategorizedSections = beforeSections.filter((section) => section['uncategorized'].length > 0);
383
+ if (uncategorizedSections.length > 0 && uncategorizedCategory === undefined) {
384
+ if (options['mergeFrom'] !== undefined) {
385
+ Runner.failFold('Selected changelog sections contain bullets outside category headings. Re-run with --uncategorized-as <updated|fixed|added|removed> to assign them before merging.');
386
+ return;
387
+ }
388
+ const uncategorizedOutput = await Runner.promptWithCancel({
389
+ type: 'select',
390
+ name: 'uncategorizedAs',
391
+ message: 'Select a category for uncategorized bullets.',
392
+ choices: libItemChangelogOrderedCategories.map((candidateCategory) => ({
393
+ title: candidateCategory.toUpperCase(),
394
+ value: candidateCategory,
395
+ })),
396
+ });
397
+ if (uncategorizedOutput['cancelled'] === true) {
398
+ return;
399
+ }
400
+ const uncategorizedOutputResult = uncategorizedOutput['result'];
401
+ if (uncategorizedOutputResult.uncategorizedAs === undefined) {
402
+ return;
403
+ }
404
+ uncategorizedCategory = uncategorizedOutputResult.uncategorizedAs;
405
+ }
406
+ if (uncategorizedCategory !== undefined) {
407
+ for (const uncategorizedSection of uncategorizedSections) {
408
+ const uncategorizedMessages = uncategorizedSection['categories'].get(uncategorizedCategory) ?? [];
409
+ for (const uncategorizedMessage of uncategorizedSection['uncategorized']) {
410
+ uncategorizedMessages.push(uncategorizedMessage);
411
+ }
412
+ uncategorizedSection['categories'].set(uncategorizedCategory, uncategorizedMessages);
413
+ Reflect.set(uncategorizedSection, 'uncategorized', []);
414
+ }
415
+ }
416
+ for (const category of libItemChangelogOrderedCategories) {
417
+ const targetMessages = targetSection['categories'].get(category) ?? [];
418
+ const deduplicatedMessages = [];
419
+ const seenMessages = new Set();
420
+ for (const targetMessage of targetMessages) {
421
+ if (seenMessages.has(targetMessage) === false) {
422
+ deduplicatedMessages.push(targetMessage);
423
+ seenMessages.add(targetMessage);
424
+ }
425
+ }
426
+ for (const sourceSection of sourceSections) {
427
+ const sourceMessages = sourceSection['categories'].get(category) ?? [];
428
+ for (const sourceMessage of sourceMessages) {
429
+ if (seenMessages.has(sourceMessage) === false) {
430
+ deduplicatedMessages.push(sourceMessage);
431
+ seenMessages.add(sourceMessage);
432
+ }
433
+ }
434
+ }
435
+ if (deduplicatedMessages.length === 0) {
436
+ targetSection['categories'].delete(category);
437
+ }
438
+ else {
439
+ targetSection['categories'].set(category, deduplicatedMessages);
440
+ }
441
+ }
442
+ Reflect.set(document, 'sections', document['sections'].filter((section) => sourceSections.includes(section) === false));
443
+ }
444
+ else {
445
+ if (targetSection['uncategorized'].length > 0) {
446
+ Runner.failFold('The target section contains bullets outside category headings. Merge it with --uncategorized-as <updated|fixed|added|removed> to assign them before editing.');
447
+ return;
448
+ }
449
+ if ((action === 'edit'
450
+ || action === 'remove')
451
+ && [...targetSection['categories'].values()].every((messages) => messages.length === 0) === true) {
452
+ Runner.failFold(`Version "${targetVersion}" has no entries to ${action}.`);
453
+ return;
454
+ }
455
+ if (action === 'add'
456
+ && (options['entry'] !== undefined
457
+ || options['match'] !== undefined)) {
458
+ Runner.failFold('--entry and --match are only valid with --edit or --remove.');
459
+ return;
460
+ }
461
+ if (action === 'remove' && options['message'] !== undefined) {
462
+ Runner.failFold('--message is only valid with --add or --edit.');
463
+ return;
464
+ }
465
+ let category = undefined;
466
+ if (options['category'] !== undefined) {
467
+ const validCategory = libItemChangelogValidCategories.find((libItemChangelogValidCategory) => libItemChangelogValidCategory === options['category']);
468
+ if (validCategory === undefined) {
469
+ Runner.failFold(`Category "${options['category']}" is invalid. Use: ${libItemChangelogValidCategories.join(', ')}.`);
470
+ return;
471
+ }
472
+ category = validCategory;
473
+ }
474
+ else {
475
+ const categoryOutput = await Runner.promptWithCancel({
476
+ type: 'select',
477
+ name: 'category',
478
+ message: 'Select a category.',
479
+ choices: libItemChangelogOrderedCategories
480
+ .filter((candidateCategory) => action === 'add' || (targetSection['categories'].get(candidateCategory) ?? []).length > 0)
481
+ .map((candidateCategory) => ({
482
+ title: candidateCategory.toUpperCase(),
483
+ value: candidateCategory,
484
+ })),
485
+ });
486
+ if (categoryOutput['cancelled'] === true) {
487
+ return;
488
+ }
489
+ const categoryOutputResult = categoryOutput['result'];
490
+ if (categoryOutputResult.category === undefined) {
491
+ return;
492
+ }
493
+ category = categoryOutputResult.category;
494
+ }
495
+ beforeSectionContent = Runner.formatChangelogSection(targetSection);
496
+ const messages = targetSection['categories'].get(category) ?? [];
497
+ let selectedIndex = undefined;
498
+ if (action === 'edit' || action === 'remove') {
499
+ if (messages.length === 0) {
500
+ Runner.failFold(`Category "${category}" has no entries in version "${targetVersion}".`);
501
+ return;
502
+ }
503
+ if (options['entry'] !== undefined && options['match'] !== undefined) {
504
+ Runner.failFold('Use either --entry or --match, not both.');
505
+ return;
506
+ }
507
+ if (options['entry'] !== undefined) {
508
+ const parsedEntryNumber = Number(options['entry']);
509
+ if (Number.isSafeInteger(parsedEntryNumber) === false
510
+ || parsedEntryNumber < 1
511
+ || parsedEntryNumber > messages.length) {
512
+ Runner.failFold(`Entry "${options['entry']}" does not exist in category "${category}" for version "${targetVersion}".`);
513
+ return;
514
+ }
515
+ selectedIndex = parsedEntryNumber - 1;
516
+ }
517
+ else if (options['match'] !== undefined) {
518
+ const matchingIndexes = [];
519
+ for (let i = 0; i < messages.length; i += 1) {
520
+ if (messages[i] === options['match']) {
521
+ matchingIndexes.push(i);
522
+ }
523
+ }
524
+ if (matchingIndexes.length === 0) {
525
+ Runner.failFold(`No entry exactly matching "${options['match']}" was found in category "${category}" for version "${targetVersion}".`);
526
+ return;
527
+ }
528
+ if (matchingIndexes.length > 1 || matchingIndexes[0] === undefined) {
529
+ Runner.failFold(`Entry text "${options['match']}" is ambiguous in category "${category}" for version "${targetVersion}"; use --entry instead.`);
530
+ return;
531
+ }
532
+ selectedIndex = matchingIndexes[0];
533
+ }
534
+ else {
535
+ const entryOutput = await Runner.promptWithCancel({
536
+ type: 'select',
537
+ name: 'entry',
538
+ message: 'Select an entry.',
539
+ choices: messages.map((message, index) => ({
540
+ title: message,
541
+ description: `Entry ${index + 1}`,
542
+ value: index,
543
+ })),
544
+ });
545
+ if (entryOutput['cancelled'] === true) {
546
+ return;
547
+ }
548
+ const entryOutputResult = entryOutput['result'];
549
+ if (entryOutputResult.entry === undefined) {
550
+ return;
551
+ }
552
+ selectedIndex = entryOutputResult.entry;
553
+ }
554
+ }
555
+ let message = undefined;
556
+ if (action === 'add' || action === 'edit') {
557
+ if (options['message'] !== undefined) {
558
+ message = options['message'].trim();
559
+ if (message === '') {
560
+ Runner.failFold('Message cannot be empty.');
561
+ return;
562
+ }
563
+ const messageValidation = Runner.validateMessage(message, category);
564
+ if (messageValidation !== true) {
565
+ Runner.failFold(messageValidation);
566
+ return;
567
+ }
568
+ }
569
+ else {
570
+ const messageOutput = await Runner.promptWithCancel({
571
+ type: 'text',
572
+ name: 'message',
573
+ message: (action === 'add') ? 'Describe the entry.' : 'Edit the entry.',
574
+ initial: (action === 'edit' && selectedIndex !== undefined) ? messages[selectedIndex] : undefined,
575
+ validate: (messageValue) => Runner.validateMessage(messageValue, category),
576
+ });
577
+ if (messageOutput['cancelled'] === true) {
578
+ return;
579
+ }
580
+ const messageOutputResult = messageOutput['result'];
581
+ if (messageOutputResult.message === undefined) {
582
+ return;
583
+ }
584
+ message = messageOutputResult.message.trim();
585
+ }
586
+ }
587
+ if (action === 'add' && message !== undefined) {
588
+ messages.push(message);
589
+ }
590
+ else if (action === 'edit'
591
+ && message !== undefined
592
+ && selectedIndex !== undefined) {
593
+ messages.splice(selectedIndex, 1, message);
594
+ }
595
+ else if (action === 'remove' && selectedIndex !== undefined) {
596
+ messages.splice(selectedIndex, 1);
597
+ }
598
+ if (messages.length === 0) {
599
+ targetSection['categories'].delete(category);
600
+ }
601
+ else {
602
+ targetSection['categories'].set(category, messages);
603
+ }
604
+ }
605
+ let androidBuild = undefined;
606
+ let appleBuild = undefined;
607
+ let nativeBuild = undefined;
608
+ if (action !== 'merge' && options['buildBump'] !== false) {
609
+ try {
610
+ const nativeBuilds = await Promise.all([
611
+ Runner.syncAndroidVersion(packageDirectory, currentVersion, currentVersion, 1, false),
612
+ Runner.syncAppleVersion(packageDirectory, currentVersion, currentVersion, 1, false),
613
+ ]);
614
+ androidBuild = nativeBuilds[0];
615
+ appleBuild = nativeBuilds[1];
616
+ }
617
+ catch (error) {
618
+ Runner.failFold((error instanceof Error) ? error.message : 'Unable to validate native version manifests.');
619
+ return;
620
+ }
621
+ if (androidBuild !== undefined && appleBuild !== undefined) {
622
+ Runner.failFold(`Native workspace "${packageDirectory}" cannot define both Android and Apple version manifests.`);
623
+ return;
624
+ }
625
+ nativeBuild = androidBuild ?? appleBuild;
626
+ if (nativeBuild !== undefined && targetSection['version'] !== currentVersion) {
627
+ Runner.failFold(`Native workspace "${selectedPackage}" can only bump build numbers in its current version "${currentVersion}"; target version "${targetSection['version']}" is not current. Use --no-build-bump to fold an older section.`);
628
+ return;
629
+ }
630
+ if (nativeBuild !== undefined) {
631
+ Reflect.set(targetSection, 'header', Runner.formatChangelogHeader(targetSection, nativeBuild));
632
+ Reflect.set(targetSection, 'build', nativeBuild);
633
+ }
634
+ }
635
+ const nextContent = Runner.renderChangelog(document);
636
+ const afterSectionContent = Runner.formatChangelogSection(targetSection);
637
+ const diff = Runner.formatChangelogDiff(changelogPath, beforeSectionContent, afterSectionContent);
638
+ let buildSummary = 'Native build: not applicable.';
639
+ if (action === 'merge') {
640
+ buildSummary = 'Native build: unchanged (merge operations never bump builds).';
641
+ }
642
+ else if (options['buildBump'] === false) {
643
+ buildSummary = 'Native build: unchanged (--no-build-bump).';
644
+ }
645
+ else if (androidBuild !== undefined) {
646
+ buildSummary = `Android versionCode: ${androidBuild - 1} -> ${androidBuild}.`;
647
+ }
648
+ else if (appleBuild !== undefined) {
649
+ buildSummary = `Apple CURRENT_PROJECT_VERSION: ${appleBuild - 1} -> ${appleBuild}.`;
650
+ }
651
+ if (isDryRun === true) {
652
+ Logger.customize({
653
+ name: 'Runner.fold',
654
+ purpose: 'dryRun',
655
+ padTop: 1,
656
+ }).info(`Would update "${changelogPath}":`);
657
+ const dryRunLines = [
658
+ diff,
659
+ buildSummary,
660
+ '',
661
+ ];
662
+ process.stdout.write(dryRunLines.join('\n'));
663
+ return;
664
+ }
665
+ try {
666
+ if (androidBuild !== undefined) {
667
+ await Runner.syncAndroidVersion(packageDirectory, currentVersion, currentVersion, 1, true);
668
+ }
669
+ if (appleBuild !== undefined) {
670
+ await Runner.syncAppleVersion(packageDirectory, currentVersion, currentVersion, 1, true);
671
+ }
672
+ await fs.writeFile(changelogPath, nextContent, 'utf-8');
673
+ }
674
+ catch (error) {
675
+ Runner.failFold((error instanceof Error) ? error.message : `Unable to update "${changelogPath}".`);
676
+ return;
677
+ }
678
+ let actionVerb = 'Folded';
679
+ if (action === 'add') {
680
+ actionVerb = 'Added an entry to';
681
+ }
682
+ else if (action === 'edit') {
683
+ actionVerb = 'Edited an entry in';
684
+ }
685
+ else if (action === 'remove') {
686
+ actionVerb = 'Removed an entry from';
687
+ }
688
+ else if (action === 'merge') {
689
+ actionVerb = 'Merged sections into';
690
+ }
691
+ Logger.customize({
692
+ name: 'Runner.fold',
693
+ purpose: 'complete',
694
+ padTop: 1,
695
+ }).info(`${actionVerb} version ${targetVersion} in "${changelogPath}".`);
80
696
  return;
81
697
  }
82
698
  static async record(options) {
@@ -181,6 +797,15 @@ export class Runner {
181
797
  process.exitCode = 1;
182
798
  return;
183
799
  }
800
+ const messageValidation = Runner.validateMessage(validMessage, validCategory);
801
+ if (messageValidation !== true) {
802
+ Logger.customize({
803
+ name: 'Runner.record',
804
+ purpose: 'validate',
805
+ }).error(messageValidation);
806
+ process.exitCode = 1;
807
+ return;
808
+ }
184
809
  selectedPackage = validPackage;
185
810
  selectedCategory = validCategory;
186
811
  selectedMessage = validMessage;
@@ -258,7 +883,7 @@ export class Runner {
258
883
  type: 'text',
259
884
  name: 'message',
260
885
  message: 'Describe the change.',
261
- validate: Runner['validateMessage'],
886
+ validate: (messageValue) => Runner.validateMessage(messageValue, selectedCategory),
262
887
  });
263
888
  if (messageOutput['cancelled'] === true) {
264
889
  return;
@@ -1423,16 +2048,184 @@ export class Runner {
1423
2048
  result,
1424
2049
  };
1425
2050
  }
2051
+ static failFold(message) {
2052
+ Logger.customize({
2053
+ name: 'Runner.fold',
2054
+ purpose: 'validate',
2055
+ }).error(message);
2056
+ process.exitCode = 1;
2057
+ return;
2058
+ }
2059
+ static formatChangelogDiff(changelogPath, beforeContent, afterContent) {
2060
+ const beforeLines = beforeContent.split('\n');
2061
+ const afterLines = afterContent.split('\n');
2062
+ const diffLines = [
2063
+ `--- ${changelogPath} (before)`,
2064
+ `+++ ${changelogPath} (after)`,
2065
+ '@@',
2066
+ ];
2067
+ for (const beforeLine of beforeLines) {
2068
+ diffLines.push(`-${beforeLine}`);
2069
+ }
2070
+ for (const afterLine of afterLines) {
2071
+ diffLines.push(`+${afterLine}`);
2072
+ }
2073
+ return diffLines.join('\n');
2074
+ }
2075
+ static formatChangelogHeader(section, nativeBuild) {
2076
+ const headerPrefix = `## ${section['version']}`;
2077
+ const headerSuffix = section['header'].slice(headerPrefix.length);
2078
+ if (headerSuffix.startsWith(' (') === true) {
2079
+ const buildEndIndex = headerSuffix.indexOf(')');
2080
+ const suffixAfterBuild = headerSuffix.slice(buildEndIndex + 1);
2081
+ return `${headerPrefix} (${nativeBuild})${suffixAfterBuild}`;
2082
+ }
2083
+ return `${headerPrefix} (${nativeBuild})${headerSuffix}`;
2084
+ }
2085
+ static formatChangelogSection(section) {
2086
+ const sectionParts = [section['header']];
2087
+ const categoryOrder = [...libItemChangelogOrderedCategories];
2088
+ if (section['categories'].size === 0 && section['uncategorized'].length === 0) {
2089
+ sectionParts.push('');
2090
+ sectionParts.push('No changes.');
2091
+ return sectionParts.join('\n');
2092
+ }
2093
+ if (section['uncategorized'].length > 0) {
2094
+ sectionParts.push('');
2095
+ for (const uncategorizedMessage of section['uncategorized']) {
2096
+ sectionParts.push(`- ${uncategorizedMessage}`);
2097
+ }
2098
+ }
2099
+ for (const category of categoryOrder) {
2100
+ const messages = section['categories'].get(category);
2101
+ if (messages === undefined || messages.length === 0) {
2102
+ continue;
2103
+ }
2104
+ sectionParts.push('');
2105
+ sectionParts.push(`### ${category.toUpperCase()}`);
2106
+ for (const message of messages) {
2107
+ sectionParts.push(`- ${message}`);
2108
+ }
2109
+ }
2110
+ return sectionParts.join('\n');
2111
+ }
2112
+ static parseChangelog(content) {
2113
+ const lines = content.trimEnd().split('\n');
2114
+ const packageHeading = lines[0];
2115
+ if (packageHeading === undefined
2116
+ || packageHeading.startsWith('# ') === false
2117
+ || packageHeading.startsWith('## ') === true) {
2118
+ throw new Error('CHANGELOG.md must begin with one package heading.');
2119
+ }
2120
+ const sections = [];
2121
+ let currentSection = undefined;
2122
+ let currentCategory = undefined;
2123
+ for (const line of lines.slice(1)) {
2124
+ if (line.startsWith('## ') === true) {
2125
+ const headerBody = line.slice(3);
2126
+ const versionSeparatorIndex = headerBody.indexOf(' ');
2127
+ const version = (versionSeparatorIndex === -1) ? headerBody : headerBody.slice(0, versionSeparatorIndex);
2128
+ if (version === '') {
2129
+ throw new Error(`Invalid changelog section heading "${line}".`);
2130
+ }
2131
+ const section = {
2132
+ header: line,
2133
+ version,
2134
+ categories: new Map(),
2135
+ uncategorized: [],
2136
+ };
2137
+ const buildPrefix = `${version} (`;
2138
+ if (headerBody.startsWith(buildPrefix) === true) {
2139
+ const buildEndIndex = headerBody.indexOf(')', buildPrefix.length);
2140
+ if (buildEndIndex === -1) {
2141
+ throw new Error(`Invalid native build in changelog heading "${line}".`);
2142
+ }
2143
+ const buildValue = headerBody.slice(buildPrefix.length, buildEndIndex);
2144
+ const parsedBuild = Number(buildValue);
2145
+ if (Number.isSafeInteger(parsedBuild) === false) {
2146
+ throw new Error(`Invalid native build "${buildValue}" in changelog heading "${line}".`);
2147
+ }
2148
+ Reflect.set(section, 'build', parsedBuild);
2149
+ }
2150
+ sections.push(section);
2151
+ currentSection = section;
2152
+ currentCategory = undefined;
2153
+ continue;
2154
+ }
2155
+ if (line.startsWith('### ') === true) {
2156
+ if (currentSection === undefined) {
2157
+ throw new Error(`Category heading "${line}" appears before a version section.`);
2158
+ }
2159
+ const categoryValue = line.slice(4).toLowerCase();
2160
+ const category = libItemChangelogValidCategories.find((libItemChangelogValidCategory) => libItemChangelogValidCategory === categoryValue);
2161
+ if (category === undefined) {
2162
+ throw new Error(`Unsupported changelog category heading "${line}".`);
2163
+ }
2164
+ if (currentSection['categories'].has(category) === true) {
2165
+ throw new Error(`Category "${category}" appears more than once in version "${currentSection['version']}".`);
2166
+ }
2167
+ currentSection['categories'].set(category, []);
2168
+ currentCategory = category;
2169
+ continue;
2170
+ }
2171
+ if (line.startsWith('- ') === true) {
2172
+ if (currentSection === undefined) {
2173
+ throw new Error(`Changelog bullet "${line}" appears before a version section.`);
2174
+ }
2175
+ const message = line.slice(2);
2176
+ if (message === '') {
2177
+ throw new Error(`Version "${currentSection['version']}" contains an empty changelog bullet.`);
2178
+ }
2179
+ if (currentCategory === undefined) {
2180
+ currentSection['uncategorized'].push(message);
2181
+ continue;
2182
+ }
2183
+ const messages = currentSection['categories'].get(currentCategory) ?? [];
2184
+ messages.push(message);
2185
+ currentSection['categories'].set(currentCategory, messages);
2186
+ continue;
2187
+ }
2188
+ if (line === '' || line === 'No changes.') {
2189
+ continue;
2190
+ }
2191
+ throw new Error(`Unsupported changelog content "${line}". Fold only edits Nova-formatted sections.`);
2192
+ }
2193
+ return {
2194
+ packageHeading,
2195
+ sections,
2196
+ };
2197
+ }
2198
+ static renderChangelog(document) {
2199
+ const sectionContents = document['sections'].map((section) => Runner.formatChangelogSection(section));
2200
+ const parts = [
2201
+ document['packageHeading'],
2202
+ '',
2203
+ sectionContents.join('\n\n'),
2204
+ '',
2205
+ ];
2206
+ return parts.join('\n');
2207
+ }
1426
2208
  static generateFileName() {
1427
2209
  const adjective = libItemChangelogAdjectives[Math.floor(Math.random() * libItemChangelogAdjectives.length)];
1428
2210
  const noun = libItemChangelogNouns[Math.floor(Math.random() * libItemChangelogNouns.length)];
1429
2211
  const verb = libItemChangelogVerbs[Math.floor(Math.random() * libItemChangelogVerbs.length)];
1430
2212
  return `${adjective}-${noun}-${verb}`;
1431
2213
  }
1432
- static validateMessage(messageValue) {
2214
+ static validateMessage(messageValue, category) {
1433
2215
  if (typeof messageValue !== 'string' || messageValue.trim() === '') {
1434
2216
  return 'Enter a description.';
1435
2217
  }
2218
+ if (LIB_REGEX_PATTERN_CHANGELOG_CAPITAL_START.test(messageValue.trim()) === false) {
2219
+ return 'Start the entry with a capital letter.';
2220
+ }
2221
+ if (category === undefined) {
2222
+ return true;
2223
+ }
2224
+ const firstWordMatch = messageValue.trim().match(LIB_REGEX_PATTERN_CHANGELOG_FIRST_WORD);
2225
+ const firstWord = (firstWordMatch !== null) ? (firstWordMatch[1] ?? '') : '';
2226
+ if (libItemChangelogCategoryOpeningWords[category].includes(firstWord.toLowerCase()) === true) {
2227
+ return `Entries under "${category}" can't start with "${firstWord}", because the heading already says it. Start with what changed instead.`;
2228
+ }
1436
2229
  return true;
1437
2230
  }
1438
2231
  static validateVersion(currentVersion, versionStrategy, packageJsonPath) {