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(remodel): generate index.ts and .jsiirc.json files #23970

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion tools/@aws-cdk/cfn2ts/lib/augmentation-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import { SpecName } from './spec-utils';
* ```
*/
export class AugmentationGenerator {
public readonly outputFile: string;
private readonly code = new CodeMaker();
private readonly outputFile: string;

constructor(moduleName: string, private readonly spec: schema.Specification, private readonly affix: string) {
this.outputFile = `${moduleName}-augmentations.generated.ts`;
Expand Down
2 changes: 1 addition & 1 deletion tools/@aws-cdk/cfn2ts/lib/canned-metrics-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { CodeMaker, toCamelCase } from 'codemaker';
* ```
*/
export class CannedMetricsGenerator {
public readonly outputFile: string;
private readonly code = new CodeMaker({ indentationLevel: 2 });
private readonly outputFile: string;

constructor(moduleName: string, private readonly namespace: string) {
this.outputFile = `${moduleName}-canned-metrics.generated.ts`;
Expand Down
29 changes: 29 additions & 0 deletions tools/@aws-cdk/cfn2ts/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,44 @@ export async function generateAll(outPath: string, options: CodeGeneratorOptions
const generator = new CodeGenerator(name, spec, affix, options);
generator.emitCode();
await generator.save(packagePath);
const outputFiles = [generator.outputFile];

const augs = new AugmentationGenerator(name, spec, affix);
if (augs.emitCode()) {
await augs.save(packagePath);
outputFiles.push(augs.outputFile);
}

const canned = new CannedMetricsGenerator(name, scope);
if (canned.generate()) {
await canned.save(packagePath);
outputFiles.push(canned.outputFile);
}

// Create index.ts file if needed
if (!fs.existsSync(path.join(packagePath, 'index.ts'))) {
const lines = [`// ${scope} CloudFormation Resources:`];
lines.push(...outputFiles.map((f) => `export * from './${f.replace('.ts', '')}'`));

await fs.writeFile(path.join(packagePath, 'index.ts'), lines.join('\n') + '\n');
}

// Create .jsiirc.json file if needed
if (!fs.existsSync(path.join(packagePath, '.jsiirc.json'))) {
const jsiirc = {
targets: {
java: {
package: module.javaPackage,
},
dotnet: {
package: module.dotnetPackage,
},
python: {
module: module.pythonModuleName,
},
},
};
await fs.writeJson(path.join(packagePath, '.jsiirc.json'), jsiirc, { spaces: 2 });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import * as path from 'path';

const srcDir = path.join(__dirname, '..', 'lib');
generateAll(srcDir, {
coreImport: 'aws-cdk-lib',
coreImport: '../../core',
});