Skip to content

Commit 4cf7249

Browse files
committed
feat: add cartridges config option and improve deploy command output
Add `cartridges` config key (with `cartridgesPath` alias) to dw.json, env vars (SFCC_CARTRIDGES), and NormalizedConfig. Supports comma or colon-separated strings and arrays. Falls back from `-c` flag to config value in CartridgeCommand. Deploy command now logs cartridge list, delete step, and summary to stdout.
1 parent 16bd9d6 commit 4cf7249

7 files changed

Lines changed: 53 additions & 13 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@salesforce/b2c-cli': patch
3+
'@salesforce/b2c-tooling-sdk': patch
4+
---
5+
6+
Add `cartridges` config option to specify which cartridges to deploy/watch. Supports comma or colon-separated strings, or arrays in dw.json. Also accepts `cartridgesPath` as an alias. The `-c` flag still takes precedence when provided.

packages/b2c-cli/src/commands/code/deploy.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ export default class CodeDeploy extends CartridgeCommand<typeof CodeDeploy> {
134134
this.error(t('commands.code.deploy.noCartridges', 'No cartridges found in {{path}}', {path: this.cartridgePath}));
135135
}
136136

137-
this.logger?.info(
138-
{path: this.cartridgePath, server: hostname, codeVersion: version},
139-
t('commands.code.deploy.deploying', 'Deploying {{path}} to {{hostname}} ({{version}})', {
137+
this.log(
138+
t('commands.code.deploy.deploying', 'Deploying {{path}} to {{hostname}} ({{version}})...', {
140139
path: this.cartridgePath,
141140
hostname,
142141
version,
@@ -145,12 +144,13 @@ export default class CodeDeploy extends CartridgeCommand<typeof CodeDeploy> {
145144

146145
// Log found cartridges
147146
for (const c of cartridges) {
148-
this.logger?.debug({cartridgeName: c.name, path: c.src}, ` ${c.name}`);
147+
this.log(` ${c.name} (${c.src})`);
149148
}
150149

151150
try {
152151
// Optionally delete existing cartridges first
153152
if (this.flags.delete) {
153+
this.log(t('commands.code.deploy.deleting', 'Deleting existing cartridges...'));
154154
await this.operations.deleteCartridges(this.instance, cartridges);
155155
}
156156

@@ -174,12 +174,15 @@ export default class CodeDeploy extends CartridgeCommand<typeof CodeDeploy> {
174174
reloaded,
175175
};
176176

177-
this.logger?.info(
178-
{codeVersion: result.codeVersion, cartridgeCount: result.cartridges.length},
179-
t('commands.code.deploy.summary', 'Deployed {{count}} cartridge(s) to {{codeVersion}}', {
180-
count: result.cartridges.length,
181-
codeVersion: result.codeVersion,
182-
}),
177+
this.log(
178+
t(
179+
'commands.code.deploy.summary',
180+
'Deployed {{count}} cartridge(s) to version "{{codeVersion}}" successfully!',
181+
{
182+
count: result.cartridges.length,
183+
codeVersion: result.codeVersion,
184+
},
185+
),
183186
);
184187

185188
if (result.reloaded) {

packages/b2c-tooling-sdk/src/cli/cartridge-command.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,15 @@ export abstract class CartridgeCommand<T extends typeof Command> extends Instanc
107107
}
108108

109109
/**
110-
* Gets the cartridge filter options from flags.
110+
* Gets the cartridge filter options from flags, falling back to
111+
* the `cartridges` config value (from dw.json or env) when no
112+
* `-c` / `--cartridge` flag is provided.
111113
*/
112114
protected get cartridgeOptions(): FindCartridgesOptions {
115+
const flagCartridges = this.flags.cartridge as string[] | undefined;
116+
const configCartridges = this.resolvedConfig?.values.cartridges;
113117
return {
114-
include: this.flags.cartridge as string[] | undefined,
118+
include: flagCartridges ?? configCartridges,
115119
exclude: this.flags['exclude-cartridge'] as string[] | undefined,
116120
};
117121
}

packages/b2c-tooling-sdk/src/config/dw-json.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export interface DwJsonConfig {
7575
sandboxApiHost?: string;
7676
/** Default ODS realm for sandbox operations */
7777
realm?: string;
78+
/** Cartridge names to include in deploy/watch (string with colon/comma separators, or array) */
79+
cartridges?: string | string[];
7880
/** Default content library ID for content export/list commands */
7981
contentLibrary?: string;
8082
/** Optional CIP analytics host override */

packages/b2c-tooling-sdk/src/config/mapping.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const CONFIG_KEY_ALIASES: Record<string, string> = {
4444
'secure-server': 'webdavHostname',
4545
secureHostname: 'webdavHostname',
4646
passphrase: 'certificatePassphrase',
47+
cartridgesPath: 'cartridges',
4748
cloudOrigin: 'mrtOrigin',
4849
selfsigned: 'selfSigned',
4950
'oauth-scopes': 'oauthScopes',
@@ -103,6 +104,20 @@ export function normalizeConfigKeys(raw: Record<string, unknown>): Record<string
103104
* // { hostname: 'example.com', codeVersion: 'v1' }
104105
* ```
105106
*/
107+
/**
108+
* Parses a cartridges value that may be a colon-separated string,
109+
* comma-separated string, or already an array.
110+
*/
111+
function parseCartridges(value: string | string[] | undefined): string[] | undefined {
112+
if (value === undefined) return undefined;
113+
if (Array.isArray(value)) return value.length > 0 ? value : undefined;
114+
const items = value
115+
.split(/[,:]/)
116+
.map((s) => s.trim())
117+
.filter(Boolean);
118+
return items.length > 0 ? items : undefined;
119+
}
120+
106121
export function mapDwJsonToNormalizedConfig(json: DwJsonConfig): NormalizedConfig {
107122
return {
108123
hostname: json.hostname,
@@ -120,6 +135,7 @@ export function mapDwJsonToNormalizedConfig(json: DwJsonConfig): NormalizedConfi
120135
tenantId: json.tenantId,
121136
sandboxApiHost: json.sandboxApiHost,
122137
realm: json.realm,
138+
cartridges: parseCartridges(json.cartridges),
123139
contentLibrary: json.contentLibrary,
124140
cipHost: json.cipHost,
125141
instanceName: json.name,
@@ -204,6 +220,9 @@ export function mapNormalizedConfigToDwJson(config: Partial<NormalizedConfig>, n
204220
if (config.accountManagerHost !== undefined) {
205221
result.accountManagerHost = config.accountManagerHost;
206222
}
223+
if (config.cartridges !== undefined) {
224+
result.cartridges = config.cartridges;
225+
}
207226
if (config.cipHost !== undefined) {
208227
result.cipHost = config.cipHost;
209228
}
@@ -328,6 +347,7 @@ export function mergeConfigsWithProtection(
328347
accountManagerHost: overrides.accountManagerHost ?? base.accountManagerHost,
329348
shortCode: overrides.shortCode ?? base.shortCode,
330349
tenantId: overrides.tenantId ?? base.tenantId,
350+
cartridges: overrides.cartridges ?? base.cartridges,
331351
contentLibrary: overrides.contentLibrary ?? base.contentLibrary,
332352
cipHost: overrides.cipHost ?? base.cipHost,
333353
sandboxApiHost: overrides.sandboxApiHost ?? base.sandboxApiHost,

packages/b2c-tooling-sdk/src/config/sources/env-source.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const ENV_VAR_MAP: Record<string, keyof NormalizedConfig> = {
3333
SFCC_OAUTH_SCOPES: 'scopes',
3434
SFCC_SHORTCODE: 'shortCode',
3535
SFCC_TENANT_ID: 'tenantId',
36+
SFCC_CARTRIDGES: 'cartridges',
3637
SFCC_AUTH_METHODS: 'authMethods',
3738
SFCC_ACCOUNT_MANAGER_HOST: 'accountManagerHost',
3839
SFCC_SANDBOX_API_HOST: 'sandboxApiHost',
@@ -48,7 +49,7 @@ const ENV_VAR_MAP: Record<string, keyof NormalizedConfig> = {
4849
};
4950

5051
/** Fields that should be parsed as comma-separated arrays. */
51-
const ARRAY_FIELDS = new Set<keyof NormalizedConfig>(['scopes', 'authMethods']);
52+
const ARRAY_FIELDS = new Set<keyof NormalizedConfig>(['scopes', 'authMethods', 'cartridges']);
5253

5354
/** Fields that should be parsed as booleans. */
5455
const BOOLEAN_FIELDS = new Set<keyof NormalizedConfig>(['selfSigned']);

packages/b2c-tooling-sdk/src/config/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ export interface NormalizedConfig {
8787
/** MRT API origin URL override */
8888
mrtOrigin?: string;
8989

90+
// Cartridges
91+
/** Cartridge names to include in deploy/watch operations */
92+
cartridges?: string[];
93+
9094
// Content
9195
/** Default content library ID for content export/list commands */
9296
contentLibrary?: string;

0 commit comments

Comments
 (0)