Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Vinayak Kukreja <vinakuk@amazon.com>
  • Loading branch information
vinayak-kukreja committed May 8, 2023
1 parent e6d8d50 commit ad707c6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/codemaker/src/codemaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ export class CodeMaker {
return caseutils.toSnakeCase(s, sep);
}

/**
* Gets currently opened file path
* @returns Currently opened file path.
*/
public getCurrentFilePath(): string | undefined {
return this.currentFile?.filePath;
}

private makeIndent(): string {
const length = this.currentIndentLength;
if (length <= 0) {
Expand Down
18 changes: 16 additions & 2 deletions packages/jsii-pacmak/lib/targets/go/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { VersionFile } from './version-file';

export const GOMOD_FILENAME = 'go.mod';
export const GO_VERSION = '1.18';
const MAIN_FILE = 'main.go';

/*
* Package represents a single `.go` source file within a package. This can be the root package file or a submodule
Expand Down Expand Up @@ -203,9 +204,9 @@ export abstract class Package {
if (this.types.length > 0) {
const { code } = context;

const initFile = join(this.directory, `main.go`);
const initFile = join(this.directory, MAIN_FILE);
code.openFile(initFile);
code.line(`package ${this.packageName}`);
this.emitHeader(code);
code.line();
importGoModules(code, [GO_REFLECT, JSII_RT_MODULE]);
code.line();
Expand Down Expand Up @@ -469,6 +470,19 @@ export class RootPackage extends Package {
);
}

protected emitHeader(code: CodeMaker) {
const currentFilePath = code.getCurrentFilePath();
if (
this.assembly.description !== '' &&
currentFilePath !== undefined &&
currentFilePath.includes(MAIN_FILE)
) {
code.line(`// ${this.assembly.description}`);
}
code.line(`package ${this.packageName}`);
code.line();
}

private emitJsiiPackage({ code }: EmitContext) {
const dependencies = this.packageDependencies.sort((l, r) =>
l.moduleName.localeCompare(r.moduleName),
Expand Down

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

Loading

0 comments on commit ad707c6

Please sign in to comment.