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: add support for bin-scripts (python only) #1941

Merged
merged 18 commits into from
Dec 10, 2020
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
7 changes: 7 additions & 0 deletions packages/@jsii/spec/lib/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ export interface Assembly extends AssemblyConfiguration, Documentable {
* @default none
*/
readme?: { markdown: string };

/**
* List of bin-scripts
*
* @default none
*/
bin?: { [script: string]: string };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's tighten this one up from the start (cannot fix the older fields to readonly because... backwards-compatibility... but we can be nice with the new ones!)

Suggested change
bin?: { [script: string]: string };
bin?: { readonly [script: string]: string };

}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,13 @@ class PythonModule implements PythonType {
code.line(`from ${'.'.repeat(distanceFromRoot + 1)}_jsii import *`);

this.emitRequiredImports(code, context);
if (this.assembly.bin) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like being explicit here (JS' truthiness/falsiness is a little awkward)

Suggested change
if (this.assembly.bin) {
if (this.assembly.bin != null) {

code.line(`print('BIN-scripts were found.');`);
const scripts = Object.keys(this.assembly.bin);
for (const script of scripts) {
code.line(`print('${script}: ${this.assembly.bin[script]}');`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const scripts = Object.keys(this.assembly.bin);
for (const script of scripts) {
code.line(`print('${script}: ${this.assembly.bin[script]}');`);
}
const scripts = Object.keys(this.assembly.bin);
for (const [name, path] of Object.entries(this.assembly.bin)) {
code.line(`print('${name}: ${path}');`);
}

}
}

// Emit all of our members.
Expand Down
1 change: 1 addition & 0 deletions packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class Assembler implements Emitter {
readme,
jsiiVersion,
fingerprint: '<TBD>',
bin: this.projectInfo.bin,
};

const validator = new Validator(this.projectInfo, assembly);
Expand Down
2 changes: 2 additions & 0 deletions packages/jsii/lib/project-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ProjectInfo {
readonly excludeTypescript: string[];
readonly projectReferences?: boolean;
readonly tsc?: TSCompilerOptions;
readonly bin?: { readonly [name: string]: string };
}

export async function loadProjectInfo(
Expand Down Expand Up @@ -202,6 +203,7 @@ export async function loadProjectInfo(
outDir: pkg.jsii?.tsc?.outDir,
rootDir: pkg.jsii?.tsc?.rootDir,
},
bin: pkg.bin,
};
}

Expand Down