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(go): version file in the generated module directory #2492

Merged
merged 5 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
4 changes: 4 additions & 0 deletions packages/jsii-pacmak/lib/targets/go/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from './runtime';
import { GoClass, GoType, Enum, Interface, Struct } from './types';
import { findTypeInTree, goPackageName, flatMap } from './util';
import { VersionFile } from './version-file';

export const GOMOD_FILENAME = 'go.mod';
export const GO_VERSION = '1.15';
Expand Down Expand Up @@ -181,6 +182,7 @@ export class RootPackage extends Package {
public readonly assembly: Assembly;
public readonly version: string;
private readonly readme?: ReadmeFile;
private readonly versionFile: VersionFile;

public constructor(assembly: Assembly) {
const packageName = goPackageName(assembly.name);
Expand All @@ -197,6 +199,7 @@ export class RootPackage extends Package {

this.assembly = assembly;
this.version = assembly.version;
this.versionFile = new VersionFile(this.version);

if (this.assembly.readme?.markdown) {
this.readme = new ReadmeFile(
Expand All @@ -212,6 +215,7 @@ export class RootPackage extends Package {
this.readme?.emit(context);

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

private emitGomod(code: CodeMaker) {
Expand Down
17 changes: 17 additions & 0 deletions packages/jsii-pacmak/lib/targets/go/version-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CodeMaker } from 'codemaker';

/**
* Represents the version of the go module. This is needed because the version is not
* available in standard go module files.
*/
export class VersionFile {
private static readonly NAME = 'version';

public constructor(private readonly version: string) {}

public emit(code: CodeMaker) {
code.openFile(VersionFile.NAME);
code.line(this.version);
code.closeFile(VersionFile.NAME);
}
}

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

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