@b64hub/sfpm-cli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/README.md +416 -204
  2. package/dist/commands/add.d.ts +10 -0
  3. package/dist/commands/add.js +50 -0
  4. package/dist/commands/add.js.map +1 -0
  5. package/dist/commands/bootstrap.d.ts +18 -5
  6. package/dist/commands/bootstrap.js +372 -167
  7. package/dist/commands/bootstrap.js.map +1 -1
  8. package/dist/commands/build/index.d.ts +59 -0
  9. package/dist/commands/build/index.js +425 -0
  10. package/dist/commands/build/index.js.map +1 -0
  11. package/dist/commands/build/status.d.ts +3 -4
  12. package/dist/commands/build/status.js +13 -162
  13. package/dist/commands/build/status.js.map +1 -1
  14. package/dist/commands/deploy/artifact.d.ts +17 -13
  15. package/dist/commands/deploy/artifact.js +31 -88
  16. package/dist/commands/deploy/artifact.js.map +1 -1
  17. package/dist/commands/deploy/index.d.ts +52 -0
  18. package/dist/commands/deploy/index.js +162 -0
  19. package/dist/commands/deploy/index.js.map +1 -0
  20. package/dist/commands/dev/pool-list-replay.d.ts +11 -0
  21. package/dist/commands/dev/pool-list-replay.js +19 -0
  22. package/dist/commands/dev/pool-list-replay.js.map +1 -0
  23. package/dist/commands/dev/pool-replay.d.ts +16 -0
  24. package/dist/commands/dev/pool-replay.js +80 -0
  25. package/dist/commands/dev/pool-replay.js.map +1 -0
  26. package/dist/commands/dev/replay.d.ts +21 -0
  27. package/dist/commands/dev/replay.js +103 -0
  28. package/dist/commands/dev/replay.js.map +1 -0
  29. package/dist/commands/install.d.ts +10 -4
  30. package/dist/commands/install.js +73 -70
  31. package/dist/commands/install.js.map +1 -1
  32. package/dist/commands/package/create.d.ts +31 -0
  33. package/dist/commands/package/create.js +270 -0
  34. package/dist/commands/package/create.js.map +1 -0
  35. package/dist/commands/pool/delete.d.ts +4 -5
  36. package/dist/commands/pool/delete.js +64 -52
  37. package/dist/commands/pool/delete.js.map +1 -1
  38. package/dist/commands/pool/fetch.d.ts +5 -4
  39. package/dist/commands/pool/fetch.js +77 -37
  40. package/dist/commands/pool/fetch.js.map +1 -1
  41. package/dist/commands/pool/fill.d.ts +22 -0
  42. package/dist/commands/pool/fill.js +172 -0
  43. package/dist/commands/pool/fill.js.map +1 -0
  44. package/dist/commands/pool/list.d.ts +3 -6
  45. package/dist/commands/pool/list.js +60 -58
  46. package/dist/commands/pool/list.js.map +1 -1
  47. package/dist/commands/{project.d.ts → project/index.d.ts} +1 -1
  48. package/dist/commands/{project.js → project/index.js} +6 -6
  49. package/dist/commands/project/index.js.map +1 -0
  50. package/dist/commands/project/init/turbo.js +3 -11
  51. package/dist/commands/project/init/turbo.js.map +1 -1
  52. package/dist/commands/project/sync.js +2 -10
  53. package/dist/commands/project/sync.js.map +1 -1
  54. package/dist/commands/project/version/bump.js +12 -13
  55. package/dist/commands/project/version/bump.js.map +1 -1
  56. package/dist/commands/publish.d.ts +14 -0
  57. package/dist/commands/publish.js +60 -0
  58. package/dist/commands/publish.js.map +1 -0
  59. package/dist/commands/watch/cancel.d.ts +12 -0
  60. package/dist/commands/watch/cancel.js +44 -0
  61. package/dist/commands/watch/cancel.js.map +1 -0
  62. package/dist/commands/watch/clean.d.ts +10 -0
  63. package/dist/commands/watch/clean.js +29 -0
  64. package/dist/commands/watch/clean.js.map +1 -0
  65. package/dist/commands/watch/status.d.ts +13 -0
  66. package/dist/commands/watch/status.js +137 -0
  67. package/dist/commands/watch/status.js.map +1 -0
  68. package/dist/logger.d.ts +80 -0
  69. package/dist/logger.js +143 -0
  70. package/dist/logger.js.map +1 -0
  71. package/dist/sfpm-command.d.ts +40 -3
  72. package/dist/sfpm-command.js +112 -18
  73. package/dist/sfpm-command.js.map +1 -1
  74. package/dist/types/bootstrap.d.ts +67 -0
  75. package/dist/types/bootstrap.js +78 -0
  76. package/dist/types/bootstrap.js.map +1 -0
  77. package/dist/ui/apps/BuildApp.d.ts +11 -0
  78. package/dist/ui/apps/BuildApp.js +32 -0
  79. package/dist/ui/apps/BuildApp.js.map +1 -0
  80. package/dist/ui/apps/PoolDeleteApp.d.ts +6 -0
  81. package/dist/ui/apps/PoolDeleteApp.js +77 -0
  82. package/dist/ui/apps/PoolDeleteApp.js.map +1 -0
  83. package/dist/ui/apps/PoolFillApp.d.ts +7 -0
  84. package/dist/ui/apps/PoolFillApp.js +107 -0
  85. package/dist/ui/apps/PoolFillApp.js.map +1 -0
  86. package/dist/ui/apps/PoolListApp.d.ts +14 -0
  87. package/dist/ui/apps/PoolListApp.js +33 -0
  88. package/dist/ui/apps/PoolListApp.js.map +1 -0
  89. package/dist/ui/build-event-bridge.d.ts +21 -0
  90. package/dist/ui/build-event-bridge.js +140 -0
  91. package/dist/ui/build-event-bridge.js.map +1 -0
  92. package/dist/ui/build-progress-renderer.d.ts +21 -35
  93. package/dist/ui/build-progress-renderer.js +147 -505
  94. package/dist/ui/build-progress-renderer.js.map +1 -1
  95. package/dist/ui/build-summary.d.ts +15 -0
  96. package/dist/ui/build-summary.js +26 -0
  97. package/dist/ui/build-summary.js.map +1 -0
  98. package/dist/ui/components/OrchestrationView.d.ts +20 -0
  99. package/dist/ui/components/OrchestrationView.js +59 -0
  100. package/dist/ui/components/OrchestrationView.js.map +1 -0
  101. package/dist/ui/components/PackageRow.d.ts +130 -0
  102. package/dist/ui/components/PackageRow.js +80 -0
  103. package/dist/ui/components/PackageRow.js.map +1 -0
  104. package/dist/ui/components/ValidationView.d.ts +4 -0
  105. package/dist/ui/components/ValidationView.js +9 -0
  106. package/dist/ui/components/ValidationView.js.map +1 -0
  107. package/dist/ui/components/base/Divider.d.ts +4 -0
  108. package/dist/ui/components/base/Divider.js +9 -0
  109. package/dist/ui/components/base/Divider.js.map +1 -0
  110. package/dist/ui/components/base/ElapsedTime.d.ts +14 -0
  111. package/dist/ui/components/base/ElapsedTime.js +19 -0
  112. package/dist/ui/components/base/ElapsedTime.js.map +1 -0
  113. package/dist/ui/components/base/Footer.d.ts +58 -0
  114. package/dist/ui/components/base/Footer.js +59 -0
  115. package/dist/ui/components/base/Footer.js.map +1 -0
  116. package/dist/ui/components/base/GradientBar.d.ts +7 -0
  117. package/dist/ui/components/base/GradientBar.js +19 -0
  118. package/dist/ui/components/base/GradientBar.js.map +1 -0
  119. package/dist/ui/components/base/OrgBadge.d.ts +8 -0
  120. package/dist/ui/components/base/OrgBadge.js +10 -0
  121. package/dist/ui/components/base/OrgBadge.js.map +1 -0
  122. package/dist/ui/components/base/StatusIcon.d.ts +4 -0
  123. package/dist/ui/components/base/StatusIcon.js +22 -0
  124. package/dist/ui/components/base/StatusIcon.js.map +1 -0
  125. package/dist/ui/components/pool/OrgRow.d.ts +17 -0
  126. package/dist/ui/components/pool/OrgRow.js +37 -0
  127. package/dist/ui/components/pool/OrgRow.js.map +1 -0
  128. package/dist/ui/components/pool/PoolOrgRow.d.ts +16 -0
  129. package/dist/ui/components/pool/PoolOrgRow.js +44 -0
  130. package/dist/ui/components/pool/PoolOrgRow.js.map +1 -0
  131. package/dist/ui/connect-devhub.d.ts +41 -0
  132. package/dist/ui/connect-devhub.js +52 -0
  133. package/dist/ui/connect-devhub.js.map +1 -0
  134. package/dist/ui/fixtures/happy-path.d.ts +85 -0
  135. package/dist/ui/fixtures/happy-path.js +62 -0
  136. package/dist/ui/fixtures/happy-path.js.map +1 -0
  137. package/dist/ui/fixtures/large-scale.d.ts +19 -0
  138. package/dist/ui/fixtures/large-scale.js +140 -0
  139. package/dist/ui/fixtures/large-scale.js.map +1 -0
  140. package/dist/ui/fixtures/partial-failure.d.ts +71 -0
  141. package/dist/ui/fixtures/partial-failure.js +21 -0
  142. package/dist/ui/fixtures/partial-failure.js.map +1 -0
  143. package/dist/ui/fixtures/pool-happy-path.d.ts +14 -0
  144. package/dist/ui/fixtures/pool-happy-path.js +74 -0
  145. package/dist/ui/fixtures/pool-happy-path.js.map +1 -0
  146. package/dist/ui/fixtures/pool-list.d.ts +6 -0
  147. package/dist/ui/fixtures/pool-list.js +44 -0
  148. package/dist/ui/fixtures/pool-list.js.map +1 -0
  149. package/dist/ui/fixtures/pool-partial-failure.d.ts +15 -0
  150. package/dist/ui/fixtures/pool-partial-failure.js +86 -0
  151. package/dist/ui/fixtures/pool-partial-failure.js.map +1 -0
  152. package/dist/ui/hooks/use-event-bus-wiring.d.ts +7 -0
  153. package/dist/ui/hooks/use-event-bus-wiring.js +32 -0
  154. package/dist/ui/hooks/use-event-bus-wiring.js.map +1 -0
  155. package/dist/ui/hooks/use-term-width.d.ts +2 -0
  156. package/dist/ui/hooks/use-term-width.js +7 -0
  157. package/dist/ui/hooks/use-term-width.js.map +1 -0
  158. package/dist/ui/install-event-bridge.d.ts +9 -0
  159. package/dist/ui/install-event-bridge.js +91 -0
  160. package/dist/ui/install-event-bridge.js.map +1 -0
  161. package/dist/ui/install-progress-renderer.d.ts +20 -60
  162. package/dist/ui/install-progress-renderer.js +161 -307
  163. package/dist/ui/install-progress-renderer.js.map +1 -1
  164. package/dist/ui/orchestration-listr.d.ts +35 -187
  165. package/dist/ui/orchestration-listr.js +164 -328
  166. package/dist/ui/orchestration-listr.js.map +1 -1
  167. package/dist/ui/pino-bridge.d.ts +11 -0
  168. package/dist/ui/pino-bridge.js +24 -0
  169. package/dist/ui/pino-bridge.js.map +1 -0
  170. package/dist/ui/pool-delete-event-bridge.d.ts +12 -0
  171. package/dist/ui/pool-delete-event-bridge.js +18 -0
  172. package/dist/ui/pool-delete-event-bridge.js.map +1 -0
  173. package/dist/ui/pool-fill-event-bridge.d.ts +9 -0
  174. package/dist/ui/pool-fill-event-bridge.js +51 -0
  175. package/dist/ui/pool-fill-event-bridge.js.map +1 -0
  176. package/dist/ui/pool-utils.d.ts +6 -0
  177. package/dist/ui/pool-utils.js +49 -0
  178. package/dist/ui/pool-utils.js.map +1 -0
  179. package/dist/ui/renderer-utils.d.ts +58 -4
  180. package/dist/ui/renderer-utils.js +65 -0
  181. package/dist/ui/renderer-utils.js.map +1 -1
  182. package/dist/ui/run-pool-delete.d.ts +11 -0
  183. package/dist/ui/run-pool-delete.js +15 -0
  184. package/dist/ui/run-pool-delete.js.map +1 -0
  185. package/dist/ui/run-pool-fill.d.ts +15 -0
  186. package/dist/ui/run-pool-fill.js +19 -0
  187. package/dist/ui/run-pool-fill.js.map +1 -0
  188. package/dist/ui/run-pool-list.d.ts +3 -0
  189. package/dist/ui/run-pool-list.js +7 -0
  190. package/dist/ui/run-pool-list.js.map +1 -0
  191. package/dist/ui/run.d.ts +12 -0
  192. package/dist/ui/run.js +7 -0
  193. package/dist/ui/run.js.map +1 -0
  194. package/dist/ui/state/adapters.d.ts +4 -0
  195. package/dist/ui/state/adapters.js +62 -0
  196. package/dist/ui/state/adapters.js.map +1 -0
  197. package/dist/ui/state/pool-delete-reducer.d.ts +37 -0
  198. package/dist/ui/state/pool-delete-reducer.js +47 -0
  199. package/dist/ui/state/pool-delete-reducer.js.map +1 -0
  200. package/dist/ui/state/pool-fill-reducer.d.ts +87 -0
  201. package/dist/ui/state/pool-fill-reducer.js +109 -0
  202. package/dist/ui/state/pool-fill-reducer.js.map +1 -0
  203. package/dist/ui/state/reducer.d.ts +7 -0
  204. package/dist/ui/state/reducer.js +150 -0
  205. package/dist/ui/state/reducer.js.map +1 -0
  206. package/dist/ui/state/selectors.d.ts +18 -0
  207. package/dist/ui/state/selectors.js +36 -0
  208. package/dist/ui/state/selectors.js.map +1 -0
  209. package/dist/ui/state/types.d.ts +35 -0
  210. package/dist/ui/state/types.js +2 -0
  211. package/dist/ui/state/types.js.map +1 -0
  212. package/dist/ui/strategies/display-strategy.d.ts +51 -0
  213. package/dist/ui/strategies/display-strategy.js +5 -0
  214. package/dist/ui/strategies/display-strategy.js.map +1 -0
  215. package/dist/ui/strategies/index.d.ts +14 -0
  216. package/dist/ui/strategies/index.js +24 -0
  217. package/dist/ui/strategies/index.js.map +1 -0
  218. package/dist/ui/strategies/interactive.d.ts +36 -0
  219. package/dist/ui/strategies/interactive.js +149 -0
  220. package/dist/ui/strategies/interactive.js.map +1 -0
  221. package/dist/ui/strategies/plain.d.ts +24 -0
  222. package/dist/ui/strategies/plain.js +72 -0
  223. package/dist/ui/strategies/plain.js.map +1 -0
  224. package/dist/ui/strategies/silent.d.ts +22 -0
  225. package/dist/ui/strategies/silent.js +25 -0
  226. package/dist/ui/strategies/silent.js.map +1 -0
  227. package/dist/ui/strategies/validation-display-strategy.d.ts +64 -0
  228. package/dist/ui/strategies/validation-display-strategy.js +109 -0
  229. package/dist/ui/strategies/validation-display-strategy.js.map +1 -0
  230. package/dist/ui/table.d.ts +4 -0
  231. package/dist/ui/table.js +33 -0
  232. package/dist/ui/table.js.map +1 -0
  233. package/dist/ui/theme.d.ts +12 -0
  234. package/dist/ui/theme.js +4 -0
  235. package/dist/ui/theme.js.map +1 -0
  236. package/dist/ui/validation-progress-renderer.d.ts +48 -0
  237. package/dist/ui/validation-progress-renderer.js +114 -0
  238. package/dist/ui/validation-progress-renderer.js.map +1 -0
  239. package/dist/utils/package-resolver.d.ts +20 -0
  240. package/dist/utils/package-resolver.js +44 -0
  241. package/dist/utils/package-resolver.js.map +1 -0
  242. package/dist/utils/project-dir.d.ts +9 -0
  243. package/dist/utils/project-dir.js +13 -0
  244. package/dist/utils/project-dir.js.map +1 -0
  245. package/dist/utils/suppress.d.ts +13 -0
  246. package/dist/utils/suppress.js +29 -0
  247. package/dist/utils/suppress.js.map +1 -0
  248. package/dist/utils/validation-runner.js +69 -0
  249. package/dist/utils/validation-runner.js.map +1 -0
  250. package/dist/utils/watcher-runner.d.ts +1 -0
  251. package/dist/utils/watcher-runner.js +148 -0
  252. package/dist/utils/watcher-runner.js.map +1 -0
  253. package/dist/utils/watcher.d.ts +27 -0
  254. package/dist/utils/watcher.js +51 -0
  255. package/dist/utils/watcher.js.map +1 -0
  256. package/oclif.manifest.json +1519 -501
  257. package/package.json +19 -8
  258. package/dist/commands/build.d.ts +0 -30
  259. package/dist/commands/build.js +0 -228
  260. package/dist/commands/build.js.map +0 -1
  261. package/dist/commands/deploy.d.ts +0 -20
  262. package/dist/commands/deploy.js +0 -141
  263. package/dist/commands/deploy.js.map +0 -1
  264. package/dist/commands/hello/index.d.ts +0 -12
  265. package/dist/commands/hello/index.js +0 -20
  266. package/dist/commands/hello/index.js.map +0 -1
  267. package/dist/commands/hello/world.d.ts +0 -8
  268. package/dist/commands/hello/world.js +0 -15
  269. package/dist/commands/hello/world.js.map +0 -1
  270. package/dist/commands/pool/provision.d.ts +0 -22
  271. package/dist/commands/pool/provision.js +0 -115
  272. package/dist/commands/pool/provision.js.map +0 -1
  273. package/dist/commands/project.js.map +0 -1
  274. package/dist/ui/pool-progress-renderer.d.ts +0 -68
  275. package/dist/ui/pool-progress-renderer.js +0 -298
  276. package/dist/ui/pool-progress-renderer.js.map +0 -1
  277. package/dist/utils/validation-watcher.js +0 -114
  278. package/dist/utils/validation-watcher.js.map +0 -1
  279. /package/dist/utils/{validation-watcher.d.ts → validation-runner.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { BootstrapTier, BuildOrchestrator, getPackagesForTier, InstallOrchestrator, PackageCreator, PackageService, ProjectService, } from '@b64hub/sfpm-core';
1
+ import { BuildOrchestrator, InstallOrchestrator, PackageCreator, PackageService, ProjectService, stripScope, ValidationResolver, WorkspaceProvider, } from '@b64hub/sfpm-core';
2
2
  import { confirm, select } from '@inquirer/prompts';
3
3
  import { Flags } from '@oclif/core';
4
4
  import { Org } from '@salesforce/core';
@@ -9,8 +9,10 @@ import os from 'node:os';
9
9
  import path from 'node:path';
10
10
  import ora from 'ora';
11
11
  import SfpmCommand from '../sfpm-command.js';
12
- import { errorBox, infoBox, successBox, warningBox, } from '../ui/boxes.js';
12
+ import { BootstrapTier, getPackagesForTier, resolveAction, } from '../types/bootstrap.js';
13
+ import { errorBox, infoBox, successBox, } from '../ui/boxes.js';
13
14
  import { BuildProgressRenderer } from '../ui/build-progress-renderer.js';
15
+ import { connectDevHub } from '../ui/connect-devhub.js';
14
16
  import { InstallProgressRenderer } from '../ui/install-progress-renderer.js';
15
17
  const BOOTSTRAP_REPO = 'https://github.com/b64hub/sfpm-bootstrap';
16
18
  const TIER_DESCRIPTIONS = {
@@ -27,9 +29,7 @@ export default class Bootstrap extends SfpmCommand {
27
29
  '<%= config.bin %> <%= command.id %> -o my-prod-org --force',
28
30
  ];
29
31
  static flags = {
30
- force: Flags.boolean({ char: 'f', description: 'force re-install even if packages are already installed' }),
31
- json: Flags.boolean({ description: 'output as JSON for CI/CD', exclusive: ['quiet'] }),
32
- quiet: Flags.boolean({ char: 'q', description: 'only show errors', exclusive: ['json'] }),
32
+ force: Flags.boolean({ char: 'f', description: 'force rebuild, re-promote, and re-install all packages' }),
33
33
  'target-org': Flags.string({ char: 'o', description: 'target org username (must also be a DevHub)', required: true }),
34
34
  tier: Flags.string({
35
35
  char: 't',
@@ -39,171 +39,149 @@ export default class Bootstrap extends SfpmCommand {
39
39
  };
40
40
  async execute() {
41
41
  const { flags } = await this.parse(Bootstrap);
42
- const mode = flags.json ? 'json' : flags.quiet ? 'quiet' : 'interactive';
43
- const isInteractive = mode === 'interactive';
44
- const logger = {
45
- debug: (msg) => this.debug(msg),
46
- error: (msg) => this.error(msg),
47
- info: (msg) => this.debug(msg),
48
- log: (msg) => this.log(msg),
49
- trace: (msg) => this.debug(msg),
50
- warn: (msg) => this.warn(msg),
42
+ const ctx = {
43
+ isInteractive: this.outputMode === 'interactive',
44
+ logger: this.sfpmLogger,
45
+ mode: this.outputMode,
46
+ targetOrg: flags['target-org'],
51
47
  };
52
- // ── Step 1: Select tier ─────────────────────────────────────────────
53
- const tier = await this.resolveTier(flags.tier, isInteractive);
48
+ const tier = await this.resolveTier(flags.tier, ctx.isInteractive);
54
49
  const selectedPackages = getPackagesForTier(tier);
55
50
  const packageNames = selectedPackages.map(p => p.name);
56
- if (isInteractive) {
51
+ if (ctx.isInteractive) {
57
52
  this.log(infoBox('Bootstrap', {
58
53
  Packages: packageNames.join(', '),
59
- 'Target Org': flags['target-org'],
54
+ 'Target Org': ctx.targetOrg,
60
55
  Tier: tier,
61
56
  }));
62
57
  }
63
- // ── Step 2: Clone bootstrap repo ────────────────────────────────────
64
- const tmpDir = await this.cloneRepo(isInteractive);
58
+ const tmpDir = await this.cloneRepo(ctx.isInteractive);
65
59
  try {
66
- // ── Step 3: Connect to org and verify DevHub ────────────────────
67
- const org = await this.connectToOrg(flags['target-org'], isInteractive);
68
- // ── Step 4: Check if packages are already installed ─────────────
69
- if (!flags.force) {
70
- const alreadyInstalled = await this.checkInstalledPackages(org, packageNames, logger);
71
- if (alreadyInstalled.length > 0) {
72
- if (isInteractive) {
73
- this.log(warningBox('Already Installed', {
74
- Hint: 'Use --force to re-install',
75
- Packages: alreadyInstalled.join(', '),
76
- }));
77
- }
78
- if (flags.json) {
79
- const result = {
80
- packages: alreadyInstalled.map(name => ({
81
- packageName: name, skipped: true, success: true,
82
- })),
83
- success: true,
84
- targetOrg: flags['target-org'],
85
- tier,
86
- };
87
- this.logJson(result);
88
- return result;
89
- }
90
- return;
91
- }
92
- }
93
- // ── Step 5: Ensure Package2 containers exist in DevHub ──────────
94
- const creator = new PackageCreator(org, logger);
95
- await creator.ensurePackages(selectedPackages, tmpDir, async (name) => {
96
- if (!isInteractive)
97
- return true;
98
- return confirm({
99
- default: true,
100
- message: `Package '${name}' does not exist in the DevHub. Create it?`,
101
- });
102
- });
103
- // ── Step 6: Load project from cloned repo ─────────────────────
104
- const projectService = await ProjectService.create(tmpDir);
105
- const projectConfig = projectService.getDefinitionProvider();
106
- const projectGraph = projectService.getProjectGraph();
107
- const sfpmConfig = projectService.getSfpmConfig();
108
- // ── Step 7: Build packages ────────────────────────────────────
109
- if (isInteractive) {
110
- this.log(chalk.bold('\nBuilding packages...\n'));
111
- }
112
- const buildOptions = {
113
- devhubUsername: flags['target-org'],
114
- force: true,
115
- includeDependencies: true,
116
- };
117
- const buildOrchestrator = new BuildOrchestrator(projectConfig, projectGraph, buildOptions, logger, tmpDir);
118
- const buildRenderer = new BuildProgressRenderer({
119
- logger: {
120
- error: (msgOrError) => this.error(msgOrError),
121
- log: (msg) => this.log(msg),
122
- },
123
- mode,
60
+ const { devhub: org } = await connectDevHub({
61
+ alias: ctx.targetOrg,
62
+ showSpinner: ctx.mode === 'interactive',
63
+ validate: [
64
+ {
65
+ label: 'Verifying DevHub status...',
66
+ async run(devhub) {
67
+ if (!await devhub.determineIfDevHubOrg()) {
68
+ throw new Error(`The target org '${ctx.targetOrg}' is not a DevHub. `
69
+ + 'Bootstrap requires a DevHub org to create and build packages. '
70
+ + 'Enable DevHub in Setup > Dev Hub or use a different org.');
71
+ }
72
+ },
73
+ },
74
+ ],
124
75
  });
125
- buildRenderer.attachTo(buildOrchestrator);
126
- const buildResult = await buildOrchestrator.buildAll(packageNames);
127
- if (!buildResult.success) {
128
- const failedNames = buildResult.failedPackages.join(', ');
129
- if (flags.json) {
130
- const result = {
131
- packages: buildResult.results.map(p => ({
132
- error: p.error, packageName: p.packageName, skipped: p.skipped, success: p.success,
133
- })),
134
- success: false,
135
- targetOrg: flags['target-org'],
136
- tier,
137
- };
138
- this.logJson(result);
139
- return result;
140
- }
141
- this.error(`Build failed for: ${failedNames}`, { exit: 1 });
76
+ // ── 1. Resolve per-package status ──────────────────────────────
77
+ const statuses = await this.resolvePackageStatuses(org, selectedPackages, flags.force ?? false, ctx);
78
+ // If everything is up-to-date, short-circuit
79
+ if (statuses.every(s => s.action === 'skip')) {
80
+ return this.handleAllUpToDate(statuses, tier, flags, ctx);
142
81
  }
143
- // ── Step 8: Install packages ──────────────────────────────────
144
- if (isInteractive) {
145
- this.log(chalk.bold('\nInstalling packages...\n'));
82
+ if (ctx.isInteractive) {
83
+ this.logPackageStatuses(statuses);
146
84
  }
147
- const installOptions = {
148
- force: flags.force,
149
- includeDependencies: true,
150
- targetOrg: flags['target-org'],
151
- trackHistory: sfpmConfig.artifacts?.trackHistory,
152
- };
153
- const installOrchestrator = new InstallOrchestrator(projectConfig, projectGraph, installOptions, logger);
154
- const installRenderer = new InstallProgressRenderer({
155
- logger: {
156
- error: (msgOrError) => this.error(msgOrError),
157
- log: (msg) => this.log(msg),
158
- },
159
- mode,
160
- targetOrg: flags['target-org'],
161
- });
162
- installRenderer.attachTo(installOrchestrator);
163
- const installResult = await installOrchestrator.installAll(packageNames);
164
- // ── Step 9: Report results ────────────────────────────────────
165
- const result = {
166
- packages: installResult.results.map(p => ({
167
- error: p.error, packageName: p.packageName, skipped: p.skipped, success: p.success,
168
- })),
169
- success: installResult.success,
170
- targetOrg: flags['target-org'],
171
- tier,
172
- };
173
- if (flags.json) {
174
- this.logJson(result);
175
- return result;
85
+ // ── 2. Setup project for packages that need building ──────────
86
+ const needsBuild = statuses.filter(s => s.action === 'build');
87
+ const needsPromote = statuses.filter(s => s.action === 'promote');
88
+ const needsInstall = statuses.filter(s => s.action === 'install' || s.action === 'build' || s.action === 'promote');
89
+ const results = statuses
90
+ .filter(s => s.action === 'skip')
91
+ .map(s => ({
92
+ action: 'skip', packageName: s.name, skipped: true, success: true, version: s.installedVersion,
93
+ }));
94
+ let projectService;
95
+ if (needsBuild.length > 0) {
96
+ projectService = await ProjectService.create(tmpDir);
97
+ const provider = projectService.getDefinitionProvider();
98
+ await this.ensurePackageContainers(org, {
99
+ ctx, packages: selectedPackages, provider, tmpDir,
100
+ });
101
+ // ponytail: syncSfdxProject now handled by WorkspaceProvider.resolve()
102
+ // ── 3. Build packages that need it ─────────────────────────
103
+ const buildNames = needsBuild.map(s => s.name);
104
+ const buildResult = await this.buildPackages(projectService, buildNames, flags.force ?? false, ctx);
105
+ if (!buildResult.success) {
106
+ for (const name of buildNames) {
107
+ const failed = buildResult.failedPackages?.includes(name);
108
+ if (failed) {
109
+ results.push({
110
+ action: 'build',
111
+ error: 'Build failed',
112
+ packageName: name,
113
+ skipped: false,
114
+ success: false,
115
+ });
116
+ }
117
+ }
118
+ }
119
+ const pendingValidations = buildResult.results.map(packageResult => packageResult.result?.pendingValidation).filter(descriptor => descriptor && descriptor.operationType === 'package-version-request');
120
+ const resolver = new ValidationResolver(projectService.getDefinitionProvider(), projectService.getProjectGraph(), this.sfpmLogger);
121
+ const validationResults = await resolver.resolve(pendingValidations);
176
122
  }
177
- if (installResult.success) {
178
- this.log(successBox('Bootstrap Complete', {
179
- Packages: packageNames.join(', '),
180
- 'Target Org': flags['target-org'],
181
- Tier: tier,
182
- }));
123
+ // ── 4. Promote unpromoted versions (newly built + previously built but not promoted) ──
124
+ const promoteNames = [
125
+ ...needsBuild.map(s => s.name),
126
+ ...needsPromote.map(s => s.name),
127
+ ];
128
+ if (promoteNames.length > 0) {
129
+ const promoteResults = await this.promotePackages(org, promoteNames, ctx);
130
+ for (const pr of promoteResults) {
131
+ if (!pr.success) {
132
+ results.push({
133
+ action: 'promote',
134
+ error: pr.error,
135
+ packageName: pr.name,
136
+ promoted: false,
137
+ skipped: false,
138
+ success: false,
139
+ });
140
+ }
141
+ }
183
142
  }
184
- else {
185
- const failedNames = installResult.failedPackages.join(', ');
186
- this.log(errorBox('Bootstrap Failed', {
187
- 'Failed Packages': failedNames,
188
- 'Target Org': flags['target-org'],
189
- }));
190
- this.error(`Install failed for: ${failedNames}`, { exit: 2 });
143
+ // ── 5. Install packages that need it ─────────────────────────
144
+ // Only install packages that haven't already failed
145
+ const failedNames = new Set(results.filter(r => !r.success).map(r => r.packageName));
146
+ const installNames = needsInstall
147
+ .map(s => s.name)
148
+ .filter(name => !failedNames.has(name));
149
+ if (installNames.length > 0) {
150
+ // Use a fresh dist-aware provider so packageVersionId + sourceHash from
151
+ // dist/package.json (written by the build step above) are visible.
152
+ const installService = await ProjectService.create(tmpDir, new WorkspaceProvider({ distAware: true, projectDir: tmpDir }));
153
+ const installResults = await this.installPackages(installService, installNames, flags, ctx);
154
+ for (const ir of installResults) {
155
+ results.push(ir);
156
+ }
191
157
  }
192
- return result;
158
+ return this.finalizeResult(results, tier, flags, ctx);
193
159
  }
194
160
  finally {
195
- // ── Step 10: Cleanup ──────────────────────────────────────────
196
- await this.cleanup(tmpDir, isInteractive);
161
+ await this.cleanup(tmpDir, ctx.isInteractive);
197
162
  }
198
163
  }
199
164
  // ====================================================================
200
- // Private helpers
165
+ // Pipeline steps
201
166
  // ====================================================================
202
- async checkInstalledPackages(org, packageNames, logger) {
203
- const service = new PackageService(org, logger);
204
- const installed = await service.getAllInstalled2GPPackages();
205
- const installedNames = new Set(installed.map(p => p.name));
206
- return packageNames.filter(name => installedNames.has(name));
167
+ async buildPackages(projectService, packageNames, force, ctx) {
168
+ if (ctx.isInteractive) {
169
+ this.log(chalk.bold('\nBuilding packages...\n'));
170
+ }
171
+ const devhubOrg = await Org.create({ aliasOrUsername: ctx.targetOrg });
172
+ const buildOrchestrator = BuildOrchestrator.create(projectService.getDefinitionProvider(), { devhub: devhubOrg }, projectService.getProjectGraph(), {
173
+ force, includeDependencies: true,
174
+ validation: 'org',
175
+ }, ctx.logger);
176
+ const buildRenderer = new BuildProgressRenderer({
177
+ logger: {
178
+ error: (msgOrError) => this.error(msgOrError),
179
+ log: (msg) => this.log(msg),
180
+ },
181
+ mode: ctx.mode,
182
+ });
183
+ buildRenderer.attachTo(buildOrchestrator.buildBus, buildOrchestrator.orchestrationBus);
184
+ return buildOrchestrator.buildAll(packageNames);
207
185
  }
208
186
  async cleanup(tmpDir, isInteractive) {
209
187
  try {
@@ -235,29 +213,256 @@ export default class Bootstrap extends SfpmCommand {
235
213
  }
236
214
  return tmpDir;
237
215
  }
238
- async connectToOrg(username, isInteractive) {
239
- let spinner;
240
- if (isInteractive) {
241
- spinner = ora(`Connecting to ${username}...`).start();
216
+ // ====================================================================
217
+ // Private helpers
218
+ // ====================================================================
219
+ async ensurePackageContainers(org, options) {
220
+ const creator = new PackageCreator(org, options.ctx.logger);
221
+ await creator.ensurePackages(options.packages, options.provider, options.tmpDir, async (name) => {
222
+ if (!options.ctx.isInteractive)
223
+ return true;
224
+ return confirm({
225
+ default: true,
226
+ message: `Package '${name}' does not exist in the DevHub. Create it?`,
227
+ });
228
+ });
229
+ }
230
+ finalizeResult(results, tier, flags, ctx) {
231
+ const result = {
232
+ packages: results,
233
+ success: results.every(r => r.success),
234
+ targetOrg: ctx.targetOrg,
235
+ tier,
236
+ };
237
+ if (this.outputMode !== 'json') {
238
+ this.renderFinalResult(result, ctx);
242
239
  }
243
- try {
244
- const org = await Org.create({ aliasOrUsername: username });
245
- if (!await org.determineIfDevHubOrg()) {
246
- spinner?.fail(`${username} is not a DevHub`);
247
- throw new Error(`The target org '${username}' is not a DevHub. `
248
- + 'Bootstrap requires a DevHub org to create and build packages. '
249
- + 'Enable DevHub in Setup > Dev Hub or use a different org.');
240
+ return result;
241
+ }
242
+ handleAllUpToDate(statuses, tier, _flags, ctx) {
243
+ const result = {
244
+ packages: statuses.map(s => ({
245
+ action: 'skip',
246
+ packageName: s.name,
247
+ skipped: true,
248
+ success: true,
249
+ version: s.installedVersion,
250
+ })),
251
+ success: true,
252
+ targetOrg: ctx.targetOrg,
253
+ tier,
254
+ };
255
+ if (ctx.isInteractive) {
256
+ this.log(successBox('All packages up-to-date', {
257
+ Hint: 'Use --force to rebuild and re-install',
258
+ Packages: statuses.map(s => `${stripScope(s.name)} (${s.installedVersion})`).join(', '),
259
+ 'Target Org': ctx.targetOrg,
260
+ }));
261
+ }
262
+ return result;
263
+ }
264
+ async installPackages(projectService, packageNames, flags, ctx) {
265
+ if (ctx.isInteractive) {
266
+ this.log(chalk.bold('\nInstalling packages...\n'));
267
+ }
268
+ const sfpmConfig = projectService.getSfpmConfig();
269
+ const targetOrg = await Org.create({ aliasOrUsername: ctx.targetOrg });
270
+ const installOrchestrator = InstallOrchestrator.forArtifact(targetOrg, projectService.getDefinitionProvider(), projectService.getProjectGraph(), {
271
+ force: flags.force,
272
+ includeDependencies: true,
273
+ testLevel: 'RunLocalTests',
274
+ }, ctx.logger);
275
+ const installRenderer = new InstallProgressRenderer({
276
+ logger: {
277
+ error: (msgOrError) => this.error(msgOrError),
278
+ log: (msg) => this.log(msg),
279
+ },
280
+ mode: ctx.mode,
281
+ targetOrg: ctx.targetOrg,
282
+ });
283
+ installRenderer.attachTo(installOrchestrator.installBus, installOrchestrator.orchestrationBus);
284
+ const installResult = await installOrchestrator.installAll(packageNames);
285
+ return installResult.results.map(p => ({
286
+ action: 'install',
287
+ error: p.error,
288
+ packageName: p.packageName,
289
+ skipped: p.skipped,
290
+ success: p.success,
291
+ }));
292
+ }
293
+ logPackageStatuses(statuses) {
294
+ const lines = [];
295
+ for (const s of statuses) {
296
+ const name = stripScope(s.name);
297
+ switch (s.action) {
298
+ case 'build': {
299
+ lines.push(chalk.yellow(` [build] ${name}`));
300
+ break;
301
+ }
302
+ case 'install': {
303
+ lines.push(chalk.blue(` [install] ${name} (${s.latestReleasedVersion})`));
304
+ break;
305
+ }
306
+ case 'promote': {
307
+ lines.push(chalk.magenta(` [promote] ${name} (${s.latestReleasedVersion})`));
308
+ break;
309
+ }
310
+ case 'skip': {
311
+ lines.push(chalk.dim(` [skip] ${name} (${s.installedVersion})`));
312
+ break;
313
+ }
250
314
  }
251
- spinner?.succeed(`Connected to ${username} (DevHub)`);
252
- return org;
253
315
  }
254
- catch (error) {
255
- if (error instanceof Error && error.message.includes('not a DevHub')) {
256
- throw error;
316
+ this.log(`\n${lines.join('\n')}\n`);
317
+ }
318
+ async promotePackages(org, packageNames, ctx) {
319
+ if (ctx.isInteractive) {
320
+ this.log(chalk.bold('\nPromoting package versions...\n'));
321
+ }
322
+ const devhubService = new PackageService(org, ctx.logger);
323
+ const results = [];
324
+ // Pre-fetch all packages once to avoid repeated API calls
325
+ const allPackages = await devhubService.listPackages();
326
+ for (const name of packageNames) {
327
+ const unscopedName = stripScope(name);
328
+ let spinner;
329
+ if (ctx.isInteractive) {
330
+ spinner = ora(`Promoting ${unscopedName}...`).start();
331
+ }
332
+ try {
333
+ const pkg = allPackages.find(p => p.Name === unscopedName);
334
+ if (!pkg) {
335
+ const error = `Package "${unscopedName}" not found in DevHub`;
336
+ spinner?.fail(error);
337
+ results.push({ error, name, success: false });
338
+ continue;
339
+ }
340
+ // Get the latest non-released version (the one we just built)
341
+ const versions = await devhubService.listPackageVersions({ packages: [pkg.Id] }); // eslint-disable-line no-await-in-loop
342
+ const unpromoted = versions.find(v => !v.IsReleased);
343
+ if (!unpromoted) {
344
+ // All versions are already promoted — nothing to do
345
+ spinner?.succeed(`${unscopedName} -- already promoted`);
346
+ results.push({ name, success: true });
347
+ continue;
348
+ }
349
+ await devhubService.promoteVersion(unpromoted.SubscriberPackageVersionId); // eslint-disable-line no-await-in-loop
350
+ spinner?.succeed(`${unscopedName} -- promoted (${unpromoted.SubscriberPackageVersionId})`);
351
+ results.push({ name, success: true });
257
352
  }
258
- spinner?.fail(`Failed to connect to ${username}`);
259
- throw new Error(`Unable to connect to org '${username}'. Ensure the org is authenticated via 'sf org login'.`, { cause: error instanceof Error ? error : undefined });
353
+ catch (error) {
354
+ const message = error instanceof Error ? error.message : String(error);
355
+ spinner?.fail(`${unscopedName} -- promote failed: ${message}`);
356
+ results.push({ error: message, name, success: false });
357
+ // Continue with next package — promotion can be retried on re-run
358
+ }
359
+ }
360
+ return results;
361
+ }
362
+ renderFinalResult(result, ctx) {
363
+ if (!ctx.isInteractive)
364
+ return;
365
+ if (result.success) {
366
+ const details = {
367
+ 'Target Org': ctx.targetOrg,
368
+ Tier: result.tier,
369
+ };
370
+ const installed = result.packages.filter(p => !p.skipped);
371
+ if (installed.length > 0) {
372
+ details.Installed = installed.map(p => p.packageName).join(', ');
373
+ }
374
+ const skipped = result.packages.filter(p => p.skipped);
375
+ if (skipped.length > 0) {
376
+ details.Skipped = skipped.map(p => p.packageName).join(', ');
377
+ }
378
+ this.log(successBox('Bootstrap Complete', details));
379
+ }
380
+ else {
381
+ const failed = result.packages.filter(p => !p.success);
382
+ this.log(errorBox('Bootstrap Failed', {
383
+ 'Failed Packages': failed.map(p => `${p.packageName}: ${p.error ?? 'unknown error'}`).join('\n'),
384
+ Hint: 'Re-run the command to retry failed packages',
385
+ 'Target Org': ctx.targetOrg,
386
+ }));
387
+ }
388
+ }
389
+ /**
390
+ * Resolve per-package action by comparing DevHub versions to what's installed.
391
+ *
392
+ * - skip: installed version >= latest released version
393
+ * - install: a released version exists that's newer than what's installed
394
+ * - promote: an unreleased version exists (built but not promoted)
395
+ * - build: no version exists at all, or --force is set
396
+ */
397
+ async resolvePackageStatuses(org, selectedPackages, force, ctx) {
398
+ let spinner;
399
+ if (ctx.isInteractive) {
400
+ spinner = ora('Checking package versions...').start();
401
+ }
402
+ const devhubService = new PackageService(org, ctx.logger);
403
+ const installed = await devhubService.listInstalledPackages();
404
+ const installedByName = new Map(installed.map(p => [p.SubscriberPackage?.Name ?? '', p]));
405
+ const allDevHubPackages = await devhubService.listPackages();
406
+ const statuses = [];
407
+ // Sequential: each package queried individually from DevHub
408
+ for (const pkg of selectedPackages) {
409
+ const unscopedName = stripScope(pkg.name);
410
+ if (force) {
411
+ statuses.push({ action: 'build', name: pkg.name });
412
+ continue;
413
+ }
414
+ // Find the Package2 in the DevHub
415
+ const devhubPkg = allDevHubPackages.find(p => p.Name === unscopedName);
416
+ if (!devhubPkg) {
417
+ statuses.push({
418
+ action: resolveAction({
419
+ force, hasPackage: false, hasReleasedVersions: false, hasUnreleasedVersions: false,
420
+ }), name: pkg.name,
421
+ });
422
+ continue;
423
+ }
424
+ // Get released versions
425
+ // eslint-disable-next-line no-await-in-loop
426
+ const releasedVersions = await devhubService.listPackageVersions({ isReleased: true, packages: [devhubPkg.Id] });
427
+ // Get all versions (to detect unreleased)
428
+ const allVersions = releasedVersions.length === 0
429
+ ? await devhubService.listPackageVersions({ packages: [devhubPkg.Id] }) // eslint-disable-line no-await-in-loop
430
+ : releasedVersions;
431
+ const latestReleased = releasedVersions[0];
432
+ const latestVersion = latestReleased
433
+ ? `${latestReleased.MajorVersion}.${latestReleased.MinorVersion}.${latestReleased.PatchVersion}.${latestReleased.BuildNumber}`
434
+ : undefined;
435
+ const installedPkg = installedByName.get(unscopedName);
436
+ const installedSpv = installedPkg?.SubscriberPackageVersion;
437
+ const installedVersion = installedSpv
438
+ ? `${installedSpv.MajorVersion}.${installedSpv.MinorVersion}.${installedSpv.PatchVersion}.${installedSpv.BuildNumber}`
439
+ : undefined;
440
+ const action = resolveAction({
441
+ force,
442
+ hasPackage: true,
443
+ hasReleasedVersions: releasedVersions.length > 0,
444
+ hasUnreleasedVersions: allVersions.length > 0 && releasedVersions.length === 0,
445
+ installedVersion,
446
+ latestVersion,
447
+ });
448
+ const latest = latestReleased ?? allVersions[0];
449
+ const versionStr = latest
450
+ ? `${latest.MajorVersion}.${latest.MinorVersion}.${latest.PatchVersion}.${latest.BuildNumber}`
451
+ : undefined;
452
+ statuses.push({
453
+ action,
454
+ installedVersion,
455
+ latestReleasedVersion: versionStr,
456
+ name: pkg.name,
457
+ subscriberVersionId: latest?.SubscriberPackageVersionId,
458
+ });
260
459
  }
460
+ const skipped = statuses.filter(s => s.action === 'skip').length;
461
+ const builds = statuses.filter(s => s.action === 'build').length;
462
+ const promotes = statuses.filter(s => s.action === 'promote').length;
463
+ const installs = statuses.filter(s => s.action === 'install').length;
464
+ spinner?.succeed(`Version check complete: ${skipped} up-to-date, ${builds} need build, ${promotes} need promote, ${installs} need install`);
465
+ return statuses;
261
466
  }
262
467
  async resolveTier(flagValue, isInteractive) {
263
468
  if (flagValue) {