Skip to content

Commit ecc1a9b

Browse files
authored
update env create semantics (#12)
* update env create semantics * removing demo data
1 parent f29479a commit ecc1a9b

10 files changed

Lines changed: 271 additions & 150 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ docs/.vitepress/cache
2424
docs/api/
2525

2626
dw.json
27+
dw.json*

AGENTS.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1+
# B2C CLI
12

2-
- this is a monorepo project; packages:
3-
- ./packages/b2c-cli - the command line interface built with oclif
4-
- ./packages/b2c-tooling-sdk - the SDK/library for B2C Commerce operations; support the CLI and can be used standalone
3+
This is a monorepo project with the following packages:
4+
- `./packages/b2c-cli` - the command line interface built with oclif
5+
- `./packages/b2c-tooling-sdk` - the SDK/library for B2C Commerce operations; supports the CLI and can be used standalone
6+
7+
## Common Commands
8+
9+
```bash
10+
# Install dependencies
11+
pnpm install
12+
13+
# Build all packages
14+
pnpm run build
15+
16+
# Build specific package
17+
pnpm --filter @salesforce/b2c-cli run build
18+
pnpm --filter @salesforce/b2c-tooling-sdk run build
19+
20+
# Run tests (includes linting)
21+
pnpm run test
22+
23+
# Run tests for specific package
24+
pnpm --filter @salesforce/b2c-cli run test
25+
pnpm --filter @salesforce/b2c-tooling-sdk run test
26+
27+
# Format code with prettier
28+
pnpm run -r format
29+
30+
# Lint only (without tests)
31+
pnpm run -r lint
32+
33+
# Run CLI in development mode
34+
./packages/b2c-cli/bin/dev.js <command>
35+
```
536

637
## Setup/Packaging
738

b2c_log_center_stream3.png

-46.8 KB
Binary file not shown.

dw.json.bak

Lines changed: 0 additions & 1 deletion
This file was deleted.

easy-setup-step-by-step.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

easy-setup.sh

Lines changed: 0 additions & 85 deletions
This file was deleted.

packages/b2c-cli/src/commands/mrt/env/create.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import {Args, Flags, ux} from '@oclif/core';
77
import cliui from 'cliui';
88
import {MrtCommand} from '@salesforce/b2c-tooling-sdk/cli';
9-
import {createEnv, type MrtEnvironment} from '@salesforce/b2c-tooling-sdk/operations/mrt';
9+
import {createEnv, waitForEnv, type MrtEnvironment} from '@salesforce/b2c-tooling-sdk/operations/mrt';
1010
import {t} from '../../../i18n/index.js';
1111

1212
/**
@@ -140,18 +140,19 @@ export default class MrtEnvCreate extends MrtCommand<typeof MrtEnvCreate> {
140140
static enableJsonFlag = true;
141141

142142
static examples = [
143+
'<%= config.bin %> <%= command.id %> staging --project my-storefront',
143144
'<%= config.bin %> <%= command.id %> staging --project my-storefront --name "Staging Environment"',
144-
'<%= config.bin %> <%= command.id %> production --project my-storefront --name "Production" --production',
145-
'<%= config.bin %> <%= command.id %> feature-test -p my-storefront -n "Feature Test" --region eu-west-1',
146-
'<%= config.bin %> <%= command.id %> staging -p my-storefront -n "Staging" --proxy api=api.example.com --proxy ocapi=ocapi.example.com',
145+
'<%= config.bin %> <%= command.id %> production --project my-storefront --production',
146+
'<%= config.bin %> <%= command.id %> feature-test -p my-storefront --region eu-west-1',
147+
'<%= config.bin %> <%= command.id %> staging -p my-storefront --proxy api=api.example.com --proxy ocapi=ocapi.example.com',
148+
'<%= config.bin %> <%= command.id %> staging -p my-storefront --wait',
147149
];
148150

149151
static flags = {
150152
...MrtCommand.baseFlags,
151153
name: Flags.string({
152154
char: 'n',
153-
description: 'Display name for the environment',
154-
required: true,
155+
description: 'Display name for the environment (defaults to slug)',
155156
}),
156157
region: Flags.string({
157158
char: 'r',
@@ -185,6 +186,11 @@ export default class MrtEnvCreate extends MrtCommand<typeof MrtEnvCreate> {
185186
description: 'Proxy configuration in format path=host (can be specified multiple times)',
186187
multiple: true,
187188
}),
189+
wait: Flags.boolean({
190+
char: 'w',
191+
description: 'Wait for the environment to be ready before returning',
192+
default: false,
193+
}),
188194
};
189195

190196
async run(): Promise<MrtEnvironment> {
@@ -200,7 +206,7 @@ export default class MrtEnvCreate extends MrtCommand<typeof MrtEnvCreate> {
200206
}
201207

202208
const {
203-
name,
209+
name: nameFlag,
204210
region,
205211
production: isProduction,
206212
hostname,
@@ -209,8 +215,12 @@ export default class MrtEnvCreate extends MrtCommand<typeof MrtEnvCreate> {
209215
'allow-cookies': allowCookies,
210216
'enable-source-maps': enableSourceMaps,
211217
proxy: proxyStrings,
218+
wait,
212219
} = this.flags;
213220

221+
// Default name to slug if not provided
222+
const name = nameFlag ?? slug;
223+
214224
// Parse proxy configurations
215225
const proxyConfigs = proxyStrings?.map((p) => parseProxyString(p));
216226

@@ -219,7 +229,7 @@ export default class MrtEnvCreate extends MrtCommand<typeof MrtEnvCreate> {
219229
);
220230

221231
try {
222-
const result = await createEnv(
232+
let result = await createEnv(
223233
{
224234
projectSlug: project,
225235
slug,
@@ -237,6 +247,32 @@ export default class MrtEnvCreate extends MrtCommand<typeof MrtEnvCreate> {
237247
this.getMrtAuth(),
238248
);
239249

250+
// Wait for environment to be ready if requested
251+
if (wait) {
252+
this.log(t('commands.mrt.env.create.waiting', 'Waiting for environment "{{slug}}" to be ready...', {slug}));
253+
254+
const waitStartTime = Date.now();
255+
result = await waitForEnv(
256+
{
257+
projectSlug: project,
258+
slug,
259+
origin: this.resolvedConfig.mrtOrigin,
260+
onPoll: (env) => {
261+
if (!this.jsonEnabled()) {
262+
const elapsed = Math.round((Date.now() - waitStartTime) / 1000);
263+
this.log(
264+
t('commands.mrt.env.create.state', '[{{elapsed}}s] State: {{state}}', {
265+
elapsed: String(elapsed),
266+
state: env.state ?? 'unknown',
267+
}),
268+
);
269+
}
270+
},
271+
},
272+
this.getMrtAuth(),
273+
);
274+
}
275+
240276
if (this.jsonEnabled()) {
241277
return result;
242278
}

packages/b2c-cli/src/commands/ods/create.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ export default class OdsCreate extends OdsCommand<typeof OdsCreate> {
253253
const startTime = Date.now();
254254
const pollIntervalMs = pollIntervalSeconds * 1000;
255255
const timeoutMs = timeoutSeconds * 1000;
256-
let lastState: SandboxState | undefined;
257256

258257
this.log(t('commands.ods.create.waiting', 'Waiting for sandbox to be ready...'));
259258

@@ -285,17 +284,14 @@ export default class OdsCreate extends OdsCommand<typeof OdsCreate> {
285284
const sandbox = result.data.data;
286285
const currentState = sandbox.state as SandboxState;
287286

288-
// Log state changes
289-
if (currentState !== lastState) {
290-
const elapsed = Math.round((Date.now() - startTime) / 1000);
291-
this.log(
292-
t('commands.ods.create.stateChange', '[{{elapsed}}s] State: {{state}}', {
293-
elapsed: String(elapsed),
294-
state: currentState || 'unknown',
295-
}),
296-
);
297-
lastState = currentState;
298-
}
287+
// Log current state on each poll
288+
const elapsed = Math.round((Date.now() - startTime) / 1000);
289+
this.log(
290+
t('commands.ods.create.stateChange', '[{{elapsed}}s] State: {{state}}', {
291+
elapsed: String(elapsed),
292+
state: currentState || 'unknown',
293+
}),
294+
);
299295

300296
// Check for terminal states
301297
if (currentState && TERMINAL_STATES.has(currentState)) {

0 commit comments

Comments
 (0)