Skip to content

Commit

Permalink
feat: make license holder overridable (#388)
Browse files Browse the repository at this point in the history
I added an option to override the license holder.
  • Loading branch information
mbialon authored Jan 17, 2024
1 parent 986ceab commit de50451
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
13 changes: 13 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/customized-license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ const SPDX = "MPL-2.0";

export class CustomizedLicense extends License {
private year: number;
private licensee: string;

constructor(project: TypeScriptProject, overrideYear?: number) {
constructor(
project: TypeScriptProject,
overrideYear?: number,
overrideLicensee?: string
) {
super(project, { spdx: SPDX });

this.year = overrideYear ?? new Date().getFullYear();
this.licensee = overrideLicensee ?? "HashiCorp, Inc.";

project.addFields({ license: SPDX });
}

synthesizeContent(resolver: IResolver) {
return (
`Copyright (c) ${this.year} HashiCorp, Inc.\n\n` +
`Copyright (c) ${this.year} ${this.licensee}\n\n` +
super.synthesizeContent(resolver)
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export interface CdktfProviderProjectOptions extends cdk.JsiiProjectOptions {
* If no date is provided, then the date of the build will be used by default.
*/
readonly deprecationDate?: string;
/**
* defaults to "HashiCorp, Inc."
*/
readonly licensee?: string;
}

const getMavenName = (providerName: string): string => {
Expand Down Expand Up @@ -362,7 +366,7 @@ export class CdktfProviderProject extends cdk.JsiiProject {
deprecationDate,
isDeprecated: !!isDeprecated,
});
new CustomizedLicense(this, options.creationYear);
new CustomizedLicense(this, options.creationYear, options.licensee);
new GithubIssues(this, { providerName });
new AutoApprove(this);
new AutoCloseCommunityIssues(this, { providerName });
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ test("has a custom workflow and README if the project is deprecated", () => {
);
});

test("override licensee", () => {
const snapshot = synthSnapshot(
getProject({ creationYear: 2021, licensee: "Acme Corp" })
);

expect(snapshot.LICENSE).toEqual(
expect.stringContaining("Copyright (c) 2021 Acme Corp")
);
});

test("override maven org", () => {
const snapshot = synthSnapshot(getProject({ mavenOrg: "gofer" }));

Expand Down

0 comments on commit de50451

Please sign in to comment.