Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pacmak): emit LICENSE file with SPDX license text, NOTICE file #2604

Merged
merged 5 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/jsii-pacmak/lib/targets/go/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CodeMaker } from 'codemaker';
import { Assembly, Type, Submodule as JsiiSubmodule } from 'jsii-reflect';
import { basename, dirname, join } from 'path';
import * as semver from 'semver';
import * as spdx from 'spdx-license-list/full';

import { VERSION } from '../../version';
import { EmitContext } from './emit-context';
Expand Down Expand Up @@ -210,6 +211,7 @@ export class RootPackage extends Package {
public readonly version: string;
private readonly readme?: ReadmeFile;
private readonly versionFile: VersionFile;
private readonly licenseFile?: LicenseFile;

public constructor(assembly: Assembly) {
const packageName = goPackageName(assembly.name);
Expand All @@ -228,6 +230,7 @@ export class RootPackage extends Package {
this.assembly = assembly;
this.version = assembly.version;
this.versionFile = new VersionFile(this.version);
this.licenseFile = LicenseFile.from(assembly.license);

if (this.assembly.readme?.markdown) {
this.readme = new ReadmeFile(
Expand All @@ -244,6 +247,7 @@ export class RootPackage extends Package {

this.emitGomod(context.code);
this.versionFile.emit(context.code);
this.licenseFile?.emit(context.code);
}

private emitGomod(code: CodeMaker) {
Expand Down Expand Up @@ -501,3 +505,23 @@ function importGoModules(code: CodeMaker, modules: readonly ImportedModule[]) {
return mod.alias === JSII_RT_ALIAS || mod.alias === JSII_INIT_ALIAS;
}
}

class LicenseFile {
public static from(spdxId: string): LicenseFile | undefined {
if (spdxId in spdx) {
return new LicenseFile(spdx[spdxId].licenseText);
}
return undefined;
}

private constructor(private readonly licenseText: string) {}

public emit(code: CodeMaker): void {
const licenseFileName = 'LICENSE';
code.openFile(licenseFileName);
for (const line of this.licenseText.split('\n')) {
code.line(line);
}
code.closeFile(licenseFileName);
}
}
Loading