|
1 | | -import { Args, Command, Flags } from '@oclif/core'; |
2 | | -import { B2CInstance, uploadCartridges } from '@salesforce/b2c-tooling'; |
3 | | -import { loadConfig } from '../../config/loader.js'; |
4 | | -import { AuthResolver } from '../../config/auth-resolver.js'; |
| 1 | +import { Args } from '@oclif/core' |
| 2 | +import { uploadCartridges } from '@salesforce/b2c-tooling' |
| 3 | +import { InstanceCommand } from '@salesforce/b2c-tooling/cli' |
5 | 4 |
|
6 | | -export default class Deploy extends Command { |
| 5 | +export default class Deploy extends InstanceCommand<typeof Deploy> { |
7 | 6 | static args = { |
8 | 7 | cartridgePath: Args.string({ |
9 | 8 | description: 'Path to cartridges directory', |
10 | 9 | default: './cartridges', |
11 | 10 | }), |
12 | | - }; |
| 11 | + } |
13 | 12 |
|
14 | | - static description = 'Deploy cartridges to a B2C Commerce instance'; |
| 13 | + static description = 'Deploy cartridges to a B2C Commerce instance' |
15 | 14 |
|
16 | 15 | static examples = [ |
17 | 16 | '<%= config.bin %> <%= command.id %>', |
18 | 17 | '<%= config.bin %> <%= command.id %> ./my-cartridges', |
19 | | - '<%= config.bin %> <%= command.id %> --hostname my-sandbox.demandware.net --code-version v1', |
20 | | - ]; |
21 | | - |
22 | | - static flags = { |
23 | | - hostname: Flags.string({ |
24 | | - char: 'h', |
25 | | - description: 'Instance hostname', |
26 | | - }), |
27 | | - 'code-version': Flags.string({ |
28 | | - char: 'v', |
29 | | - description: 'Code version to deploy to', |
30 | | - }), |
31 | | - username: Flags.string({ |
32 | | - char: 'u', |
33 | | - description: 'Username for Basic Auth', |
34 | | - }), |
35 | | - password: Flags.string({ |
36 | | - char: 'p', |
37 | | - description: 'Password for Basic Auth', |
38 | | - }), |
39 | | - 'client-id': Flags.string({ |
40 | | - description: 'Client ID for OAuth', |
41 | | - }), |
42 | | - 'client-secret': Flags.string({ |
43 | | - description: 'Client Secret for OAuth', |
44 | | - }), |
45 | | - }; |
| 18 | + '<%= config.bin %> <%= command.id %> --server my-sandbox.demandware.net --code-version v1', |
| 19 | + ] |
46 | 20 |
|
47 | 21 | async run(): Promise<void> { |
48 | | - const { args, flags } = await this.parse(Deploy); |
49 | | - |
50 | | - // 1. Load Config with precedence (CLI > Env > dw.json) |
51 | | - const config = await loadConfig({ |
52 | | - hostname: flags.hostname, |
53 | | - codeVersion: flags['code-version'], |
54 | | - username: flags.username, |
55 | | - password: flags.password, |
56 | | - clientId: flags['client-id'], |
57 | | - clientSecret: flags['client-secret'], |
58 | | - }); |
59 | | - |
60 | | - // Validate required config |
61 | | - if (!config.hostname) { |
62 | | - this.error('Hostname is required. Set via --hostname, DW_HOSTNAME env var, or dw.json'); |
63 | | - } |
64 | | - |
65 | | - if (!config.codeVersion) { |
66 | | - this.error( |
67 | | - 'Code version is required. Set via --code-version, DW_CODE_VERSION env var, or dw.json' |
68 | | - ); |
69 | | - } |
70 | | - |
71 | | - // 2. Create Auth Resolver |
72 | | - const resolver = new AuthResolver(config); |
73 | | - |
74 | | - if (!resolver.hasWebDavCredentials()) { |
75 | | - this.error( |
76 | | - 'No valid credentials found. Provide username/password or clientId/clientSecret.' |
77 | | - ); |
78 | | - } |
| 22 | + this.requireServer() |
| 23 | + this.requireCodeVersion() |
| 24 | + this.requireWebDavCredentials() |
79 | 25 |
|
80 | | - // 3. Create Instance with WebDAV Auth Strategy |
81 | | - const instance = new B2CInstance( |
82 | | - { |
83 | | - hostname: config.hostname, |
84 | | - codeVersion: config.codeVersion, |
85 | | - }, |
86 | | - resolver.getForWebDav() |
87 | | - ); |
| 26 | + const instance = this.createWebDavInstance() |
88 | 27 |
|
89 | | - // 4. Execute the operation |
90 | | - this.log(`Deploying cartridges from ${args.cartridgePath}...`); |
91 | | - this.log(`Target: ${config.hostname}`); |
92 | | - this.log(`Code Version: ${config.codeVersion}`); |
| 28 | + this.log(`Deploying cartridges from ${this.args.cartridgePath}...`) |
| 29 | + this.log(`Target: ${this.resolvedConfig.hostname}`) |
| 30 | + this.log(`Code Version: ${this.resolvedConfig.codeVersion}`) |
93 | 31 |
|
94 | 32 | try { |
95 | | - await uploadCartridges(instance, args.cartridgePath); |
96 | | - this.log('✓ Deployment complete'); |
| 33 | + await uploadCartridges(instance, this.args.cartridgePath) |
| 34 | + this.log('Deployment complete') |
97 | 35 | } catch (error) { |
98 | 36 | if (error instanceof Error) { |
99 | | - this.error(`Deployment failed: ${error.message}`); |
| 37 | + this.error(`Deployment failed: ${error.message}`) |
100 | 38 | } |
101 | | - throw error; |
| 39 | + throw error |
102 | 40 | } |
103 | 41 | } |
104 | 42 | } |
0 commit comments