-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathactivate.ts
More file actions
107 lines (96 loc) · 3.35 KB
/
activate.ts
File metadata and controls
107 lines (96 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (c) 2025, Salesforce, Inc.
* SPDX-License-Identifier: Apache-2
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import {Args, Flags} from '@oclif/core';
import {InstanceCommand} from '@salesforce/b2c-tooling-sdk/cli';
import {activateCodeVersion, reloadCodeVersion} from '@salesforce/b2c-tooling-sdk/operations/code';
import {t} from '../../i18n/index.js';
export default class CodeActivate extends InstanceCommand<typeof CodeActivate> {
static args = {
codeVersion: Args.string({
description: 'Code version ID to activate',
required: false,
}),
};
static description = t('commands.code.activate.description', 'Activate or reload a code version');
static examples = [
'<%= config.bin %> <%= command.id %> v1',
'<%= config.bin %> <%= command.id %> v1 --server my-sandbox.demandware.net',
'<%= config.bin %> <%= command.id %> --reload',
'<%= config.bin %> <%= command.id %> v1 --reload',
];
static flags = {
...InstanceCommand.baseFlags,
reload: Flags.boolean({
char: 'r',
description: 'Reload the code version (toggle activation to force reload)',
default: false,
}),
};
async run(): Promise<void> {
this.requireOAuthCredentials();
const codeVersionArg = this.args.codeVersion;
const hostname = this.resolvedConfig.values.hostname!;
// Get code version from arg, flag, or config
const codeVersion = codeVersionArg ?? this.resolvedConfig.values.codeVersion;
if (this.flags.reload) {
// Reload mode - re-activate the code version
this.log(
t('commands.code.activate.reloading', 'Reloading code version{{version}} on {{hostname}}...', {
hostname,
version: codeVersion ? ` ${codeVersion}` : '',
}),
);
try {
await reloadCodeVersion(this.instance, codeVersion);
this.log(
t('commands.code.activate.reloaded', 'Code version{{version}} reloaded successfully', {
version: codeVersion ? ` ${codeVersion}` : '',
}),
);
} catch (error) {
if (error instanceof Error) {
this.error(
t('commands.code.activate.reloadFailed', 'Failed to reload code version: {{message}}', {
message: error.message,
}),
);
}
throw error;
}
} else {
// Activate mode - just activate the code version
if (!codeVersion) {
this.error(
t(
'commands.code.activate.versionRequired',
'Code version is required. Provide as argument or use --code-version flag.',
),
);
}
this.log(
t('commands.code.activate.activating', 'Activating code version {{codeVersion}} on {{hostname}}...', {
hostname,
codeVersion,
}),
);
try {
await activateCodeVersion(this.instance, codeVersion);
this.log(
t('commands.code.activate.activated', 'Code version {{codeVersion}} activated successfully', {codeVersion}),
);
} catch (error) {
if (error instanceof Error) {
this.error(
t('commands.code.activate.failed', 'Failed to activate code version: {{message}}', {
message: error.message,
}),
);
}
throw error;
}
}
}
}