Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,39 @@ The output directory will include a python module that corresponds to the
original module. This code depends on the following python modules:

- [jsii](https://pypi.org/project/jsii/)
- [publication](https://pypi.org/project/publication/)

### Java Output

To produce a Java module from your source, use the `java` option:

```ts
await srcmak('srcdir', {
java: {
outdir: '/path/to/project/root',
package: 'hello.world',
maven: {
groupId: 'hello',
artifactId: 'world',
},
Comment thread
campionfellin marked this conversation as resolved.
Outdated
}
});
```

Or the `--java-*` switches in the CLI:

```bash
$ jsii-srcmak /src/dir --java-outdir=dir --java-package-name=hello.world --java-maven-group-id hello --java-maven-artifact-id world
```

* The `outdir`/`--java-outdir` option points to the root directory of your Java project.
* The `packageName`/`--java-package-name` option is the java package name.
Comment thread
campionfellin marked this conversation as resolved.
Outdated
* The `maven { groupId }`/`--java-maven-group-id` option is the maven group id.
* The `maven { artifactId }`/`--java-maven-artifact-id` option is the maven artifact id.
Comment thread
campionfellin marked this conversation as resolved.
Outdated

The output directory will include a java module that corresponds to the
original module. This code depends on the following java modules:
Comment thread
campionfellin marked this conversation as resolved.
Outdated

- [jsii](https://mvnrepository.com/artifact/software.amazon.jsii)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also worth mentioning that the output will include a tarball resource that must be bundled in the project (maybe provide an example snippet from a pom.xml?)


### Entrypoint

Expand Down Expand Up @@ -115,6 +147,21 @@ Or through the CLI:
$ jsii-srcmak /src/dir --dep node_modules/@types/node --dep node_modules/constructs
```

## Contributing
Comment thread
campionfellin marked this conversation as resolved.

To build this project, you must first generate the `package.json`:

```
npx projen
```

Then you can install your dependencies and build:

```
yarn install
yarn build
```

## What's with this name?

It's a silly little pun that stems from another pun: jsii has `jsii-pacmak`
Expand Down
26 changes: 26 additions & 0 deletions bin/jsii-srcmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ async function main() {
.option('jsii-path', { desc: 'write .jsii output to this path', type: 'string' })
.option('python-outdir', { desc: 'python output directory (requires --python-module-name)', type: 'string' })
.option('python-module-name', { desc: 'python module name', type: 'string' })
.option('java-outdir', { desc: 'java output directory (requires --java-package-name and --java-maven-group-id)', type: 'string' })
.option('java-package-name', { desc: 'java package name', type: 'string' })
Comment thread
campionfellin marked this conversation as resolved.
Outdated
.option('java-maven-group-id', { desc: 'java maven group id', type: 'string' })
.option('java-maven-artifact-id', { desc: 'java maven artifact id', type: 'string' })
Comment thread
campionfellin marked this conversation as resolved.
Outdated
.showHelpOnFail(true)
.help();

Expand All @@ -27,6 +31,7 @@ async function main() {
...parseDepOption(),
...parseJsiiOptions(),
...parsePythonOptions(),
...parseJavaOptions(),
});

function parseJsiiOptions() {
Expand All @@ -53,6 +58,27 @@ async function main() {
}
}

function parseJavaOptions() {
const outdir = argv['java-outdir'];
const packageName = argv['java-package-name'];
const mavenGroupId = argv['java-maven-group-id'];
const mavenArtifactId = argv['java-maven-artifact-id'];
if (!outdir && !packageName && !mavenGroupId) { return undefined; }
if (!outdir) { throw new Error('--java-outdir is required'); }
if (!packageName) { throw new Error('--java-package-name is required'); }
if (!mavenGroupId) { throw new Error('--java-maven-group-id is required'); }
return {
java: {
outdir: outdir,
package: packageName,
maven: {
groupId: mavenGroupId,
artifactId: mavenArtifactId,
},
Comment thread
campionfellin marked this conversation as resolved.
Outdated
},
}
}

function parseDepOption() {
if (argv.dep?.length === 0) { return undefined; }
return {
Expand Down
7 changes: 7 additions & 0 deletions lib/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export async function compile(workdir: string, options: Options) {
};
}

if (options.java) {
targets.java = {
package: options.java.package,
maven: options.java.maven,
Comment thread
campionfellin marked this conversation as resolved.
Outdated
};
}

await fs.writeFile(path.join(workdir, 'package.json'), JSON.stringify(pkg, undefined, 2));

await exec(compilerModule, args, {
Expand Down
36 changes: 35 additions & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export interface Options {
* @default - python is not generated
*/
python?: PythonOutputOptions;

/**
* Produce java code.
* @default - java is not generated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a note here that says that the code will be produced under src (with an example of the full path combined with the package name). Also mention the requirements from Pom.xml (dependency on jsii runtime and resource).

*/
java?: JavaOutputOptions;
}

export interface JsiiOutputOptions {
Expand All @@ -32,7 +38,7 @@ export interface JsiiOutputOptions {
path: string;
}

export interface PythonOutputOptions {
export interface PythonOutputOptions {
/**
* Base root directory.
*/
Expand All @@ -43,3 +49,31 @@ export interface PythonOutputOptions {
*/
moduleName: string;
}

export interface JavaOutputOptions {
/**
* Base root directory.
*/
outdir: string;

/**
* The name of the java package to generate
*/
package: string;

/**
* The maven info for this package
Comment thread
campionfellin marked this conversation as resolved.
Outdated
*/
maven: {

/**
* The maven group id
*/
groupId: string;

/**
* The maven artifact id
*/
artifactId?: string;
};
}
7 changes: 7 additions & 0 deletions lib/srcmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,12 @@ export async function srcmak(srcdir: string, options: Options = { }) {
const target = path.join(options.python.outdir, reldir);
await fs.move(source, target, { overwrite: true });
}

if (options.java) {
const reldir = options.java.package.replace(/\./g, '/');
const source = path.resolve(path.join(workdir, 'dist/java/src/main/java', reldir));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is it src/main? Is this where things are expected conventionally by the Pom.xml?

const target = path.join(options.java.outdir, 'src/main' , reldir);
await fs.move(source, target, { overwrite: true });
}
});
}
Loading