Skip to content

Commit f005b70

Browse files
committed
wip -- revert to this if needed
1 parent fe179cb commit f005b70

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/io/private/codes.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IoMessageCode } from '../io-message';
22

33
export interface CodeInfo {
4+
code: IoMessageCode;
45
description: string;
56
level: string;
67
interface?: any;
@@ -19,26 +20,31 @@ function codeInfo(info: CodeInfo): CodeInfo {
1920
export const CODES = {
2021
// 1: Synth
2122
CDK_TOOLKIT_I1000: codeInfo({
23+
code: 'CDK_TOOLKIT_I1000',
2224
description: 'Provides synthesis times.',
2325
level: 'info',
2426
}),
2527
CDK_TOOLKIT_I1901: codeInfo({
28+
code: 'CDK_TOOLKIT_I1901',
2629
description: 'Provides stack data',
2730
level: 'result',
2831
}),
2932
CDK_TOOLKIT_I1902: codeInfo({
33+
code: 'CDK_TOOLKIT_I1902',
3034
description: 'Successfully deployed stacks',
3135
level: 'result',
3236
}),
3337

3438
// 2: List
3539
CDK_TOOLKIT_I2901: codeInfo({
40+
code: 'CDK_TOOLKIT_I2901',
3641
description: 'Provides details on the selected stacks and their dependencies',
3742
level: 'result',
3843
}),
3944

4045
// 3: Import & Migrate
4146
CDK_TOOLKIT_E3900: codeInfo({
47+
code: 'CDK_TOOLKIT_E3900',
4248
description: 'Resource import failed',
4349
level: 'error',
4450
}),
@@ -47,69 +53,84 @@ export const CODES = {
4753

4854
// 5: Deploy & Watch
4955
CDK_TOOLKIT_I5000: codeInfo({
56+
code: 'CDK_TOOLKIT_I5000',
5057
description: 'Provides deployment times',
5158
level: 'info',
5259
}),
5360
CDK_TOOLKIT_I5001: codeInfo({
61+
code: 'CDK_TOOLKIT_I5001',
5462
description: 'Provides total time in deploy action, including synth and rollback',
5563
level: 'info',
5664
}),
5765
CDK_TOOLKIT_I5002: codeInfo({
66+
code: 'CDK_TOOLKIT_I5002',
5867
description: 'Provides time for resource migration',
5968
level: 'info',
6069
}),
6170
CDK_TOOLKIT_I5031: codeInfo({
71+
code: 'CDK_TOOLKIT_I5031',
6272
description: 'Informs about any log groups that are traced as part of the deployment',
6373
level: 'info',
6474
}),
6575
CDK_TOOLKIT_I5050: codeInfo({
76+
code: 'CDK_TOOLKIT_I5050',
6677
description: 'Confirm rollback during deployment',
6778
level: 'response',
6879
}),
6980
CDK_TOOLKIT_I5060: codeInfo({
81+
code: 'CDK_TOOLKIT_I5060',
7082
description: 'Confirm deploy security sensitive changes',
7183
level: 'response',
7284
}),
7385
CDK_TOOLKIT_I5900: codeInfo({
86+
code: 'CDK_TOOLKIT_I5900',
7487
description: 'Deployment results on success',
7588
level: 'result',
7689
}),
7790

7891
CDK_TOOLKIT_E5001: codeInfo({
92+
code: 'CDK_TOOLKIT_E5001',
7993
description: 'No stacks found',
8094
level: 'error',
8195
}),
8296

8397
// 6: Rollback
8498
CDK_TOOLKIT_I6000: codeInfo({
99+
code: 'CDK_TOOLKIT_I6000',
85100
description: 'Provides rollback times',
86101
level: 'info',
87102
}),
88103

89104
CDK_TOOLKIT_E6001: codeInfo({
105+
code: 'CDK_TOOLKIT_E6001',
90106
description: 'No stacks found',
91107
level: 'error',
92108
}),
93109
CDK_TOOLKIT_E6900: codeInfo({
110+
code: 'CDK_TOOLKIT_E6900',
94111
description: 'Rollback failed',
95112
level: 'error',
96113
}),
97114

98115
// 7: Destroy
99116
CDK_TOOLKIT_I7000: codeInfo({
117+
code: 'CDK_TOOLKIT_I7000',
100118
description: 'Provides destroy times',
101119
level: 'info',
102120
}),
103121
CDK_TOOLKIT_I7010: codeInfo({
122+
code: 'CDK_TOOLKIT_I7010',
104123
description: 'Confirm destroy stacks',
105124
level: 'response',
106125
}),
107126

108127
CDK_TOOLKIT_E7010: codeInfo({
128+
code: 'CDK_TOOLKIT_E7010',
109129
description: 'Action was aborted due to negative confirmation of request',
110130
level: 'error',
111131
}),
112132
CDK_TOOLKIT_E7900: codeInfo({
133+
code: 'CDK_TOOLKIT_E7900',
113134
description: 'Stack deletion failed',
114135
level: 'error',
115136
}),
@@ -118,30 +139,37 @@ export const CODES = {
118139

119140
// Assembly codes
120141
CDK_ASSEMBLY_I0042: codeInfo({
142+
code: 'CDK_ASSEMBLY_I0042',
121143
description: 'Writing updated context',
122144
level: 'debug',
123145
}),
124146
CDK_ASSEMBLY_I0241: codeInfo({
147+
code: 'CDK_ASSEMBLY_I0241',
125148
description: 'Fetching missing context',
126149
level: 'debug',
127150
}),
128151
CDK_ASSEMBLY_I1000: codeInfo({
152+
code: 'CDK_ASSEMBLY_I1000',
129153
description: 'Cloud assembly output starts',
130154
level: 'debug',
131155
}),
132156
CDK_ASSEMBLY_I1001: codeInfo({
157+
code: 'CDK_ASSEMBLY_I1001',
133158
description: 'Output lines emitted by the cloud assembly to stdout',
134159
level: 'info',
135160
}),
136161
CDK_ASSEMBLY_E1002: codeInfo({
162+
code: 'CDK_ASSEMBLY_E1002',
137163
description: 'Output lines emitted by the cloud assembly to stderr',
138164
level: 'error',
139165
}),
140166
CDK_ASSEMBLY_I1003: codeInfo({
167+
code: 'CDK_ASSEMBLY_I1003',
141168
description: 'Cloud assembly output finished',
142169
level: 'info',
143170
}),
144171
CDK_ASSEMBLY_E1111: codeInfo({
172+
code: 'CDK_ASSEMBLY_E1111',
145173
description: 'Incompatible CDK CLI version. Upgrade needed.',
146174
level: 'error',
147175
}),

packages/@aws-cdk/toolkit-lib/lib/api/io/private/messages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as chalk from 'chalk';
22
import type { IoMessageCodeCategory, IoMessageLevel } from '../io-message';
3-
import { type VALID_CODE } from './codes';
3+
import { CodeInfo, type VALID_CODE } from './codes';
44
import type { ActionLessMessage, ActionLessRequest, Optional, SimplifiedMessage } from './types';
55

66
/**
@@ -83,10 +83,10 @@ export const error = <T>(message: string, code: VALID_CODE, payload?: T) => {
8383
* However actions that operate on Cloud Assemblies might include a result per Stack.
8484
* Unlike other messages, results must always have a code and a payload.
8585
*/
86-
export const result = <T>(message: string, code: VALID_CODE, payload: T) => {
86+
export const result = <T>(message: string, code: CodeInfo, payload: T) => {
8787
return formatMessage({
8888
level: 'result',
89-
code,
89+
code: code.code,
9090
message,
9191
data: payload,
9292
});

packages/@aws-cdk/toolkit-lib/lib/toolkit/private/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ export interface ToolkitServices {
1010
ioHost: ActionAwareIoHost;
1111
}
1212

13-
// export inter
13+
export interface StackData {
14+
assemblyDirectory: string;
15+
stacksCount: number;
16+
stackIds: string[];
17+
stack: {
18+
stackName: string;
19+
hierarchicalId: string;
20+
template: any;
21+
stringifiedJson: string;
22+
stringifiedYaml: string;
23+
};
24+
}

packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as cxapi from '@aws-cdk/cx-api';
33
import * as chalk from 'chalk';
44
import * as chokidar from 'chokidar';
55
import * as fs from 'fs-extra';
6-
import { ToolkitServices } from './private';
6+
import { StackData, ToolkitServices } from './private';
77
import { AssetBuildTime, type DeployOptions, RequireApproval } from '../actions/deploy';
88
import { type ExtendedDeployOptions, buildParameterMap, createHotswapPropertyOverrides, removePublishedAssets } from '../actions/deploy/private';
99
import { type DestroyOptions } from '../actions/destroy';
@@ -19,7 +19,7 @@ import { CachedCloudAssemblySource, IdentityCloudAssemblySource, StackAssembly,
1919
import { ALL_STACKS, CloudAssemblySourceBuilder } from '../api/cloud-assembly/private';
2020
import { ToolkitError } from '../api/errors';
2121
import { IIoHost, IoMessageCode, IoMessageLevel } from '../api/io';
22-
import { asSdkLogger, withAction, Timer, confirm, error, info, success, warn, ActionAwareIoHost, debug, result, withoutEmojis, withoutColor, withTrimmedWhitespace } from '../api/io/private';
22+
import { asSdkLogger, withAction, Timer, confirm, error, info, success, warn, ActionAwareIoHost, debug, result, withoutEmojis, withoutColor, withTrimmedWhitespace, CODES } from '../api/io/private';
2323

2424
/**
2525
* The current action being performed by the CLI. 'none' represents the absence of an action.
@@ -177,7 +177,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
177177
const firstStack = stacks.firstStack!;
178178
const template = firstStack.template;
179179
const obscuredTemplate = obscureTemplate(template);
180-
await ioHost.notify(result(message, 'CDK_TOOLKIT_I1901', {
180+
await ioHost.notify(result(message, CODES.CDK_TOOLKIT_I1901, {
181181
...assemblyData,
182182
stack: {
183183
stackName: firstStack.stackName,
@@ -186,10 +186,10 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
186186
stringifiedJson: serializeStructure(obscuredTemplate, true),
187187
stringifiedYaml: serializeStructure(obscuredTemplate, false),
188188
},
189-
}));
189+
} as StackData));
190190
} else {
191191
// not outputting template to stdout, let's explain things to the user a little bit...
192-
await ioHost.notify(result(chalk.green(message), 'CDK_TOOLKIT_I1902', assemblyData));
192+
await ioHost.notify(result(chalk.green(message), CODES.CDK_TOOLKIT_I1902, assemblyData));
193193
await ioHost.notify(info(`Supply a stack id (${stacks.stackArtifacts.map((s) => chalk.green(s.hierarchicalId)).join(', ')}) to display its template.`));
194194
}
195195

@@ -211,7 +211,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
211211
const stacks = stackCollection.withDependencies();
212212
const message = stacks.map(s => s.id).join('\n');
213213

214-
await ioHost.notify(result(message, 'CDK_TOOLKIT_I2901', { stacks }));
214+
await ioHost.notify(result(message, CODES.CDK_TOOLKIT_I2901, { stacks }));
215215
return stacks;
216216
}
217217

@@ -458,7 +458,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
458458
? ` ✅ ${stack.displayName} (no changes)`
459459
: ` ✅ ${stack.displayName}`;
460460

461-
await ioHost.notify(result(chalk.green('\n' + message), 'CDK_TOOLKIT_I5900', deployResult));
461+
await ioHost.notify(result(chalk.green('\n' + message), CODES.CDK_TOOLKIT_I5900, deployResult));
462462
deployDuration = await deployTimer.endAs(ioHost, 'deploy');
463463

464464
if (Object.keys(deployResult.outputs).length > 0) {

packages/@aws-cdk/toolkit-lib/scripts/gen-code-registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ function codesToMarkdownTable(codes: Record<string, CodeInfo>, mdPrefix?: string
77
let table = '| Code | Description | Level | Data Interface |\n';
88
table += '|------|-------------|-------|----------------|\n';
99

10-
Object.entries(codes).forEach(([id, code]) => {
11-
table += `| ${id} | ${code.description} | ${code.level} | ${code.interface ?? 'n/a'} |\n`;
10+
Object.values(codes).forEach((code) => {
11+
table += `| ${code.code} | ${code.description} | ${code.level} | ${code.interface ?? 'n/a'} |\n`;
1212
});
1313

1414
const prefix = mdPrefix ? `${mdPrefix}\n\n` : '';

0 commit comments

Comments
 (0)