Skip to content

Commit

Permalink
Merge pull request #23970 from aws/madeline-k/gen-files-for-new-modules
Browse files Browse the repository at this point in the history
feat(remodel): generate index.ts and .jsiirc.json files
  • Loading branch information
madeline-k authored Feb 2, 2023
2 parents 019252b + 4b80e08 commit 7813aa7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
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',
});

0 comments on commit 7813aa7

Please sign in to comment.