Skip to content

Commit

Permalink
Merge branch 'main' into fix-aws-api-call-type-length
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 20, 2022
2 parents f3ff870 + 384ba2b commit dee2d49
Show file tree
Hide file tree
Showing 21 changed files with 186 additions and 275 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.v2.alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.42.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.42.0-alpha.0...v2.42.1-alpha.0) (2022-09-19)

## [2.42.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.41.0-alpha.0...v2.42.0-alpha.0) (2022-09-15)


Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.42.1](https://github.com/aws/aws-cdk/compare/v2.42.0...v2.42.1) (2022-09-19)


### Reverts

* **init-templates:** csharp and fsharp app init fails when path contains space ([#22112](https://github.com/aws/aws-cdk/issues/22112)) ([89f64d4](https://github.com/aws/aws-cdk/commit/89f64d4082d1a339caa1eab04a9ffc63b9088d9a)), closes [aws/aws-cdk#21049](https://github.com/aws/aws-cdk/issues/21049)

## [2.42.0](https://github.com/aws/aws-cdk/compare/v2.41.0...v2.42.0) (2022-09-15)


Expand Down
90 changes: 90 additions & 0 deletions packages/aws-cdk/lib/init-hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as path from 'path';
import { shell } from './os';

export type SubstitutePlaceholders = (...fileNames: string[]) => Promise<void>;

/**
* Helpers passed to hook functions
*/
export interface HookContext {
/**
* Callback function to replace placeholders on arbitrary files
*
* This makes token substitution available to non-`.template` files.
*/
readonly substitutePlaceholdersIn: SubstitutePlaceholders;

/**
* Return a single placeholder
*/
placeholder(name: string): string;
}

export type InvokeHook = (targetDirectory: string, context: HookContext) => Promise<void>;

export interface HookTarget {
readonly targetDirectory: string;
readonly templateName: string;
readonly language: string;
}

/**
* Invoke hooks for the given init template
*
* Sometimes templates need more complex logic than just replacing tokens. A 'hook' can be
* used to do additional processing other than copying files.
*
* Hooks used to be defined externally to the CLI, by running arbitrarily
* substituted shell scripts in the target directory.
*
* In practice, they're all TypeScript files and all the same, and the dynamism
* that the original solution allowed wasn't used at all. Worse, since the CLI
* is now bundled the hooks can't even reuse code from the CLI libraries at all
* anymore, so all shared code would have to be copy/pasted.
*
* Bundle hooks as built-ins into the CLI, so they get bundled and can take advantage
* of all shared code.
*/
export async function invokeBuiltinHooks(target: HookTarget, context: HookContext) {
switch (target.language) {
case 'csharp':
if (['app', 'sample-app'].includes(target.templateName)) {
return dotnetAddProject(target.targetDirectory, context);
}
break;

case 'fsharp':
if (['app', 'sample-app'].includes(target.templateName)) {
return dotnetAddProject(target.targetDirectory, context, 'fsproj');
}
break;

case 'python':
// We can't call this file 'requirements.template.txt' because Dependabot needs to be able to find it.
// Therefore, keep the in-repo name but still substitute placeholders.
await context.substitutePlaceholdersIn('requirements.txt');
break;

case 'java':
// We can't call this file 'pom.template.xml'... for the same reason as Python above.
await context.substitutePlaceholdersIn('pom.xml');
break;

case 'javascript':
case 'typescript':
// See above, but for 'package.json'.
await context.substitutePlaceholdersIn('package.json');

}
}

async function dotnetAddProject(targetDirectory: string, context: HookContext, ext = 'csproj') {
const pname = context.placeholder('name.PascalCased');
const slnPath = path.join(targetDirectory, 'src', `${pname}.sln`);
const csprojPath = path.join(targetDirectory, 'src', pname, `${pname}.${ext}`);
try {
await shell(['dotnet', 'sln', slnPath, 'add', csprojPath]);
} catch (e) {
throw new Error(`Could not add project ${pname}.${ext} to solution ${pname}.sln. ${e.message}`);
}
};
33 changes: 0 additions & 33 deletions packages/aws-cdk/lib/init-templates/app/csharp/add-project.hook.ts

This file was deleted.

33 changes: 0 additions & 33 deletions packages/aws-cdk/lib/init-templates/app/fsharp/add-project.hook.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit dee2d49

Please sign in to comment.