Skip to content

Commit

Permalink
chore(init-templates): allow renaming in templates for cdk migrate ap…
Browse files Browse the repository at this point in the history
…ps (#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*
  • Loading branch information
HBobertz authored Oct 11, 2023
1 parent f1b2fae commit 6143b16
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
using System.Collections.Generic;
using System.Linq;

namespace %name.PascalCased%
namespace %PascalNameSpace%
{
sealed class Program
{
public static void Main(string[] args)
{
var app = new App();
new %name.PascalCased%Stack(app, "%stackname%", new StackProps
new %name.PascalCased%Stack(app, "%stackname%", new %PascalStackProps%
{
// If you don't specify 'env', this stack will be environment-agnostic.
// Account/Region-dependent features and context lookups will not work,
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ export class InitTemplate {
}
return template.replace(/%name%/g, project.name)
.replace(/%stackname%/, project.stackName ?? '%name.PascalCased%Stack')
.replace(/%PascalNameSpace%/, project.stackName ? camelCase(project.stackName + 'Stack', { pascalCase: true }) : '%name.PascalCased%')
.replace(/%PascalStackProps%/, project.stackName ? (camelCase(project.stackName, { pascalCase: true }) + 'StackProps') : 'StackProps')
.replace(/%name\.camelCased%/g, camelCase(project.name))
.replace(/%name\.PascalCased%/g, camelCase(project.name, { pascalCase: true }))
.replace(/%cdk-version%/g, cdkVersion)
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/commands/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('Migrate Function Tests', () => {
// Replaced stack file is referenced correctly in app file
const app = fs.readFileSync(path.join(workDir, 'GoodCSharp', 'src', 'GoodCSharp', 'Program.cs'), 'utf8').split('\n');
expect(app.map(line => line.match('namespace GoodCSharp')).filter(line => line).length).toEqual(1);
expect(app.map(line => line.match(/ new GoodCSharpStack\(app, "GoodCSharp", new StackProps/)).filter(line => line).length).toEqual(1);
expect(app.map(line => line.match(/ new GoodCSharpStack\(app, "GoodCSharp", new GoodCSharpStackProps/)).filter(line => line).length).toEqual(1);

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

0 comments on commit 6143b16

Please sign in to comment.