Skip to content

Commit 6143b16

Browse files
authored
chore(init-templates): allow renaming in templates for cdk migrate apps (#27166)
New integ test for the new CDK migrate command. Template.txt is a sample cloudformation template with enough complexity to be a good enough sample. Tests for Java and Csharp aren't there because they are broken right now. Add them back after we fix ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent f1b2fae commit 6143b16

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

packages/aws-cdk/lib/init-templates/app/csharp/src/%name.PascalCased%/Program.template.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
using System.Collections.Generic;
44
using System.Linq;
55

6-
namespace %name.PascalCased%
6+
namespace %PascalNameSpace%
77
{
88
sealed class Program
99
{
1010
public static void Main(string[] args)
1111
{
1212
var app = new App();
13-
new %name.PascalCased%Stack(app, "%stackname%", new StackProps
13+
new %name.PascalCased%Stack(app, "%stackname%", new %PascalStackProps%
1414
{
1515
// If you don't specify 'env', this stack will be environment-agnostic.
1616
// Account/Region-dependent features and context lookups will not work,

packages/aws-cdk/lib/init.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ export class InitTemplate {
173173
}
174174
return template.replace(/%name%/g, project.name)
175175
.replace(/%stackname%/, project.stackName ?? '%name.PascalCased%Stack')
176+
.replace(/%PascalNameSpace%/, project.stackName ? camelCase(project.stackName + 'Stack', { pascalCase: true }) : '%name.PascalCased%')
177+
.replace(/%PascalStackProps%/, project.stackName ? (camelCase(project.stackName, { pascalCase: true }) + 'StackProps') : 'StackProps')
176178
.replace(/%name\.camelCased%/g, camelCase(project.name))
177179
.replace(/%name\.PascalCased%/g, camelCase(project.name, { pascalCase: true }))
178180
.replace(/%cdk-version%/g, cdkVersion)

packages/aws-cdk/test/commands/migrate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('Migrate Function Tests', () => {
177177
// Replaced stack file is referenced correctly in app file
178178
const app = fs.readFileSync(path.join(workDir, 'GoodCSharp', 'src', 'GoodCSharp', 'Program.cs'), 'utf8').split('\n');
179179
expect(app.map(line => line.match('namespace GoodCSharp')).filter(line => line).length).toEqual(1);
180-
expect(app.map(line => line.match(/ new GoodCSharpStack\(app, "GoodCSharp", new StackProps/)).filter(line => line).length).toEqual(1);
180+
expect(app.map(line => line.match(/ new GoodCSharpStack\(app, "GoodCSharp", new GoodCSharpStackProps/)).filter(line => line).length).toEqual(1);
181181

182182
// Replaced stack file is correctly generated
183183
const replacedStack = fs.readFileSync(path.join(workDir, 'GoodCSharp', 'src', 'GoodCSharp', 'GoodCSharpStack.cs'), 'utf8');

0 commit comments

Comments
 (0)