The AWS CDK uses jsii to package it's modules to multiple programming languages. The following document describes how to use a tool called jsii-reflect to explore the CDK's type system.
Create a working directory:
mkdir cdk-explore
cd cdk-explore
Download the .zip release of the CDK from GitHub Releases:
curl -LO https://github.com/awslabs/aws-cdk/releases/download/v0.23.0/aws-cdk-0.23.0.zip
Now, we need to extract all .jsii files from the release. Download the extract-jsii.sh
script:
curl -LO "https://gist.github.com/eladb/68a009cf9c953b04a637bac5c40afdbc/raw/extract-jsii.sh"
chmod +x ./extract-jsii.sh
This will create a jsii
subdirectory with all CDKK .jsii files.
Next, we'll use the jsii-reflect module to reflect load the entire type system into memory and explore it.
Install the jsii-reflect npm module:
npm i --no-save jsii-reflect
Now, create a file explore.js
(if you use VSCode, you'll get nice code completion and stuffs):
const { TypeSystem } = require('jsii-reflect');
const fs = require('fs');
const path = require('path');
const ts = new TypeSystem();
async function main() {
// load all .jsii files into the type system
for (const file of fs.readdirSync('./jsii')) {
await ts.load(path.join('./jsii', file));
}
// ready to explore!
for (const cls of ts.classes) {
console.log('===========================================================')
console.log('class name:', cls.name);
console.log('base class:', cls.base && cls.base.fqn);
console.log('properties:', cls.properties.map(p => p.name).join());
console.log('method:', cls.methods.map(m => m.name).join());
}
}
main().catch(e => {
console.error(e);
process.exit(1);
});